Search in sources :

Example 46 with SQL

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

the class DataServiceExecutorTest method testWithLazyConversion.

@Test
public void testWithLazyConversion() throws Exception {
    RowMeta rowMeta = new RowMeta();
    ValueMetaInterface vm = new ValueMetaString("aBinaryStoredString");
    vm.setStorageType(ValueMetaInterface.STORAGE_TYPE_BINARY_STRING);
    vm.setStorageMetadata(new ValueMetaString());
    rowMeta.addValueMeta(vm);
    String query = "SELECT * FROM " + DATA_SERVICE_NAME + " WHERE aBinaryStoredString = 'value'";
    when(transMeta.getStepFields(DATA_SERVICE_STEP)).thenReturn(rowMeta);
    DataServiceExecutor executor = new DataServiceExecutor.Builder(new SQL(query), dataService, context).serviceTrans(new Trans(transMeta)).prepareExecution(false).build();
    executor.getSql().getWhereCondition().getCondition().evaluate(rowMeta, new Object[] { "value".getBytes() });
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Matchers.anyString(org.mockito.Matchers.anyString) Trans(org.pentaho.di.trans.Trans) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) SQL(org.pentaho.di.core.sql.SQL) Test(org.junit.Test)

Example 47 with SQL

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

the class DataServiceExecutorTest method testRowLimitAux.

private StreamingServiceTransExecutor testRowLimitAux(int userLimit, int metaLimit, String kettleLimit) throws Exception {
    when(genTrans.isFinishedOrStopped()).thenReturn(true);
    SQL sql = new SQL("SELECT * FROM " + DATA_SERVICE_NAME);
    when(serviceTrans.getTransMeta().listParameters()).thenReturn(new String[0]);
    when(sqlTransGenerator.getSql()).thenReturn(sql);
    System.setProperty(DataServiceConstants.ROW_LIMIT_PROPERTY, kettleLimit);
    dataService.setStreaming(true);
    dataService.setRowLimit(metaLimit);
    IMetaStore metastore = mock(IMetaStore.class);
    DataServiceExecutor executor = new DataServiceExecutor.Builder(sql, dataService, context).serviceTrans(serviceTrans).sqlTransGenerator(sqlTransGenerator).genTrans(genTrans).metastore(metastore).rowLimit(userLimit).windowMode(IDataServiceClientService.StreamingMode.ROW_BASED).windowSize(1).windowEvery(0).windowLimit(0).build();
    StreamingServiceTransExecutor exec = context.getServiceTransExecutor(dataService.getName());
    context.removeServiceTransExecutor(dataService.getName());
    return exec;
}
Also used : IMetaStore(org.pentaho.metastore.api.IMetaStore) StreamingServiceTransExecutor(org.pentaho.di.trans.dataservice.streaming.execution.StreamingServiceTransExecutor) SQL(org.pentaho.di.core.sql.SQL)

Example 48 with SQL

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

the class SqlTransGeneratorTest method testGenTransSelectStar.

@Test
public void testGenTransSelectStar() throws KettleException {
    SQL sql = new SQL("SELECT * FROM table");
    RowMetaInterface rowMeta = new RowMeta();
    rowMeta.addValueMeta(new ValueMetaString("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 : 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) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) SQL(org.pentaho.di.core.sql.SQL) Test(org.junit.Test)

Example 49 with SQL

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

the class SqlTransGeneratorTest method testUniqueStep.

@Test
public void testUniqueStep() throws KettleException {
    SQL sql = new SQL("SELECT DISTINCT foo FROM table");
    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 50 with SQL

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

the class SqlTransGeneratorTest method testLimitClause.

@Test
public void testLimitClause() throws KettleException {
    SQL sql = new SQL("SELECT * FROM table LIMIT 1");
    RowMetaInterface rowMeta = new RowMeta();
    rowMeta.addValueMeta(new ValueMetaString("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 }));
    assertThat(sql.getLimitClause(), notNullValue());
}
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) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) 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