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" }));
}
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 }));
}
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 }));
}
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());
}
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;
}
Aggregations