Search in sources :

Example 56 with SQL

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());
}
Also used : SQLCondition(org.pentaho.di.core.sql.SQLCondition) Condition(org.pentaho.di.core.Condition) OptimizationImpactInfo(org.pentaho.di.trans.dataservice.optimization.OptimizationImpactInfo) SQL(org.pentaho.di.core.sql.SQL) Test(org.junit.Test)

Example 57 with SQL

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);
}
Also used : Query(org.pentaho.di.trans.dataservice.clients.Query) RowMeta(org.pentaho.di.core.row.RowMeta) OutputStream(java.io.OutputStream) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) SQL(org.pentaho.di.core.sql.SQL) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) SQLFields(org.pentaho.di.core.sql.SQLFields) InvocationOnMock(org.mockito.invocation.InvocationOnMock) SQLField(org.pentaho.di.core.sql.SQLField) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Trans(org.pentaho.di.trans.Trans) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) XulComponent(org.pentaho.ui.xul.XulComponent) Before(org.junit.Before)

Example 58 with SQL

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;
}
Also used : SQLFields(org.pentaho.di.core.sql.SQLFields) 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