Java Code Examples for org.pentaho.di.core.row.ValueMetaInterface#TYPE_BIGNUMBER
The following examples show how to use
org.pentaho.di.core.row.ValueMetaInterface#TYPE_BIGNUMBER .
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: TypeConverterFactory.java From pentaho-hadoop-shims with Apache License 2.0 | 6 votes |
/** * Determine the Hadoop writable type to pass Kettle type back to Hadoop as. * * @param kettleType * @return Java type to convert {@code kettleType} to when sending data back to Hadoop. */ public static Class<? extends Writable> getWritableForKettleType( ValueMetaInterface kettleType ) { if ( kettleType == null ) { return NullWritable.class; } switch ( kettleType.getType() ) { case ValueMetaInterface.TYPE_STRING: case ValueMetaInterface.TYPE_BIGNUMBER: case ValueMetaInterface.TYPE_DATE: return Text.class; case ValueMetaInterface.TYPE_INTEGER: return LongWritable.class; case ValueMetaInterface.TYPE_NUMBER: return DoubleWritable.class; case ValueMetaInterface.TYPE_BOOLEAN: return BooleanWritable.class; case ValueMetaInterface.TYPE_BINARY: return BytesWritable.class; default: return Text.class; } }
Example 2
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 3
Source File: CiviStep.java From civicrm-data-integration with GNU General Public License v3.0 | 5 votes |
protected Object getObjectValue(String field, String object) { try { if (object == null || object.equals("")) { return null; } CiviField cf = ((CiviMeta) civiMeta).getCiviCrmListingFields().get(field); int metaType = ValueMetaInterface.TYPE_STRING; if (cf != null) metaType = cf.getMetaInterfaceType(); switch (metaType) { case ValueMetaInterface.TYPE_INTEGER: return Long.parseLong(object); case ValueMetaInterface.TYPE_STRING: return object.toString(); case ValueMetaInterface.TYPE_NUMBER: return Double.parseDouble(object); case ValueMetaInterface.TYPE_DATE: SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); return formatter.parse(object); case ValueMetaInterface.TYPE_BIGNUMBER: return new BigDecimal(object.toString()); case ValueMetaInterface.TYPE_BOOLEAN: return Boolean.parseBoolean(object); case ValueMetaInterface.TYPE_BINARY: throw new KettleValueException(toString() + " : I don't know how to convert binary values to integers."); case ValueMetaInterface.TYPE_SERIALIZABLE: throw new KettleValueException(toString() + " : I don't know how to convert serializable values to integers."); default: throw new KettleValueException(toString() + " : Unknown type " + metaType + " specified."); } } catch (Exception e) { e.printStackTrace(); } return null; }
Example 4
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 5
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 6
Source File: ValueMetaConverter.java From pentaho-kettle with Apache License 2.0 | 5 votes |
protected Object convertFromNumberMetaInterface( int targetValueMetaType, Object value ) throws ValueMetaConversionException { if ( value == null ) { return null; } if ( !( value instanceof Double ) ) { handleConversionError( "Error. Expecting value of type Double. actual value type = '" + value.getClass() + "'. value = '" + value + "'." ); } try { switch ( targetValueMetaType ) { case ValueMetaInterface.TYPE_STRING: return Double.toString( (Double) value ); case ValueMetaInterface.TYPE_NUMBER: Double doubleValue = new Double( (Double) value ); if ( getPrecision() > 0 ) { BigDecimal bigDecimal = new BigDecimal( doubleValue ); bigDecimal = bigDecimal.setScale( getPrecision(), RoundingMode.HALF_UP ); doubleValue = bigDecimal.doubleValue(); } return doubleValue; case ValueMetaInterface.TYPE_INTEGER: return ( (Double) value ).longValue(); case ValueMetaInterface.TYPE_BIGNUMBER: return new BigDecimal( (Double) value ); default: throwBadConversionCombination( ValueMetaInterface.TYPE_NUMBER, targetValueMetaType, value ); } } catch ( Exception e ) { throwErroredConversion( ValueMetaInterface.TYPE_NUMBER, targetValueMetaType, value, e ); } return null; }
Example 7
Source File: ValueMetaConverter.java From pentaho-kettle with Apache License 2.0 | 4 votes |
protected Object convertFromIntegerMetaInterface( int targetValueMetaType, Object value ) throws ValueMetaConversionException { if ( value == null ) { return value; } if ( !( value instanceof Long ) ) { handleConversionError( "Error. Expecting value of type Long. actual value type = '" + value.getClass() + "'. value = '" + value + "'." ); } try { switch ( targetValueMetaType ) { case ValueMetaInterface.TYPE_STRING: return Long.toString( (Long) value ); case ValueMetaInterface.TYPE_INTEGER: return new Long( (Long) value ); case ValueMetaInterface.TYPE_NUMBER: Double doubleValue = ( (Long) value ).doubleValue(); if ( getPrecision() > 0 ) { BigDecimal bigDecimal = new BigDecimal( doubleValue ); bigDecimal = bigDecimal.setScale( getPrecision(), RoundingMode.HALF_UP ); doubleValue = bigDecimal.doubleValue(); } return doubleValue; case ValueMetaInterface.TYPE_BIGNUMBER: return new BigDecimal( ( (Long) value ).doubleValue() ); case ValueMetaInterface.TYPE_DATE: return new Date( (long) value ); case ValueMetaInterface.TYPE_TIMESTAMP: return new Timestamp( (long) value ); default: throwBadConversionCombination( ValueMetaInterface.TYPE_INTEGER, targetValueMetaType, value ); } } catch ( Exception e ) { throwErroredConversion( ValueMetaInterface.TYPE_INTEGER, targetValueMetaType, value, e ); } return value; }
Example 8
Source File: UniVerseDatabaseMeta.java From pentaho-kettle with Apache License 2.0 | 4 votes |
@Override public String getFieldDefinition( ValueMetaInterface v, String tk, String pk, boolean useAutoinc, boolean addFieldName, boolean addCr ) { String retval = ""; String fieldname = v.getName(); int length = v.getLength(); int precision = v.getPrecision(); if ( addFieldName ) { retval += fieldname + " "; } int type = v.getType(); switch ( type ) { case ValueMetaInterface.TYPE_DATE: retval += "DATE"; break; case ValueMetaInterface.TYPE_BOOLEAN: retval += "CHAR(1)"; break; case ValueMetaInterface.TYPE_NUMBER: case ValueMetaInterface.TYPE_INTEGER: case ValueMetaInterface.TYPE_BIGNUMBER: if ( fieldname.equalsIgnoreCase( tk ) || // Technical key fieldname.equalsIgnoreCase( pk ) // Primary key ) { retval += "INTEGER"; } else { if ( length > 0 ) { if ( precision > 0 || length > 18 ) { retval += "DECIMAL(" + length + ", " + precision + ")"; } else { retval += "INTEGER"; } } else { retval += "DOUBLE PRECISION"; } } break; case ValueMetaInterface.TYPE_STRING: if ( length >= MAX_VARCHAR_LENGTH || length <= 0 ) { retval += "VARCHAR(" + MAX_VARCHAR_LENGTH + ")"; } else { retval += "VARCHAR(" + length + ")"; } break; default: retval += " UNKNOWN"; break; } if ( addCr ) { retval += Const.CR; } return retval; }
Example 9
Source File: TestCWM.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 4 votes |
public void storeTable() { CwmTable table = cwm.getTable( TEST_TABLE_NAME ); if ( table == null ) { System.out.println( "Table [" + TEST_TABLE_NAME + "] not found: creating..." ); //$NON-NLS-1$ //$NON-NLS-2$ } else { System.out.println( "Table [" + TEST_TABLE_NAME + "] found: overwriting..." ); //$NON-NLS-1$ //$NON-NLS-2$ } cwm.beginTransaction(); RowMetaInterface fields = new RowMeta(); ValueMetaInterface field1 = new ValueMeta( "field1", ValueMetaInterface.TYPE_STRING ); //$NON-NLS-1$ field1.setLength( 35 ); field1.setOrigin( "field1 description" ); //$NON-NLS-1$ fields.addValueMeta( field1 ); ValueMetaInterface field2 = new ValueMeta( "field2", ValueMetaInterface.TYPE_NUMBER ); //$NON-NLS-1$ field2.setLength( 7, 2 ); field2.setOrigin( "field2 description" ); //$NON-NLS-1$ fields.addValueMeta( field2 ); ValueMetaInterface field3 = new ValueMeta( "field3", ValueMetaInterface.TYPE_INTEGER ); field3.setLength( 5 ); field3.setOrigin( "field3 description" ); fields.addValueMeta( field3 ); ValueMetaInterface field4 = new ValueMeta( "field4", ValueMetaInterface.TYPE_DATE ); field4.setOrigin( "field4 description" ); fields.addValueMeta( field4 ); ValueMetaInterface field5 = new ValueMeta( "field5", ValueMetaInterface.TYPE_BIGNUMBER ); field5.setLength( 52, 16 ); field5.setOrigin( "field5 description" ); fields.addValueMeta( field5 ); ValueMetaInterface field6 = new ValueMeta( "field6", ValueMetaInterface.TYPE_BOOLEAN ); field6.setOrigin( "field6 description" ); fields.addValueMeta( field6 ); table = cwm.createTable( TEST_TABLE_NAME, fields ); // Add descriptions to table and columns... CwmDescription description = cwm.createDescription( "This is a table description" ); //$NON-NLS-1$ cwm.setDescription( table, description ); @SuppressWarnings( "unchecked" ) Collection<CwmColumn> collection = table.getOwnedElement(); CwmColumn[] columns = (CwmColumn[]) collection.toArray( new CwmColumn[collection.size()] ); for ( int i = 0; i < fields.size(); i++ ) { ValueMetaInterface field = fields.getValueMeta( i ); CwmColumn column = columns[i]; // Add a description to the column // description = cwm.createDescription( field.getOrigin() ); cwm.setDescription( column, description ); } // Try to create a package here... CwmPackage p = cwm.createPackage( DOMAIN + " package" ); //$NON-NLS-1$ @SuppressWarnings( "unchecked" ) Collection<CwmTable> ca = p.getImportedElement(); ca.add( table ); cwm.setDescription( p, cwm.createDescription( "This is a package description for [" + DOMAIN + "]" ) ); //$NON-NLS-1$ //$NON-NLS-2$ cwm.endTransaction(); System.out.println( "Finished writing to table [" + TEST_TABLE_NAME + "]." ); //$NON-NLS-1$ //$NON-NLS-2$ }
Example 10
Source File: OracleDatabaseMeta.java From pentaho-kettle with Apache License 2.0 | 4 votes |
@Override public String getFieldDefinition( ValueMetaInterface v, String tk, String pk, boolean useAutoinc, boolean addFieldName, boolean addCr ) { StringBuilder retval = new StringBuilder( 128 ); String fieldname = v.getName(); int length = v.getLength(); int precision = v.getPrecision(); if ( addFieldName ) { retval.append( fieldname ).append( ' ' ); } int type = v.getType(); switch ( type ) { case ValueMetaInterface.TYPE_TIMESTAMP: if ( supportsTimestampDataType() ) { retval.append( "TIMESTAMP" ); } else { retval.append( "DATE" ); } break; case ValueMetaInterface.TYPE_DATE: retval.append( "DATE" ); break; case ValueMetaInterface.TYPE_BOOLEAN: retval.append( "CHAR(1)" ); break; case ValueMetaInterface.TYPE_NUMBER: case ValueMetaInterface.TYPE_BIGNUMBER: retval.append( "NUMBER" ); if ( length > 0 ) { retval.append( '(' ).append( length ); if ( precision > 0 ) { retval.append( ", " ).append( precision ); } retval.append( ')' ); } break; case ValueMetaInterface.TYPE_INTEGER: retval.append( "INTEGER" ); break; case ValueMetaInterface.TYPE_STRING: if ( length >= DatabaseMeta.CLOB_LENGTH ) { retval.append( "CLOB" ); } else { if ( length == 1 ) { retval.append( "CHAR(1)" ); } else if ( length > 0 && length <= getMaxVARCHARLength() ) { retval.append( "VARCHAR2(" ).append( length ).append( ')' ); } else { if ( length <= 0 ) { retval.append( "VARCHAR2(2000)" ); // We don't know, so we just use the maximum... } else { retval.append( "CLOB" ); } } } break; case ValueMetaInterface.TYPE_BINARY: // the BLOB can contain binary data. retval.append( "BLOB" ); break; default: retval.append( " UNKNOWN" ); break; } if ( addCr ) { retval.append( Const.CR ); } return retval.toString(); }
Example 11
Source File: TableProducer.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 4 votes |
/** * This method is called when a row is written to another step (even if there is no next step) * * @param rowMeta the metadata of the row * @param row the data of the row * @throws org.pentaho.di.core.exception.KettleStepException an exception that can be thrown to hard stop the step */ public void rowWrittenEvent( final RowMetaInterface rowMeta, final Object[] row ) throws KettleStepException { if ( firstCall ) { this.tableModel = createTableModel( rowMeta ); firstCall = false; } if ( queryLimit > 0 && rowsWritten > queryLimit ) { return; } try { rowsWritten += 1; final int count = tableModel.getColumnCount(); final Object dataRow[] = new Object[ count ]; for ( int columnNo = 0; columnNo < count; columnNo++ ) { final ValueMetaInterface valueMeta = rowMeta.getValueMeta( columnNo ); switch( valueMeta.getType() ) { case ValueMetaInterface.TYPE_BIGNUMBER: dataRow[ columnNo ] = rowMeta.getBigNumber( row, columnNo ); break; case ValueMetaInterface.TYPE_BOOLEAN: dataRow[ columnNo ] = rowMeta.getBoolean( row, columnNo ); break; case ValueMetaInterface.TYPE_DATE: dataRow[ columnNo ] = rowMeta.getDate( row, columnNo ); break; case ValueMetaInterface.TYPE_INTEGER: dataRow[ columnNo ] = rowMeta.getInteger( row, columnNo ); break; case ValueMetaInterface.TYPE_NONE: dataRow[ columnNo ] = rowMeta.getString( row, columnNo ); break; case ValueMetaInterface.TYPE_NUMBER: dataRow[ columnNo ] = rowMeta.getNumber( row, columnNo ); break; case ValueMetaInterface.TYPE_STRING: dataRow[ columnNo ] = rowMeta.getString( row, columnNo ); break; case ValueMetaInterface.TYPE_BINARY: dataRow[ columnNo ] = rowMeta.getBinary( row, columnNo ); break; default: dataRow[ columnNo ] = rowMeta.getString( row, columnNo ); } } tableModel.addRow( dataRow ); } catch ( final KettleValueException kve ) { throw new KettleStepException( kve ); } catch ( final Exception e ) { throw new KettleStepException( e ); } }
Example 12
Source File: MSSQLServerDatabaseMeta.java From pentaho-kettle with Apache License 2.0 | 4 votes |
@Override public String getFieldDefinition( ValueMetaInterface v, String tk, String pk, boolean useAutoinc, boolean addFieldName, boolean addCr ) { String retval = ""; String fieldname = v.getName(); int length = v.getLength(); int precision = v.getPrecision(); if ( addFieldName ) { retval += fieldname + " "; } int type = v.getType(); switch ( type ) { case ValueMetaInterface.TYPE_TIMESTAMP: case ValueMetaInterface.TYPE_DATE: retval += "DATETIME"; break; case ValueMetaInterface.TYPE_BOOLEAN: if ( supportsBooleanDataType() ) { retval += "BIT"; } else { retval += "CHAR(1)"; } break; case ValueMetaInterface.TYPE_NUMBER: case ValueMetaInterface.TYPE_INTEGER: case ValueMetaInterface.TYPE_BIGNUMBER: if ( fieldname.equalsIgnoreCase( tk ) || // Technical key fieldname.equalsIgnoreCase( pk ) // Primary key ) { if ( useAutoinc ) { retval += "BIGINT PRIMARY KEY IDENTITY(0,1)"; } else { retval += "BIGINT PRIMARY KEY"; } } else { if ( precision == 0 ) { if ( length > 18 ) { retval += "DECIMAL(" + length + ",0)"; } else { if ( length > 9 ) { retval += "BIGINT"; } else { retval += "INT"; } } } else { if ( precision > 0 && length > 0 ) { retval += "DECIMAL(" + length + "," + precision + ")"; } else { retval += "FLOAT(53)"; } } } break; case ValueMetaInterface.TYPE_STRING: if ( length < getMaxVARCHARLength() ) { // Maybe use some default DB String length in case length<=0 if ( length > 0 ) { retval += "VARCHAR(" + length + ")"; } else { retval += "VARCHAR(100)"; } } else { retval += "TEXT"; // Up to 2bilion characters. } break; case ValueMetaInterface.TYPE_BINARY: retval += "VARBINARY(MAX)"; break; default: retval += " UNKNOWN"; break; } if ( addCr ) { retval += Const.CR; } return retval; }
Example 13
Source File: GuptaDatabaseMeta.java From pentaho-kettle with Apache License 2.0 | 4 votes |
@Override public String getFieldDefinition( ValueMetaInterface v, String tk, String pk, boolean useAutoinc, boolean addFieldName, boolean addCr ) { String retval = ""; String fieldname = v.getName(); int length = v.getLength(); int precision = v.getPrecision(); if ( addFieldName ) { retval += fieldname + " "; } int type = v.getType(); switch ( type ) { case ValueMetaInterface.TYPE_TIMESTAMP: case ValueMetaInterface.TYPE_DATE: retval += "DATETIME NULL"; break; case ValueMetaInterface.TYPE_BOOLEAN: retval += "CHAR(1)"; break; case ValueMetaInterface.TYPE_NUMBER: case ValueMetaInterface.TYPE_INTEGER: case ValueMetaInterface.TYPE_BIGNUMBER: if ( fieldname.equalsIgnoreCase( tk ) || // Technical key fieldname.equalsIgnoreCase( pk ) // Primary key ) { retval += "INTEGER NOT NULL"; } else { if ( ( length < 0 && precision < 0 ) || precision > 0 || length > 9 ) { retval += "DOUBLE PRECISION"; } else { // Precision == 0 && length<=9 retval += "INTEGER"; } } break; case ValueMetaInterface.TYPE_STRING: if ( length > 254 || length < 0 ) { retval += "LONG VARCHAR"; } else { retval += "VARCHAR(" + length + ")"; } break; default: retval += " UNKNOWN"; break; } if ( addCr ) { retval += Const.CR; } return retval; }
Example 14
Source File: IngresDatabaseMeta.java From pentaho-kettle with Apache License 2.0 | 4 votes |
@Override public String getFieldDefinition( ValueMetaInterface v, String tk, String pk, boolean useAutoinc, boolean addFieldName, boolean addCr ) { String retval = ""; String fieldname = v.getName(); int length = v.getLength(); int precision = v.getPrecision(); if ( addFieldName ) { retval += fieldname + " "; } int type = v.getType(); switch ( type ) { case ValueMetaInterface.TYPE_TIMESTAMP: retval += "TIMESTAMP"; break; case ValueMetaInterface.TYPE_DATE: retval += "DATE"; break; case ValueMetaInterface.TYPE_BOOLEAN: retval += "CHAR(1)"; break; case ValueMetaInterface.TYPE_NUMBER: case ValueMetaInterface.TYPE_INTEGER: case ValueMetaInterface.TYPE_BIGNUMBER: if ( fieldname.equalsIgnoreCase( tk ) || // Technical key fieldname.equalsIgnoreCase( pk ) // Primary key ) { if ( useAutoinc ) { retval += "BIGINT PRIMARY KEY IDENTITY(0,1)"; } else { retval += "BIGINT PRIMARY KEY NOT NULL"; } } else { if ( precision == 0 ) { // integer numbers if ( length > 9 ) { retval += "BIGINT"; } else { if ( length > 4 ) { retval += "INTEGER"; } else { if ( length > 2 ) { retval += "SMALLINT"; } else { retval += "INTEGER1"; } } } } else { retval += "FLOAT"; } } break; case ValueMetaInterface.TYPE_STRING: // Maybe use some default DB String length in case length<=0 if ( length > 0 ) { retval += "VARCHAR(" + length + ")"; } else { retval += "VARCHAR(2000)"; } break; default: retval += " UNKNOWN"; break; } if ( addCr ) { retval += Const.CR; } return retval; }
Example 15
Source File: GPBulkDataOutput.java From pentaho-kettle with Apache License 2.0 | 4 votes |
public void writeLine( RowMetaInterface mi, Object[] row ) throws KettleException { if ( first ) { first = false; enclosure = meta.getEnclosure(); // Setup up the fields we need to take for each of the rows // as this speeds up processing. fieldNumbers = new int[meta.getFieldStream().length]; for ( int i = 0; i < fieldNumbers.length; i++ ) { fieldNumbers[i] = mi.indexOfValue( meta.getFieldStream()[i] ); if ( fieldNumbers[i] < 0 ) { throw new KettleException( "Could not find field " + meta.getFieldStream()[i] + " in stream" ); } } sdfDate = new SimpleDateFormat( "yyyy-MM-dd" ); sdfDateTime = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss.SSS" ); } // Write the data to the output ValueMetaInterface v = null; int number = 0; for ( int i = 0; i < fieldNumbers.length; i++ ) { if ( i != 0 ) { output.print( "," ); } number = fieldNumbers[i]; v = mi.getValueMeta( number ); if ( row[number] == null ) { // TODO (SB): special check for null in case of Strings. output.print( enclosure ); output.print( enclosure ); } else { switch ( v.getType() ) { case ValueMetaInterface.TYPE_STRING: String s = mi.getString( row, number ); if ( s.indexOf( enclosure ) >= 0 ) { s = createEscapedString( s, enclosure ); } output.print( enclosure ); output.print( s ); output.print( enclosure ); break; case ValueMetaInterface.TYPE_INTEGER: Long l = mi.getInteger( row, number ); output.print( enclosure ); output.print( l ); output.print( enclosure ); break; case ValueMetaInterface.TYPE_NUMBER: Double d = mi.getNumber( row, number ); output.print( enclosure ); output.print( d ); output.print( enclosure ); break; case ValueMetaInterface.TYPE_BIGNUMBER: BigDecimal bd = mi.getBigNumber( row, number ); output.print( enclosure ); output.print( bd ); output.print( enclosure ); break; case ValueMetaInterface.TYPE_DATE: Date dt = mi.getDate( row, number ); output.print( enclosure ); String mask = meta.getDateMask()[i]; if ( GPBulkLoaderMeta.DATE_MASK_DATETIME.equals( mask ) ) { output.print( sdfDateTime.format( dt ) ); } else { // Default is date format output.print( sdfDate.format( dt ) ); } output.print( enclosure ); break; case ValueMetaInterface.TYPE_BOOLEAN: Boolean b = mi.getBoolean( row, number ); output.print( enclosure ); if ( b.booleanValue() ) { output.print( "Y" ); } else { output.print( "N" ); } output.print( enclosure ); break; case ValueMetaInterface.TYPE_BINARY: byte[] byt = mi.getBinary( row, number ); output.print( "<startlob>" ); output.print( byt ); output.print( "<endlob>" ); break; default: throw new KettleException( "Unsupported type" ); } } } output.print( Const.CR ); }
Example 16
Source File: InterbaseDatabaseMeta.java From pentaho-kettle with Apache License 2.0 | 4 votes |
@Override public String getFieldDefinition( ValueMetaInterface v, String tk, String pk, boolean useAutoinc, boolean addFieldName, boolean addCr ) { String retval = ""; String fieldname = v.getName(); int length = v.getLength(); int precision = v.getPrecision(); if ( addFieldName ) { if ( Const.indexOfString( fieldname, getReservedWords() ) >= 0 ) { retval += getStartQuote() + fieldname + getEndQuote(); } else { retval += fieldname + " "; } } int type = v.getType(); switch ( type ) { case ValueMetaInterface.TYPE_DATE: retval += "DATE"; break; case ValueMetaInterface.TYPE_BOOLEAN: retval += "CHAR(1)"; break; case ValueMetaInterface.TYPE_NUMBER: case ValueMetaInterface.TYPE_INTEGER: case ValueMetaInterface.TYPE_BIGNUMBER: if ( fieldname.equalsIgnoreCase( tk ) || // Technical key fieldname.equalsIgnoreCase( pk ) // Primary key ) { retval += "INTEGER NOT NULL PRIMARY KEY"; } else { if ( length > 0 ) { if ( precision > 0 || length > 9 ) { retval += "NUMERIC(" + length; if ( precision > 0 ) { retval += ", " + precision; } retval += ")"; } else { if ( length <= 5 ) { retval += "SMALLINT"; } else { retval += "INTEGER"; } } } else { retval += "DOUBLE PRECISION"; } } break; case ValueMetaInterface.TYPE_STRING: if ( length < 32664 ) { retval += "VARCHAR"; if ( length > 0 ) { retval += "(" + length + ")"; } else { retval += "(32664)"; // Maybe use some default DB String length? } } else { retval += "BLOB SUB_TYPE TEXT"; } break; default: retval += " UNKNOWN"; break; } if ( addCr ) { retval += Const.CR; } return retval; }
Example 17
Source File: SAPDBDatabaseMeta.java From pentaho-kettle with Apache License 2.0 | 4 votes |
@Override public String getFieldDefinition( ValueMetaInterface v, String tk, String pk, boolean useAutoinc, boolean addFieldName, boolean addCr ) { String retval = ""; String fieldname = v.getName(); int length = v.getLength(); int precision = v.getPrecision(); if ( addFieldName ) { if ( Const.indexOfString( fieldname, getReservedWords() ) >= 0 ) { retval += getStartQuote() + fieldname + getEndQuote(); } else { retval += fieldname + " "; } } int type = v.getType(); switch ( type ) { case ValueMetaInterface.TYPE_TIMESTAMP: case ValueMetaInterface.TYPE_DATE: retval += "TIMESTAMP"; break; case ValueMetaInterface.TYPE_BOOLEAN: retval += "CHAR(1)"; break; case ValueMetaInterface.TYPE_NUMBER: case ValueMetaInterface.TYPE_INTEGER: case ValueMetaInterface.TYPE_BIGNUMBER: if ( fieldname.equalsIgnoreCase( tk ) || // Technical key fieldname.equalsIgnoreCase( pk ) // Primary key ) { retval += "BIGINT NOT NULL PRIMARY KEY"; } else { if ( length > 0 ) { if ( precision > 0 || length > 18 ) { retval += "DECIMAL(" + length; if ( precision > 0 ) { retval += ", " + precision; } retval += ")"; } else { if ( length > 9 ) { retval += "INT64"; } else { if ( length < 5 ) { retval += "SMALLINT"; } else { retval += "INTEGER"; } } } } else { retval += "DOUBLE"; } } break; case ValueMetaInterface.TYPE_STRING: if ( length < 32720 ) { retval += "VARCHAR"; if ( length > 0 ) { retval += "(" + length + ")"; } else { retval += "(8000)"; // Maybe use some default DB String length? } } else { retval += "BLOB SUB_TYPE TEXT"; } break; default: retval += " UNKNOWN"; break; } if ( addCr ) { retval += Const.CR; } return retval; }
Example 18
Source File: ValueMetaBigNumber.java From pentaho-kettle with Apache License 2.0 | 4 votes |
public ValueMetaBigNumber( String name, int length, int precision ) { super( name, ValueMetaInterface.TYPE_BIGNUMBER, length, precision ); }
Example 19
Source File: DbaseDatabaseMeta.java From pentaho-kettle with Apache License 2.0 | 4 votes |
@Override public String getFieldDefinition( ValueMetaInterface v, String tk, String pk, boolean useAutoinc, boolean addFieldName, boolean addCr ) { String retval = ""; String fieldname = v.getName(); int length = v.getLength(); int precision = v.getPrecision(); if ( addFieldName ) { retval += fieldname + " "; } int type = v.getType(); switch ( type ) { case ValueMetaInterface.TYPE_TIMESTAMP: case ValueMetaInterface.TYPE_DATE: retval += "DATETIME"; break; case ValueMetaInterface.TYPE_BOOLEAN: retval += "CHAR(1)"; break; case ValueMetaInterface.TYPE_NUMBER: case ValueMetaInterface.TYPE_INTEGER: case ValueMetaInterface.TYPE_BIGNUMBER: retval += "DECIMAL"; if ( length > 0 ) { retval += "(" + length; if ( precision > 0 ) { retval += ", " + precision; } retval += ")"; } break; case ValueMetaInterface.TYPE_STRING: if ( length >= DatabaseMeta.CLOB_LENGTH ) { retval += "CLOB"; } else { retval += "VARCHAR"; if ( length > 0 ) { retval += "(" + length; } else { retval += "("; // Maybe use some default DB String length? } retval += ")"; } break; default: retval += " UNKNOWN"; break; } if ( addCr ) { retval += Const.CR; } return retval; }
Example 20
Source File: H2DatabaseMeta.java From pentaho-kettle with Apache License 2.0 | 4 votes |
@Override public String getFieldDefinition( ValueMetaInterface v, String tk, String pk, boolean useAutoinc, boolean addFieldName, boolean addCr ) { String retval = ""; String fieldname = v.getName(); int length = v.getLength(); int precision = v.getPrecision(); if ( addFieldName ) { retval += fieldname + " "; } int type = v.getType(); switch ( type ) { case ValueMetaInterface.TYPE_TIMESTAMP: case ValueMetaInterface.TYPE_DATE: retval += "TIMESTAMP"; break; case ValueMetaInterface.TYPE_BOOLEAN: if ( supportsBooleanDataType() ) { retval += "BOOLEAN"; } else { retval += "CHAR(1)"; } break; case ValueMetaInterface.TYPE_NUMBER: case ValueMetaInterface.TYPE_INTEGER: case ValueMetaInterface.TYPE_BIGNUMBER: if ( fieldname.equalsIgnoreCase( tk ) || // Technical key fieldname.equalsIgnoreCase( pk ) // Primary key ) { retval += "IDENTITY"; } else { if ( length > 0 ) { if ( precision > 0 || length > 18 ) { retval += "DECIMAL(" + length + ", " + precision + ")"; } else { if ( length > 9 ) { retval += "BIGINT"; } else { if ( length < 5 ) { if ( length < 3 ) { retval += "TINYINT"; } else { retval += "SMALLINT"; } } else { retval += "INTEGER"; } } } } else { retval += "DOUBLE"; } } break; case ValueMetaInterface.TYPE_STRING: if ( length >= DatabaseMeta.CLOB_LENGTH ) { retval += "TEXT"; } else { retval += "VARCHAR"; if ( length > 0 ) { retval += "(" + length; } else { // http://www.h2database.com/html/datatypes.html#varchar_type retval += "(" + Integer.MAX_VALUE; } retval += ")"; } break; case ValueMetaInterface.TYPE_BINARY: retval += "BLOB"; break; default: retval += "UNKNOWN"; break; } if ( addCr ) { retval += Const.CR; } return retval; }