/** * Get a String value from a row of data. Convert data if this needed. * * @param dataRow the row of data * @param index the index * @return The string found on that position in the row * @throws KettleValueException in case there was a problem converting the data. */ @Override public String getString( Object[] dataRow, int index ) throws KettleValueException { if ( dataRow == null ) { return null; } ValueMetaInterface meta = getValueMeta( index ); return meta.getString( dataRow[ index ] ); }
/** * 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 ] ); }
/** * Get a BigNumber value from a row of data. Convert data if this needed. * * @param dataRow the row of data * @param index the index * @return The bignumber found on that position in the row * @throws KettleValueException in case there was a problem converting the data. */ @Override public BigDecimal getBigNumber( Object[] dataRow, int index ) throws KettleValueException { if ( dataRow == null ) { return null; } ValueMetaInterface meta = getValueMeta( index ); return meta.getBigNumber( dataRow[ index ] ); }
/** * Determines whether a value in a row is null. A value is null when the object is null or when it's an empty String * * @param dataRow The row of data * @param index the index to reference * @return true if the value on the index is null. * @throws KettleValueException in case there is a conversion error (only thrown in case of lazy conversion) */ @Override public boolean isNull( Object[] dataRow, int index ) throws KettleValueException { if ( dataRow == null ) { // I guess so... return true; } return getValueMeta( index ).isNull( dataRow[ index ] ); }
/** * 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 ] ); }
/** * Get a Date value from a row of data. Convert data if this needed. * * @param dataRow the row of data * @param index the index * @return The date found on that position in the row * @throws KettleValueException in case there was a problem converting the data. */ @Override public Date getDate( Object[] dataRow, int index ) throws KettleValueException { if ( dataRow == null ) { return null; } ValueMetaInterface meta = getValueMeta( index ); return meta.getDate( dataRow[ index ] ); }
/** * Get a Binary value from a row of data. Convert data if this needed. * * @param dataRow the row of data * @param index the index * @return The binary found on that position in the row * @throws KettleValueException in case there was a problem converting the data. */ @Override public byte[] getBinary( Object[] dataRow, int index ) throws KettleValueException { if ( dataRow == null ) { return null; } ValueMetaInterface meta = getValueMeta( index ); return meta.getBinary( dataRow[ index ] ); }
/** * Get a Boolean value from a row of data. Convert data if this needed. * * @param dataRow the row of data * @param index the index * @return The boolean found on that position in the row * @throws KettleValueException in case there was a problem converting the data. */ @Override public Boolean getBoolean( Object[] dataRow, int index ) throws KettleValueException { if ( dataRow == null ) { return null; } ValueMetaInterface meta = getValueMeta( index ); return meta.getBoolean( dataRow[ index ] ); }
/** * @param rowData the row of data to serialize as XML * @return an XML representation of the row data * @throws IOException Thrown in case there is an (Base64/GZip) encoding problem */ @Override public String getDataXML( Object[] rowData ) throws IOException { StringBuilder xml = new StringBuilder(); xml.append( "<" ).append( XML_DATA_TAG ).append( ">" ); lock.readLock().lock(); try { for ( int i = 0; i < size(); i++ ) { xml.append( getValueMeta( i ).getDataXML( rowData[ i ] ) ); } } finally { lock.readLock().unlock(); } xml.append( "</" ).append( XML_DATA_TAG ).append( ">" ); return xml.toString(); }
/** * @return an XML representation of the row metadata * @throws IOException Thrown in case there is an (Base64/GZip) encoding problem */ @Override public String getMetaXML() throws IOException { StringBuilder xml = new StringBuilder(); xml.append( "<" ).append( XML_META_TAG ).append( ">" ); lock.readLock().lock(); try { for ( int i = 0; i < size(); i++ ) { xml.append( getValueMeta( i ).getMetaXML() ); } } finally { lock.readLock().unlock(); } xml.append( "</" ).append( XML_META_TAG ).append( ">" ); return xml.toString(); }
/** * Compare 2 rows with each other using certain values in the rows and also considering the specified ascending * clauses of the value metadata. * * @param rowData1 The first row of data * @param rowData2 The second row of data * @param fieldnrs the fields to compare on (in that order) * @return 0 if the rows are considered equal, -1 is data1 is smaller, 1 if data2 is smaller. * @throws KettleValueException */ @Override public int compare( Object[] rowData1, Object[] rowData2, int[] fieldnrs ) throws KettleValueException { lock.readLock().lock(); try { for ( int fieldnr : fieldnrs ) { ValueMetaInterface valueMeta = getValueMeta( fieldnr ); int cmp = valueMeta.compare( rowData1[ fieldnr ], rowData2[ fieldnr ] ); if ( cmp != 0 ) { return cmp; } } return 0; } finally { lock.readLock().unlock(); } }
/** * Compare 2 rows with each other for equality using certain values in the rows and also considering the case * sensitivity flag. * * @param rowData1 The first row of data * @param rowData2 The second row of data * @param fieldnrs the fields to compare on (in that order) * @return true if the rows are considered equal, false if they are not. * @throws KettleValueException */ @Override public boolean equals( Object[] rowData1, Object[] rowData2, int[] fieldnrs ) throws KettleValueException { lock.readLock().lock(); try { for ( int fieldnr : fieldnrs ) { ValueMetaInterface valueMeta = getValueMeta( fieldnr ); int cmp = valueMeta.compare( rowData1[ fieldnr ], rowData2[ fieldnr ] ); if ( cmp != 0 ) { return false; } } return true; } finally { lock.readLock().unlock(); } }
/** * Compare 2 rows with each other using all values in the rows and also considering the specified ascending clauses of * the value metadata. * * @param rowData1 The first row of data * @param rowData2 The second row of data * @return 0 if the rows are considered equal, -1 is data1 is smaller, 1 if data2 is smaller. * @throws KettleValueException */ @Override public int compare( Object[] rowData1, Object[] rowData2 ) throws KettleValueException { lock.readLock().lock(); try { for ( int i = 0; i < size(); i++ ) { ValueMetaInterface valueMeta = getValueMeta( i ); int cmp = valueMeta.compare( rowData1[ i ], rowData2[ i ] ); if ( cmp != 0 ) { return cmp; } } return 0; } finally { lock.readLock().unlock(); } }
/** * Get an array of the names of all the Values in the Row. * * @return an array of Strings: the names of all the Values in the Row. */ @Override public String[] getFieldNames() { lock.readLock().lock(); try { String[] retval = new String[ size() ]; for ( int i = 0; i < size(); i++ ) { String valueName = getValueMeta( i ).getName(); retval[i] = valueName == null ? "" : valueName; } return retval; } finally { lock.readLock().unlock(); } }
/** * Get an array of strings showing the name of the values in the row padded to a maximum length, followed by the types * of the values. * * @param maxlen The length to which the name will be padded. * @return an array of strings: the names and the types of the fieldnames in the row. */ @Override public String[] getFieldNamesAndTypes( int maxlen ) { lock.readLock().lock(); try { final int size = size(); String[] retval = new String[ size ]; for ( int i = 0; i < size; i++ ) { ValueMetaInterface v = getValueMeta( i ); retval[ i ] = Const.rightPad( v.getName(), maxlen ) + " (" + v.getTypeDesc() + ")"; } return retval; } finally { lock.readLock().unlock(); } }
/** * Convert an XML node into binary data using the row metadata supplied. * * @param node The data row node * @return a row of data, converted from XML * @throws IOException Thrown in case there is an (Base64/GZip) decoding problem */ @Override public Object[] getRow( Node node ) throws KettleException { lock.readLock().lock(); try { Object[] rowData = RowDataUtil.allocateRowData( size() ); for ( int i = 0; i < size(); i++ ) { Node valueDataNode = XMLHandler.getSubNodeByNr( node, ValueMeta.XML_DATA_TAG, i ); rowData[ i ] = getValueMeta( i ).getValue( valueDataNode ); } return rowData; } finally { lock.readLock().unlock(); } }
@Override public Object[] readData( DataInputStream inputStream ) throws KettleFileException, SocketTimeoutException { lock.readLock().lock(); try { Object[] data = new Object[ size() ]; for ( int i = 0; i < size(); i++ ) { data[ i ] = getValueMeta( i ).readData( inputStream ); } if ( size() == 0 ) { try { inputStream.readBoolean(); } catch ( EOFException e ) { throw new KettleEOFException( e ); } catch ( SocketTimeoutException e ) { throw e; } catch ( IOException e ) { throw new KettleFileException( toString() + " : Unable to read the marker flag data from input stream", e ); } } return data; } finally { lock.readLock().unlock(); } }
@Test public void testGetFields() throws KettleStepException { CreditCardValidatorMeta meta = new CreditCardValidatorMeta(); meta.setDefault(); meta.setResultFieldName( "The Result Field" ); meta.setCardType( "The Card Type Field" ); meta.setNotValidMsg( "Is Card Valid" ); RowMeta rowMeta = new RowMeta(); meta.getFields( rowMeta, "this step", null, null, new Variables(), null, null ); assertEquals( 3, rowMeta.size() ); assertEquals( "The Result Field", rowMeta.getValueMeta( 0 ).getName() ); assertEquals( ValueMetaInterface.TYPE_BOOLEAN, rowMeta.getValueMeta( 0 ).getType() ); assertEquals( "this step", rowMeta.getValueMeta( 0 ).getOrigin() ); assertEquals( "The Card Type Field", rowMeta.getValueMeta( 1 ).getName() ); assertEquals( ValueMetaInterface.TYPE_STRING, rowMeta.getValueMeta( 1 ).getType() ); assertEquals( "this step", rowMeta.getValueMeta( 1 ).getOrigin() ); assertEquals( "Is Card Valid", rowMeta.getValueMeta( 2 ).getName() ); assertEquals( ValueMetaInterface.TYPE_STRING, rowMeta.getValueMeta( 2 ).getType() ); assertEquals( "this step", rowMeta.getValueMeta( 2 ).getOrigin() ); } }
@Test public void testGetFields() throws KettleStepException { DetectLastRowMeta meta = new DetectLastRowMeta(); meta.setDefault(); meta.setResultFieldName( "The Result" ); RowMeta rowMeta = new RowMeta(); meta.getFields( rowMeta, "this step", null, null, new Variables(), null, null ); assertEquals( 1, rowMeta.size() ); assertEquals( "The Result", rowMeta.getValueMeta( 0 ).getName() ); assertEquals( ValueMetaInterface.TYPE_BOOLEAN, rowMeta.getValueMeta( 0 ).getType() ); }
@Test public void getFields() throws Exception { MappingInputMeta meta = new MappingInputMeta(); meta.setInputRowMeta( inputRowMeta ); meta.setValueRenames( renames ); meta.allocate( fields.length ); meta.setFieldName( fields ); meta.setSelectingAndSortingUnspecifiedFields( sortUnspecified ); RowMeta rowMeta = new RowMeta(); meta.getFields( rowMeta, "origin", new RowMetaInterface[ 0 ], null, null, null, null ); assertEquals( Arrays.toString( expectedOutputFields ), expectedOutputFields.length, rowMeta.size() ); for ( int i = 0; i < rowMeta.size(); i++ ) { assertEquals( String.format( "Element %d", i ), expectedOutputFields[ i ], rowMeta.getValueMeta( i ).getName() ); } } }