Java Code Examples for org.pentaho.di.core.row.ValueMetaInterface#getInteger()
The following examples show how to use
org.pentaho.di.core.row.ValueMetaInterface#getInteger() .
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: RowForumulaContext.java From pentaho-kettle with Apache License 2.0 | 6 votes |
public static Object getPrimitive( ValueMetaInterface valueMeta, Object valueData ) throws KettleValueException { switch ( valueMeta.getType() ) { case ValueMetaInterface.TYPE_BIGNUMBER: return valueMeta.getBigNumber( valueData ); case ValueMetaInterface.TYPE_BINARY: return valueMeta.getBinary( valueData ); case ValueMetaInterface.TYPE_BOOLEAN: return valueMeta.getBoolean( valueData ); case ValueMetaInterface.TYPE_DATE: return valueMeta.getDate( valueData ); case ValueMetaInterface.TYPE_INTEGER: return valueMeta.getInteger( valueData ); case ValueMetaInterface.TYPE_NUMBER: return valueMeta.getNumber( valueData ); // case ValueMetaInterface.TYPE_SERIALIZABLE: return valueMeta.(valueData); case ValueMetaInterface.TYPE_STRING: return valueMeta.getString( valueData ); default: return null; } }
Example 2
Source File: ValueMetaBase.java From pentaho-kettle with Apache License 2.0 | 6 votes |
/** * Convert the specified data to the data type specified in this object. * * @param meta2 * the metadata of the object to be converted * @param data2 * the data of the object to be converted * @return the object in the data type of this value metadata object * @throws KettleValueException * in case there is a data conversion error */ @Override public Object convertData( ValueMetaInterface meta2, Object data2 ) throws KettleValueException { switch ( getType() ) { case TYPE_NONE: case TYPE_STRING: return meta2.getString( data2 ); case TYPE_NUMBER: return meta2.getNumber( data2 ); case TYPE_INTEGER: return meta2.getInteger( data2 ); case TYPE_DATE: return meta2.getDate( data2 ); case TYPE_BIGNUMBER: return meta2.getBigNumber( data2 ); case TYPE_BOOLEAN: return meta2.getBoolean( data2 ); case TYPE_BINARY: return meta2.getBinary( data2 ); default: throw new KettleValueException( toString() + " : I can't convert the specified value to data type : " + getType() ); } }
Example 3
Source File: ValueMetaBase.java From pentaho-kettle with Apache License 2.0 | 6 votes |
/** * Convert the specified data to the data type specified in this object. For String conversion, be compatible with * version 2.5.2. * * @param meta2 * the metadata of the object to be converted * @param data2 * the data of the object to be converted * @return the object in the data type of this value metadata object * @throws KettleValueException * in case there is a data conversion error */ @Override public Object convertDataCompatible( ValueMetaInterface meta2, Object data2 ) throws KettleValueException { switch ( getType() ) { case TYPE_STRING: return meta2.getCompatibleString( data2 ); case TYPE_NUMBER: return meta2.getNumber( data2 ); case TYPE_INTEGER: return meta2.getInteger( data2 ); case TYPE_DATE: return meta2.getDate( data2 ); case TYPE_BIGNUMBER: return meta2.getBigNumber( data2 ); case TYPE_BOOLEAN: return meta2.getBoolean( data2 ); case TYPE_BINARY: return meta2.getBinary( data2 ); default: throw new KettleValueException( toString() + " : I can't convert the specified value to data type : " + getType() ); } }
Example 4
Source File: ValueMetaStringTest.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@Test public void testGetIntegerWithoutConversionMask() throws KettleValueException, ParseException { String value = "100.56"; ValueMetaInterface stringValueMeta = new ValueMetaString( "test" ); Long expected = 100L; Long result = stringValueMeta.getInteger( value ); assertEquals( expected, result ); }
Example 5
Source File: HBaseValueMeta.java From pentaho-hadoop-shims with Apache License 2.0 | 4 votes |
public static byte[] encodeColumnValue( Object columnValue, ValueMetaInterface colMeta, HBaseValueMeta mappingColMeta, HBaseBytesUtilShim bytesUtil ) throws KettleException { byte[] encoded = null; switch ( mappingColMeta.getType() ) { case TYPE_STRING: String toEncode = colMeta.getString( columnValue ); encoded = bytesUtil.toBytes( toEncode ); break; case TYPE_INTEGER: Long l = colMeta.getInteger( columnValue ); if ( mappingColMeta.getIsLongOrDouble() ) { encoded = bytesUtil.toBytes( l.longValue() ); } else { encoded = bytesUtil.toBytes( l.intValue() ); } break; case TYPE_NUMBER: Double d = colMeta.getNumber( columnValue ); if ( mappingColMeta.getIsLongOrDouble() ) { encoded = bytesUtil.toBytes( d.doubleValue() ); } else { encoded = bytesUtil.toBytes( d.floatValue() ); } break; case TYPE_DATE: Date date = colMeta.getDate( columnValue ); encoded = bytesUtil.toBytes( date.getTime() ); break; case TYPE_BOOLEAN: Boolean b = colMeta.getBoolean( columnValue ); String boolString = ( b.booleanValue() ) ? "Y" : "N"; encoded = bytesUtil.toBytes( boolString ); break; case TYPE_BIGNUMBER: BigDecimal bd = colMeta.getBigNumber( columnValue ); String bds = bd.toString(); encoded = bytesUtil.toBytes( bds ); break; case TYPE_SERIALIZABLE: try { encoded = encodeObject( columnValue ); } catch ( IOException e ) { throw new KettleException( BaseMessages.getString( PKG, "HBaseValueMeta.Error.UnableToSerialize", colMeta.getName() ), e ); } break; case TYPE_BINARY: encoded = colMeta.getBinary( columnValue ); break; } if ( encoded == null ) { throw new KettleException( BaseMessages.getString( PKG, "HBaseValueMeta.Error.UnknownTypeForColumn" ) ); } return encoded; }
Example 6
Source File: AccessOutputMeta.java From pentaho-kettle with Apache License 2.0 | 4 votes |
public static Object[] createObjectsForRow( RowMetaInterface rowMeta, Object[] rowData ) throws KettleValueException { Object[] values = new Object[rowMeta.size()]; for ( int i = 0; i < rowMeta.size(); i++ ) { ValueMetaInterface valueMeta = rowMeta.getValueMeta( i ); Object valueData = rowData[i]; // Prevent a NullPointerException below if ( valueData == null || valueMeta == null ) { values[i] = null; continue; } int length = valueMeta.getLength(); switch ( valueMeta.getType() ) { case ValueMetaInterface.TYPE_INTEGER: if ( length < 3 ) { values[i] = new Byte( valueMeta.getInteger( valueData ).byteValue() ); } else { if ( length < 5 ) { values[i] = new Short( valueMeta.getInteger( valueData ).shortValue() ); } else { values[i] = valueMeta.getInteger( valueData ); } } break; case ValueMetaInterface.TYPE_NUMBER: values[i] = valueMeta.getNumber( valueData ); break; case ValueMetaInterface.TYPE_DATE: values[i] = valueMeta.getDate( valueData ); break; case ValueMetaInterface.TYPE_STRING: values[i] = valueMeta.getString( valueData ); break; case ValueMetaInterface.TYPE_BINARY: values[i] = valueMeta.getBinary( valueData ); break; case ValueMetaInterface.TYPE_BOOLEAN: values[i] = valueMeta.getBoolean( valueData ); break; case ValueMetaInterface.TYPE_BIGNUMBER: values[i] = valueMeta.getNumber( valueData ); break; default: break; } } return values; }