use of org.pentaho.di.core.sql.SQL in project pdi-dataservice-server-plugin by pentaho.
the class ParameterGenerationTest method testPreview.
@Test
public void testPreview() throws KettleValueException, PushDownOptimizationException {
Condition condition = newCondition("A_src", "A_value");
SQL query = mockSql(condition);
when(executor.getSql()).thenReturn(query);
OptimizationImpactInfo optImpact = mock(OptimizationImpactInfo.class);
when(service.preview(any(Condition.class), same(paramGen), same(stepInterface))).thenReturn(optImpact);
assertEquals(optImpact, paramGen.preview(executor, stepInterface));
ArgumentCaptor<Condition> pushDownCaptor = ArgumentCaptor.forClass(Condition.class);
verify(service).preview(pushDownCaptor.capture(), same(paramGen), same(stepInterface));
Condition verify = pushDownCaptor.getValue();
assertEquals("A_tgt", verify.getLeftValuename());
assertEquals("A_value", verify.getRightExactString());
}
use of org.pentaho.di.core.sql.SQL in project pdi-dataservice-server-plugin by pentaho.
the class DataServiceTestControllerTest method initMocks.
@Before
public void initMocks() throws Exception {
MockitoAnnotations.initMocks(this);
when(dataService.getServiceTrans()).thenReturn(transMeta);
when(transMeta.realClone(false)).thenReturn(transMeta);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
((OutputStream) invocation.getArguments()[0]).write(TEST_ANNOTATIONS.getBytes());
return null;
}
}).when(annotationsQuery).writeTo(any(OutputStream.class));
doAnswer(new Answer<Query>() {
@Override
public Query answer(InvocationOnMock invocation) {
String sql = (String) invocation.getArguments()[0];
if (null != sql && sql.startsWith("show annotations from ")) {
return annotationsQuery;
}
return null;
}
}).when(annotationsQueryService).prepareQuery(any(String.class), anyInt(), any(Map.class));
when(streamingExecution.getId()).thenReturn(TEST_TABLE_NAME);
when(context.getServiceTransExecutor(TEST_TABLE_NAME)).thenReturn(streamingExecution);
when(dataServiceExecutor.getServiceTrans()).thenReturn(mock(Trans.class));
when(dataServiceExecutor.getGenTrans()).thenReturn(mock(Trans.class));
when(dataServiceExecutor.getServiceTransMeta()).thenReturn(transMeta);
when(dataServiceExecutor.getServiceTrans().getLogChannel()).thenReturn(mock(LogChannelInterface.class));
when(dataServiceExecutor.getGenTrans().getLogChannel()).thenReturn(mock(LogChannelInterface.class));
when(dataServiceExecutor.getSql()).thenReturn(mock(SQL.class));
when(dataServiceExecutor.getSql().getSelectFields()).thenReturn(mock(SQLFields.class));
when(dataServiceExecutor.getSql().getRowMeta()).thenReturn(new RowMeta());
when(dataServiceExecutor.getSql().getSelectFields().getFields()).thenReturn(new ArrayList<SQLField>());
when(rowMeta.getValueMetaList()).thenReturn(Collections.EMPTY_LIST);
when(transMeta.listParameters()).thenReturn(new String[] { "foo", "bar" });
when(transMeta.listVariables()).thenReturn(new String[] { "varFoo", "varBar" });
when(transMeta.getStepFields(anyString())).thenReturn(rowMeta);
when(transMeta.getVariable("varFoo")).thenReturn("varFooVal");
when(transMeta.getVariable("varBar")).thenReturn("varBarVal");
when(transMeta.getParameterDefault("foo")).thenReturn("fooVal");
when(transMeta.getParameterDefault("bar")).thenReturn("barVal");
when(bindingFactory.createBinding(same(model), anyString(), any(XulComponent.class), anyString())).thenReturn(binding);
// mocks to deal with Xul multithreading.
when(xulDomContainer.getDocumentRoot()).thenReturn(document);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
((Runnable) invocationOnMock.getArguments()[0]).run();
return null;
}
}).when(document).invokeLater(any(Runnable.class));
when(dataService.getName()).thenReturn(TEST_TABLE_NAME);
when(dataService.isStreaming()).thenReturn(false);
when(model.getWindowMode()).thenReturn(null);
when(model.getWindowSize()).thenReturn(0L);
when(model.getWindowEvery()).thenReturn(0L);
when(model.getWindowLimit()).thenReturn(0L);
dataServiceTestController = new DataServiceTestControllerTester();
dataServiceTestController.setXulDomContainer(xulDomContainer);
dataServiceTestController.setAnnotationsQueryService(annotationsQueryService);
}
use of org.pentaho.di.core.sql.SQL in project pdi-dataservice-server-plugin by pentaho.
the class CachedService method answersQuery.
public boolean answersQuery(DataServiceExecutor executor) {
SQL sql = executor.getSql();
// If this loader is complete, it always answers the query
if (isComplete()) {
return true;
}
// If aggregate functions or grouping is queried, a complete set is needed
SQLFields selectFields = sql.getSelectFields();
SQLFields groupFields = sql.getGroupFields();
if (selectFields.hasAggregates() || selectFields.isDistinct() || !groupFields.getFields().isEmpty()) {
if (ranking.or(Integer.MAX_VALUE) < Integer.MAX_VALUE) {
return false;
}
}
boolean outRanks = true;
if (this.ranking.isPresent()) {
outRanks &= this.ranking.get() >= calculateRank(executor);
}
// the two row limits my or may not be related, treating as independent
if (this.rankingServiceRows.isPresent()) {
outRanks &= this.rankingServiceRows.get() >= calculateServiceRowRank(executor);
}
return outRanks;
}
Aggregations