Search in sources :

Example 21 with SQL

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

the class SqlTransGeneratorTest method testGenerateConstStep.

@Test
public void testGenerateConstStep() throws KettleException {
    SQL sql = new SQL("SELECT 'FOO' as 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[] { "foo" }));
}
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 22 with SQL

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

the class SqlTransGeneratorTest method testGenTransUsingSqlWithGroupByOrderByNoAlias.

@Test
public void testGenTransUsingSqlWithGroupByOrderByNoAlias() throws KettleException {
    SQL sql = new SQL("SELECT foo, bar, baz FROM table GROUP BY foo, bar, baz ORDER BY foo");
    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 23 with SQL

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

the class SqlTransGeneratorTest method testGenerateIifStep.

@Test
public void testGenerateIifStep() throws KettleException {
    SQL sql = new SQL("SELECT IIF(10 > 1, 'TRUE', 'FALSE') 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[] { "IIF(10 > 1, 'TRUE', 'FALSE')" }));
    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 24 with SQL

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

the class ParameterGenerationTest method testActivation.

@Test
public void testActivation() throws Exception {
    // ( A & ( B | C ) )
    Condition condition = newCondition("A_src", "A_value");
    condition.addCondition(newCondition(AND, "B_src", "B_value"));
    condition.getCondition(1).addCondition(newCondition(OR, "C_src", "C_value"));
    SQL query = mockSql(condition);
    when(executor.getSql()).thenReturn(query);
    assertTrue(paramGen.activate(executor, stepInterface));
    ArgumentCaptor<Condition> pushDownCaptor = ArgumentCaptor.forClass(Condition.class);
    verify(service).pushDown(pushDownCaptor.capture(), same(paramGen), same(stepInterface));
    Condition verify = pushDownCaptor.getValue();
    assertEquals("A_tgt", verify.getCondition(0).getLeftValuename());
    assertEquals("A_value", verify.getCondition(0).getRightExactString());
    assertEquals(AND, verify.getCondition(1).getOperator());
    assertEquals("B_tgt", verify.getCondition(1).getCondition(0).getLeftValuename());
    assertEquals("B_value", verify.getCondition(1).getCondition(0).getRightExactString());
    assertEquals(OR, verify.getCondition(1).getCondition(1).getOperator());
    assertEquals("C_tgt", verify.getCondition(1).getCondition(1).getLeftValuename());
    assertEquals("C_value", verify.getCondition(1).getCondition(1).getRightExactString());
}
Also used : SQLCondition(org.pentaho.di.core.sql.SQLCondition) Condition(org.pentaho.di.core.Condition) SQL(org.pentaho.di.core.sql.SQL) Test(org.junit.Test)

Example 25 with SQL

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

the class ParameterGenerationTest method mockSql.

public SQL mockSql(Condition condition) {
    SQL query = mock(SQL.class);
    when(query.getWhereCondition()).thenReturn(mock(SQLCondition.class));
    when(query.getWhereCondition().getCondition()).thenReturn(condition);
    return query;
}
Also used : SQLCondition(org.pentaho.di.core.sql.SQLCondition) SQL(org.pentaho.di.core.sql.SQL)

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