Java Code Examples for org.pentaho.di.core.row.ValueMetaInterface#STORAGE_TYPE_NORMAL
The following examples show how to use
org.pentaho.di.core.row.ValueMetaInterface#STORAGE_TYPE_NORMAL .
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: SelectValues_LocaleHandling_Test.java From pentaho-kettle with Apache License 2.0 | 6 votes |
private void executeAndCheck( String locale, String expectedWeekNumber ) throws Exception { RowMeta inputRowMeta = new RowMeta(); inputRowMeta.addValueMeta( new ValueMetaDate( "field" ) ); step.setInputRowMeta( inputRowMeta ); SelectValuesMeta stepMeta = new SelectValuesMeta(); stepMeta.allocate( 1, 0, 1 ); stepMeta.getSelectFields()[0] = new SelectField(); stepMeta.getSelectFields()[0].setName( "field" ); stepMeta.getMeta()[ 0 ] = new SelectMetadataChange( stepMeta, "field", null, ValueMetaInterface.TYPE_STRING, -2, -2, ValueMetaInterface.STORAGE_TYPE_NORMAL, "ww", false, locale, null, false, null, null, null ); SelectValuesData stepData = new SelectValuesData(); stepData.select = true; stepData.metadata = true; stepData.firstselect = true; stepData.firstmetadata = true; List<Object[]> execute = TransTestingUtil.execute( step, stepMeta, stepData, 1, true ); TransTestingUtil.assertResult( execute, Collections.singletonList( new Object[] { expectedWeekNumber } ) ); }
Example 2
Source File: StreamLookupTest.java From pentaho-kettle with Apache License 2.0 | 6 votes |
private RowSet mockDataRowSet( boolean binary ) { final int storageType = binary ? ValueMetaInterface.STORAGE_TYPE_BINARY_STRING : ValueMetaInterface.STORAGE_TYPE_NORMAL; Object[][] data = { { "Name1", "1" }, { "Name2", "2" } }; if ( binary ) { convertDataToBinary( data ); } RowSet dataRowSet = smh.getMockInputRowSet( data ); RowMeta dataRowMeta = new RowMeta(); ValueMetaString valueMeta = new ValueMetaString( "Name" ); valueMeta.setStorageType( storageType ); valueMeta.setStorageMetadata( new ValueMetaString() ); dataRowMeta.addValueMeta( valueMeta ); ValueMetaString idMeta = new ValueMetaString( "Id" ); idMeta.setStorageType( storageType ); idMeta.setStorageMetadata( new ValueMetaString() ); dataRowMeta.addValueMeta( idMeta ); doReturn( dataRowMeta ).when( dataRowSet ).getRowMeta(); return dataRowSet; }
Example 3
Source File: SelectValuesTest.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@Test public void errorRowSetObtainsFieldName() throws Exception { SelectValuesMeta stepMeta = new SelectValuesMeta(); stepMeta.allocate( 1, 0, 1 ); stepMeta.getSelectFields()[0] = new SelectField(); stepMeta.getSelectFields()[0].setName( SELECTED_FIELD ); stepMeta.getMeta()[ 0 ] = new SelectMetadataChange( stepMeta, SELECTED_FIELD, null, ValueMetaInterface.TYPE_INTEGER, -2, -2, ValueMetaInterface.STORAGE_TYPE_NORMAL, null, false, null, null, false, null, null, null ); SelectValuesData stepData = new SelectValuesData(); stepData.select = true; stepData.metadata = true; stepData.firstselect = true; stepData.firstmetadata = true; step.processRow( stepMeta, stepData ); verify( step ) .putError( any( RowMetaInterface.class ), any( Object[].class ), anyLong(), anyString(), eq( SELECTED_FIELD ), anyString() ); // additionally ensure conversion error causes KettleConversionError boolean properException = false; try { step.metadataValues( step.getInputRowMeta(), inputRow ); } catch ( KettleConversionException e ) { properException = true; } assertTrue( properException ); }
Example 4
Source File: StreamLookupTest.java From pentaho-kettle with Apache License 2.0 | 5 votes |
private RowSet mockLookupRowSet( boolean binary ) { final int storageType = binary ? ValueMetaInterface.STORAGE_TYPE_BINARY_STRING : ValueMetaInterface.STORAGE_TYPE_NORMAL; Object[][] data = { { "Value1", "1" }, { "Value2", "2" } }; if ( binary ) { convertDataToBinary( data ); } RowSet lookupRowSet = smh.getMockInputRowSet( data ); doReturn( "Lookup" ).when( lookupRowSet ).getOriginStepName(); doReturn( "StreamLookup" ).when( lookupRowSet ).getDestinationStepName(); RowMeta lookupRowMeta = new RowMeta(); ValueMetaString valueMeta = new ValueMetaString( "Value" ); valueMeta.setStorageType( storageType ); valueMeta.setStorageMetadata( new ValueMetaString() ); lookupRowMeta.addValueMeta( valueMeta ); ValueMetaString idMeta = new ValueMetaString( "Id" ); idMeta.setStorageType( storageType ); idMeta.setStorageMetadata( new ValueMetaString() ); lookupRowMeta.addValueMeta( idMeta ); doReturn( lookupRowMeta ).when( lookupRowSet ).getRowMeta(); return lookupRowSet; }
Example 5
Source File: SelectValues.java From pentaho-kettle with Apache License 2.0 | 4 votes |
/** * Change the meta-data of certain fields. * <p/> * This, we can do VERY fast. * <p/> * * @param row The row to manipulate * @return the altered RowData array * @throws KettleValueException */ @VisibleForTesting synchronized Object[] metadataValues( RowMetaInterface rowMeta, Object[] rowData ) throws KettleException { if ( data.firstmetadata ) { data.firstmetadata = false; data.metanrs = new int[ meta.getMeta().length ]; for ( int i = 0; i < data.metanrs.length; i++ ) { data.metanrs[ i ] = rowMeta.indexOfValue( meta.getMeta()[ i ].getName() ); if ( data.metanrs[ i ] < 0 ) { logError( BaseMessages .getString( PKG, "SelectValues.Log.CouldNotFindField", meta.getMeta()[ i ].getName() ) ); setErrors( 1 ); stopAll(); return null; } } // Check for doubles in the selected fields... int[] cnt = new int[ meta.getMeta().length ]; for ( int i = 0; i < meta.getMeta().length; i++ ) { cnt[ i ] = 0; for ( int j = 0; j < meta.getMeta().length; j++ ) { if ( meta.getMeta()[ i ].getName().equals( meta.getMeta()[ j ].getName() ) ) { cnt[ i ]++; } if ( cnt[ i ] > 1 ) { logError( BaseMessages.getString( PKG, "SelectValues.Log.FieldCouldNotSpecifiedMoreThanTwice2", meta .getMeta()[ i ].getName() ) ); setErrors( 1 ); stopAll(); return null; } } } // Also apply the metadata on the row meta to allow us to convert the data correctly, with the correct mask. // for ( int i = 0; i < data.metanrs.length; i++ ) { SelectMetadataChange change = meta.getMeta()[ i ]; ValueMetaInterface valueMeta = rowMeta.getValueMeta( data.metanrs[ i ] ); if ( !Utils.isEmpty( change.getConversionMask() ) ) { valueMeta.setConversionMask( change.getConversionMask() ); } valueMeta.setDateFormatLenient( change.isDateFormatLenient() ); valueMeta.setDateFormatLocale( EnvUtil.createLocale( change.getDateFormatLocale() ) ); valueMeta.setDateFormatTimeZone( EnvUtil.createTimeZone( change.getDateFormatTimeZone() ) ); valueMeta.setLenientStringToNumber( change.isLenientStringToNumber() ); if ( !Utils.isEmpty( change.getEncoding() ) ) { valueMeta.setStringEncoding( change.getEncoding() ); } if ( !Utils.isEmpty( change.getDecimalSymbol() ) ) { valueMeta.setDecimalSymbol( change.getDecimalSymbol() ); } if ( !Utils.isEmpty( change.getGroupingSymbol() ) ) { valueMeta.setGroupingSymbol( change.getGroupingSymbol() ); } if ( !Utils.isEmpty( change.getCurrencySymbol() ) ) { valueMeta.setCurrencySymbol( change.getCurrencySymbol() ); } } } // // Change the data too // for ( int i = 0; i < data.metanrs.length; i++ ) { int index = data.metanrs[ i ]; ValueMetaInterface fromMeta = rowMeta.getValueMeta( index ); ValueMetaInterface toMeta = data.metadataRowMeta.getValueMeta( index ); // If we need to change from BINARY_STRING storage type to NORMAL... // try { if ( fromMeta.isStorageBinaryString() && meta.getMeta()[ i ].getStorageType() == ValueMetaInterface.STORAGE_TYPE_NORMAL ) { rowData[ index ] = fromMeta.convertBinaryStringToNativeType( (byte[]) rowData[ index ] ); } if ( meta.getMeta()[ i ].getType() != ValueMetaInterface.TYPE_NONE && fromMeta.getType() != toMeta.getType() ) { rowData[ index ] = toMeta.convertData( fromMeta, rowData[ index ] ); } } catch ( KettleValueException e ) { throw new KettleConversionException( e.getMessage(), Collections.<Exception>singletonList( e ), Collections.singletonList( toMeta ), rowData ); } } return rowData; }