use of org.pentaho.di.core.row.value.ValueMetaInteger in project pdi-dataservice-server-plugin by pentaho.
the class DataServiceExecutorTest method testConditionResolution.
@Test
public void testConditionResolution() throws Exception {
RowMeta rowMeta = new RowMeta();
rowMeta.addValueMeta(new ValueMetaString("aString"));
rowMeta.addValueMeta(new ValueMetaInteger("anInt"));
rowMeta.addValueMeta(new ValueMetaDate("aDate"));
String query = "SELECT COUNT(aString), aString FROM " + DATA_SERVICE_NAME + " WHERE anInt = 2 AND aDate IN ('2014-12-05','2008-01-01')" + " GROUP BY aString HAVING COUNT(aString) > 2";
when(transMeta.getStepFields(DATA_SERVICE_STEP)).thenReturn(rowMeta);
DataServiceExecutor executor = new DataServiceExecutor.Builder(new SQL(query), dataService, context).serviceTrans(transMeta).prepareExecution(false).build();
Condition condition = executor.getSql().getWhereCondition().getCondition();
Calendar calendar = Calendar.getInstance();
calendar.clear();
calendar.set(2014, Calendar.DECEMBER, 5);
assertThat(condition.evaluate(rowMeta, new Object[] { "value", 2L, calendar.getTime() }), is(true));
assertThat(condition.evaluate(rowMeta, new Object[] { "value", 2L, new Date() }), is(false));
}
use of org.pentaho.di.core.row.value.ValueMetaInteger in project pdi-dataservice-server-plugin by pentaho.
the class SqlTransGeneratorTest method testDataFormatting.
@Test
public void testDataFormatting() throws Exception {
SQL sql = new SQL("SELECT * FROM table");
RowMetaInterface rowMeta = new RowMeta();
rowMeta.addValueMeta(new ValueMetaString("str"));
rowMeta.addValueMeta(new ValueMetaDate("time"));
rowMeta.addValueMeta(new ValueMetaInteger("long"));
sql.parse(new ValueMetaResolver(rowMeta).getRowMeta());
SqlTransGenerator generator = new SqlTransGenerator(sql, -1);
TransMeta transMeta = generator.generateTransMeta();
RowMetaInterface outputFields = transMeta.getStepFields(generator.getResultStepName());
Calendar calendar = Calendar.getInstance();
calendar.clear();
calendar.set(2016, Calendar.FEBRUARY, 12, 13, 20);
Object[] row = { "value", calendar.getTime(), 42L };
assertThat(outputFields.getFieldNames(), arrayContaining("str", "time", "long"));
assertThat(outputFields.getString(row, 0), is("value"));
assertThat(outputFields.getString(row, 1), is("2016-02-12"));
assertThat(outputFields.getString(row, 2), is("42"));
}
use of org.pentaho.di.core.row.value.ValueMetaInteger in project pdi-dataservice-server-plugin by pentaho.
the class SqlTransGeneratorTest method testFilterStep.
@Test
public void testFilterStep() throws KettleException {
SQL sql = new SQL("SELECT * FROM table WHERE foo > 1");
RowMetaInterface rowMeta = new RowMeta();
rowMeta.addValueMeta(new ValueMetaInteger("foo"));
sql.parse(rowMeta);
SqlTransGenerator generator = new SqlTransGenerator(sql, 0);
SelectValuesMeta selectValuesMeta = getSelectStepValuesMeta(generator.generateTransMeta());
assertThat(selectValuesMeta.getSelectName(), equalTo(new String[] { "foo" }));
assertThat(selectValuesMeta.getSelectRename(), equalTo(new String[] { null }));
}
use of org.pentaho.di.core.row.value.ValueMetaInteger in project pdi-dataservice-server-plugin by pentaho.
the class SqlTransGeneratorTest method testGenTransAllAggsNoAliases.
@Test
public void testGenTransAllAggsNoAliases() throws KettleException {
SQL sql = new SQL("SELECT sum(foo), avg(bar), max(baz) FROM table");
RowMetaInterface rowMeta = new RowMeta();
rowMeta.addValueMeta(new ValueMetaString("foo"));
rowMeta.addValueMeta(new ValueMetaInteger("bar"));
rowMeta.addValueMeta(new ValueMetaString("baz"));
sql.parse(rowMeta);
SqlTransGenerator generator = new SqlTransGenerator(sql, 0);
SelectValuesMeta selectValuesMeta = getSelectStepValuesMeta(generator.generateTransMeta());
assertThat(selectValuesMeta.getSelectName(), equalTo(new String[] { "foo", "bar", "baz" }));
assertThat(selectValuesMeta.getSelectRename(), equalTo(new String[] { null, null, null }));
}
use of org.pentaho.di.core.row.value.ValueMetaInteger in project pdi-dataservice-server-plugin by pentaho.
the class SqlTransGeneratorTest method testTypeHandlingWithAvg.
@Test
public void testTypeHandlingWithAvg() throws KettleException {
SQL sql = new SQL("SELECT avg( intVal ), avg( numericVal ), avg( bigNumber) FROM table");
RowMetaInterface rowMeta = new RowMeta();
rowMeta.addValueMeta(new ValueMetaInteger("intVal"));
rowMeta.addValueMeta(new ValueMetaNumber("numericVal"));
rowMeta.addValueMeta(new ValueMetaBigNumber("bigNumber"));
sql.parse(rowMeta);
SqlTransGenerator generator = new SqlTransGenerator(sql, 0);
SelectValuesMeta meta = (SelectValuesMeta) getStepByName(generator.generateTransMeta(), "Set Conversion");
assertThat(meta.getMeta().length, is(3));
// Integer should be converted to TYPE_NUMBER
assertThat(meta.getMeta()[0].getType(), is(TYPE_NUMBER));
// Other types should be left alone ( SelectMetadataChange.getType remains TYPE_NONE )
assertThat(meta.getMeta()[1].getType(), is(TYPE_NONE));
assertThat(meta.getMeta()[2].getType(), is(TYPE_NONE));
}
Aggregations