Search in sources :

Example 1 with ValueMetaInteger

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));
}
Also used : Condition(org.pentaho.di.core.Condition) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) Calendar(java.util.Calendar) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Matchers.anyString(org.mockito.Matchers.anyString) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) Date(java.util.Date) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) SQL(org.pentaho.di.core.sql.SQL) Test(org.junit.Test)

Example 2 with ValueMetaInteger

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"));
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) Calendar(java.util.Calendar) TransMeta(org.pentaho.di.trans.TransMeta) ValueMetaResolver(org.pentaho.di.trans.dataservice.optimization.ValueMetaResolver) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) SQL(org.pentaho.di.core.sql.SQL) Test(org.junit.Test)

Example 3 with ValueMetaInteger

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 }));
}
Also used : SelectValuesMeta(org.pentaho.di.trans.steps.selectvalues.SelectValuesMeta) RowMeta(org.pentaho.di.core.row.RowMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) SQL(org.pentaho.di.core.sql.SQL) Test(org.junit.Test)

Example 4 with ValueMetaInteger

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 }));
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) SelectValuesMeta(org.pentaho.di.trans.steps.selectvalues.SelectValuesMeta) RowMeta(org.pentaho.di.core.row.RowMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) SQL(org.pentaho.di.core.sql.SQL) Test(org.junit.Test)

Example 5 with ValueMetaInteger

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));
}
Also used : SelectValuesMeta(org.pentaho.di.trans.steps.selectvalues.SelectValuesMeta) RowMeta(org.pentaho.di.core.row.RowMeta) ValueMetaNumber(org.pentaho.di.core.row.value.ValueMetaNumber) ValueMetaBigNumber(org.pentaho.di.core.row.value.ValueMetaBigNumber) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) SQL(org.pentaho.di.core.sql.SQL) Test(org.junit.Test)

Aggregations

ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)314 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)209 RowMeta (org.pentaho.di.core.row.RowMeta)146 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)137 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)113 Test (org.junit.Test)90 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)89 ValueMetaDate (org.pentaho.di.core.row.value.ValueMetaDate)64 ValueMetaBoolean (org.pentaho.di.core.row.value.ValueMetaBoolean)61 ValueMetaNumber (org.pentaho.di.core.row.value.ValueMetaNumber)57 KettleException (org.pentaho.di.core.exception.KettleException)41 LongObjectId (org.pentaho.di.repository.LongObjectId)38 ValueMetaBigNumber (org.pentaho.di.core.row.value.ValueMetaBigNumber)34 ObjectId (org.pentaho.di.repository.ObjectId)33 ArrayList (java.util.ArrayList)32 KettleStepException (org.pentaho.di.core.exception.KettleStepException)26 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)21 ValueMetaTimestamp (org.pentaho.di.core.row.value.ValueMetaTimestamp)20 ValueMetaBinary (org.pentaho.di.core.row.value.ValueMetaBinary)18 SQLException (java.sql.SQLException)17