11 Replies Latest reply on Jul 30, 2010 6:06 AM by m_naseer

    check file size in ODI

    m_naseer
      dear all,

      how to check file size in oracle data integrator.

      regards
      Naseer
        • 1. Re: check file size in ODI
          774570
          As such there is no utility to give you the file size, But you can call the OS Command and run the command to get the file size and then using the raise command of jython you can display the file size into the operator.
          • 2. Re: check file size in ODI
            Guru Sankar
            Hi Naseer,

            How are you?

            I suggest you for a small customization in the LKM.

            1. Create a new step in your LKM, ( I tried with LKM File to SQL and tested the code in commo, pipe delimited files) Count records in file, technology as Jython and in Command on target tab paste the below code make sure your Command on Source should have File technology selected.

            # open the file
            fsrc = open('<%=odiRef.getSrcTablesList("", "[SCHEMA]/[RES_NAME]", ", ", "")%>', 'r')
            # read the first line
            lsrc=fsrc.readline()
            # set row counter, starting on the second line
            n = -1
            # count lines
            while (lsrc):
            ----lsrc=fsrc.readline()
            ----n = n + 1
            # Check for the record count
            if n<1:
            ----raise ' The file has no records to process'

            2. Make this step as the first step in your LKM.

            What this does?

            This code opens the source file, read all the lines skipping the first line ( of course its a header) and give the record count in the file, if it doesn't find any count then the load will errored out saying ' The file has no records to process'.

            P.S: Replace ---- with tab.

            Thanks,
            Guru
            • 3. Re: check file size in ODI
              m_naseer
              can u please share such command.
              • 4. Re: check file size in ODI
                774570
                http://odiexperts.com/?p=918

                Look in this post and there is XML attached so you can download and you can call as a ODI procedure or in KM
                • 5. Re: check file size in ODI
                  m_naseer
                  thanks guru,

                  how r u?

                  can we store count or exception in variable? the propose is to trigger the alert when file count is 0.


                  regards
                  Naseer
                  • 6. Re: check file size in ODI
                    Guru Sankar
                    Hi Naseer,

                    I am doing good. Thanks.

                    Can you elaborate what do u mean by "trigger the alert when file count is 0"?

                    Thanks,
                    Guru
                    • 7. Re: check file size in ODI
                      m_naseer
                      mean i want to check if the the file count is 0 then a auto mail send to user
                      • 8. Re: check file size in ODI
                        Guru Sankar
                        Hi Naseer,

                        Is that OK if u can able to do this in LKM by doing customization? If so let me know i will do the customization for you.

                        Thanks,
                        Guru
                        • 9. Re: check file size in ODI
                          m_naseer
                          thanks guru, kindly do customization for me,

                          best regards
                          Naseer
                          • 10. Re: check file size in ODI
                            Guru Sankar
                            Hi Naseer,

                            Here you go.

                            Step 1:

                            In your existing LKM add a step, "Check File Count" (Make this as first step).

                            Command on source

                            Technology : File

                            Command On Target

                            Technology : Jython

                            Command:

                            import os
                            # open the file
                            fsrc = open('<%=odiRef.getSrcTablesList("", "[SCHEMA]/[RES_NAME]", ", ", "")%>', 'r')
                            # read the first line
                            lsrc=fsrc.readline()
                            # set row counter, starting on the second line
                            n = -1
                            # count lines
                            while (lsrc):
                            -------lsrc=fsrc.readline()
                            -------n = n + 1
                            # Check for the record count
                            if n<1:
                            -------os.system('C:\OdiSendMail.bat')
                            -------raise '\n Can not process further as the file doesnt contain rows'

                            Step 2:

                            Create a batch file OdiSendMail.bat at C: and paste the below code after modifying as per your environment,

                            cd C:\OdiHome\oracledi\bin
                            startcmd.bat OdiSendMail "-MAILHOST=mail.server.com" "-FROM=user@mailfrom.com" "-SUBJECT=Hi" "-TO=user@mailto.com" "-MSGBODY=The file doesnot contains rows to process, please resend a new file."

                            Prerequisites:

                            1. Odiparams.bat should be updated with your corresponding "Repository Connection Information" .
                            2. Replace "---" with tab in Step 1.
                            3. Change Step 2 first line to point to your corresponding <ODI_HOME>\oracledi\bin location as such.

                            Hope this gives solution as you are looking for, try this and let me know. Let me know if you have any difficulties in any steps.

                            P.S: This above code is tested in my local and working as expected. I am still working on calling OdiSendMail within jython, if i got any updates will let u know.

                            Thanks,
                            Guru
                            • 11. Re: check file size in ODI
                              m_naseer
                              thanks a lot guru