Search in sources :

Example 16 with SQL

use of org.pentaho.di.core.sql.SQL in project pdi-dataservice-server-plugin by pentaho.

the class DataServiceExecutorTest method testBuilderBuildStreamingServiceContext.

@Test
public void testBuilderBuildStreamingServiceContext() throws Exception {
    SQL sql = new SQL("SELECT * FROM " + DATA_SERVICE_NAME);
    when(serviceTransExecutor.getServiceTrans()).thenReturn(serviceTrans);
    when(serviceTransExecutor.getId()).thenReturn(DATA_SERVICE_NAME);
    context.addServiceTransExecutor(serviceTransExecutor);
    dataService.setStreaming(true);
    IMetaStore metastore = mock(IMetaStore.class);
    DataServiceExecutor executor = new DataServiceExecutor.Builder(sql, dataService, context).sqlTransGenerator(sqlTransGenerator).genTrans(genTrans).metastore(metastore).enableMetrics(false).normalizeConditions(false).rowLimit(50).build();
    verify(serviceTransExecutor).getServiceTrans();
    assertSame(executor.getServiceTrans(), serviceTrans);
}
Also used : IMetaStore(org.pentaho.metastore.api.IMetaStore) SQL(org.pentaho.di.core.sql.SQL) Test(org.junit.Test)

Example 17 with SQL

use of org.pentaho.di.core.sql.SQL 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 18 with SQL

use of org.pentaho.di.core.sql.SQL 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 19 with SQL

use of org.pentaho.di.core.sql.SQL 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 20 with SQL

use of org.pentaho.di.core.sql.SQL 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

SQL (org.pentaho.di.core.sql.SQL)58 Test (org.junit.Test)49 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)31 RowMeta (org.pentaho.di.core.row.RowMeta)18 Matchers.anyString (org.mockito.Matchers.anyString)17 IMetaStore (org.pentaho.metastore.api.IMetaStore)17 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)16 SelectValuesMeta (org.pentaho.di.trans.steps.selectvalues.SelectValuesMeta)12 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)11 DataServiceExecutor (org.pentaho.di.trans.dataservice.DataServiceExecutor)7 PushDownOptimizationMeta (org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta)7 Condition (org.pentaho.di.core.Condition)6 KettleException (org.pentaho.di.core.exception.KettleException)4 SQLCondition (org.pentaho.di.core.sql.SQLCondition)4 TransMeta (org.pentaho.di.trans.TransMeta)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 DataOutputStream (java.io.DataOutputStream)3 RowProducer (org.pentaho.di.trans.RowProducer)3 Trans (org.pentaho.di.trans.Trans)3 ImmutableMap (com.google.common.collect.ImmutableMap)2