Java Code Examples for org.pentaho.di.core.RowMetaAndData#getData()

The following examples show how to use org.pentaho.di.core.RowMetaAndData#getData() . 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: KettleDatabaseRepositoryConnectionDelegate.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public synchronized ObjectId getIDWithValue( String tablename, String idfield, String lookupfield, String value,
                                             String lookupkey, ObjectId key ) throws KettleException {
  RowMetaAndData par = new RowMetaAndData();
  par.addValue( new ValueMetaString( "value" ), value );
  par.addValue( new ValueMetaInteger( "key" ), new LongObjectId( key ) );
  RowMetaAndData result =
    getOneRow( "SELECT "
      + idfield + " FROM " + tablename + " WHERE " + lookupfield + " = ? AND " + lookupkey + " = ?", par
      .getRowMeta(), par.getData() );

  if ( result != null && result.getRowMeta() != null && result.getData() != null && result.isNumeric( 0 ) ) {
    return new LongObjectId( result.getInteger( 0, 0 ) );
  }

  return null;
}
 
Example 2
Source File: KettleDatabaseRepositoryConnectionDelegate.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public synchronized LongObjectId getIDWithValue( String tablename, String idfield, String lookupfield,
                                                 String value, String[] lookupkey, ObjectId[] key )
  throws KettleException {
  RowMetaAndData par = new RowMetaAndData();
  par.addValue( new ValueMetaString( lookupfield ), value );

  String sql = "SELECT " + idfield + " FROM " + tablename + " WHERE " + lookupfield + " = ? ";

  for ( int i = 0; i < lookupkey.length; i++ ) {
    par.addValue( new ValueMetaInteger( lookupkey[ i ] ), new LongObjectId( key[ i ] ) );
    sql += "AND " + lookupkey[ i ] + " = ? ";
  }

  RowMetaAndData result = getOneRow( sql, par.getRowMeta(), par.getData() );
  if ( result != null && result.getRowMeta() != null && result.getData() != null && result.isNumeric( 0 ) ) {
    return new LongObjectId( result.getInteger( 0, 0 ) );
  }
  return null;
}
 
Example 3
Source File: KettleDatabaseRepositoryConnectionDelegate.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public synchronized ObjectId getIDWithValue( String tablename, String idfield, String[] lookupkey, ObjectId[] key )
  throws KettleException {
  RowMetaAndData par = new RowMetaAndData();
  String sql = "SELECT " + idfield + " FROM " + tablename + " ";

  for ( int i = 0; i < lookupkey.length; i++ ) {
    if ( i == 0 ) {
      sql += "WHERE ";
    } else {
      sql += "AND   ";
    }
    par.addValue( new ValueMetaInteger( lookupkey[ i ] ), new LongObjectId( key[ i ] ) );
    sql += lookupkey[ i ] + " = ? ";
  }
  RowMetaAndData result = getOneRow( sql, par.getRowMeta(), par.getData() );
  if ( result != null && result.getRowMeta() != null && result.getData() != null && result.isNumeric( 0 ) ) {
    return new LongObjectId( result.getInteger( 0, 0 ) );
  }
  return null;
}
 
Example 4
Source File: KettleDatabaseRepositoryConnectionDelegate.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public synchronized int countNrStepAttributes( ObjectId id_step, String code ) throws KettleException {
  if ( stepAttributesBuffer != null ) {
    // see if we can do this in memory...

    int nr = searchNrStepAttributes( id_step, code );
    return nr;
  } else {
    String sql =
      "SELECT COUNT(*) FROM "
        + databaseMeta.getQuotedSchemaTableCombination(
        null, KettleDatabaseRepository.TABLE_R_STEP_ATTRIBUTE ) + " WHERE "
        + quote( KettleDatabaseRepository.FIELD_STEP_ATTRIBUTE_ID_STEP ) + " = ? AND "
        + quote( KettleDatabaseRepository.FIELD_STEP_ATTRIBUTE_CODE ) + " = ?";
    RowMetaAndData table = new RowMetaAndData();
    table.addValue( new ValueMetaInteger(
      KettleDatabaseRepository.FIELD_STEP_ATTRIBUTE_ID_STEP ), id_step );
    table.addValue( new ValueMetaString(
      KettleDatabaseRepository.FIELD_STEP_ATTRIBUTE_CODE ), code );
    RowMetaAndData r = callRead( () -> database.getOneRow( sql, table.getRowMeta(), table.getData() ) );
    if ( r == null || r.getData() == null ) {
      return 0;
    }
    return (int) r.getInteger( 0, 0L );
  }
}
 
Example 5
Source File: NullIfIT.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Check the 2 lists comparing the rows in order. If they are not the same fail the test.
 */
public void checkRows( List<RowMetaAndData> rows1, List<RowMetaAndData> rows2 ) {
  int idx = 1;
  if ( rows1.size() != rows2.size() ) {
    fail( "Number of rows is not the same: " + rows1.size() + " and " + rows2.size() );
  }
  Iterator<RowMetaAndData> it1 = rows1.iterator();
  Iterator<RowMetaAndData> it2 = rows2.iterator();

  while ( it1.hasNext() && it2.hasNext() ) {
    RowMetaAndData rm1 = it1.next();
    RowMetaAndData rm2 = it2.next();

    Object[] r1 = rm1.getData();
    Object[] r2 = rm2.getData();

    if ( rm1.size() != rm2.size() ) {
      fail( "row nr " + idx + " is not equal" );
    }
    int[] fields = new int[r1.length];
    for ( int ydx = 0; ydx < r1.length; ydx++ ) {
      fields[ydx] = ydx;
    }
    try {
      if ( rm1.getRowMeta().compare( r1, r2, fields ) != 0 ) {
        fail( "row nr " + idx + " is not equal" );
      }
    } catch ( KettleValueException e ) {
      fail( "row nr " + idx + " is not equal" );
    }

    idx++;
  }
}
 
Example 6
Source File: JavaScriptSpecialIT.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Check the 2 lists comparing the rows in order. If they are not the same fail the test.
 */
public void checkRows( List<RowMetaAndData> rows1, List<RowMetaAndData> rows2 ) {
  int idx = 1;
  if ( rows1.size() != rows2.size() ) {
    fail( "Number of rows is not the same: " + rows1.size() + " and " + rows2.size() );
  }
  Iterator<RowMetaAndData> it1 = rows1.iterator();
  Iterator<RowMetaAndData> it2 = rows2.iterator();

  while ( it1.hasNext() && it2.hasNext() ) {
    RowMetaAndData rm1 = it1.next();
    RowMetaAndData rm2 = it2.next();

    Object[] r1 = rm1.getData();
    Object[] r2 = rm2.getData();

    if ( rm1.size() != rm2.size() ) {
      fail( "row nr " + idx + " is not equal" );
    }
    int[] fields = new int[ rm1.size() ];
    for ( int ydx = 0; ydx < rm1.size(); ydx++ ) {
      fields[ ydx ] = ydx;
    }
    try {
      if ( rm1.getRowMeta().compare( r1, r2, fields ) != 0 ) {
        fail( "row nr " + idx + " is not equal" );
      }
    } catch ( KettleValueException e ) {
      fail( "row nr " + idx + " is not equal" );
    }

    idx++;
  }
}
 
Example 7
Source File: DatabaseLookupIT.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Check the 2 lists comparing the rows in order. If they are not the same fail the test.
 */
public void checkRows( List<RowMetaAndData> rows1, List<RowMetaAndData> rows2 ) {
  int idx = 1;
  if ( rows1.size() != rows2.size() ) {
    fail( "Number of rows is not the same: " + rows1.size() + " and " + rows2.size() );
  }
  Iterator<RowMetaAndData> it1 = rows1.iterator();
  Iterator<RowMetaAndData> it2 = rows2.iterator();

  while ( it1.hasNext() && it2.hasNext() ) {
    RowMetaAndData rm1 = it1.next();
    RowMetaAndData rm2 = it2.next();

    Object[] r1 = rm1.getData();
    Object[] r2 = rm2.getData();

    if ( rm1.size() != rm2.size() ) {
      fail( "row nr " + idx + " is not equal" );
    }
    int[] fields = new int[r1.length];
    for ( int ydx = 0; ydx < r1.length; ydx++ ) {
      fields[ydx] = ydx;
    }
    try {
      if ( rm1.getRowMeta().compare( r1, r2, fields ) != 0 ) {
        fail( "row nr " + idx + " is not equal" );
      }
    } catch ( KettleValueException e ) {
      fail( "row nr " + idx + " is not equal" );
    }

    idx++;
  }
}
 
Example 8
Source File: HopIT.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Check the 2 lists comparing the rows in order. If they are not the same fail the test.
 */
public void checkRows( List<RowMetaAndData> rows1, List<RowMetaAndData> rows2 ) {
  int idx = 1;
  if ( rows1.size() != rows2.size() ) {
    fail( "Number of rows is not the same: " + rows1.size() + " and " + rows2.size() );
  }
  Iterator<RowMetaAndData> it1 = rows1.iterator();
  Iterator<RowMetaAndData> it2 = rows2.iterator();

  while ( it1.hasNext() && it2.hasNext() ) {
    RowMetaAndData rm1 = it1.next();
    RowMetaAndData rm2 = it2.next();

    Object[] r1 = rm1.getData();
    Object[] r2 = rm2.getData();

    if ( r1.length != r2.length ) {
      fail( "row nr " + idx + "is not equal" );
    }
    int[] fields = new int[r1.length];
    for ( int ydx = 0; ydx < r1.length; ydx++ ) {
      fields[ydx] = ydx;
    }
    try {
      if ( rm1.getRowMeta().compare( r1, r2, fields ) != 0 ) {
        fail( "row nr " + idx + "is not equal" );
      }
    } catch ( KettleValueException e ) {
      fail( "row nr " + idx + "is not equal" );
    }

    idx++;
  }
}
 
Example 9
Source File: TableOutputIT.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Check the 2 lists comparing the rows in order. If they are not the same fail the test.
 */
public void checkRows( List<RowMetaAndData> rows1, List<RowMetaAndData> rows2 ) {
  int idx = 1;
  if ( rows1.size() != rows2.size() ) {
    fail( "Number of rows is not the same: " + rows1.size() + " and " + rows2.size() );
  }
  Iterator<RowMetaAndData> it1 = rows1.iterator();
  Iterator<RowMetaAndData> it2 = rows2.iterator();

  while ( it1.hasNext() && it2.hasNext() ) {
    RowMetaAndData rm1 = it1.next();
    RowMetaAndData rm2 = it2.next();

    Object[] r1 = rm1.getData();
    Object[] r2 = rm2.getData();

    if ( rm1.size() != rm2.size() ) {
      fail( "row nr " + idx + " is not equal" );
    }
    int[] fields = new int[r1.length];
    for ( int ydx = 0; ydx < r1.length; ydx++ ) {
      fields[ydx] = ydx;
    }
    try {
      if ( rm1.getRowMeta().compare( r1, r2, fields ) != 0 ) {
        fail( "row nr " + idx + " is not equal" );
      }
    } catch ( KettleValueException e ) {
      fail( "row nr " + idx + " is not equal" );
    }

    idx++;
  }
}
 
Example 10
Source File: InjectorIT.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Check the 2 lists comparing the rows in order. If they are not the same fail the test.
 */
public void checkRows( List<RowMetaAndData> rows1, List<RowMetaAndData> rows2 ) {
  int idx = 1;
  if ( rows1.size() != rows2.size() ) {
    fail( "Number of rows is not the same: " + rows1.size() + " and " + rows2.size() );
  }
  Iterator<RowMetaAndData> it1 = rows1.iterator();
  Iterator<RowMetaAndData> it2 = rows2.iterator();

  while ( it1.hasNext() && it2.hasNext() ) {
    RowMetaAndData rm1 = it1.next();
    RowMetaAndData rm2 = it2.next();

    Object[] r1 = rm1.getData();
    Object[] r2 = rm2.getData();

    if ( r1.length != r2.length ) {
      fail( "row nr " + idx + "is not equal" );
    }
    int[] fields = new int[r1.length];
    for ( int ydx = 0; ydx < r1.length; ydx++ ) {
      fields[ydx] = ydx;
    }
    try {
      if ( rm1.getRowMeta().compare( r1, r2, fields ) != 0 ) {
        fail( "row nr " + idx + "is not equal" );
      }
    } catch ( KettleValueException e ) {
      fail( "row nr " + idx + "is not equal" );
    }

    idx++;
  }
}
 
Example 11
Source File: ValueMapperIT.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Check the 2 lists comparing the rows in order. If they are not the same fail the test.
 */
public void checkRows( List<RowMetaAndData> rows1, List<RowMetaAndData> rows2 ) {
  int idx = 1;
  if ( rows1.size() != rows2.size() ) {
    fail( "Number of rows is not the same: " + rows1.size() + " and " + rows2.size() );
  }
  Iterator<RowMetaAndData> it1 = rows1.iterator();
  Iterator<RowMetaAndData> it2 = rows2.iterator();

  while ( it1.hasNext() && it2.hasNext() ) {
    RowMetaAndData rm1 = it1.next();
    RowMetaAndData rm2 = it2.next();

    Object[] r1 = rm1.getData();
    Object[] r2 = rm2.getData();

    if ( rm1.size() != rm2.size() ) {
      fail( "row nr " + idx + " is not equal" );
    }
    int[] fields = new int[r1.length];
    for ( int ydx = 0; ydx < r1.length; ydx++ ) {
      fields[ydx] = ydx;
    }
    try {
      if ( rm1.getRowMeta().compare( r1, r2, fields ) != 0 ) {
        fail( "row nr " + idx + " is not equal" );
      }
    } catch ( KettleValueException e ) {
      fail( "row nr " + idx + " is not equal" );
    }

    idx++;
  }
}
 
Example 12
Source File: AddSequenceIT.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Check the 2 lists comparing the rows in order. If they are not the same fail the test.
 */
public void checkRows( List<RowMetaAndData> rows1, List<RowMetaAndData> rows2 ) {
  int idx = 1;
  if ( rows1.size() != rows2.size() ) {
    fail( "Number of rows is not the same: " + rows1.size() + " and " + rows2.size() );
  }
  Iterator<RowMetaAndData> it1 = rows1.iterator();
  Iterator<RowMetaAndData> it2 = rows2.iterator();

  while ( it1.hasNext() && it2.hasNext() ) {
    RowMetaAndData rm1 = it1.next();
    RowMetaAndData rm2 = it2.next();

    Object[] r1 = rm1.getData();
    Object[] r2 = rm2.getData();

    if ( rm1.size() != rm2.size() ) {
      fail( "row nr " + idx + " is not equal" );
    }
    int[] fields = new int[rm1.size()];
    for ( int ydx = 0; ydx < rm1.size(); ydx++ ) {
      fields[ydx] = ydx;
    }
    try {
      if ( rm1.getRowMeta().compare( r1, r2, fields ) != 0 ) {
        fail( "row nr " + idx + " is not equal" );
      }
    } catch ( KettleValueException e ) {
      fail( "row nr " + idx + " is not equal" );
    }

    idx++;
  }
}
 
Example 13
Source File: SortRowsIT.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Check the list, the list has to be sorted.
 */
void checkStringRows( List<RowMetaAndData> rows, boolean ascending ) throws Exception {
  String prev_key1 = null, prev_key2 = null;
  int idx = 0;

  for ( RowMetaAndData rm : rows ) {
    Object[] r1 = rm.getData();
    RowMetaInterface rmi = rm.getRowMeta();

    String key1 = rmi.getString( r1, "KEY1", "" );
    String key2 = rmi.getString( r1, "KEY2", "" );

    if ( prev_key1 != null && prev_key2 != null ) {
      if ( ascending ) {
        if ( prev_key1.compareTo( key1 ) == 0 ) {
          if ( prev_key2.compareTo( key2 ) > 0 ) {
            fail( "error in sort" );
          }
        } else if ( prev_key1.compareTo( key1 ) > 0 ) {
          fail( "error in sort" );
        }
      } else {
        if ( prev_key1.compareTo( key1 ) == 0 ) {
          if ( prev_key2.compareTo( key2 ) < 0 ) {
            fail( "error in sort" );
          }
        } else if ( prev_key1.compareTo( key1 ) < 0 ) {
          fail( "error in sort" );
        }
      }
    }
    prev_key1 = key1;
    prev_key2 = key2;
    idx++;
  }
  Assert.assertEquals( "less rows returned than expected", MAX_COUNT, idx );
}
 
Example 14
Source File: JaninoStepIT.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Check the 2 lists comparing the rows in order. If they are not the same fail the test.
 */
public void checkRows( List<RowMetaAndData> rows1, List<RowMetaAndData> rows2 ) {
  int idx = 1;
  if ( rows1.size() != rows2.size() ) {
    fail( "Number of rows is not the same: " + rows1.size() + " and " + rows2.size() );
  }
  Iterator<RowMetaAndData> it1 = rows1.iterator();
  Iterator<RowMetaAndData> it2 = rows2.iterator();

  while ( it1.hasNext() && it2.hasNext() ) {
    RowMetaAndData rm1 = it1.next();
    RowMetaAndData rm2 = it2.next();

    Object[] r1 = rm1.getData();
    Object[] r2 = rm2.getData();

    if ( rm1.size() != rm2.size() ) {
      fail( "row nr " + idx + " is not equal" );
    }
    int[] fields = new int[rm1.size()];
    for ( int ydx = 0; ydx < rm1.size(); ydx++ ) {
      fields[ydx] = ydx;
    }
    try {
      if ( rm1.getRowMeta().compare( r1, r2, fields ) != 0 ) {
        fail( "row nr "
          + idx + "i s not equal (" + rm1.getRowMeta().getString( r1 ) + " != "
          + rm1.getRowMeta().getString( r2 ) + ")" );
      }
    } catch ( KettleValueException e ) {
      fail( "row nr " + idx + " is not equal" );
    }

    idx++;
  }
}
 
Example 15
Source File: MergeRowsIT.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 *  Check the 2 lists comparing the rows in order.
 *  If they are not the same fail the test.
 */
public void checkRows( List<RowMetaAndData> rows1, List<RowMetaAndData> rows2 ) {
  int idx = 1;
  if ( rows1.size() != rows2.size() ) {
    fail( "Number of rows is not the same: " + rows1.size() + " and " + rows2.size() );
  }
  Iterator<RowMetaAndData> it1 = rows1.iterator();
  Iterator<RowMetaAndData> it2 = rows2.iterator();

  while ( it1.hasNext() && it2.hasNext() ) {
    RowMetaAndData rm1 = it1.next();
    RowMetaAndData rm2 = it2.next();

    Object[] r1 = rm1.getData();
    Object[] r2 = rm2.getData();

    if ( rm1.size() != rm2.size() ) {
      fail( "row size of row at " + idx + " is not equal (" + rm1.size() + "," + rm2.size() + ")" );
    }
    int[] fields = new int[1];
    for ( int ydx = 0; ydx < rm1.size(); ydx++ ) {
      fields[0] = ydx;
      try {
        if ( rm1.getRowMeta().compare( r1, r2, fields ) != 0 ) {
          fail( "row nr " + idx + " is not equal at field nr "
            + ydx + "(" + rm1.toString() + ";" + rm2.toString() + ")" );
        }
      } catch ( KettleValueException e ) {
        fail( "row nr " + idx + " is not equal at field nr "
          + ydx + "(" + rm1.toString() + ";" + rm2.toString() + ")" );
      }
    }

    idx++;
  }
}
 
Example 16
Source File: RowGeneratorIT.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Check the 2 lists comparing the rows in order. If they are not the same fail the test.
 */
public void checkRows( List<RowMetaAndData> rows1, List<RowMetaAndData> rows2 ) {
  int idx = 1;
  if ( rows1.size() != rows2.size() ) {
    fail( "Number of rows is not the same: " + rows1.size() + " and " + rows2.size() );
  }
  Iterator<RowMetaAndData> it1 = rows1.iterator();
  Iterator<RowMetaAndData> it2 = rows2.iterator();

  while ( it1.hasNext() && it2.hasNext() ) {
    RowMetaAndData rm1 = it1.next();
    RowMetaAndData rm2 = it2.next();

    Object[] r1 = rm1.getData();
    Object[] r2 = rm2.getData();

    if ( rm1.size() != rm2.size() ) {
      fail( "row nr " + idx + " is not equal" );
    }
    int[] fields = new int[rm1.size()];
    for ( int ydx = 0; ydx < rm1.size(); ydx++ ) {
      fields[ydx] = ydx;
    }
    try {
      if ( rm1.getRowMeta().compare( r1, r2, fields ) != 0 ) {
        fail( "row nr " + idx + "is not equal" );
      }
    } catch ( KettleValueException e ) {
      fail( "row nr " + idx + "is not equal" );
    }

    idx++;
  }
}
 
Example 17
Source File: KettleDatabaseRepositoryConditionDelegate.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public synchronized ObjectId lookupValue( String name, String type, String value_str, boolean isnull ) throws KettleException {
  RowMetaAndData table = new RowMetaAndData();
  table.addValue(
    new ValueMetaString( KettleDatabaseRepository.FIELD_VALUE_NAME ), name );
  table.addValue(
    new ValueMetaString( KettleDatabaseRepository.FIELD_VALUE_VALUE_TYPE ), type );
  table
    .addValue(
      new ValueMetaString( KettleDatabaseRepository.FIELD_VALUE_VALUE_STR ),
      value_str );
  table.addValue(
    new ValueMetaBoolean( KettleDatabaseRepository.FIELD_VALUE_IS_NULL ), Boolean
      .valueOf( isnull ) );

  String sql =
    "SELECT "
      + quote( KettleDatabaseRepository.FIELD_VALUE_ID_VALUE ) + " FROM "
      + quoteTable( KettleDatabaseRepository.TABLE_R_VALUE ) + " ";
  sql += "WHERE " + quote( KettleDatabaseRepository.FIELD_VALUE_NAME ) + "       = ? ";
  sql += "AND   " + quote( KettleDatabaseRepository.FIELD_VALUE_VALUE_TYPE ) + " = ? ";
  sql += "AND   " + quote( KettleDatabaseRepository.FIELD_VALUE_VALUE_STR ) + "  = ? ";
  sql += "AND   " + quote( KettleDatabaseRepository.FIELD_VALUE_IS_NULL ) + "    = ? ";

  RowMetaAndData result = repository.connectionDelegate.getOneRow( sql, table.getRowMeta(), table.getData() );
  if ( result != null && result.getData() != null && result.isNumeric( 0 ) ) {
    return new LongObjectId( result.getInteger( 0, 0L ) );
  } else {
    return null;
  }
}
 
Example 18
Source File: KettleDatabaseRepositoryConnectionDelegate.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public synchronized String getStringWithID( String tablename, String keyfield, ObjectId id, String fieldname )
  throws KettleException {
  String sql = "SELECT " + fieldname + " FROM " + tablename + " WHERE " + keyfield + " = ?";
  RowMetaAndData par = new RowMetaAndData();
  par.addValue( new ValueMetaInteger( keyfield ), id );
  RowMetaAndData result = getOneRow( sql, par.getRowMeta(), par.getData() );
  if ( result != null && result.getData() != null ) {
    return result.getString( 0, null );
  }
  return null;
}
 
Example 19
Source File: ConstantIT.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Check the 2 lists comparing the rows in order. If they are not the same fail the test.
 */
public void checkRows( List<RowMetaAndData> rows1, List<RowMetaAndData> rows2 ) {
  int idx = 1;
  if ( rows1.size() != rows2.size() ) {
    fail( "Number of rows is not the same: " + rows1.size() + " and " + rows2.size() );
  }
  Iterator<RowMetaAndData> it1 = rows1.iterator();
  Iterator<RowMetaAndData> it2 = rows2.iterator();

  while ( it1.hasNext() && it2.hasNext() ) {
    RowMetaAndData rm1 = it1.next();
    RowMetaAndData rm2 = it2.next();

    Object[] r1 = rm1.getData();
    Object[] r2 = rm2.getData();

    if ( rm1.size() != rm2.size() ) {
      fail( "row nr " + idx + " is not equal" );
    }
    int[] fields = new int[rm1.size()];
    for ( int ydx = 0; ydx < rm1.size(); ydx++ ) {
      fields[ydx] = ydx;
    }
    try {
      if ( rm1.getRowMeta().compare( r1, r2, fields ) != 0 ) {
        fail( "row nr " + idx + " is not equal" );
      }
    } catch ( KettleValueException e ) {
      fail( "row nr " + idx + " is not equal" );
    }

    idx++;
  }
}
 
Example 20
Source File: TestUtilities.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Check the 2 lists comparing the rows in order. If they are not the same fail the test.
 *
 * @param rows1          set 1 of rows to compare
 * @param rows2          set 2 of rows to compare
 * @param fileNameColumn Number of the column containing the filename. This is only checked for being non-null (some
 *                       systems maybe canonize names differently than we input).
 */
public static void checkRows( List<RowMetaAndData> rows1, List<RowMetaAndData> rows2, int fileNameColumn )
  throws TestFailedException {

  int idx = 1;
  if ( rows1.size() != rows2.size() ) {
    throw new TestFailedException( "Number of rows is not the same: " + rows1.size() + " and " + rows2.size() );
  }
  Iterator<RowMetaAndData> itrRows1 = rows1.iterator();
  Iterator<RowMetaAndData> itrRows2 = rows2.iterator();

  while ( itrRows1.hasNext() && itrRows2.hasNext() ) {
    RowMetaAndData rowMetaAndData1 = itrRows1.next();
    RowMetaAndData rowMetaAndData2 = itrRows2.next();

    RowMetaInterface rowMetaInterface1 = rowMetaAndData1.getRowMeta();

    Object[] rowObject1 = rowMetaAndData1.getData();
    Object[] rowObject2 = rowMetaAndData2.getData();

    if ( rowMetaAndData1.size() != rowMetaAndData2.size() ) {
      throw new TestFailedException( "row number " + idx + " is not equal" );
    }

    int[] fields = new int[ rowMetaInterface1.size() ];
    for ( int ydx = 0; ydx < rowMetaInterface1.size(); ydx++ ) {
      fields[ ydx ] = ydx;
    }

    try {
      if ( fileNameColumn >= 0 ) {
        rowObject1[ fileNameColumn ] = rowObject2[ fileNameColumn ];
      }
      if ( rowMetaAndData1.getRowMeta().compare( rowObject1, rowObject2, fields ) != 0 ) {
        throw new ComparisonFailure( "row nr " + idx + " is not equal",
        rowMetaInterface1.getString( rowObject1 ),
        rowMetaInterface1.getString( rowObject2 ) ); 
      }
    } catch ( KettleValueException e ) {
      throw new TestFailedException( "row nr " + idx + " is not equal" );
    }
    idx++;
  }
}