use of org.pentaho.di.core.Condition in project pdi-dataservice-server-plugin by pentaho.
the class DataServiceExecutorTest method testNullNotNullKeywords.
@Test
public void testNullNotNullKeywords() throws Exception {
String sql = "SELECT * FROM " + DATA_SERVICE_NAME + " WHERE column1 IS NOT NULL AND column2 IS NULL";
DataServiceExecutor executor = new DataServiceExecutor.Builder(new SQL(sql), dataService, context).serviceTrans(serviceTrans).sqlTransGenerator(sqlTransGenerator).genTrans(genTrans).build();
Condition condition = executor.getSql().getWhereCondition().getCondition();
Condition condition1 = condition.getCondition(0);
Condition condition2 = condition.getCondition(1);
assertEquals("column1", condition1.getLeftValuename());
assertNull(condition1.getRightExact());
assertEquals(Condition.FUNC_NOT_NULL, condition1.getFunction());
assertEquals("column2", condition2.getLeftValuename());
assertNull(condition2.getRightExact());
assertEquals(Condition.FUNC_NULL, condition2.getFunction());
}
use of org.pentaho.di.core.Condition 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.Condition in project pdi-dataservice-server-plugin by pentaho.
the class ParameterGenerationTest method newCondition.
public static Condition newCondition(int op, String lhs) throws KettleValueException {
Condition condition = newCondition(lhs);
condition.setOperator(op);
return condition;
}
use of org.pentaho.di.core.Condition in project pdi-dataservice-server-plugin by pentaho.
the class TableInputParameterGenerationTest method testInListCondition.
@SuppressWarnings("unchecked")
protected void testInListCondition(String valueData, String[] inListExpectedValues, String expectedSql) throws KettleValueException, PushDownOptimizationException {
ValueMetaAndData rightExactInList = new ValueMetaAndData("mock_value", valueData);
Condition inListCondition = new Condition("field_name", Condition.FUNC_IN_LIST, null, rightExactInList);
RowMeta inListParamsMeta = mock(RowMeta.class);
List<Object> inListParams = mock(List.class);
assertThat(service.convertAtomicCondition(inListCondition, inListParamsMeta, inListParams), equalTo(expectedSql));
for (String inListValue : inListExpectedValues) {
verify(inListParams).add(inListValue);
}
verify(inListParamsMeta, times(inListExpectedValues.length)).addValueMeta(resolvedValueMeta);
verifyNoMoreInteractions(inListParams, inListParamsMeta);
}
use of org.pentaho.di.core.Condition in project pdi-dataservice-server-plugin by pentaho.
the class TableInputParameterGenerationTest method testPushDown.
@Test
public void testPushDown() throws Exception {
// Add filters to both WHERE and GROUP by converting original query to a prepared statement...
String originalQuery = "SELECT DepartmentName, COUNT(*) as EmployeeCount " + "FROM Department, Employee " + "WHERE Employee.DepartmentId = Department.DepartmentId AND ${EMPLOYEE_FILTER} ";
ParameterGeneration employeeFilterParamGen = factory.createPushDown();
employeeFilterParamGen.setParameterName("EMPLOYEE_FILTER");
// Employee.Grade = "G7"
Condition employeeFilter = newCondition("Employee.Grade", "G7");
// Push Down condition
service.pushDown(employeeFilter, employeeFilterParamGen, stepInterface);
// Verify that the database for this step is now 'wrapped'
assertThat(data.db, is(instanceOf(DatabaseWrapper.class)));
final DatabaseWrapper databaseWrapper = (DatabaseWrapper) data.db;
// The employee filter variable should now be set
ArgumentCaptor<String> varCaptor = ArgumentCaptor.forClass(String.class);
verify(stepInterface).setVariable(eq(employeeFilterParamGen.getParameterName()), varCaptor.capture());
// Verify stored data for runtime injection
final List<String> fragmentIds = varCaptor.getAllValues();
assertThat(fragmentIds.size(), is(1));
assertTrue(databaseWrapper.pushDownMap.keySet().containsAll(fragmentIds));
// Update original query with variable values
Variables variables = new Variables();
variables.setVariable(employeeFilterParamGen.getParameterName(), fragmentIds.get(0));
String runtimeQuery = variables.environmentSubstitute(originalQuery);
for (String fragment : fragmentIds) {
assertThat(runtimeQuery, containsString(fragment));
}
// During trans runtime, values and sql fragments will be injected
RowMeta rowMeta = new RowMeta();
List<Object> values = new LinkedList<Object>();
String resultQuery = databaseWrapper.injectRuntime(databaseWrapper.pushDownMap, runtimeQuery, rowMeta, values);
String expectedQuery = "SELECT DepartmentName, COUNT(*) as EmployeeCount " + "FROM Department, Employee " + "WHERE Employee.DepartmentId = Department.DepartmentId AND Employee.Grade = ? ";
assertThat(resultQuery, equalTo(expectedQuery));
assertThat(rowMeta.getValueMetaList(), equalTo(Arrays.asList(resolvedValueMeta)));
assertThat(values, equalTo(Arrays.<Object>asList("G7")));
}
Aggregations