org.pentaho.di.core.row.RowMetaInterface Java Examples

The following examples show how to use org.pentaho.di.core.row.RowMetaInterface. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: YamlInputDialog.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private void setXMLStreamField() {
  try {

    wYAMLLField.removeAll();

    RowMetaInterface r = transMeta.getPrevStepFields( stepname );
    if ( r != null ) {
      r.getFieldNames();

      for ( int i = 0; i < r.getFieldNames().length; i++ ) {
        wYAMLLField.add( r.getFieldNames()[i] );

      }
    }
  } catch ( KettleException ke ) {
    new ErrorDialog(
      shell, BaseMessages.getString( PKG, "YamlInputDialog.FailedToGetFields.DialogTitle" ), BaseMessages
        .getString( PKG, "YamlInputDialog.FailedToGetFields.DialogMessage" ), ke );
  }
}
 
Example #2
Source File: DetectLastRowStepIT.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
/**
 * Create data rows.
 *
 * @param nrRows
 *          nr of rows to insert (from 0 to 3 for the moment)
 *
 * @return List of row and meta data
 */
public List<RowMetaAndData> createData( int nrRows ) {
  List<RowMetaAndData> list = new ArrayList<RowMetaAndData>();

  RowMetaInterface rm = createRowMetaInterface();

  Object[] r1 =
    new Object[] { "KETTLE1", new Long( 123L ), new Double( 10.5D ), Boolean.TRUE, BigDecimal.valueOf( 123.45 ) };
  Object[] r2 =
    new Object[] {
      "KETTLE2", new Long( 500L ), new Double( 20.0D ), Boolean.FALSE, BigDecimal.valueOf( 123.45 ) };
  Object[] r3 =
    new Object[] {
      "KETTLE3", new Long( 501L ), new Double( 21.0D ), Boolean.FALSE, BigDecimal.valueOf( 123.45 ) };

  list.add( new RowMetaAndData( rm, r1 ) );
  list.add( new RowMetaAndData( rm, r2 ) );
  list.add( new RowMetaAndData( rm, r3 ) );

  return list.subList( 0, nrRows );
}
 
Example #3
Source File: CPythonRowMetaInterfaceValidator.java    From pentaho-cpython-plugin with Apache License 2.0 6 votes vote down vote up
@Override public boolean validateTestObject( RowMetaInterface testObject, Object other ) {
  if ( other == null || !( other instanceof RowMetaInterface ) ) {
    return false;
  }
  RowMetaInterface otherRow = (RowMetaInterface) other;
  if ( testObject.size() != otherRow.size() ) {
    return false;
  }
  for ( int i = 0; i < testObject.size(); i++ ) {
    ValueMetaInterface testVmi = testObject.getValueMeta( i );
    ValueMetaInterface otherVmi = otherRow.getValueMeta( i );
    if ( !testVmi.getName().equals( otherVmi.getName() ) ) {
      return false;
    }
    if ( !testVmi.getTypeDesc().equals( otherVmi.getTypeDesc() ) ) {
      return false;
    }
  }
  return true;
}
 
Example #4
Source File: SyslogMessageDialog.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private void get() {
  if ( !gotPreviousFields ) {
    gotPreviousFields = true;
    try {
      String source = wMessageField.getText();

      wMessageField.removeAll();
      RowMetaInterface r = transMeta.getPrevStepFields( stepname );
      if ( r != null ) {
        wMessageField.setItems( r.getFieldNames() );
        if ( source != null ) {
          wMessageField.setText( source );
        }
      }
    } catch ( KettleException ke ) {
      new ErrorDialog(
        shell, BaseMessages.getString( PKG, "SyslogMessageDialog.FailedToGetFields.DialogTitle" ),
        BaseMessages.getString( PKG, "SyslogMessageDialog.FailedToGetFields.DialogMessage" ), ke );
    }
  }
}
 
Example #5
Source File: UniqueRowsMeta.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Override
public void getFields( RowMetaInterface row, String name, RowMetaInterface[] info, StepMeta nextStep,
  VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {
  // change the case insensitive flag too
  for ( int i = 0; i < compareFields.length; i++ ) {
    int idx = row.indexOfValue( compareFields[i] );
    if ( idx >= 0 ) {
      row.getValueMeta( idx ).setCaseInsensitive( caseInsensitive[i] );
    }
  }
  if ( countRows ) {
    ValueMetaInterface v = new ValueMetaInteger( countField );
    v.setLength( ValueMetaInterface.DEFAULT_INTEGER_LENGTH, 0 );
    v.setOrigin( name );
    row.addValueMeta( v );
  }
}
 
Example #6
Source File: JoinRowsMeta.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Override
public void getFields( RowMetaInterface rowMeta, String origin, RowMetaInterface[] info, StepMeta nextStep,
  VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {
  if ( space instanceof TransMeta ) {
    TransMeta transMeta = (TransMeta) space;
    StepMeta[] steps = transMeta.getPrevSteps( transMeta.findStep( origin ) );
    StepMeta mainStep = transMeta.findStep( getMainStepname() );
    rowMeta.clear();
    if ( mainStep != null ) {
      rowMeta.addRowMeta( transMeta.getStepFields( mainStep ) );
    }
    for ( StepMeta step : steps ) {
      if ( mainStep == null || !step.equals( mainStep ) ) {
        rowMeta.addRowMeta( transMeta.getStepFields( step ) );
      }
    }
  }
}
 
Example #7
Source File: InsertUpdateDialog.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private void get() {
  try {
    RowMetaInterface r = transMeta.getPrevStepFields( stepname );
    if ( r != null ) {
      TableItemInsertListener listener = new TableItemInsertListener() {
        public boolean tableItemInserted( TableItem tableItem, ValueMetaInterface v ) {
          tableItem.setText( 2, "=" );
          return true;
        }
      };
      BaseStepDialog.getFieldsFromPrevious( r, wKey, 1, new int[] { 1, 3 }, new int[] {}, -1, -1, listener );
    }
  } catch ( KettleException ke ) {
    new ErrorDialog(
      shell, BaseMessages.getString( PKG, "InsertUpdateDialog.FailedToGetFields.DialogTitle" ), BaseMessages
        .getString( PKG, "InsertUpdateDialog.FailedToGetFields.DialogMessage" ), ke );
  }
}
 
Example #8
Source File: TransformClassBase.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings( "unchecked" )
public static void getFields( boolean clearResultFields, RowMetaInterface row, String originStepname,
  RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, List<?> fields ) throws KettleStepException {
  if ( clearResultFields ) {
    row.clear();
  }
  for ( FieldInfo fi : (List<FieldInfo>) fields ) {
    try {
      ValueMetaInterface v = ValueMetaFactory.createValueMeta( fi.name, fi.type );
      v.setLength( fi.length );
      v.setPrecision( fi.precision );
      v.setOrigin( originStepname );
      row.addValueMeta( v );
    } catch ( Exception e ) {
      throw new KettleStepException( e );
    }
  }
}
 
Example #9
Source File: UniqueRowsIT.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public List<RowMetaAndData> createResultDataSortCaseInsensitiveUniqueCaseSensitive() {
  List<RowMetaAndData> list = new ArrayList<RowMetaAndData>();

  RowMetaInterface rm = createRowMetaInterface();

  Object[] r1 = new Object[] { "abc" };
  Object[] r2 = new Object[] { "ABC" };
  Object[] r3 = new Object[] { "abc" };
  Object[] r4 = new Object[] { "ABC" };

  list.add( new RowMetaAndData( rm, r1 ) );
  list.add( new RowMetaAndData( rm, r2 ) );
  list.add( new RowMetaAndData( rm, r3 ) );
  list.add( new RowMetaAndData( rm, r4 ) );

  return list;
}
 
Example #10
Source File: DatabaseLookupDialog.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private void get() {
  try {
    RowMetaInterface r = transMeta.getPrevStepFields( stepname );
    if ( r != null && !r.isEmpty() ) {
      TableItemInsertListener listener = new TableItemInsertListener() {
        public boolean tableItemInserted( TableItem tableItem, ValueMetaInterface v ) {
          tableItem.setText( 2, "=" );
          return true;
        }
      };
      BaseStepDialog.getFieldsFromPrevious( r, wKey, 1, new int[] { 1, 3 }, new int[] {}, -1, -1, listener );
    }
  } catch ( KettleException ke ) {
    new ErrorDialog(
      shell, BaseMessages.getString( PKG, "DatabaseLookupDialog.GetFieldsFailed.DialogTitle" ), BaseMessages
        .getString( PKG, "DatabaseLookupDialog.GetFieldsFailed.DialogMessage" ), ke );
  }

}
 
Example #11
Source File: GetTableNamesDialog.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private void setSchemaField() {
  if ( !gotpreviousfields ) {
    try {
      String value = wSchemaField.getText();
      wSchemaField.removeAll();

      RowMetaInterface r = transMeta.getPrevStepFields( stepname );
      if ( r != null ) {
        wSchemaField.setItems( r.getFieldNames() );
      }
      if ( value != null ) {
        wSchemaField.setText( value );
      }
    } catch ( KettleException ke ) {
      new ErrorDialog(
        shell, BaseMessages.getString( PKG, "GetTableNamesDialog.FailedToGetFields.DialogTitle" ),
        BaseMessages.getString( PKG, "GetTableNamesDialog.FailedToGetFields.DialogMessage" ), ke );
    }
    gotpreviousfields = true;
  }
}
 
Example #12
Source File: SasInputMeta.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Override
public void getFields( RowMetaInterface row, String name, RowMetaInterface[] info, StepMeta nextStep,
  VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {

  for ( SasInputField field : outputFields ) {
    try {
      ValueMetaInterface valueMeta = ValueMetaFactory.createValueMeta( field.getRename(), field.getType() );
      valueMeta.setLength( field.getLength(), field.getPrecision() );
      valueMeta.setDecimalSymbol( field.getDecimalSymbol() );
      valueMeta.setGroupingSymbol( field.getGroupingSymbol() );
      valueMeta.setConversionMask( field.getConversionMask() );
      valueMeta.setTrimType( field.getTrimType() );
      valueMeta.setOrigin( name );

      row.addValueMeta( valueMeta );
    } catch ( Exception e ) {
      throw new KettleStepException( e );
    }
  }
}
 
Example #13
Source File: ExcelInputMeta.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public RowMetaInterface getEmptyFields() {
  RowMetaInterface row = new RowMeta();
  if ( field != null ) {
    for ( int i = 0; i < field.length; i++ ) {
      ValueMetaInterface v;
      try {
        v = ValueMetaFactory.createValueMeta( field[ i ].getName(), field[ i ].getType() );
      } catch ( KettlePluginException e ) {
        v = new ValueMetaNone( field[ i ].getName() );
      }
      row.addValueMeta( v );
    }
  }

  return row;
}
 
Example #14
Source File: SingleThreaderMeta.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public void getFields( RowMetaInterface row, String origin, RowMetaInterface[] info, StepMeta nextStep,
  VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {

  // First load some interesting data...
  //
  // Then see which fields get added to the row.
  //
  TransMeta mappingTransMeta = null;
  try {
    mappingTransMeta = loadSingleThreadedTransMeta( this, repository, space );
  } catch ( KettleException e ) {
    throw new KettleStepException( BaseMessages.getString(
      PKG, "SingleThreaderMeta.Exception.UnableToLoadMappingTransformation" ), e );
  }

  row.clear();

  // Let's keep it simple!
  //
  if ( !Utils.isEmpty( space.environmentSubstitute( retrieveStep ) ) ) {
    RowMetaInterface stepFields = mappingTransMeta.getStepFields( retrieveStep );
    row.addRowMeta( stepFields );
  }
}
 
Example #15
Source File: SetVariableDialog.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private void get() {
  try {
    RowMetaInterface r = transMeta.getPrevStepFields( stepname );
    if ( r != null && !r.isEmpty() ) {
      BaseStepDialog.getFieldsFromPrevious(
        r, wFields, 1, new int[] { 1 }, new int[] {}, -1, -1, new TableItemInsertListener() {
          public boolean tableItemInserted( TableItem tableItem, ValueMetaInterface v ) {
            tableItem.setText( 2, v.getName().toUpperCase() );
            tableItem.setText( 3, SetVariableMeta
              .getVariableTypeDescription( SetVariableMeta.VARIABLE_TYPE_ROOT_JOB ) );
            return true;
          }
        } );
    }
  } catch ( KettleException ke ) {
    new ErrorDialog(
      shell, BaseMessages.getString( PKG, "SetVariableDialog.FailedToGetFields.DialogTitle" ), BaseMessages
        .getString( PKG, "Set.FailedToGetFields.DialogMessage" ), ke );
  }
}
 
Example #16
Source File: UniqueRowsIT.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public List<RowMetaAndData> createResultDataAllUnique() {
  List<RowMetaAndData> list = new ArrayList<RowMetaAndData>();

  RowMetaInterface rm = createRowMetaInterface();

  Object[] r1 = new Object[] { "A" };
  Object[] r2 = new Object[] { "B" };
  Object[] r3 = new Object[] { "C" };
  Object[] r4 = new Object[] { "D" };

  list.add( new RowMetaAndData( rm, r1 ) );
  list.add( new RowMetaAndData( rm, r2 ) );
  list.add( new RowMetaAndData( rm, r3 ) );
  list.add( new RowMetaAndData( rm, r4 ) );

  return list;
}
 
Example #17
Source File: PentahoMapReduceJobBuilderImplTest.java    From pentaho-hadoop-shims with Apache License 2.0 6 votes vote down vote up
@Test( expected = KettleException.class )
public void testVerifyTransMetaNoKeyOrdinal() throws KettleException {
  String inputStepName = "inputStepName";
  StepMeta inputStepMeta = mock( StepMeta.class );
  when( transMeta.findStep( inputStepName ) ).thenReturn( inputStepMeta );
  RowMetaInterface rowMetaInterface = mock( RowMetaInterface.class );
  when( rowMetaInterface.getFieldNames() ).thenReturn( new String[] {} );
  when( transMeta.getStepFields( inputStepMeta ) ).thenReturn( rowMetaInterface );
  try {
    pentahoMapReduceJobBuilder.verifyTransMeta( transMeta, inputStepName, null );
  } catch ( KettleException e ) {
    assertEquals( BaseMessages.getString( PentahoMapReduceJobBuilderImpl.PKG,
      PentahoMapReduceJobBuilderImpl.PENTAHO_MAP_REDUCE_JOB_BUILDER_IMPL_NO_KEY_ORDINAL, inputStepName ),
      e.getMessage().trim() );
    throw e;
  }
}
 
Example #18
Source File: TransDebugMeta.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public synchronized void addRowListenersToTransformation( final Trans trans ) {

    final TransDebugMeta self = this;

    // for every step in the map, add a row listener...
    //
    for ( final Map.Entry<StepMeta, StepDebugMeta> entry : stepDebugMetaMap.entrySet() ) {
      final StepMeta stepMeta = entry.getKey();
      final StepDebugMeta stepDebugMeta = entry.getValue();

      // What is the transformation thread to attach a listener to?
      //
      for ( StepInterface baseStep : trans.findBaseSteps( stepMeta.getName() ) ) {
        baseStep.addRowListener( new RowAdapter() {
          public void rowWrittenEvent( RowMetaInterface rowMeta, Object[] row ) throws KettleStepException {
            rowWrittenEventHandler( rowMeta, row, stepDebugMeta, trans, self );
          }
        } );
      }
    }
  }
 
Example #19
Source File: TeraFastDialog.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
/**
 * ...
 */
public void getUpdate() {
  try {
    final RowMetaInterface row = this.transMeta.getPrevStepFields( this.stepname );
    if ( row != null ) {
      TableItemInsertListener listener = new TableItemInsertListener() {
        public boolean tableItemInserted( final TableItem tableItem, final ValueMetaInterface value ) {
          // possible to check format of input fields
          return true;
        }
      };
      BaseStepDialog.getFieldsFromPrevious(
        row, this.wReturn, 1, new int[] { 1, 2 }, new int[] {}, -1, -1, listener );
    }
  } catch ( KettleException ke ) {
    new ErrorDialog(
      this.shell, BaseMessages.getString( PKG, "TeraFastDialog.FailedToGetFields.DialogTitle" ), BaseMessages
        .getString( PKG, "TeraFastDialog.FailedToGetFields.DialogMessage" ), ke );
  }
}
 
Example #20
Source File: FuzzyMatchDialog.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private void setMainStreamField() {
  if ( !gotPreviousFields ) {
    String field = wMainStreamField.getText();
    try {
      wMainStreamField.removeAll();

      RowMetaInterface r = transMeta.getPrevStepFields( stepname );
      if ( r != null ) {
        wMainStreamField.setItems( r.getFieldNames() );
      }
    } catch ( KettleException ke ) {
      new ErrorDialog(
        shell, BaseMessages.getString( PKG, "FuzzyMatchDialog.FailedToGetFields.DialogTitle" ), BaseMessages
          .getString( PKG, "FuzzyMatchDialog.FailedToGetFields.DialogMessage" ), ke );
    }
    if ( field != null ) {
      wMainStreamField.setText( field );
    }
    gotPreviousFields = true;
  }
}
 
Example #21
Source File: TextFileOutputDialog.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private void getFields() {
  if ( !gotPreviousFields ) {
    try {
      String field = wFileNameField.getText();
      RowMetaInterface r = transMeta.getPrevStepFields( stepname );
      if ( r != null ) {
        wFileNameField.setItems( r.getFieldNames() );
      }
      if ( field != null ) {
        wFileNameField.setText( field );
      }
    } catch ( KettleException ke ) {
      new ErrorDialog(
        shell, BaseMessages.getString( PKG, "TextFileOutputDialog.FailedToGetFields.DialogTitle" ),
        BaseMessages.getString( PKG, "TextFileOutputDialog.FailedToGetFields.DialogMessage" ), ke );
    }
    gotPreviousFields = true;
  }
}
 
Example #22
Source File: StringCutDialog.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private void get() {
  try {
    RowMetaInterface r = transMeta.getPrevStepFields( stepname );
    if ( r != null ) {
      TableItemInsertListener listener = new TableItemInsertListener() {
        public boolean tableItemInserted( TableItem tableItem, ValueMetaInterface v ) {
          if ( v.getType() == ValueMetaInterface.TYPE_STRING ) {
            // Only process strings
            return true;
          } else {
            return false;
          }
        }
      };

      BaseStepDialog.getFieldsFromPrevious( r, wFields, 1, new int[] { 1 }, new int[] {}, -1, -1, listener );

    }
  } catch ( KettleException ke ) {
    new ErrorDialog(
      shell, BaseMessages.getString( PKG, "StringCutDialog.FailedToGetFields.DialogTitle" ), BaseMessages
        .getString( PKG, "StringCutDialog.FailedToGetFields.DialogMessage" ), ke );
  }
}
 
Example #23
Source File: MonetDBBulkLoaderMeta.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public SQLStatement getTableDdl( TransMeta transMeta, String stepname, boolean autoSchema,
    MonetDBBulkLoaderData data, boolean safeMode ) throws KettleException {

  String name = stepname; // new name might not yet be linked to other steps!
  StepMeta stepMeta =
      new StepMeta( BaseMessages.getString( PKG, "MonetDBBulkLoaderDialog.StepMeta.Title" ), name, this );
  RowMetaInterface prev = transMeta.getPrevStepFields( stepname );

  SQLStatement sql = getSQLStatements( transMeta, stepMeta, prev, autoSchema, data, safeMode );
  return sql;
}
 
Example #24
Source File: RulesAccumulatorData.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public void initializeInput( RowMetaInterface _inputRowMeta ) {
  if ( _inputRowMeta == null ) {
    BaseMessages.getString( PKG, "RulesData.InitializeColumns.InputRowMetaIsNull" );
    return;
  }

  this.inputRowMeta = _inputRowMeta;
}
 
Example #25
Source File: TextFileInputIT.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a RowMetaInterface with a ValueMetaInterface with the name "filename".
 *
 * @return
 */
public RowMetaInterface createRowMetaInterface() {
  RowMetaInterface rowMeta = new RowMeta();

  ValueMetaInterface[] valuesMeta = { new ValueMetaString( "filename" ), };
  for ( int i = 0; i < valuesMeta.length; i++ ) {
    rowMeta.addValueMeta( valuesMeta[i] );
  }

  return rowMeta;
}
 
Example #26
Source File: ModPartitioner.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public int getPartition( RowMetaInterface rowMeta, Object[] row ) throws KettleException {
  init( rowMeta );

  if ( partitionColumnIndex < 0 ) {
    partitionColumnIndex = rowMeta.indexOfValue( fieldName );
    if ( partitionColumnIndex < 0 ) {
      throw new KettleStepException( "Unable to find partitioning field name ["
        + fieldName + "] in the output row..." + rowMeta );
    }
  }

  long value;

  ValueMetaInterface valueMeta = rowMeta.getValueMeta( partitionColumnIndex );
  Object valueData = row[partitionColumnIndex];

  switch ( valueMeta.getType() ) {
    case ValueMetaInterface.TYPE_INTEGER:
      Long longValue = rowMeta.getInteger( row, partitionColumnIndex );
      if ( longValue == null ) {
        value = valueMeta.hashCode( valueData );
      } else {
        value = longValue.longValue();
      }
      break;
    default:
      value = valueMeta.hashCode( valueData );
  }

  /*
   * value = rowMeta.getInteger(row, partitionColumnIndex);
   */

  int targetLocation = (int) ( Math.abs( value ) % nrPartitions );

  return targetLocation;
}
 
Example #27
Source File: ResultFileTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetRow() throws KettleFileException, FileSystemException {
  File tempDir = new File( new TemporaryFolder().toString() );
  FileObject tempFile = KettleVFS.createTempFile( "prefix", "suffix", tempDir.toString() );
  Date timeBeforeFile = Calendar.getInstance().getTime();
  ResultFile resultFile = new ResultFile( ResultFile.FILE_TYPE_GENERAL, tempFile, "myOriginParent", "myOrigin" );
  Date timeAfterFile = Calendar.getInstance().getTime();

  assertNotNull( resultFile );
  RowMetaInterface rm = resultFile.getRow().getRowMeta();
  assertEquals( 7, rm.getValueMetaList().size() );
  assertEquals( ValueMetaInterface.TYPE_STRING, rm.getValueMeta( 0 ).getType() );
  assertEquals( ValueMetaInterface.TYPE_STRING, rm.getValueMeta( 1 ).getType() );
  assertEquals( ValueMetaInterface.TYPE_STRING, rm.getValueMeta( 2 ).getType() );
  assertEquals( ValueMetaInterface.TYPE_STRING, rm.getValueMeta( 3 ).getType() );
  assertEquals( ValueMetaInterface.TYPE_STRING, rm.getValueMeta( 4 ).getType() );
  assertEquals( ValueMetaInterface.TYPE_STRING, rm.getValueMeta( 5 ).getType() );
  assertEquals( ValueMetaInterface.TYPE_DATE, rm.getValueMeta( 6 ).getType() );

  assertEquals( ResultFile.FILE_TYPE_GENERAL, resultFile.getType() );
  assertEquals( "myOrigin", resultFile.getOrigin() );
  assertEquals( "myOriginParent", resultFile.getOriginParent() );
  assertTrue( "ResultFile timestamp is created in the expected window",
    timeBeforeFile.compareTo( resultFile.getTimestamp() ) <= 0
    && timeAfterFile.compareTo( resultFile.getTimestamp() ) >= 0 );

  tempFile.delete();
  tempDir.delete();
}
 
Example #28
Source File: CsvInputUnicodeTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private void doTest( final String fileEncoding, final String stepEncoding, final String testData,
  final String delimiter, final boolean useHeader ) throws Exception {
  String testFilePath = createTestFile( fileEncoding, testData ).getAbsolutePath();

  CsvInputMeta meta = createStepMeta( testFilePath, stepEncoding, delimiter, useHeader );
  CsvInputData data = new CsvInputData();

  CsvInput csvInput =
    new CsvInput(
      stepMockHelper.stepMeta, stepMockHelper.stepDataInterface, 0, stepMockHelper.transMeta,
      stepMockHelper.trans );

  csvInput.init( meta, data );
  csvInput.addRowListener( new RowAdapter() {
    @Override
    public void rowWrittenEvent( RowMetaInterface rowMeta, Object[] row ) throws KettleStepException {
      for ( int i = 0; i < rowMeta.size(); i++ ) {
        Assert.assertEquals( "Value", row[ i ] );
      }
    }
  } );

  boolean haveRowsToRead;
  do {
    haveRowsToRead = !csvInput.processRow( meta, data );
  } while ( !haveRowsToRead );

  csvInput.dispose( meta, data );
  Assert.assertEquals( 2, csvInput.getLinesWritten() );
}
 
Example #29
Source File: TextFileInput.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * @deprecated Use {@link #convertLineToRow(LogChannelInterface, TextFileLine,
 * InputFileMetaInterface, Object[], int, RowMetaInterface,RowMetaInterface,
 * String, long, String, String, String, FileErrorHandler, boolean, boolean,
 * boolean, boolean, boolean, boolean, boolean, boolean, String, String, boolean,
 * Date, String, String, String, long)} instead.
 */
@Deprecated
public static final Object[] convertLineToRow( LogChannelInterface log, TextFileLine textFileLine,
    InputFileMetaInterface info, RowMetaInterface outputRowMeta, RowMetaInterface convertRowMeta, String fname,
    long rowNr, String delimiter, FileErrorHandler errorHandler, boolean addShortFilename, boolean addExtension,
    boolean addPath, boolean addSize, boolean addIsHidden, boolean addLastModificationDate, boolean addUri,
    boolean addRootUri, String shortFilename, String path, boolean hidden, Date modificationDateTime, String uri,
    String rooturi, String extension, long size ) throws KettleException {
  return convertLineToRow( log, textFileLine, info, null, 0, outputRowMeta, convertRowMeta, fname, rowNr, delimiter,
      StringUtil.substituteHex( info.getEnclosure() ), StringUtil.substituteHex( info.getEscapeCharacter() ),
      errorHandler, addShortFilename, addExtension, addPath, addSize, addIsHidden, addLastModificationDate, addUri,
      addRootUri, shortFilename, path, hidden, modificationDateTime, uri, rooturi, extension, size );
}
 
Example #30
Source File: FastloadControlBuilder.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * @param targetTableFields
 *          ...
 * @param dataFile
 *          ...
 * @return this
 */
public FastloadControlBuilder define( final RowMetaInterface targetTableFields,
  StringListPluginProperty tableFieldList, final String dataFile ) {
  Assert.assertNotNull( targetTableFields, "fields cannot be null" );
  Assert.assertNotNull( dataFile, "dataFile cannot be null" );

  this.builder.append( "DEFINE " );
  for ( int i = 0; i < targetTableFields.size(); i++ ) {
    ValueMetaInterface value = targetTableFields.getValueMeta( i );
    int tableIndex = tableFieldList.getValue().indexOf( value.getName() );
    if ( tableIndex >= 0 ) {
      this.builder.append( value.getName() );
      // all fields of type VARCHAR. converted by fastload if necessary
      int length = 0;
      if ( value.getType() == ValueMetaInterface.TYPE_DATE ) {
        length = DEFAULT_DATE_FORMAT.length();
      } else {
        length = value.getLength();
      }
      this.builder.append( "("
        + "VARCHAR(" + length + "), nullif = '" + String.format( "%1$" + length + "s", DEFAULT_NULL_VALUE )
        + "'), " );
      this.builder.append( SystemUtils.LINE_SEPARATOR );
    }
  }
  this.builder.append( " NEWLINECHAR(VARCHAR(" + SystemUtils.LINE_SEPARATOR.length() + "))" );
  this.builder.append( " FILE=" + dataFile );
  return this.newline();
}