@Override public Object answer( InvocationOnMock invocation ) throws Throwable { RowMetaInterface row = (RowMetaInterface) invocation.getArguments()[ 0 ]; ValueMetaInterface v = new ValueMetaBinary( BINARY_FIELD ); row.addValueMeta( v ); return null; } } ).when( meta ).getFields(
@Override public Object getNativeDataType( Object object ) throws KettleValueException { return getBinary( object ); }
@Override public Object answer( InvocationOnMock invocation ) throws Throwable { RowMetaInterface row = (RowMetaInterface) invocation.getArguments()[ 0 ]; ValueMetaInterface v = new ValueMetaBinary( BINARY_FIELD ); row.addValueMeta( v ); return null; } } ).when( meta ).getFields(
@Test public void getBinary_Test() throws Exception { ValueMetaBinary v = new ValueMetaBinary( "Data" ); RowMetaInterface row = mock( RowMetaInterface.class ); doReturn( v ).when( row ).searchValueMeta( anyString() ); doReturn( 0 ).when( row ).indexOfValue( anyString() ); assertArrayEquals( new byte[] { 0, 1, 2 }, new FieldHelper( row, "Data" ).getBinary( new Object[] { new byte[] { 0, 1, 2 } } ) ); }
@Test public void setValue_ValueMetaBinary() throws Exception { ValueMetaBinary v = new ValueMetaBinary( "Data" ); RowMetaInterface row = mock( RowMetaInterface.class ); doReturn( v ).when( row ).searchValueMeta( anyString() ); doReturn( 0 ).when( row ).indexOfValue( anyString() ); Object[] data = new Object[1]; new FieldHelper( row, "Data" ).setValue( data, new byte[] { 0, 1, 2 } ); assertArrayEquals( new byte[] { 0, 1, 2 }, (byte[]) data[0] ); } }
valueMeta = new ValueMetaBoolean(); } else if ( type.equals( "Binary" ) ) { valueMeta = new ValueMetaBinary(); } else if ( type.equals( "Timestamp" ) ) { valueMeta = new ValueMetaTimestamp();
@Override public void getFields( RowMetaInterface inputRowMeta, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException { // Output field (String) if ( !Utils.isEmpty( resultfieldName ) ) { ValueMetaInterface v = null; if ( checksumtype.equals( TYPE_CRC32 ) || checksumtype.equals( TYPE_ADLER32 ) ) { v = new ValueMetaInteger( space.environmentSubstitute( resultfieldName ) ); } else { switch ( resultType ) { case result_TYPE_BINARY: v = new ValueMetaBinary( space.environmentSubstitute( resultfieldName ) ); break; default: v = new ValueMetaString( space.environmentSubstitute( resultfieldName ) ); break; } } v.setOrigin( name ); inputRowMeta.addValueMeta( v ); } }
@Test public void getNativeDataTypeSimpleName_Binary() { ValueMetaBinary v = new ValueMetaBinary(); assertEquals( "Binary", FieldHelper.getNativeDataTypeSimpleName( v ) ); }
public ValueMetaAndData( String valueName, Object valueData ) throws KettleValueException { this.valueData = valueData; if ( valueData instanceof String ) { this.valueMeta = new ValueMetaString( valueName ); } else if ( valueData instanceof Double ) { this.valueMeta = new ValueMetaNumber( valueName ); } else if ( valueData instanceof Long ) { this.valueMeta = new ValueMetaInteger( valueName ); } else if ( valueData instanceof Date ) { this.valueMeta = new ValueMetaDate( valueName, ValueMetaInterface.TYPE_DATE ); } else if ( valueData instanceof BigDecimal ) { this.valueMeta = new ValueMetaBigNumber( valueName ); } else if ( valueData instanceof Boolean ) { this.valueMeta = new ValueMetaBoolean( valueName ); } else if ( valueData instanceof byte[] ) { this.valueMeta = new ValueMetaBinary( valueName ); } else { this.valueMeta = new ValueMetaSerializable( valueName ); } }
return ( !Utils.isEmpty( string_value ) ? string_value : null ); } else if ( valueMetaInterfaceType == ValueMetaInterface.TYPE_BINARY ) { ValueMetaInterface binaryValueMeta = new ValueMetaBinary( "binary_data" ); return ( !Utils.isEmpty( string_value ) ? binaryValueMeta.convertData( parameterValueMeta, string_value ) : null );
@Test public void testByteArray() throws Exception { RowMetaInterface mockedRowMetaInterface = mock( RowMetaInterface.class ); stepLoadFileInput.data.outputRowMeta = mockedRowMetaInterface; stepLoadFileInput.data.convertRowMeta = mockedRowMetaInterface; Mockito.doReturn( new ValueMetaString() ).when( mockedRowMetaInterface ).getValueMeta( anyInt() ); // byte array Mockito.doReturn( new ValueMetaBinary() ).when( mockedRowMetaInterface ).getValueMeta( anyInt() ); ( (LoadFileInputMeta) runtimeSMI ).setEncoding( "UTF-8" ); stepInputFiles.addFile( getFile( "pentaho_splash.png" ) ); inputField = new LoadFileInputField(); inputField.setType( ValueMetaInterface.TYPE_BINARY ); ( (LoadFileInputMeta) runtimeSMI ).setInputFields( new LoadFileInputField[]{ inputField } ); assertNotNull( stepLoadFileInput.getOneRow() ); assertArrayEquals( IOUtils.toByteArray( getFile( "pentaho_splash.png" ).getContent().getInputStream() ), stepLoadFileInput.data.filecontent ); }
return new ValueMetaBoolean(); } else if ( object instanceof byte[] ) { return new ValueMetaBinary();
@Test public void getGetSignature_Binary() { ValueMetaBinary v = new ValueMetaBinary( "Data" ); String accessor = FieldHelper.getAccessor( true, "Data" ); assertEquals( "byte[] Data = get(Fields.In, \"Data\").getBinary(r);", FieldHelper.getGetSignature( accessor, v ) ); assertNotNull( getMethod( FieldHelper.class, "getBinary", Object[].class ) ); }
@Override public void getFields( RowMetaInterface row, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException { ValueMetaInterface v; if ( isOutputKeyInBinary() ) { v = new ValueMetaBinary( secretKeyFieldName ); } else { v = new ValueMetaString( secretKeyFieldName ); } v.setOrigin( name ); row.addValueMeta( v ); if ( !Utils.isEmpty( getAlgorithmFieldName() ) ) { v = new ValueMetaString( algorithmFieldName ); v.setOrigin( name ); row.addValueMeta( v ); } if ( !Utils.isEmpty( getSecretKeyLengthFieldName() ) ) { v = new ValueMetaInteger( secretKeyLengthFieldName ); v.setLength( ValueMetaInterface.DEFAULT_INTEGER_LENGTH, 0 ); v.setOrigin( name ); row.addValueMeta( v ); } }
private RowMetaInterface getInputRowMeta() { RowMetaInterface rm = new RowMeta(); rm.addValueMeta( new ValueMetaString( "myGroupField2" ) ); rm.addValueMeta( new ValueMetaString( "myGroupField1" ) ); rm.addValueMeta( new ValueMetaString( "myString" ) ); rm.addValueMeta( new ValueMetaInteger( "myInteger" ) ); rm.addValueMeta( new ValueMetaNumber( "myNumber" ) ); rm.addValueMeta( new ValueMetaBigNumber( "myBigNumber" ) ); rm.addValueMeta( new ValueMetaBinary( "myBinary" ) ); rm.addValueMeta( new ValueMetaBoolean( "myBoolean" ) ); rm.addValueMeta( new ValueMetaDate( "myDate" ) ); rm.addValueMeta( new ValueMetaTimestamp( "myTimestamp" ) ); rm.addValueMeta( new ValueMetaInternetAddress( "myInternetAddress" ) ); return rm; } @Test
valueMeta = new ValueMetaBinary( "image" ); valueMeta.setOrigin( origin ); rowMeta.addValueMeta( valueMeta );
private ValueMetaInterface getValueMetaInterface( String fieldName, int fieldType ) { switch ( fieldType ) { case ValueMetaInterface.TYPE_INET: return new ValueMetaInternetAddress( fieldName ); case ValueMetaInterface.TYPE_STRING: return new ValueMetaString( fieldName ); case ValueMetaInterface.TYPE_INTEGER: return new ValueMetaInteger( fieldName ); case ValueMetaInterface.TYPE_NUMBER: return new ValueMetaNumber( fieldName ); case ValueMetaInterface.TYPE_BIGNUMBER: return new ValueMetaBigNumber( fieldName ); case ValueMetaInterface.TYPE_TIMESTAMP: return new ValueMetaTimestamp( fieldName ); case ValueMetaInterface.TYPE_DATE: return new ValueMetaDate( fieldName ); case ValueMetaInterface.TYPE_BOOLEAN: return new ValueMetaBoolean( fieldName ); case ValueMetaInterface.TYPE_BINARY: return new ValueMetaBinary( fieldName ); } return null; } }
private void addValueMeta( int pdiType, String pentahoFieldName ) { switch ( pdiType ) { case ValueMetaInterface.TYPE_BINARY: fields.addValueMeta( new ValueMetaBinary( pentahoFieldName ) ); break; case ValueMetaInterface.TYPE_BIGNUMBER:
@Test public void testEncodeKeyValueWithMeta() throws Exception { HBaseValueMeta hbMeta = getHBaseValueMeta(); Object keyValue = 1; assertArrayEquals( new byte[] { 1 }, HBaseValueMeta.encodeKeyValue( keyValue, new ValueMetaString(), Mapping.KeyType.STRING, BYTES_UTIL ) ); keyValue = new Date(); assertArrayEquals( new byte[] { 3 }, HBaseValueMeta.encodeKeyValue( keyValue, new ValueMetaDate(), Mapping.KeyType.DATE, BYTES_UTIL ) ); keyValue = new Date(); assertArrayEquals( new byte[] { 3 }, HBaseValueMeta.encodeKeyValue( keyValue, new ValueMetaDate(), Mapping.KeyType.UNSIGNED_DATE, BYTES_UTIL ) ); keyValue = (long) 0; assertArrayEquals( new byte[] { 2 }, HBaseValueMeta.encodeKeyValue( keyValue, new ValueMetaInteger(), Mapping.KeyType.INTEGER, BYTES_UTIL ) ); keyValue = (long) 0; assertArrayEquals( new byte[] { 2 }, HBaseValueMeta.encodeKeyValue( keyValue, new ValueMetaInteger(), Mapping.KeyType.UNSIGNED_INTEGER, BYTES_UTIL ) ); keyValue = (double) 0; assertArrayEquals( new byte[] { 3 }, HBaseValueMeta.encodeKeyValue( keyValue, new ValueMetaNumber(), Mapping.KeyType.LONG, BYTES_UTIL ) ); keyValue = (double) 0; assertArrayEquals( new byte[] { 3 }, HBaseValueMeta.encodeKeyValue( keyValue, new ValueMetaNumber(), Mapping.KeyType.UNSIGNED_LONG, BYTES_UTIL ) ); keyValue = new byte[] { 3 }; assertArrayEquals( (byte[]) keyValue, HBaseValueMeta.encodeKeyValue( keyValue, new ValueMetaBinary(), Mapping.KeyType.BINARY, BYTES_UTIL ) ); }
keyValue = new byte[] { 1 }; assertArrayEquals( new byte[] { 1 }, HBaseValueMeta.encodeColumnValue( keyValue, new ValueMetaBinary(), hbMeta, BYTES_UTIL ) );