Java Code Examples for org.pentaho.di.core.row.ValueMetaInterface#getLength()
The following examples show how to use
org.pentaho.di.core.row.ValueMetaInterface#getLength() .
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: StepTransform.java From kettle-beam with Apache License 2.0 | 6 votes |
private StepMeta createInjectorStep( TransMeta transMeta, String injectorStepName, RowMetaInterface injectorRowMeta, int x, int y ) { InjectorMeta injectorMeta = new InjectorMeta(); injectorMeta.allocate( injectorRowMeta.size() ); for ( int i = 0; i < injectorRowMeta.size(); i++ ) { ValueMetaInterface valueMeta = injectorRowMeta.getValueMeta( i ); injectorMeta.getFieldname()[ i ] = valueMeta.getName(); injectorMeta.getType()[ i ] = valueMeta.getType(); injectorMeta.getLength()[ i ] = valueMeta.getLength(); injectorMeta.getPrecision()[ i ] = valueMeta.getPrecision(); } StepMeta injectorStepMeta = new StepMeta( injectorStepName, injectorMeta ); injectorStepMeta.setLocation( x, y ); injectorStepMeta.setDraw( true ); transMeta.addStep( injectorStepMeta ); return injectorStepMeta; }
Example 2
Source File: ConcatFieldsDialog.java From pentaho-kettle with Apache License 2.0 | 5 votes |
private void get() { try { RowMetaInterface r = transMeta.getPrevStepFields( stepname ); if ( r != null ) { TableItemInsertListener listener = new TableItemInsertListener() { @Override public boolean tableItemInserted( TableItem tableItem, ValueMetaInterface v ) { if ( v.isNumber() ) { if ( v.getLength() > 0 ) { int le = v.getLength(); int pr = v.getPrecision(); if ( v.getPrecision() <= 0 ) { pr = 0; } String mask = ""; for ( int m = 0; m < le - pr; m++ ) { mask += "0"; } if ( pr > 0 ) { mask += "."; } for ( int m = 0; m < pr; m++ ) { mask += "0"; } tableItem.setText( 3, mask ); } } return true; } }; BaseStepDialog.getFieldsFromPrevious( r, wFields, 1, new int[] { 1 }, new int[] { 2 }, 4, 5, listener ); } } catch ( KettleException ke ) { new ErrorDialog( shell, BaseMessages.getString( PKG, "System.Dialog.GetFieldsFailed.Title" ), BaseMessages .getString( PKG, "System.Dialog.GetFieldsFailed.Message" ), ke ); } }
Example 3
Source File: MSSQLServerDatabaseMeta_FieldDefinitionTest.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@Test public void numberType_MoreThanEighteenLength_ZeroPrecision() { ValueMetaInterface valueMeta = new MetaInterfaceBuilder( ValueMetaInterface.TYPE_NUMBER ) .length( 19 ) .precision( 0 ) .build(); final String expected = STRING_DECIMAL + "(" + valueMeta.getLength() + "," + valueMeta.getPrecision() + ")"; assertEquals( expected, dbMeta.getFieldDefinition( valueMeta, null, null, false, false, false ) ); }
Example 4
Source File: XMLOutputDialog.java From pentaho-kettle with Apache License 2.0 | 5 votes |
private void get() { try { RowMetaInterface r = transMeta.getPrevStepFields( stepname ); if ( r != null && !r.isEmpty() ) { TableItemInsertListener listener = new TableItemInsertListener() { public boolean tableItemInserted( TableItem tableItem, ValueMetaInterface v ) { tableItem.setText( 3, ContentType.Element.name() ); if ( v.isNumber() ) { if ( v.getLength() > 0 ) { int le = v.getLength(); int pr = v.getPrecision(); if ( v.getPrecision() <= 0 ) { pr = 0; } String mask = " "; for ( int m = 0; m < le - pr; m++ ) { mask += "0"; } if ( pr > 0 ) { mask += "."; } for ( int m = 0; m < pr; m++ ) { mask += "0"; } tableItem.setText( 4, mask ); } } return true; } }; BaseStepDialog.getFieldsFromPrevious( r, wFields, 1, new int[] { 1 }, new int[] { 4 }, 6, 7, listener ); } } catch ( KettleException ke ) { new ErrorDialog( shell, BaseMessages.getString( PKG, "System.Dialog.GetFieldsFailed.Title" ), BaseMessages .getString( PKG, "System.Dialog.GetFieldsFailed.Message" ), ke ); } }
Example 5
Source File: ExcelOutputDialog.java From pentaho-kettle with Apache License 2.0 | 5 votes |
private void get() { try { RowMetaInterface r = transMeta.getPrevStepFields( stepname ); if ( r != null ) { TableItemInsertListener listener = new TableItemInsertListener() { @Override public boolean tableItemInserted( TableItem tableItem, ValueMetaInterface v ) { if ( v.isNumber() ) { if ( v.getLength() > 0 ) { int le = v.getLength(); int pr = v.getPrecision(); if ( v.getPrecision() <= 0 ) { pr = 0; } String mask = ""; for ( int m = 0; m < le - pr; m++ ) { mask += "0"; } if ( pr > 0 ) { mask += "."; } for ( int m = 0; m < pr; m++ ) { mask += "0"; } tableItem.setText( 3, mask ); } } return true; } }; BaseStepDialog.getFieldsFromPrevious( r, wFields, 1, new int[] { 1 }, new int[] { 2 }, 4, 5, listener ); } } catch ( KettleException ke ) { new ErrorDialog( shell, BaseMessages.getString( PKG, "System.Dialog.GetFieldsFailed.Title" ), BaseMessages .getString( PKG, "System.Dialog.GetFieldsFailed.Message" ), ke ); } }
Example 6
Source File: TransTestFactory.java From pentaho-kettle with Apache License 2.0 | 5 votes |
static StepMeta getInjectorStepMeta( RowMetaInterface outputRowMeta ) { InjectorMeta zeroMeta = new InjectorMeta(); // Sets output fields for cases when no rows are sent to the test step, but metadata is still needed if ( outputRowMeta != null && outputRowMeta.size() > 0 ) { String[] fieldName = new String[outputRowMeta.size()]; int[] fieldLength = new int[outputRowMeta.size()]; int[] fieldPrecision = new int[outputRowMeta.size()]; int[] fieldType = new int[outputRowMeta.size()]; for ( int i = 0; i < outputRowMeta.size(); i++ ) { ValueMetaInterface field = outputRowMeta.getValueMeta( i ); fieldName[i] = field.getName(); fieldLength[i] = field.getLength(); fieldPrecision[i] = field.getPrecision(); fieldType[i] = field.getType(); } zeroMeta.setFieldname( fieldName ); zeroMeta.setLength( fieldLength ); zeroMeta.setPrecision( fieldPrecision ); zeroMeta.setType( fieldType ); } StepMeta zero = new StepMeta( registry.getPluginId( StepPluginType.class, zeroMeta ), INJECTOR_STEPNAME, zeroMeta ); zero.setLocation( 50, 50 ); zero.setDraw( true ); return zero; }
Example 7
Source File: TextFileOutput.java From pentaho-kettle with Apache License 2.0 | 5 votes |
private byte[] formatField( ValueMetaInterface v, Object valueData ) throws KettleValueException { if ( v.isString() ) { if ( v.isStorageBinaryString() && v.getTrimType() == ValueMetaInterface.TRIM_TYPE_NONE && v.getLength() < 0 && Utils.isEmpty( v.getStringEncoding() ) ) { return (byte[]) valueData; } else { String svalue = ( valueData instanceof String ) ? (String) valueData : v.getString( valueData ); return convertStringToBinaryString( v, Const.trimToType( svalue, v.getTrimType() ) ); } } else { return v.getBinaryString( valueData ); } }
Example 8
Source File: TableAgileMart.java From pentaho-kettle with Apache License 2.0 | 5 votes |
protected Object[] writeToTable( RowMetaInterface rowMeta, Object[] r ) throws KettleException { // see if we need to truncate any string fields try { int index = 0; List<ValueMetaInterface> valueMetas = rowMeta.getValueMetaList(); for ( ValueMetaInterface valueMeta : valueMetas ) { Object valueData = r[index]; if ( valueData != null ) { if ( valueMeta.getType() == ValueMetaInterface.TYPE_STRING ) { String str = valueMeta.getString( valueData ); int len = valueMeta.getLength(); if ( len < 1 ) { len = MonetDBDatabaseMeta.DEFAULT_VARCHAR_LENGTH; } if ( str.length() > len ) { // TODO log this event str = str.substring( 0, len ); } r[index] = str; } } index++; } } catch ( Exception e ) { throw new KettleException( "Error serializing rows of data to the psql command", e ); } return super.writeToTable( rowMeta, r ); }
Example 9
Source File: KingbaseESDatabaseMeta.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 += "BIGSERIAL"; } else { if ( length > 0 ) { if ( precision > 0 || length > 18 ) { retval += "NUMERIC(" + length + ", " + precision + ")"; } else { if ( length > 9 ) { retval += "BIGINT"; } else { if ( length < 5 ) { retval += "SMALLINT"; } else { retval += "INTEGER"; } } } } else { retval += "DOUBLE PRECISION"; } } break; case ValueMetaInterface.TYPE_STRING: if ( length < 1 || length >= DatabaseMeta.CLOB_LENGTH ) { retval += "TEXT"; } else { retval += "VARCHAR(" + length + ")"; } break; default: retval += " UNKNOWN"; break; } if ( addCr ) { retval += Const.CR; } return retval; }
Example 10
Source File: VectorWiseDatabaseMeta.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: 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 += "GENERATED ALWAYS AS IDENTITY START WITH 1 INCREMENT BY 1"; } else { retval += "BIGINT PRIMARY KEY NOT NULL"; } } else { if ( precision == 0 ) { // integer numbers if ( length > 9 ) { retval += "BIGINT"; } else { if ( length == -1 || length > 4 ) { // If the length is undefined or greater than 4, use a standard INTEGER retval += "INTEGER"; } else { if ( length > 2 ) { retval += "SMALLINT"; } else { retval += "INTEGER1"; } } } } else { retval += "FLOAT8"; } } break; case ValueMetaInterface.TYPE_STRING: // Maybe use some default DB String length in case length<=0 if ( length > 0 ) { if ( length > 32000 ) { retval += "VARCHAR(32000)"; } else { retval += "VARCHAR(" + length + ")"; } } else { retval += "VARCHAR(9999)"; } break; default: retval += " UNKNOWN"; break; } if ( addCr ) { retval += Const.CR; } return retval; }
Example 11
Source File: LucidDBDatabaseMeta.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 ) { if ( useAutoinc ) { retval += "BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL PRIMARY KEY"; } 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 ) { if ( length > 0 ) { retval += "DECIMAL(" + length + "," + precision + ")"; } } else { retval += "DOUBLE"; } } } 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(100)"; } break; default: retval += " UNKNOWN"; break; } if ( addCr ) { retval += Const.CR; } return retval; }
Example 12
Source File: AS400DatabaseMeta.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: retval += "CHAR(1)"; break; case ValueMetaInterface.TYPE_NUMBER: case ValueMetaInterface.TYPE_INTEGER: case ValueMetaInterface.TYPE_BIGNUMBER: if ( length <= 0 && precision <= 0 ) { retval += "DOUBLE"; } else { retval += "DECIMAL"; if ( length > 0 ) { retval += "(" + length; if ( precision > 0 ) { retval += ", " + precision; } retval += ")"; } } break; case ValueMetaInterface.TYPE_STRING: if ( length > getMaxVARCHARLength() || 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 13
Source File: FirebirdDatabaseMeta.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: 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 ) { 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 += "BIGINT"; } 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; case ValueMetaInterface.TYPE_BINARY: retval += "BLOB"; break; default: retval += "UNKNOWN"; break; } if ( addCr ) { retval += Const.CR; } return retval; }
Example 14
Source File: SQLiteDatabaseMeta.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; // There is no Date or Timestamp data type in SQLite!!! 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 PRIMARY KEY AUTOINCREMENT"; } else { if ( precision != 0 || length < 0 || length > 18 ) { retval += "NUMERIC"; } else { retval += "INTEGER"; } } break; case ValueMetaInterface.TYPE_STRING: if ( length >= DatabaseMeta.CLOB_LENGTH ) { retval += "BLOB"; } else { retval += "TEXT"; } break; case ValueMetaInterface.TYPE_BINARY: retval += "BLOB"; break; default: retval += "UNKNOWN"; break; } if ( addCr ) { retval += Const.CR; } return retval; }
Example 15
Source File: CacheDatabaseMeta.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: retval += "CHAR(1)"; break; case ValueMetaInterface.TYPE_NUMBER: case ValueMetaInterface.TYPE_INTEGER: case ValueMetaInterface.TYPE_BIGNUMBER: if ( fieldname.equalsIgnoreCase( tk ) ) { // Technical & primary key : see at bottom retval += "DECIMAL"; } else { if ( length < 0 || precision < 0 ) { retval += "DOUBLE"; } else if ( precision > 0 || length > 9 ) { retval += "DECIMAL(" + length; if ( precision > 0 ) { retval += ", " + precision; } retval += ")"; } else { // Precision == 0 && length<=9 retval += "INT"; } } break; case ValueMetaInterface.TYPE_STRING: // CLOBs are just VARCHAR in the Cache database: can be very large! retval += "VARCHAR"; if ( length > 0 ) { retval += "(" + length + ")"; } break; default: retval += " UNKNOWN"; break; } if ( addCr ) { retval += Const.CR; } return retval; }
Example 16
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 17
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 18
Source File: DataSetHelper.java From pentaho-pdi-dataset with Apache License 2.0 | 4 votes |
/** * Create a new data set with the output from */ public void createDataSetFromStep() { Spoon spoon = ( (Spoon) SpoonFactory.getInstance() ); TransGraph transGraph = spoon.getActiveTransGraph(); IMetaStore metaStore = spoon.getMetaStore(); if ( transGraph == null ) { return; } StepMeta stepMeta = transGraph.getCurrentStep(); TransMeta transMeta = spoon.getActiveTransformation(); if ( stepMeta == null || transMeta == null ) { return; } try { FactoriesHierarchy hierarchy = getHierarchy(); MetaStoreFactory<DataSetGroup> groupFactory = hierarchy.getGroupFactory(); List<DatabaseMeta> databases = getAvailableDatabases( spoon.getRepository() ); groupFactory.addNameList( DataSetConst.DATABASE_LIST_KEY, databases ); List<DataSetGroup> groups = groupFactory.getElements(); MetaStoreFactory<DataSet> setFactory = hierarchy.getSetFactory(); setFactory.addNameList( DataSetConst.GROUP_LIST_KEY, groups ); DataSet dataSet = new DataSet(); RowMetaInterface rowMeta = transMeta.getStepFields( stepMeta ); for ( int i = 0; i < rowMeta.size(); i++ ) { ValueMetaInterface valueMeta = rowMeta.getValueMeta( i ); String setFieldname = valueMeta.getName(); String columnName = "field" + i; DataSetField field = new DataSetField( setFieldname, columnName, valueMeta.getType(), valueMeta.getLength(), valueMeta.getPrecision(), valueMeta.getComments(), valueMeta.getFormatMask() ); dataSet.getFields().add( field ); } editDataSet( spoon, dataSet, groups, setFactory, null ); } catch ( Exception e ) { new ErrorDialog( spoon.getShell(), "Error", "Error creating a new data set", e ); } }
Example 19
Source File: DB2DatabaseMeta.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: retval += "CHARACTER(1)"; break; case ValueMetaInterface.TYPE_NUMBER: case ValueMetaInterface.TYPE_BIGNUMBER: if ( fieldname.equalsIgnoreCase( tk ) && useAutoinc ) { // Technical key: auto increment field! retval += "BIGINT NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 0, INCREMENT BY 1, NOCACHE)"; } else { if ( length > 0 ) { retval += "DECIMAL(" + length; if ( precision > 0 ) { retval += ", " + precision; } retval += ")"; } else { retval += "FLOAT"; } } break; case ValueMetaInterface.TYPE_INTEGER: if ( fieldname.equalsIgnoreCase( tk ) && useAutoinc ) { // Technical key: auto increment field! retval += "INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 0, INCREMENT BY 1, NOCACHE)"; } else { retval += "INTEGER"; } break; case ValueMetaInterface.TYPE_STRING: if ( length > getMaxVARCHARLength() || 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; case ValueMetaInterface.TYPE_BINARY: if ( length > getMaxVARCHARLength() || length >= DatabaseMeta.CLOB_LENGTH ) { retval += "BLOB(" + length + ")"; } else { if ( length > 0 ) { retval += "CHAR(" + length + ") FOR BIT DATA"; } else { retval += "BLOB"; // not going to work, but very close } } break; default: retval += " UNKNOWN"; break; } if ( addCr ) { retval += Const.CR; } return retval; }
Example 20
Source File: OracleRDBDatabaseMeta.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_DATE: retval.append( "DATE" ); break; case ValueMetaInterface.TYPE_BOOLEAN: retval.append( "CHAR(1)" ); break; case ValueMetaInterface.TYPE_NUMBER: case ValueMetaInterface.TYPE_INTEGER: 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_STRING: if ( length >= DatabaseMeta.CLOB_LENGTH ) { retval.append( "CLOB" ); } else { if ( length > 0 && length <= 2000 ) { 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; default: retval.append( " UNKNOWN" ); break; } if ( addCr ) { retval.append( Const.CR ); } return retval.toString(); }