Java Code Examples for org.pentaho.di.core.row.ValueMetaInterface#TYPE_INET
The following examples show how to use
org.pentaho.di.core.row.ValueMetaInterface#TYPE_INET .
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: PentahoOrcRecordWriter.java From pentaho-hadoop-shims with Apache License 2.0 | 6 votes |
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; }
Example 2
Source File: PentahoOrcReadWriteTest.java From pentaho-hadoop-shims with Apache License 2.0 | 6 votes |
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; }
Example 3
Source File: ParquetConverter.java From pentaho-hadoop-shims with Apache License 2.0 | 5 votes |
private void addValueMeta( int pdiType, String pentahoFieldName ) { switch ( pdiType ) { case ValueMetaInterface.TYPE_BINARY: fields.addValueMeta( new ValueMetaBinary( pentahoFieldName ) ); break; case ValueMetaInterface.TYPE_BIGNUMBER: fields.addValueMeta( new ValueMetaBigNumber( pentahoFieldName ) ); break; case ValueMetaInterface.TYPE_BOOLEAN: fields.addValueMeta( new ValueMetaBoolean( pentahoFieldName ) ); break; case ValueMetaInterface.TYPE_DATE: fields.addValueMeta( new ValueMetaDate( pentahoFieldName ) ); break; case ValueMetaInterface.TYPE_INET: fields.addValueMeta( new ValueMetaInternetAddress( pentahoFieldName ) ); break; case ValueMetaInterface.TYPE_INTEGER: fields.addValueMeta( new ValueMetaInteger( pentahoFieldName ) ); break; case ValueMetaInterface.TYPE_NUMBER: fields.addValueMeta( new ValueMetaNumber( pentahoFieldName ) ); break; case ValueMetaInterface.TYPE_STRING: fields.addValueMeta( new ValueMetaString( pentahoFieldName ) ); break; case ValueMetaInterface.TYPE_TIMESTAMP: fields.addValueMeta( new ValueMetaTimestamp( pentahoFieldName ) ); break; } }
Example 4
Source File: ParquetConverter.java From pentaho-hadoop-shims with Apache License 2.0 | 5 votes |
private void addValueMeta( int pdiType, String pentahoFieldName ) { switch ( pdiType ) { case ValueMetaInterface.TYPE_BINARY: fields.addValueMeta( new ValueMetaBinary( pentahoFieldName ) ); break; case ValueMetaInterface.TYPE_BIGNUMBER: fields.addValueMeta( new ValueMetaBigNumber( pentahoFieldName ) ); break; case ValueMetaInterface.TYPE_BOOLEAN: fields.addValueMeta( new ValueMetaBoolean( pentahoFieldName ) ); break; case ValueMetaInterface.TYPE_DATE: fields.addValueMeta( new ValueMetaDate( pentahoFieldName ) ); break; case ValueMetaInterface.TYPE_INET: fields.addValueMeta( new ValueMetaInternetAddress( pentahoFieldName ) ); break; case ValueMetaInterface.TYPE_INTEGER: fields.addValueMeta( new ValueMetaInteger( pentahoFieldName ) ); break; case ValueMetaInterface.TYPE_NUMBER: fields.addValueMeta( new ValueMetaNumber( pentahoFieldName ) ); break; case ValueMetaInterface.TYPE_STRING: fields.addValueMeta( new ValueMetaString( pentahoFieldName ) ); break; case ValueMetaInterface.TYPE_TIMESTAMP: fields.addValueMeta( new ValueMetaTimestamp( pentahoFieldName ) ); break; } }
Example 5
Source File: StreamingInputTest.java From pentaho-hadoop-shims with Apache License 2.0 | 5 votes |
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: ValueMetaTimestamp valueMetaTimestamp = new ValueMetaTimestamp( fieldName ); valueMetaTimestamp.setConversionMask( "yyyy/MM/dd HH:mm:ss.SSS" ); return valueMetaTimestamp; case ValueMetaInterface.TYPE_DATE: ValueMetaDate valueMetaDate = new ValueMetaDate( fieldName ); valueMetaDate.setConversionMask( "yyyy/MM/dd HH:mm:ss.SSS" ); return valueMetaDate; case ValueMetaInterface.TYPE_BOOLEAN: return new ValueMetaBoolean( fieldName ); case ValueMetaInterface.TYPE_BINARY: return new ValueMetaBinary( fieldName ); } return null; }
Example 6
Source File: PentahoAvroReadWriteTest.java From pentaho-hadoop-shims with Apache License 2.0 | 5 votes |
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: ValueMetaTimestamp valueMetaTimestamp = new ValueMetaTimestamp( fieldName ); valueMetaTimestamp.setConversionMask( "yyyy/MM/dd HH:mm:ss.SSS" ); return valueMetaTimestamp; case ValueMetaInterface.TYPE_DATE: ValueMetaDate valueMetaDate = new ValueMetaDate( fieldName ); valueMetaDate.setConversionMask( "yyyy/MM/dd HH:mm:ss.SSS" ); return valueMetaDate; case ValueMetaInterface.TYPE_BOOLEAN: return new ValueMetaBoolean( fieldName ); case ValueMetaInterface.TYPE_BINARY: return new ValueMetaBinary( fieldName ); } return null; }
Example 7
Source File: ValueMetaBaseTest.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@Test public void testNullHashCodes() throws Exception { ValueMetaBase valueMetaString = new ValueMetaBase( ); valueMetaString.type = ValueMetaInterface.TYPE_BOOLEAN; assertEquals( valueMetaString.hashCode( null ), 0 ^ 1 ); valueMetaString.type = ValueMetaInterface.TYPE_DATE; assertEquals( valueMetaString.hashCode( null ), 0 ^ 2 ); valueMetaString.type = ValueMetaInterface.TYPE_NUMBER; assertEquals( valueMetaString.hashCode( null ), 0 ^ 4 ); valueMetaString.type = ValueMetaInterface.TYPE_STRING; assertEquals( valueMetaString.hashCode( null ), 0 ^ 8 ); valueMetaString.type = ValueMetaInterface.TYPE_INTEGER; assertEquals( valueMetaString.hashCode( null ), 0 ^ 16 ); valueMetaString.type = ValueMetaInterface.TYPE_BIGNUMBER; assertEquals( valueMetaString.hashCode( null ), 0 ^ 32 ); valueMetaString.type = ValueMetaInterface.TYPE_BINARY; assertEquals( valueMetaString.hashCode( null ), 0 ^ 64 ); valueMetaString.type = ValueMetaInterface.TYPE_TIMESTAMP; assertEquals( valueMetaString.hashCode( null ), 0 ^ 128 ); valueMetaString.type = ValueMetaInterface.TYPE_INET; assertEquals( valueMetaString.hashCode( null ), 0 ^ 256 ); valueMetaString.type = ValueMetaInterface.TYPE_NONE; assertEquals( valueMetaString.hashCode( null ), 0 ); }
Example 8
Source File: ValueMetaConverter.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@Override public Object convertFromSourceToTargetDataType( int sourceValueMetaType, int targetValueMetaType, Object value ) throws ValueMetaConversionException { if ( value == null ) { return null; } switch ( sourceValueMetaType ) { case ValueMetaInterface.TYPE_INET: return convertFromInetMetaInterface( targetValueMetaType, value ); case ValueMetaInterface.TYPE_STRING: return convertFromStringMetaInterface( targetValueMetaType, value ); case ValueMetaInterface.TYPE_INTEGER: return convertFromIntegerMetaInterface( targetValueMetaType, value ); case ValueMetaInterface.TYPE_NUMBER: return convertFromNumberMetaInterface( targetValueMetaType, value ); case ValueMetaInterface.TYPE_BIGNUMBER: return convertFromBigNumberMetaInterface( targetValueMetaType, value ); case ValueMetaInterface.TYPE_TIMESTAMP: return convertFromTimestampMetaInterface( targetValueMetaType, value ); case ValueMetaInterface.TYPE_DATE: return convertFromDateMetaInterface( targetValueMetaType, value ); case ValueMetaInterface.TYPE_BOOLEAN: return convertFromBooleanMetaInterface( targetValueMetaType, value ); case ValueMetaInterface.TYPE_BINARY: return convertFromBinaryMetaInterface( targetValueMetaType, value ); case ValueMetaInterface.TYPE_SERIALIZABLE: return convertFromSerializableMetaInterface( targetValueMetaType, value ); default: throwBadConversionCombination( sourceValueMetaType, targetValueMetaType, value ); } return null; }
Example 9
Source File: RowMetaAndData.java From pentaho-kettle with Apache License 2.0 | 5 votes |
public boolean isEmptyValue( String valueName ) throws KettleValueException { int idx = rowMeta.indexOfValue( valueName ); if ( idx < 0 ) { throw new KettleValueException( "Unknown column '" + valueName + "'" ); } ValueMetaInterface metaType = rowMeta.getValueMeta( idx ); // find by source value type switch ( metaType.getType() ) { case ValueMetaInterface.TYPE_STRING: return rowMeta.getString( data, idx ) == null; case ValueMetaInterface.TYPE_BOOLEAN: return rowMeta.getBoolean( data, idx ) == null; case ValueMetaInterface.TYPE_INTEGER: return rowMeta.getInteger( data, idx ) == null; case ValueMetaInterface.TYPE_NUMBER: return rowMeta.getNumber( data, idx ) == null; case ValueMetaInterface.TYPE_BIGNUMBER: return rowMeta.getBigNumber( data, idx ) == null; case ValueMetaInterface.TYPE_BINARY: return rowMeta.getBinary( data, idx ) == null; case ValueMetaInterface.TYPE_DATE: case ValueMetaInterface.TYPE_TIMESTAMP: return rowMeta.getDate( data, idx ) == null; case ValueMetaInterface.TYPE_INET: return rowMeta.getString( data, idx ) == null; } throw new KettleValueException( "Unknown source type: " + metaType.getTypeDesc() ); }
Example 10
Source File: SalesforceInputMetaInjectionTest.java From pentaho-kettle with Apache License 2.0 | 4 votes |
@Test public void test() throws Exception { check( "SALESFORCE_URL", () -> meta.getTargetURL() ); check( "SALESFORCE_USERNAME", () -> meta.getUsername() ); check( "SALESFORCE_PASSWORD", () -> meta.getPassword() ); check( "TIME_OUT", () -> meta.getTimeout() ); check( "USE_COMPRESSION", () -> meta.isCompression() ); check( "MODULE", () -> meta.getModule() ); check( "INCLUDE_SQL_IN_OUTPUT", () -> meta.includeSQL() ); check( "SQL_FIELDNAME", () -> meta.getSQLField() ); check( "INCLUDE_TIMESTAMP_IN_OUTPUT", () -> meta.includeTimestamp() ); check( "TIMESTAMP_FIELDNAME", () -> meta.getTimestampField() ); check( "INCLUDE_URL_IN_OUTPUT", () -> meta.includeTargetURL() ); check( "URL_FIELDNAME", () -> meta.getTargetURLField() ); check( "INCLUDE_MODULE_IN_OUTPUT", () -> meta.includeModule() ); check( "MODULE_FIELDNAME", () -> meta.getModuleField() ); check( "INCLUDE_DELETION_DATE_IN_OUTPUT", () -> meta.includeDeletionDate() ); check( "DELETION_DATE_FIELDNAME", () -> meta.getDeletionDateField() ); check( "INCLUDE_ROWNUM_IN_OUTPUT", () -> meta.includeRowNumber() ); check( "ROWNUM_FIELDNAME", () -> meta.getRowNumberField() ); check( "QUERY_CONDITION", () -> meta.getCondition() ); check( "LIMIT", () -> meta.getRowLimit() ); check( "USE_SPECIFIED_QUERY", () -> meta.isSpecifyQuery() ); check( "SPECIFY_QUERY", () -> meta.getQuery() ); check( "END_DATE", () -> meta.getReadTo() ); check( "START_DATE", () -> meta.getReadFrom() ); check( "QUERY_ALL", () -> meta.isQueryAll() ); checkStringToInt( "RETRIEVE", () -> meta.getRecordsFilter(), SalesforceConnectionUtils.recordsFilterCode, new int[]{ RECORDS_FILTER_ALL, RECORDS_FILTER_UPDATED, RECORDS_FILTER_DELETED } ); check( "NAME", () -> meta.getInputFields()[0].getName() ); check( "FIELD", () -> meta.getInputFields()[0].getField() ); check( "LENGTH", () -> meta.getInputFields()[0].getLength() ); check( "FORMAT", () -> meta.getInputFields()[0].getFormat() ); check( "PRECISION", () -> meta.getInputFields()[0].getPrecision() ); check( "CURRENCY", () -> meta.getInputFields()[0].getCurrencySymbol() ); check( "DECIMAL", () -> meta.getInputFields()[0].getDecimalSymbol() ); check( "GROUP", () -> meta.getInputFields()[0].getGroupSymbol() ); check( "REPEAT", () -> meta.getInputFields()[0].isRepeated() ); check( "ISIDLOOKUP", () -> meta.getInputFields()[0].isIdLookup() ); checkStringToInt( "TRIM_TYPE", () -> meta.getInputFields()[0].getTrimType(), SalesforceInputField.trimTypeCode, new int[]{ TYPE_TRIM_NONE, TYPE_TRIM_LEFT, TYPE_TRIM_RIGHT, TYPE_TRIM_BOTH }); int[] types = new int[]{ ValueMetaInterface.TYPE_NONE, ValueMetaInterface.TYPE_NUMBER, ValueMetaInterface.TYPE_STRING, ValueMetaInterface.TYPE_DATE, ValueMetaInterface.TYPE_BOOLEAN, ValueMetaInterface.TYPE_INTEGER, ValueMetaInterface.TYPE_BIGNUMBER, ValueMetaInterface.TYPE_SERIALIZABLE, ValueMetaInterface.TYPE_BINARY, ValueMetaInterface.TYPE_TIMESTAMP, ValueMetaInterface.TYPE_INET }; ValueMetaString valueMeta = new ValueMetaString(); checkStringToInt("TYPE", () -> meta.getInputFields()[0].getType(), valueMeta.typeCodes, types ); }
Example 11
Source File: OrcConverter.java From pentaho-hadoop-shims with Apache License 2.0 | 4 votes |
protected static Object convertFromSourceToTargetDataType( ColumnVector columnVector, int currentBatchRow, int orcValueMetaInterface ) { if ( columnVector.isNull[ currentBatchRow ] ) { return null; } switch ( orcValueMetaInterface ) { case ValueMetaInterface.TYPE_INET: try { return InetAddress.getByName( new String( ( (BytesColumnVector) columnVector ).vector[ currentBatchRow ], ( (BytesColumnVector) columnVector ).start[ currentBatchRow ], ( (BytesColumnVector) columnVector ).length[ currentBatchRow ] ) ); } catch ( UnknownHostException e ) { e.printStackTrace(); } case ValueMetaInterface.TYPE_STRING: return new String( ( (BytesColumnVector) columnVector ).vector[ currentBatchRow ], ( (BytesColumnVector) columnVector ).start[ currentBatchRow ], ( (BytesColumnVector) columnVector ).length[ currentBatchRow ] ); case ValueMetaInterface.TYPE_INTEGER: return (long) ( (LongColumnVector) columnVector ).vector[ currentBatchRow ]; case ValueMetaInterface.TYPE_NUMBER: return ( (DoubleColumnVector) columnVector ).vector[ currentBatchRow ]; case ValueMetaInterface.TYPE_BIGNUMBER: HiveDecimalWritable obj = ( (DecimalColumnVector) columnVector ).vector[ currentBatchRow ]; return obj.getHiveDecimal().bigDecimalValue(); case ValueMetaInterface.TYPE_TIMESTAMP: Timestamp timestamp = new Timestamp( ( (TimestampColumnVector) columnVector ).time[ currentBatchRow ] ); timestamp.setNanos( ( (TimestampColumnVector) columnVector ).nanos[ currentBatchRow ] ); return timestamp; case ValueMetaInterface.TYPE_DATE: LocalDate localDate = LocalDate.ofEpochDay( 0 ).plusDays( ( (LongColumnVector) columnVector ).vector[ currentBatchRow ] ); Date dateValue = Date.from( localDate.atStartOfDay( ZoneId.systemDefault() ).toInstant() ); return dateValue; case ValueMetaInterface.TYPE_BOOLEAN: return ( (LongColumnVector) columnVector ).vector[ currentBatchRow ] == 0 ? false : true; case ValueMetaInterface.TYPE_BINARY: byte[] origBytes = ( (BytesColumnVector) columnVector ).vector[ currentBatchRow ]; int startPos = ( (BytesColumnVector) columnVector ).start[ currentBatchRow ]; byte[] newBytes = Arrays.copyOfRange( origBytes, startPos, startPos + ( (BytesColumnVector) columnVector ).length[ currentBatchRow ] ); return newBytes; } //if none of the cases match return a null return null; }
Example 12
Source File: ValueMetaBaseTest.java From pentaho-kettle with Apache License 2.0 | 4 votes |
@Test public void testHashCodes() throws Exception { ValueMetaBase valueMetaString = new ValueMetaBase( ); valueMetaString.type = ValueMetaInterface.TYPE_BOOLEAN; assertEquals( valueMetaString.hashCode( true ), 1231 ); SimpleDateFormat sdf = new SimpleDateFormat( "dd/M/yyyy" ); String dateInString = "1/1/2018"; Date dateObj = sdf.parse( dateInString ); valueMetaString.type = ValueMetaInterface.TYPE_DATE; assertEquals( valueMetaString.hashCode( dateObj ), -1358655136 ); Double numberObj = Double.valueOf( 5.1 ); valueMetaString.type = ValueMetaInterface.TYPE_NUMBER; assertEquals( valueMetaString.hashCode( numberObj ), 645005312 ); valueMetaString.type = ValueMetaInterface.TYPE_STRING; assertEquals( valueMetaString.hashCode( "test" ), 3556498 ); Long longObj = 123L; valueMetaString.type = ValueMetaInterface.TYPE_INTEGER; assertEquals( valueMetaString.hashCode( longObj ), 123 ); BigDecimal bDecimalObj = new BigDecimal( 123.1 ); valueMetaString.type = ValueMetaInterface.TYPE_BIGNUMBER; assertEquals( valueMetaString.hashCode( bDecimalObj ), 465045870 ); byte[] bBinary = new byte[2]; bBinary[0] = 1; bBinary[1] = 0; valueMetaString.type = ValueMetaInterface.TYPE_BINARY; assertEquals( valueMetaString.hashCode( bBinary ), 992 ); Timestamp timestampObj = Timestamp.valueOf( "2018-01-01 10:10:10.000000000" ); valueMetaString.type = ValueMetaInterface.TYPE_TIMESTAMP; assertEquals( valueMetaString.hashCode( timestampObj ), -1322045776 ); byte[] ipAddr = new byte[]{127, 0, 0, 1}; InetAddress addrObj = InetAddress.getByAddress( ipAddr ); valueMetaString.type = ValueMetaInterface.TYPE_INET; assertEquals( valueMetaString.hashCode( addrObj ), 2130706433 ); valueMetaString.type = ValueMetaInterface.TYPE_NONE; assertEquals( valueMetaString.hashCode( "any" ), 0 ); }
Example 13
Source File: ValueMetaBaseTest.java From pentaho-kettle with Apache License 2.0 | 4 votes |
@Test public void testGetDataXML() throws IOException { BigDecimal bigDecimal = BigDecimal.ONE; ValueMetaBase valueDoubleMetaBase = new ValueMetaBase( String.valueOf( bigDecimal ), ValueMetaInterface.TYPE_BIGNUMBER ); assertEquals( "<value-data>" + Encode.forXml( String.valueOf( bigDecimal ) ) + "</value-data>" + SystemUtils.LINE_SEPARATOR, valueDoubleMetaBase.getDataXML( bigDecimal ) ); boolean valueBoolean = Boolean.TRUE; ValueMetaBase valueBooleanMetaBase = new ValueMetaBase( String.valueOf( valueBoolean ), ValueMetaInterface.TYPE_BOOLEAN ); assertEquals( "<value-data>" + Encode.forXml( String.valueOf( valueBoolean ) ) + "</value-data>" + SystemUtils.LINE_SEPARATOR, valueBooleanMetaBase.getDataXML( valueBoolean ) ); Date date = new Date( 0 ); ValueMetaBase dateMetaBase = new ValueMetaBase( date.toString(), ValueMetaInterface.TYPE_DATE ); SimpleDateFormat formaterData = new SimpleDateFormat( ValueMetaBase.DEFAULT_DATE_FORMAT_MASK ); assertEquals( "<value-data>" + Encode.forXml( formaterData.format( date ) ) + "</value-data>" + SystemUtils.LINE_SEPARATOR, dateMetaBase.getDataXML( date ) ); InetAddress inetAddress = InetAddress.getByName( "127.0.0.1" ); ValueMetaBase inetAddressMetaBase = new ValueMetaBase( inetAddress.toString(), ValueMetaInterface.TYPE_INET ); assertEquals( "<value-data>" + Encode.forXml( inetAddress.toString() ) + "</value-data>" + SystemUtils.LINE_SEPARATOR, inetAddressMetaBase.getDataXML( inetAddress ) ); long value = Long.MAX_VALUE; ValueMetaBase integerMetaBase = new ValueMetaBase( String.valueOf( value ), ValueMetaInterface.TYPE_INTEGER ); assertEquals( "<value-data>" + Encode.forXml( String.valueOf( value ) ) + "</value-data>" + SystemUtils.LINE_SEPARATOR, integerMetaBase.getDataXML( value ) ); String stringValue = "TEST_STRING"; ValueMetaBase valueMetaBase = new ValueMetaString( stringValue ); assertEquals( "<value-data>" + Encode.forXml( stringValue ) + "</value-data>" + SystemUtils.LINE_SEPARATOR, valueMetaBase.getDataXML( stringValue ) ); Timestamp timestamp = new Timestamp( 0 ); ValueMetaBase valueMetaBaseTimeStamp = new ValueMetaBase( timestamp.toString(), ValueMetaInterface.TYPE_TIMESTAMP ); SimpleDateFormat formater = new SimpleDateFormat( ValueMetaBase.DEFAULT_TIMESTAMP_FORMAT_MASK ); assertEquals( "<value-data>" + Encode.forXml( formater.format( timestamp ) ) + "</value-data>" + SystemUtils.LINE_SEPARATOR, valueMetaBaseTimeStamp.getDataXML( timestamp ) ); byte[] byteTestValues = { 0, 1, 2, 3 }; ValueMetaBase valueMetaBaseByteArray = new ValueMetaBase( byteTestValues.toString(), ValueMetaInterface.TYPE_STRING ); valueMetaBaseByteArray.setStorageType( ValueMetaInterface.STORAGE_TYPE_BINARY_STRING ); assertEquals( "<value-data><binary-string>" + Encode.forXml( XMLHandler.encodeBinaryData( byteTestValues ) ) + "</binary-string>" + Const.CR + "</value-data>", valueMetaBaseByteArray.getDataXML( byteTestValues ) ); }
Example 14
Source File: ValueMetaInternetAddress.java From pentaho-kettle with Apache License 2.0 | 4 votes |
public ValueMetaInternetAddress( String name ) { super( name, ValueMetaInterface.TYPE_INET ); }
Example 15
Source File: FieldHelper.java From pentaho-kettle with Apache License 2.0 | 4 votes |
public static String getGetSignature( String accessor, ValueMetaInterface v ) { StringBuilder sb = new StringBuilder(); switch ( v.getType() ) { case ValueMetaInterface.TYPE_BIGNUMBER: sb.append( "BigDecimal " ); break; case ValueMetaInterface.TYPE_BINARY: sb.append( "byte[] " ); break; case ValueMetaInterface.TYPE_BOOLEAN: sb.append( "Boolean " ); break; case ValueMetaInterface.TYPE_DATE: sb.append( "Date " ); break; case ValueMetaInterface.TYPE_INTEGER: sb.append( "Long " ); break; case ValueMetaInterface.TYPE_NUMBER: sb.append( "Double " ); break; case ValueMetaInterface.TYPE_STRING: sb.append( "String " ); break; case ValueMetaInterface.TYPE_INET: sb.append( "InetAddress " ); break; case ValueMetaInterface.TYPE_TIMESTAMP: sb.append( "Timestamp " ); break; case ValueMetaInterface.TYPE_SERIALIZABLE: default: sb.append( "Object " ); break; } if ( validJavaIdentifier.matcher( v.getName() ).matches() ) { sb.append( v.getName() ); } else { sb.append( "value" ); } String name = getNativeDataTypeSimpleName( v ); sb .append( " = " ).append( accessor ).append( ".get" ).append( "-".equals( name ) ? "Object" : name ) .append( "(r);" ); return sb.toString(); }
Example 16
Source File: JaninoStepIT.java From pentaho-kettle with Apache License 2.0 | 4 votes |
/** * Test case for janino step. */ @Test public void testJaninoStep() throws Exception { KettleEnvironment.init(); // // Create a new transformation... // TransMeta transMeta = new TransMeta(); transMeta.setName( "janino test" ); PluginRegistry registry = PluginRegistry.getInstance(); // create an injector step... String injectorStepName = "injector step"; InjectorMeta im = new InjectorMeta(); // Set the information of the injector. String injectorPid = registry.getPluginId( StepPluginType.class, im ); StepMeta injectorStep = new StepMeta( injectorPid, injectorStepName, im ); transMeta.addStep( injectorStep ); // // create a janino step... // String stepname = "janino"; JaninoMeta jm = new JaninoMeta(); // Set the information of the step String janinoPid = registry.getPluginId( StepPluginType.class, jm ); StepMeta janinoStep = new StepMeta( janinoPid, stepname, jm ); transMeta.addStep( janinoStep ); jm.setDefault(); JaninoMetaFunction[] formulas = { new JaninoMetaFunction( "string", "(string==null)?null:\"string-value\"", ValueMetaInterface.TYPE_STRING, -1, -1, "string" ), new JaninoMetaFunction( "integer", "(integer==null)?null:new Long(42L)", ValueMetaInterface.TYPE_INTEGER, -1, -1, "integer" ), new JaninoMetaFunction( "number", "(number==null)?null:new Double(23.0)", ValueMetaInterface.TYPE_NUMBER, -1, -1, "number" ), new JaninoMetaFunction( "bigdecimal", "(bigdecimal==null)?null:new java.math.BigDecimal(11.0)", ValueMetaInterface.TYPE_BIGNUMBER, -1, -1, "bigdecimal" ), new JaninoMetaFunction( "date", "(date==null)?null:new java.util.Date(10000000)", ValueMetaInterface.TYPE_DATE, -1, -1, "date" ), new JaninoMetaFunction( "binary", "(binary==null)?null:new byte[]{1,2,3,4,5}", ValueMetaInterface.TYPE_BINARY, -1, -1, "binary" ), new JaninoMetaFunction( "bool", "(bool==null)?null:Boolean.TRUE", ValueMetaInterface.TYPE_BOOLEAN, -1, -1, "bool" ), new JaninoMetaFunction( "timestamp", "(timestamp==null)?null:new java.sql.Timestamp(0L)", ValueMetaInterface.TYPE_TIMESTAMP, -1, -1, "timestamp" ), new JaninoMetaFunction( "inetaddress", "(inetaddress==null)?null:java.net.InetAddress.getByAddress( new byte[]{ 127, 0, 0, 1} )", ValueMetaInterface.TYPE_INET, -1, -1, "inetaddress" ), }; jm.setFormula( formulas ); transMeta.addTransHop( new TransHopMeta( injectorStep, janinoStep ) ); // // Create a dummy step // String dummyStepname = "dummy step"; DummyTransMeta dm = new DummyTransMeta(); String dummyPid = registry.getPluginId( StepPluginType.class, dm ); StepMeta dummyStep = new StepMeta( dummyPid, dummyStepname, dm ); transMeta.addStep( dummyStep ); TransHopMeta hi = new TransHopMeta( janinoStep, dummyStep ); transMeta.addTransHop( hi ); // Now execute the transformation... Trans trans = new Trans( transMeta ); trans.prepareExecution( null ); StepInterface si = trans.getStepInterface( dummyStepname, 0 ); RowStepCollector rc = new RowStepCollector(); si.addRowListener( rc ); RowProducer rp = trans.addRowProducer( injectorStepName, 0 ); trans.startThreads(); for ( RowMetaAndData rm : createInputList() ) { rp.putRow( rm.getRowMeta(), rm.getData() ); } rp.finished(); trans.waitUntilFinished(); List<RowMetaAndData> checkList = createExpectedList(); List<RowMetaAndData> resultRows = rc.getRowsWritten(); checkRows( resultRows, checkList ); }
Example 17
Source File: AvroNestedReader.java From pentaho-hadoop-shims with Apache License 2.0 | 4 votes |
/** * Perform Kettle type conversions for the Avro leaf field value. * * @param fieldValue the leaf value from the Avro structure * @return an Object of the appropriate Kettle type * @throws KettleException if a problem occurs */ protected Object getKettleValue( AvroInputField avroInputField, Object fieldValue ) throws KettleException { switch ( avroInputField.getTempValueMeta().getType() ) { case ValueMetaInterface.TYPE_BIGNUMBER: return avroInputField.getTempValueMeta().getBigNumber( fieldValue ); case ValueMetaInterface.TYPE_BINARY: return avroInputField.getTempValueMeta().getBinary( fieldValue ); case ValueMetaInterface.TYPE_BOOLEAN: return avroInputField.getTempValueMeta().getBoolean( fieldValue ); case ValueMetaInterface.TYPE_DATE: if ( avroInputField.getAvroType().getBaseType() == AvroSpec.DataType.INTEGER.getBaseType() ) { LocalDate localDate = LocalDate.ofEpochDay( 0 ).plusDays( (Long) fieldValue ); return Date.from( localDate.atStartOfDay( ZoneId.systemDefault() ).toInstant() ); } else if ( avroInputField.getAvroType().getBaseType() == AvroSpec.DataType.STRING.getBaseType() ) { Object pentahoData = null; String dateFormatStr = avroInputField.getStringFormat(); if ( ( dateFormatStr == null ) || ( dateFormatStr.trim().length() == 0 ) ) { dateFormatStr = ValueMetaBase.DEFAULT_DATE_FORMAT_MASK; } SimpleDateFormat datePattern = new SimpleDateFormat( dateFormatStr ); try { return datePattern.parse( fieldValue.toString() ); } catch ( Exception e ) { return null; } } return avroInputField.getTempValueMeta().getDate( fieldValue ); case ValueMetaInterface.TYPE_TIMESTAMP: return new Timestamp( (Long) fieldValue ); case ValueMetaInterface.TYPE_INTEGER: return avroInputField.getTempValueMeta().getInteger( fieldValue ); case ValueMetaInterface.TYPE_NUMBER: return avroInputField.getTempValueMeta().getNumber( fieldValue ); case ValueMetaInterface.TYPE_STRING: return avroInputField.getTempValueMeta().getString( fieldValue ); case ValueMetaInterface.TYPE_INET: try { return InetAddress.getByName( fieldValue.toString() ); } catch ( UnknownHostException ex ) { return null; } default: return null; } }