org.pentaho.di.core.exception.KettleValueException Java Examples

The following examples show how to use org.pentaho.di.core.exception.KettleValueException. 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: ValueMetaInternetAddressTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void testCompare_Representations() throws UnknownHostException, KettleValueException {
  ValueMetaInternetAddress vm = new ValueMetaInternetAddress();

  InetAddress extended = InetAddress.getByName( "1080:0:0:0:8:800:200C:417A" );
  InetAddress condensed = InetAddress.getByName( "1080::8:800:200C:417A" );

  assertEquals( 0, vm.compare( extended, condensed ) );
  assertEquals( 0, vm.compare( condensed, extended ) );

  extended = InetAddress.getByName( "0:0:0:0:0:0:0:1" );
  condensed = InetAddress.getByName( "::1" );

  assertEquals( 0, vm.compare( extended, condensed ) );
  assertEquals( 0, vm.compare( condensed, extended ) );

  extended = InetAddress.getByName( "0:0:0:0:0:0:0:0" );
  condensed = InetAddress.getByName( "::0" );

  assertEquals( 0, vm.compare( extended, condensed ) );
  assertEquals( 0, vm.compare( condensed, extended ) );
}
 
Example #2
Source File: GraphOutput.java    From knowbi-pentaho-pdi-neo4j-output with Apache License 2.0 6 votes vote down vote up
public String getGraphNodeDataId( GraphNode node, List<NodeAndPropertyData> nodeProperties ) throws KettleValueException {

    StringBuffer id = new StringBuffer();

    for ( NodeAndPropertyData napd : nodeProperties ) {
      if ( napd.node.equals( node ) ) {
        if ( napd.property.isPrimary() ) {

          String propertyString = napd.sourceValueMeta.getString( napd.sourceValueData );
          if ( id.length() > 0 ) {
            id.append( "-" );
          }
          id.append( propertyString );
        }
      }
    }
    return id.toString();
  }
 
Example #3
Source File: ValueMetaBase.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
/**
 * Convert the binary data to the actual data type.<br>
 * - byte[] --> Long (Integer) - byte[] --> Double (Number) - byte[] --> BigDecimal (BigNumber) - byte[] --> Date
 * (Date) - byte[] --> Boolean (Boolean) - byte[] --> byte[] (Binary)
 *
 * @param binary
 * @return
 * @throws KettleValueException
 */
@Override
public Object convertBinaryStringToNativeType( byte[] binary ) throws KettleValueException {
  if ( binary == null ) {
    return null;
  }

  numberOfBinaryStringConversions++;

  // OK, so we have an internal representation of the original object, read
  // from file.
  // First we decode it in the correct encoding
  //
  String string = convertBinaryStringToString( binary );

  // In this method we always must convert the data.
  // We use the storageMetadata object to convert the binary string object.
  //
  // --> Convert from the String format to the current data type...
  //
  return convertData( storageMetadata, string );
}
 
Example #4
Source File: ValueMetaInternetAddress.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
protected InetAddress convertIntegerToInternetAddress( Long l ) throws KettleValueException {
  if ( l == null ) {
    return null;
  }

  byte[] addr;
  if ( l >= Math.pow( 256, 4 ) ) {
    addr = new byte[16];
  } else {
    addr = new byte[4];
  }

  for ( int i = 0; i < addr.length; i++ ) {
    long mask = 0xFF << ( i * 8 );
    addr[addr.length - 1 - i] = (byte) ( ( l & mask ) >> ( 8 * i ) );
  }

  try {
    return InetAddress.getByAddress( addr );
  } catch ( Exception e ) {
    throw new KettleValueException( "Unable to convert an Integer to an internet address", e );
  }
}
 
Example #5
Source File: TableProducerTest.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void rowWrittenEvent_boolean() throws KettleStepException, ReportDataFactoryException, KettleValueException {
  Boolean[] row = new Boolean[] { true };
  RowMetaInterface rowMetaInterface = mock( RowMetaInterface.class );
  when( rowMetaInterface.size() ).thenReturn( 1 );

  ValueMetaInterface valueMeta1 = mock( ValueMetaInterface.class );
  when( valueMeta1.getName() ).thenReturn( "COLUMN_1" );
  when( valueMeta1.getType() ).thenReturn( ValueMetaInterface.TYPE_BOOLEAN );
  when( rowMetaInterface.getValueMeta( eq( 0 ) ) ).thenReturn( valueMeta1 );
  when( rowMetaInterface.getBoolean( eq( row ), eq( 0 ) ) ).thenReturn( row[0] );

  TableProducer tableProducer = new TableProducer( rowMetaInterface, 0, true );
  tableProducer.rowWrittenEvent( rowMetaInterface, row );

  TypedTableModel expectedModel = new TypedTableModel( new String[] { "COLUMN_1" }, new Class[] { Boolean.class } );
  expectedModel.addRow( true );

  assertEquals( expectedModel, tableProducer.getTableModel() );
}
 
Example #6
Source File: ValueDataUtil.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
/**
 * Rounding with no decimal places (using default rounding method ROUND_HALF_CEILING)
 *
 * @param metaA
 *          Metadata of value to round
 * @param dataA
 *          Value to round
 * @return The rounded value
 * @throws KettleValueException
 */
public static Object round( ValueMetaInterface metaA, Object dataA ) throws KettleValueException {
  if ( dataA == null ) {
    return null;
  }

  switch ( metaA.getType() ) {
    case ValueMetaInterface.TYPE_NUMBER:
      return new Double( Math.round( metaA.getNumber( dataA ).doubleValue() ) );
    case ValueMetaInterface.TYPE_INTEGER:
      return metaA.getInteger( dataA );
    case ValueMetaInterface.TYPE_BIGNUMBER:
      return new BigDecimal( Math.round( metaA.getNumber( dataA ).doubleValue() ) );

    default:
      throw new KettleValueException( "The 'round' function only works on numeric data" );
  }
}
 
Example #7
Source File: TableProducerTest.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void rowWrittenEvent_none() throws KettleStepException, ReportDataFactoryException, KettleValueException {
  String[] row = new String[] { "NONE" };
  RowMetaInterface rowMetaInterface = mock( RowMetaInterface.class );
  when( rowMetaInterface.size() ).thenReturn( 1 );

  ValueMetaInterface valueMeta1 = mock( ValueMetaInterface.class );
  when( valueMeta1.getName() ).thenReturn( "COLUMN_1" );
  when( valueMeta1.getType() ).thenReturn( ValueMetaInterface.TYPE_NONE );
  when( rowMetaInterface.getValueMeta( eq( 0 ) ) ).thenReturn( valueMeta1 );
  when( rowMetaInterface.getString( eq( row ), eq( 0 ) ) ).thenReturn( row[0] );

  TableProducer tableProducer = new TableProducer( rowMetaInterface, 0, true );
  tableProducer.rowWrittenEvent( rowMetaInterface, row );

  TypedTableModel expectedModel = new TypedTableModel( new String[] { "COLUMN_1" }, new Class[] { String.class } );
  expectedModel.addRow( "NONE" );

  assertEquals( expectedModel, tableProducer.getTableModel() );
}
 
Example #8
Source File: ValueMetaBase.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
/**
 * Convert the specified data to the data type specified in this object.
 *
 * @param meta2
 *          the metadata of the object to be converted
 * @param data2
 *          the data of the object to be converted
 * @return the object in the data type of this value metadata object
 * @throws KettleValueException
 *           in case there is a data conversion error
 */
@Override
public Object convertData( ValueMetaInterface meta2, Object data2 ) throws KettleValueException {
  switch ( getType() ) {
    case TYPE_NONE:
    case TYPE_STRING:
      return meta2.getString( data2 );
    case TYPE_NUMBER:
      return meta2.getNumber( data2 );
    case TYPE_INTEGER:
      return meta2.getInteger( data2 );
    case TYPE_DATE:
      return meta2.getDate( data2 );
    case TYPE_BIGNUMBER:
      return meta2.getBigNumber( data2 );
    case TYPE_BOOLEAN:
      return meta2.getBoolean( data2 );
    case TYPE_BINARY:
      return meta2.getBinary( data2 );
    default:
      throw new KettleValueException( toString() + " : I can't convert the specified value to data type : "
          + getType() );
  }
}
 
Example #9
Source File: StringUtil.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public static Date str2dat( String arg0, String arg1, String val ) throws KettleValueException {
  SimpleDateFormat df = new SimpleDateFormat();

  DateFormatSymbols dfs = new DateFormatSymbols();
  if ( arg1 != null ) {
    dfs.setLocalPatternChars( arg1 );
  }
  if ( arg0 != null ) {
    df.applyPattern( arg0 );
  }

  try {
    return df.parse( val );
  } catch ( Exception e ) {
    throw new KettleValueException( "TO_DATE Couldn't convert String to Date " + e.toString() );
  }
}
 
Example #10
Source File: ValueDataUtil.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
/**
 * Rounding with no decimal places with a given rounding method
 *
 * @param metaA
 *          Metadata of value to round
 * @param dataA
 *          Value to round
 * @param roundingMode
 *          The mode for rounding, e.g. java.math.BigDecimal.ROUND_HALF_EVEN
 * @return The rounded value
 * @throws KettleValueException
 */
public static Object round( ValueMetaInterface metaA, Object dataA, int roundingMode ) throws KettleValueException {
  if ( dataA == null ) {
    return null;
  }

  switch ( metaA.getType() ) {
  // Use overloaded Const.round(value, precision, mode)
    case ValueMetaInterface.TYPE_NUMBER:
      return new Double( Const.round( metaA.getNumber( dataA ), 0, roundingMode ) );
    case ValueMetaInterface.TYPE_INTEGER:
      return new Long( Const.round( metaA.getInteger( dataA ), 0, roundingMode ) );
    case ValueMetaInterface.TYPE_BIGNUMBER:
      return Const.round( metaA.getBigNumber( dataA ), 0, roundingMode );
    default:
      throw new KettleValueException( "The 'round' function only works on numeric data" );
  }
}
 
Example #11
Source File: ValueDataUtil.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public static Object hourOfDay( ValueMetaInterface metaA, Object dataA ) throws KettleValueException {
  if ( dataA == null ) {
    return null;
  }

  Calendar calendar = Calendar.getInstance();
  calendar.setTime( metaA.getDate( dataA ) );

  Boolean oldDateCalculation = Boolean.parseBoolean(
    Const.getEnvironmentVariable( Const.KETTLE_COMPATIBILITY_CALCULATION_TIMEZONE_DECOMPOSITION, "false" ) );
  if ( !oldDateCalculation ) {
    calendar.setTimeZone( metaA.getDateFormatTimeZone() );
  }

  return new Long( calendar.get( Calendar.HOUR_OF_DAY ) );
}
 
Example #12
Source File: ValueMetaBase.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
/**
 * Converts the specified data object to the binary string storage type.
 *
 * @param object
 *          the data object to convert
 * @return the data in a binary string storage type
 * @throws KettleValueException
 *           In case there is a data conversion error.
 */
@Override
public Object convertToBinaryStringStorageType( Object object ) throws KettleValueException {
  if ( object == null ) {
    return null;
  }

  switch ( storageType ) {
    case STORAGE_TYPE_NORMAL:
      return convertNormalStorageTypeToBinaryString( object );
    case STORAGE_TYPE_BINARY_STRING:
      return object;
    case STORAGE_TYPE_INDEXED:
      return convertNormalStorageTypeToBinaryString( index[(Integer) object] );
    default:
      throw new KettleValueException( toStringMeta() + " : Unknown storage type [" + storageType
          + "] while converting to normal storage type" );
  }
}
 
Example #13
Source File: ValueDataUtil.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
protected static Object multiplyString( ValueMetaInterface metaA, Object dataA, ValueMetaInterface metaB,
  Object dataB ) throws KettleValueException {
  StringBuffer s;
  String append = "";
  int n;
  if ( metaB.isString() ) {
    s = new StringBuffer( metaB.getString( dataB ) );
    append = metaB.getString( dataB );
    n = metaA.getInteger( dataA ).intValue();
  } else {
    s = new StringBuffer( metaA.getString( dataA ) );
    append = metaA.getString( dataA );
    n = metaB.getInteger( dataB ).intValue();
  }

  if ( n == 0 ) {
    s.setLength( 0 );
  } else {
    for ( int i = 1; i < n; i++ ) {
      s.append( append );
    }
  }

  return s.toString();
}
 
Example #14
Source File: ValueMetaBase.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
protected synchronized String convertIntegerToString( Long integer ) throws KettleValueException {
  if ( integer == null ) {
    if ( !outputPaddingEnabled || length < 1 ) {
      return null;
    } else {
      // Return strings padded to the specified length...
      // This is done for backward compatibility with 2.5.x
      // We just optimized this a bit...
      //
      String[] emptyPaddedStrings = Const.getEmptyPaddedStrings();
      if ( length < emptyPaddedStrings.length ) {
        return emptyPaddedStrings[length];
      } else {
        return Const.rightPad( "", length );
      }
    }
  }

  try {
    return getDecimalFormat( false ).format( integer );
  } catch ( Exception e ) {
    throw new KettleValueException( toString() + " : couldn't convert Long to String ", e );
  }
}
 
Example #15
Source File: ValueMetaBase.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
/**
 * Convert the specified data to the data type specified in this object. For String conversion, be compatible with
 * version 2.5.2.
 *
 * @param meta2
 *          the metadata of the object to be converted
 * @param data2
 *          the data of the object to be converted
 * @return the object in the data type of this value metadata object
 * @throws KettleValueException
 *           in case there is a data conversion error
 */
@Override
public Object convertDataCompatible( ValueMetaInterface meta2, Object data2 ) throws KettleValueException {
  switch ( getType() ) {
    case TYPE_STRING:
      return meta2.getCompatibleString( data2 );
    case TYPE_NUMBER:
      return meta2.getNumber( data2 );
    case TYPE_INTEGER:
      return meta2.getInteger( data2 );
    case TYPE_DATE:
      return meta2.getDate( data2 );
    case TYPE_BIGNUMBER:
      return meta2.getBigNumber( data2 );
    case TYPE_BOOLEAN:
      return meta2.getBoolean( data2 );
    case TYPE_BINARY:
      return meta2.getBinary( data2 );
    default:
      throw new KettleValueException( toString() + " : I can't convert the specified value to data type : "
          + getType() );
  }
}
 
Example #16
Source File: RowForumulaContext.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
/**
 * We return the content of a Value with the given name. We cache the position of the field indexes.
 *
 * @see org.jfree.formula.FormulaContext#resolveReference(java.lang.Object)
 */
public Object resolveReference( Object name ) throws EvaluationException {
  if ( name instanceof String ) {
    ValueMetaInterface valueMeta;
    Integer idx = valueIndexMap.get( name );
    if ( idx != null ) {
      valueMeta = rowMeta.getValueMeta( idx.intValue() );
    } else {
      int index = rowMeta.indexOfValue( (String) name );
      if ( index < 0 ) {
        ErrorValue errorValue = new LibFormulaErrorValue( LibFormulaErrorValue.ERROR_INVALID_ARGUMENT );
        throw new EvaluationException( errorValue );
      }
      valueMeta = rowMeta.getValueMeta( index );
      idx = new Integer( index );
      valueIndexMap.put( (String) name, idx );
    }
    Object valueData = rowData[idx];
    try {
      return getPrimitive( valueMeta, valueData );
    } catch ( KettleValueException e ) {
      throw new EvaluationException( LibFormulaErrorValue.ERROR_ARITHMETIC_VALUE );
    }
  }
  return null;
}
 
Example #17
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 #18
Source File: DetectLastRowStepIT.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.
 *
 * @param rows1
 *          first row set to compare
 * @param rows2
 *          second row set to compare
 */
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 #19
Source File: RowMetaAndData.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public long getInteger( String valueName, long def ) throws KettleValueException {
  int idx = rowMeta.indexOfValue( valueName );
  if ( idx < 0 ) {
    throw new KettleValueException( "Unknown column '" + valueName + "'" );
  }
  return getInteger( idx, def );
}
 
Example #20
Source File: ValueMetaBase.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Override
public Object getNativeDataType( Object object ) throws KettleValueException {
  switch ( getStorageType() ) {
    case STORAGE_TYPE_BINARY_STRING:
      return convertBinaryStringToNativeType( (byte[]) object );
    case STORAGE_TYPE_INDEXED:
      return index[(Integer) object];
    case STORAGE_TYPE_NORMAL:
    default:
      return object;
  }
}
 
Example #21
Source File: RowDataUtilTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public void testAddRowData() throws KettleValueException {
  Object[] arr = new Object[] { new Long( 1L ), new Long( 2L ), new Long( 3L ) };

  // Do all different combinations of adding rows to
  // each other
  Object[] newArr1 =
    RowDataUtil.addRowData(
      new Object[] {}, 0, new Object[] { new Long( 1L ), new Long( 2L ), new Long( 3L ) } );
  assertTrue( newArr1.length >= arr.length );
  assertTrue( arrayCompare( newArr1, 0, arr, 0, arr.length ) );

  Object[] newArr2 =
    RowDataUtil.addRowData(
      new Object[] { new Long( 1L ), new Long( 2L ), new Long( 3L ) }, 3, new Object[] {} );
  assertTrue( newArr2.length >= arr.length );
  assertTrue( arrayCompare( newArr2, 0, arr, 0, arr.length ) );

  Object[] newArr3 =
    RowDataUtil.addRowData(
      new Object[] { new Long( 1L ) }, 1, new Object[] { new Long( 2L ), new Long( 3L ) } );
  assertTrue( newArr3.length >= arr.length );
  assertTrue( arrayCompare( newArr3, 0, arr, 0, arr.length ) );

  Object[] newArr4 =
    RowDataUtil.addRowData(
      new Object[] { new Long( 1L ), new Long( 2L ) }, 2, new Object[] { new Long( 3L ) } );
  assertTrue( newArr4.length >= arr.length );
  assertTrue( arrayCompare( newArr4, 0, arr, 0, arr.length ) );
}
 
Example #22
Source File: DenormaliserAggregationsTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * PDI-9662 respect to KETTLE_AGGREGATION_ALL_NULLS_ARE_ZERO variable
 *
 * @throws KettleValueException
 */
@Test
public void testBuildResultWithNullsY() throws KettleValueException {
  step.setAllNullsAreZero( true );

  Object[] rowData = new Object[10];
  data.targetResult = new Object[1];
  // this removal of input rows?
  RowMetaInterface rmi = testSumPreconditions( "-" );
  data.removeNrs = new int[]{ 0 };
  Object[] outputRowData = step.buildResult( rmi, rowData );

  Assert.assertEquals( "Output row: nulls are zeros", new Long( 0 ), outputRowData[2] );
}
 
Example #23
Source File: RowMeta.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Get a Number value from a row of data. Convert data if this needed.
 *
 * @param dataRow the row of data
 * @param index   the index
 * @return The number found on that position in the row
 * @throws KettleValueException in case there was a problem converting the data.
 */
@Override
public Double getNumber( Object[] dataRow, int index ) throws KettleValueException {
  if ( dataRow == null ) {
    return null;
  }
  ValueMetaInterface meta = getValueMeta( index );
  return meta.getNumber( dataRow[ index ] );
}
 
Example #24
Source File: ValueDataUtil.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public static Object weekOfYear( ValueMetaInterface metaA, Object dataA ) throws KettleValueException {
  if ( dataA == null ) {
    return null;
  }

  Calendar calendar = Calendar.getInstance();
  calendar.setTime( metaA.getDate( dataA ) );
  return new Long( calendar.get( Calendar.WEEK_OF_YEAR ) );
}
 
Example #25
Source File: Value.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public Value atan2( double arg0 ) throws KettleValueException {
  if ( isNull() ) {
    return this;
  }

  if ( isNumeric() ) {
    setValue( Math.atan2( getNumber(), arg0 ) );
  } else {
    throw new KettleValueException( "Function ATAN2 only works with numbers" );
  }
  return this;
}
 
Example #26
Source File: JobEntryDeleteFiles.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * For job execution path to files and file masks should be provided.
 * These values can be obtained in two ways:
 * 1. As an argument of a current job entry
 * 2. As a table, that comes as a result of execution previous job/transformation.
 *
 * As the logic of processing this data is the same for both of this cases, we first
 * populate this data (in this method) and then process it.
 *
 * We are using guava multimap here, because if allows key duplication and there could be a
 * situation where two paths to one folder with different wildcards are provided.
 */
private Multimap<String, String> populateDataForJobExecution( List<RowMetaAndData> rowsFromPreviousMeta ) throws KettleValueException {
  Multimap<String, String> pathToMaskMap = ArrayListMultimap.create();
  if ( argFromPrevious && rowsFromPreviousMeta != null ) {
    for ( RowMetaAndData resultRow : rowsFromPreviousMeta ) {
      if ( resultRow.size() < 2 ) {
        logError( BaseMessages.getString(
          PKG, "JobDeleteFiles.Error.InvalidNumberOfRowsFromPrevMeta", resultRow.size() ) );
        return pathToMaskMap;
      }
      String pathToFile = resultRow.getString( 0, null );
      String fileMask = resultRow.getString( 1, null );

      if ( log.isDetailed() ) {
        logDetailed( BaseMessages.getString(
          PKG, "JobEntryDeleteFiles.ProcessingRow", pathToFile, fileMask ) );
      }

      pathToMaskMap.put( pathToFile, fileMask );
    }
  } else if ( arguments != null ) {
    for ( int i = 0; i < arguments.length; i++ ) {
      if ( log.isDetailed() ) {
        logDetailed( BaseMessages.getString(
          PKG, "JobEntryDeleteFiles.ProcessingArg", arguments[ i ], filemasks[ i ] ) );
      }
      pathToMaskMap.put( arguments[ i ], filemasks[ i ] );
    }
  }

  return pathToMaskMap;
}
 
Example #27
Source File: GPLoadDataOutputTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
public void testWritiLine_Date() throws KettleValueException, ParseException {
  String sampleDate = "2000-10-09";
  Date sample = DateDetector.getDateFromString( sampleDate );
  Mockito.when( value.getType() ).thenReturn( ValueMetaInterface.TYPE_DATE );
  Mockito.when( mi.getDate( Mockito.any( Object[].class ), Mockito.anyInt() ) ).thenReturn( sample );
  testWritiLine( new String[] { String.valueOf( sample ) }, value, sampleDate + Const.CR );
}
 
Example #28
Source File: ValueMetaInternetAddress.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
protected synchronized String convertInternetAddressToString( InetAddress inetAddress ) throws KettleValueException {

    if ( inetAddress == null ) {
      return null;
    }

    return inetAddress.getHostAddress();
  }
 
Example #29
Source File: RowMeta.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Get an Integer value from a row of data. Convert data if this needed.
 *
 * @param dataRow the row of data
 * @param index   the index
 * @return The integer found on that position in the row
 * @throws KettleValueException in case there was a problem converting the data.
 */
@Override
public Long getInteger( Object[] dataRow, int index ) throws KettleValueException {
  if ( dataRow == null ) {
    return null;
  }
  ValueMetaInterface meta = getValueMeta( index );
  return meta.getInteger( dataRow[ index ] );
}
 
Example #30
Source File: SortRowsIT.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private void checkGrouppingFieldSort( List<RowMetaAndData> list, boolean asc ) throws KettleValueException {
  Long prev = null;
  List<Long> actual = new ArrayList<Long>();
  List<Long> expected = new ArrayList<Long>();
  for ( RowMetaAndData row : list ) {
    Long group = row.getInteger( INTG1 );
    if ( prev == null ) {
      // first row
      prev = group;
    }
    if ( !prev.equals( group ) ) {
      // group has changed
      // do assertion
      if ( asc ) {
        Collections.sort( expected );
        Assert.assertEquals( "Values under one group properly sorted asc", expected, actual );
      } else {
        Collections.sort( expected );
        Collections.reverse( expected );
        Assert.assertEquals( "Values under one group properly sorted desc", expected, actual );
      }
      actual.clear();
      expected.clear();
    }
    prev = group;

    Long value = row.getInteger( INT );
    actual.add( value );
    expected.add( value );
  }
}