use of org.pentaho.di.core.row.value.ValueMetaNumber in project pentaho-kettle by pentaho.
the class KettleDatabaseRepositoryConnectionDelegate method insertStepAttribute.
public synchronized ObjectId insertStepAttribute(ObjectId id_transformation, ObjectId id_step, long nr, String code, double value_num, String value_str) throws KettleException {
ObjectId id = getNextStepAttributeID();
RowMetaAndData table = new RowMetaAndData();
table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_STEP_ATTRIBUTE_ID_STEP_ATTRIBUTE), id);
table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_STEP_ATTRIBUTE_ID_TRANSFORMATION), id_transformation);
table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_STEP_ATTRIBUTE_ID_STEP), id_step);
table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_STEP_ATTRIBUTE_NR), new Long(nr));
table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_STEP_ATTRIBUTE_CODE), code);
table.addValue(new ValueMetaNumber(KettleDatabaseRepository.FIELD_STEP_ATTRIBUTE_VALUE_NUM), new Double(value_num));
table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_STEP_ATTRIBUTE_VALUE_STR), value_str);
if (psStepAttributesInsert == null) {
String sql = database.getInsertStatement(KettleDatabaseRepository.TABLE_R_STEP_ATTRIBUTE, table.getRowMeta());
psStepAttributesInsert = database.prepareSQL(sql);
}
database.setValues(table, psStepAttributesInsert);
database.insertRow(psStepAttributesInsert, useBatchProcessing);
if (log.isDebug()) {
log.logDebug("saved attribute [" + code + "]");
}
return id;
}
use of org.pentaho.di.core.row.value.ValueMetaNumber in project pentaho-kettle by pentaho.
the class ValueMetaTest method testNumberToStringToNumber.
@Test
public void testNumberToStringToNumber() throws Exception {
ValueMetaInterface numValueMeta = new ValueMetaNumber("i");
numValueMeta.setConversionMask(null);
numValueMeta.setLength(7, 3);
numValueMeta.setDecimalSymbol(",");
numValueMeta.setGroupingSymbol(".");
Double originalValue = new Double(123.456);
String string = numValueMeta.getString(originalValue);
assertEquals(" 0123,456", string);
ValueMetaInterface strValueMeta = new ValueMeta("str", ValueMetaInterface.TYPE_STRING);
strValueMeta.setConversionMetadata(numValueMeta);
Double x = (Double) strValueMeta.convertDataUsingConversionMetaData(string);
assertEquals(originalValue, x);
}
use of org.pentaho.di.core.row.value.ValueMetaNumber in project pentaho-kettle by pentaho.
the class CacheDatabaseMetaTest method testSQLStatements.
@Test
public void testSQLStatements() {
assertEquals("ALTER TABLE FOO ADD COLUMN ( BAR VARCHAR(15) ) ", cdm.getAddColumnStatement("FOO", new ValueMetaString("BAR", 15, 0), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD COLUMN ( BAR TIMESTAMP ) ", cdm.getAddColumnStatement("FOO", new ValueMetaDate("BAR"), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD COLUMN ( BAR TIMESTAMP ) ", cdm.getAddColumnStatement("FOO", new ValueMetaTimestamp("BAR"), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD COLUMN ( BAR CHAR(1) ) ", cdm.getAddColumnStatement("FOO", new ValueMetaBoolean("BAR"), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD COLUMN ( BAR INT ) ", cdm.getAddColumnStatement("FOO", new ValueMetaNumber("BAR", 0, 0), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD COLUMN ( BAR DOUBLE ) ", // I believe this is a bug!
cdm.getAddColumnStatement("FOO", new ValueMetaInteger("BAR"), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD COLUMN ( BAR DOUBLE ) ", cdm.getAddColumnStatement("FOO", new ValueMetaNumber("BAR", 10, -7), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD COLUMN ( BAR DOUBLE ) ", cdm.getAddColumnStatement("FOO", new ValueMetaNumber("BAR", -10, 7), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD COLUMN ( BAR DECIMAL(5, 7) ) ", cdm.getAddColumnStatement("FOO", new ValueMetaNumber("BAR", 5, 7), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD COLUMN ( BAR UNKNOWN ) ", cdm.getAddColumnStatement("FOO", new ValueMetaInternetAddress("BAR"), "", false, "", false));
String lineSep = System.getProperty("line.separator");
assertEquals("ALTER TABLE FOO DROP COLUMN BAR" + lineSep, cdm.getDropColumnStatement("FOO", new ValueMetaString("BAR", 15, 0), "", false, "", true));
assertEquals("ALTER TABLE FOO ALTER COLUMN BAR VARCHAR(15)", cdm.getModifyColumnStatement("FOO", new ValueMetaString("BAR", 15, 0), "", false, "", true));
}
use of org.pentaho.di.core.row.value.ValueMetaNumber in project pentaho-kettle by pentaho.
the class DatabaseTest method testGetQueryFieldsFallback.
@Test
public void testGetQueryFieldsFallback() throws Exception {
when(rsMetaData.getColumnCount()).thenReturn(1);
when(rsMetaData.getColumnName(1)).thenReturn(columnName);
when(rsMetaData.getColumnLabel(1)).thenReturn(columnName);
when(rsMetaData.getColumnType(1)).thenReturn(Types.DECIMAL);
when(ps.executeQuery()).thenReturn(rs);
when(meta.stripCR(anyString())).thenReturn(sql);
when(meta.getDatabaseInterface()).thenReturn(new MySQLDatabaseMeta());
when(conn.prepareStatement(sql)).thenReturn(ps);
when(rs.getMetaData()).thenReturn(rsMetaData);
Database db = new Database(log, meta);
db.setConnection(conn);
RowMetaInterface rowMetaInterface = db.getQueryFieldsFallback(sql, false, null, null);
assertEquals(rowMetaInterface.size(), 1);
assertEquals(rowMetaInterface.getValueMeta(0).getName(), columnName);
assertTrue(rowMetaInterface.getValueMeta(0) instanceof ValueMetaNumber);
}
use of org.pentaho.di.core.row.value.ValueMetaNumber in project pentaho-kettle by pentaho.
the class Exasol4DatabaseMetaTest method testSQLStatements.
@Test
public void testSQLStatements() {
assertEquals(" WHERE ROWNUM <= 15", nativeMeta.getLimitClause(15));
assertEquals("SELECT /*+FIRST_ROWS*/ * FROM FOO WHERE 1=0", nativeMeta.getSQLQueryFields("FOO"));
assertEquals("SELECT /*+FIRST_ROWS*/ * FROM FOO WHERE 1=0", nativeMeta.getSQLTableExists("FOO"));
assertEquals("SELECT /*+FIRST_ROWS*/ FOO FROM BAR WHERE 1=0", nativeMeta.getSQLQueryColumnFields("FOO", "BAR"));
assertEquals("SELECT /*+FIRST_ROWS*/ FOO FROM BAR WHERE 1=0", nativeMeta.getSQLColumnExists("FOO", "BAR"));
String lineSep = System.getProperty("line.separator");
assertEquals("ALTER TABLE FOO DROP COLUMN BAR" + lineSep, nativeMeta.getDropColumnStatement("FOO", new ValueMetaString("BAR", 15, 0), "", false, "", true));
assertEquals("ALTER TABLE FOO ADD ( BAR TIMESTAMP ) ", nativeMeta.getAddColumnStatement("FOO", new ValueMetaDate("BAR"), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD ( BAR TIMESTAMP ) ", nativeMeta.getAddColumnStatement("FOO", new ValueMetaTimestamp("BAR"), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD ( BAR BOOLEAN ) ", nativeMeta.getAddColumnStatement("FOO", new ValueMetaBoolean("BAR"), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD ( BAR DECIMAL ) ", nativeMeta.getAddColumnStatement("FOO", new ValueMetaNumber("BAR"), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD ( BAR DECIMAL ) ", nativeMeta.getAddColumnStatement("FOO", new ValueMetaBigNumber("BAR"), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD ( BAR DECIMAL(15) ) ", nativeMeta.getAddColumnStatement("FOO", new ValueMetaNumber("BAR", 15, 0), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD ( BAR DECIMAL(15) ) ", nativeMeta.getAddColumnStatement("FOO", new ValueMetaBigNumber("BAR", 15, 0), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD ( BAR DECIMAL(15, 5) ) ", nativeMeta.getAddColumnStatement("FOO", new ValueMetaNumber("BAR", 15, 5), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD ( BAR DECIMAL(15, 5) ) ", nativeMeta.getAddColumnStatement("FOO", new ValueMetaBigNumber("BAR", 15, 5), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD ( BAR INTEGER ) ", nativeMeta.getAddColumnStatement("FOO", new ValueMetaInteger("BAR"), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD ( BAR VARCHAR(15) ) ", nativeMeta.getAddColumnStatement("FOO", new ValueMetaString("BAR", 15, 0), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD ( BAR VARCHAR(2000000) ) ", nativeMeta.getAddColumnStatement("FOO", new ValueMetaString("BAR", nativeMeta.getMaxVARCHARLength() + 15, 0), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD ( BAR UNKNOWN ) ", nativeMeta.getAddColumnStatement("FOO", new ValueMetaInternetAddress("BAR"), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD ( BAR BIGINT NOT NULL PRIMARY KEY ) ", nativeMeta.getAddColumnStatement("FOO", new ValueMetaInteger("BAR"), "BAR", false, "", false));
}
Aggregations