Search code examples
oracle-data-integrator

ODI 11g Reverse Engineering File modification


Sorry if this question is a bit too broad, I constantly use Reverse Engineering to read .TXT files in ODI 11g.

I was wondering if there is any way to modify or create an RKM(not sure if this is responsible) which by default assigns column Physical and Logical length to 300 for string datatype.

The default length which is assigned by ODI 11g is 50.

Is there any way to edit this?


Solution

  • You can do bulk changes of physical length and length with the next Groovy script.

    Go to ODI > Tools > Groovy > New Script and copy paste the next Groovy code:

    //Created by DI Studio
    import ro.ns.odi.proxy.*
    import oracle.odi.domain.model.*
    import oracle.odi.domain.model.finder.*
    import oracle.odi.domain.xrefs.expression.*
    import oracle.odi.languages.support.*
    
    IOdiEntityFactory odiFactory=OdiEntityFactory.createInstance(odiInstance)
    IOdiBasicTemplate odiTemplate=odiFactory.newOdiTemplate()
    
    
    String TABLE_NAME="SB_FINANCIALS_NEW_UU" //change with what you need
    String MODEL_CODE="FILE" //change with what you need
    
    odiTemplate.executeInTransaction{IOdiCommandContext ctx->
    
      IOdiEntityManager odiManager=ctx.getSupportingOdiInstance().getTransactionalEntityManager()
      IOdiDataStoreFinder dataStoreFinder=odiManager.getFinder(OdiDataStore)
      OdiDataStore dataStore=dataStoreFinder.findByName(TABLE_NAME,MODEL_CODE)
    
      assert dataStore!=null : "No data store was found. Please review the model code and data store name" 
    
      for (OdiColumn column:dataStore.columns){
         println "Analyzing column ${column.name} with type ${column.dataType.name}, length ${column.getLength()} and scale ${column.scale}"
    
         String dataTypeName=column.dataType.name
    
         column.fileFieldDescriptor.bytes=4000 //change with what you need
         //column.fileFieldDescriptor?.bytes=3000
         column.length=4000 //change with what you need
         column.dataType.name="String"
    
         switch(dataTypeName){
          case "String":
            //column.scale=2
            //column.fileFieldDescriptor?.decimalSeparator="x"
            println "--Column Modified"
          break
           case "Numeric":
            //column.scale=2
            //column.fileFieldDescriptor?.decimalSeparator="x"
            println "--Column Modified"
          break
    
        } 
    
    
      }
    }
    

    Read the Groovy code and change:

    • TABLE_NAME - name of datastore that you need to change the datatypes;
    • MODEL_CODE - code of MODEL from ODI > Models;
    • column.fileFieldDescriptor;
    • column.length;
    • column.dataType.