/** * 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 ] ); }
/** * Change a string into its hexadecimal representation. E.g. if Value contains string "a" afterwards it would contain * value "0061". * * Note that transformations happen in groups of 4 hex characters, so the value of a characters is always in the range * 0-65535. * * @return A string with Hex code * @throws KettleValueException * In case of a data conversion problem. */ public static String charToHexEncode( ValueMetaInterface meta, Object data ) throws KettleValueException { final char[] hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; if ( meta.isNull( data ) ) { return null; } String hex = meta.getString( data ); char[] s = hex.toCharArray(); StringBuffer hexString = new StringBuffer( 2 * s.length ); for ( int i = 0; i < s.length; i++ ) { hexString.append( hexDigits[( s[i] & 0xF000 ) >> 12] ); // hex 1 hexString.append( hexDigits[( s[i] & 0x0F00 ) >> 8] ); // hex 2 hexString.append( hexDigits[( s[i] & 0x00F0 ) >> 4] ); // hex 3 hexString.append( hexDigits[s[i] & 0x000F] ); // hex 4 } return hexString.toString(); }
private void addCumulativeSums( Object[] row ) throws KettleValueException { // We need to adjust this row with cumulative averages? // for ( int i = 0; i < data.cumulativeSumSourceIndexes.size(); i++ ) { int sourceIndex = data.cumulativeSumSourceIndexes.get( i ); Object previousTarget = data.previousSums[ i ]; Object sourceValue = row[ sourceIndex ]; int targetIndex = data.cumulativeSumTargetIndexes.get( i ); ValueMetaInterface sourceMeta = data.inputRowMeta.getValueMeta( sourceIndex ); ValueMetaInterface targetMeta = data.outputRowMeta.getValueMeta( targetIndex ); // If the first values where null, or this is the first time around, just take the source value... // if ( targetMeta.isNull( previousTarget ) ) { row[ targetIndex ] = sourceMeta.convertToNormalStorageType( sourceValue ); } else { // If the source value is null, just take the previous target value // if ( sourceMeta.isNull( sourceValue ) ) { row[ targetIndex ] = previousTarget; } else { row[ targetIndex ] = ValueDataUtil.plus( targetMeta, data.previousSums[ i ], sourceMeta, row[ sourceIndex ] ); } } data.previousSums[ i ] = row[ targetIndex ]; } }
if ( meta.isNull( data ) ) { return null;
if ( meta.isNull( data ) ) { return null;
if ( valueMeta.isNull( valueData ) ) { ins.append( "null" ); } else {
if ( !vCurrentValue.isNull( data ) ) { xml.append( " <" ); if ( qualifyWSField ) {
if ( nullString != null && v.isNull( valueData ) ) { str = nullString; } else {
/** * Produce the XML representation of this value. * * @return a String containing the XML to represent this Value. * @throws KettleValueException * in case there is a data conversion error, only throws in case of lazy conversion */ public String getXML() throws KettleValueException { ValueMetaInterface meta = valueMeta.clone(); meta.setDecimalSymbol( "." ); meta.setGroupingSymbol( null ); meta.setCurrencySymbol( null ); StringBuilder retval = new StringBuilder( 128 ); retval.append( "<" + XML_TAG + ">" ); retval.append( XMLHandler.addTagValue( "name", meta.getName(), false ) ); retval.append( XMLHandler.addTagValue( "type", meta.getTypeDesc(), false ) ); try { retval.append( XMLHandler.addTagValue( "text", meta.getCompatibleString( valueData ), false ) ); } catch ( KettleValueException e ) { // LogWriter.getInstance().logError(toString(), Const.getStackTracker(e)); retval.append( XMLHandler.addTagValue( "text", "", false ) ); } retval.append( XMLHandler.addTagValue( "length", meta.getLength(), false ) ); retval.append( XMLHandler.addTagValue( "precision", meta.getPrecision(), false ) ); retval.append( XMLHandler.addTagValue( "isnull", meta.isNull( valueData ), false ) ); retval.append( XMLHandler.addTagValue( "mask", meta.getConversionMask(), false ) ); retval.append( "</" + XML_TAG + ">" ); return retval.toString(); }
when( data.valueMeta.isNull( any() ) ).thenAnswer( new Answer<Object>() { @Override public Object answer( InvocationOnMock invocation ) throws Throwable {
@VisibleForTesting Object[] getRowForData( TableItem item, int rowNr ) throws KettleException { try { Object[] row = RowDataUtil.allocateRowData( rowMeta.size() ); for ( int i = 0; i < rowMeta.size(); i++ ) { ValueMetaInterface valueMeta = rowMeta.getValueMeta( i ); ValueMetaInterface stringValueMeta = stringRowMeta.getValueMeta( i ); int colnr = i + 1; if ( isDisplayingNullValue( item, colnr ) ) { row[i] = null; // <null> value } else { String string = item.getText( colnr ); if ( stringValueMeta.isNull( string ) ) { string = null; } row[i] = valueMeta.convertDataFromString( string, stringValueMeta, null, null, ValueMetaInterface.TRIM_TYPE_NONE ); } } return row; } catch ( KettleException e ) { throw new KettleException( BaseMessages.getString( PKG, "EditRowsDialog.Error.ErrorGettingRowForData", Integer.toString( rowNr ) ), e ); } }
Object object = rowData[data.fieldnrs[i]]; if ( valueMeta.isNull( object ) ) {
Object value = rowData[data.fieldnrs[i]]; if ( valueMeta.isNull( value ) ) {
private void updateFields( Object[] r ) throws Exception { // Loop through fields for ( int i = 0; i < data.fieldnr; i++ ) { ValueMetaInterface sourceValueMeta = data.convertRowMeta.getValueMeta( data.fieldnrs[i] ); if ( data.outputRowMeta.getValueMeta( data.fieldnrs[i] ).isNull( r[data.fieldnrs[i]] ) ) { if ( meta.isSelectValuesType() ) { ValueMetaInterface fieldMeta = data.outputRowMeta.getValueMeta( data.fieldnrs[i] ); int pos = data.ListTypes.get( fieldMeta.getTypeDesc() ); replaceNull( r, sourceValueMeta, data.fieldnrs[i], data.defaultValues[pos], data.defaultMasks[pos], data.setEmptyString[pos] ); } else if ( meta.isSelectFields() ) { replaceNull( r, sourceValueMeta, data.fieldnrs[i], data.defaultValues[i], data.defaultMasks[i], data.setEmptyString[i] ); } else { // all if ( data.outputRowMeta.getValueMeta( data.fieldnrs[i] ).isDate() ) { replaceNull( r, sourceValueMeta, data.fieldnrs[i], data.realReplaceByValue, data.realconversionMask, false ); } else { // don't use any special date format when not a date replaceNull( r, sourceValueMeta, data.fieldnrs[i], data.realReplaceByValue, null, data.realSetEmptyString ); } } } } }
String valueData = outputLine.get( i ); if ( valueData != null && valueMeta.isNull( valueData ) ) { valueData = null;
Set<RowSet> rowSetSet = ( data.valueMeta.isNull( lookupData ) ) ? data.nullRowSetSet : data.outputMap.get( lookupData );
@Override public void saveRep( Repository rep, ObjectId id_transformation, ObjectId id_step ) throws KettleException { try { rep.saveStepAttribute( id_transformation, id_step, "value_name", value.getValueMeta().getName() ); rep.saveStepAttribute( id_transformation, id_step, 0, "value_type", value.getValueMeta().getTypeDesc() ); rep.saveStepAttribute( id_transformation, id_step, 0, "value_text", value.getValueMeta().getString( value.getValueData() ) ); rep.saveStepAttribute( id_transformation, id_step, 0, "value_null", value.getValueMeta().isNull( value.getValueData() ) ); rep.saveStepAttribute( id_transformation, id_step, 0, "value_length", value.getValueMeta().getLength() ); rep.saveStepAttribute( id_transformation, id_step, 0, "value_precision", value.getValueMeta().getPrecision() ); } catch ( KettleDatabaseException dbe ) { throw new KettleException( "Unable to save step information to the repository, id_step=" + id_step, dbe ); } }
insertValue( valueMeta.getName(), valueMeta.getTypeDesc(), stringValue, valueMeta.isNull( v .getValueData() ), condition.getRightExactID() ); condition.setRightExactID( id_value );