Search in sources :

Example 26 with SQL

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

the class ParameterGenerationTest method testActivationFailure.

@Test
public void testActivationFailure() throws Exception {
    SQL query = mockSql(newCondition("A_src"));
    when(executor.getSql()).thenReturn(query);
    // All okay
    assertTrue(paramGen.activate(executor, stepInterface));
    // Parameter value is blank
    paramGen.setParameterName("");
    assertFalse(paramGen.activate(executor, stepInterface));
    paramGen.setParameterName(PARAM_NAME);
    assertTrue(paramGen.activate(executor, stepInterface));
    // Service throws an error the first time
    doThrow(PushDownOptimizationException.class).doNothing().when(service).pushDown(any(Condition.class), same(paramGen), same(stepInterface));
    assertFalse(paramGen.activate(executor, stepInterface));
    assertTrue(paramGen.activate(executor, stepInterface));
    // Step type is not supported
    when(serviceProvider.getService(stepMeta)).thenReturn(null, service);
    assertFalse(paramGen.activate(executor, stepInterface));
    assertTrue(paramGen.activate(executor, stepInterface));
    // Query does not have a WHERE clause
    when(executor.getSql()).thenReturn(mock(SQL.class));
    assertFalse(paramGen.activate(executor, stepInterface));
    // Query could not be mapped
    query = mockSql(newCondition("UNMAPPED"));
    when(executor.getSql()).thenReturn(query);
    assertFalse(paramGen.activate(executor, stepInterface));
}
Also used : SQLCondition(org.pentaho.di.core.sql.SQLCondition) Condition(org.pentaho.di.core.Condition) PushDownOptimizationException(org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationException) SQL(org.pentaho.di.core.sql.SQL) Test(org.junit.Test)

Example 27 with SQL

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

the class ParameterPushdownTest method query.

private void query(String whereClause) throws Exception {
    SQL sql = new SQL(SELECT + whereClause);
    sql.parse(rowMeta);
    when(executor.getSql()).thenReturn(sql);
}
Also used : SQL(org.pentaho.di.core.sql.SQL)

Example 28 with SQL

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

the class TransientResolverTest method testBuilderPassesLogLevel.

@Test
public void testBuilderPassesLogLevel() throws Exception {
    File localFolder = temporaryFolder.newFolder("local");
    File localFile = new File(localFolder, "name.ktr");
    Files.write(transMeta.getXML().getBytes(StandardCharsets.UTF_8), localFile);
    String transientId = TransientResolver.buildTransient(localFile.getPath(), "OUTPUT");
    when(repository.getTransformationID(any(), eq(root))).thenThrow(new KettleException());
    DataServiceExecutor.Builder builder = transientResolver.createBuilder(new SQL("select * from " + transientId));
    DataServiceExecutor build = builder.build();
    assertEquals(LogLevel.DEBUG, build.getServiceTransMeta().getLogLevel());
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) DataServiceExecutor(org.pentaho.di.trans.dataservice.DataServiceExecutor) File(java.io.File) SQL(org.pentaho.di.core.sql.SQL) Test(org.junit.Test)

Example 29 with SQL

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

the class CachedServiceTest method testCreateCacheKey.

@Test
public void testCreateCacheKey() throws Exception {
    CacheKey unbounded, withCondition, withConditionOrdered, withLimit, otherVersion;
    unbounded = cacheKey(BASE_QUERY);
    withCondition = cacheKey(BASE_QUERY + " WHERE A = 42");
    withConditionOrdered = cacheKey(BASE_QUERY + " WHERE A=42 ORDER BY B");
    withLimit = cacheKey(BASE_QUERY + " LIMIT 20");
    when(transMeta.getCacheVersion()).thenReturn(2);
    otherVersion = cacheKey(BASE_QUERY);
    // Verifies order from most specific to general
    assertThat(withConditionOrdered.all(), contains(withConditionOrdered, withCondition, unbounded));
    assertThat(withLimit, equalTo(unbounded));
    for (CacheKey cacheKey : ImmutableList.of(withCondition, withConditionOrdered, otherVersion)) {
        assertThat(cacheKey, not(equalTo(unbounded)));
    }
    assertThat(withCondition.withoutCondition(), equalTo(unbounded));
    assertThat(withConditionOrdered.withoutOrder(), equalTo(withCondition));
    // Verify that execution parameters will change the key
    SQL sql = new SQL(BASE_QUERY);
    sql.parse(rowMeta);
    assertThat(CacheKey.create(new DataServiceExecutor.Builder(sql, dataServiceMeta, context).prepareExecution(false).parameters(ImmutableMap.of("foo", "bar")).serviceTrans(serviceTrans).build()), not(equalTo(CacheKey.create(new DataServiceExecutor.Builder(sql, dataServiceMeta, context).prepareExecution(false).serviceTrans(serviceTrans).build()))));
}
Also used : DataServiceExecutor(org.pentaho.di.trans.dataservice.DataServiceExecutor) CacheKey(org.pentaho.di.trans.dataservice.optimization.cache.CachedService.CacheKey) SQL(org.pentaho.di.core.sql.SQL) Test(org.junit.Test)

Example 30 with SQL

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

the class DataServiceTestController method getNewDataServiceExecutor.

protected DataServiceExecutor getNewDataServiceExecutor(boolean enableMetrics) throws KettleException {
    try {
        resetVariablesAndParameters();
        DataServiceExecutor.Builder builder;
        if (dataService.isStreaming()) {
            builder = new DataServiceExecutor.Builder(new SQL(model.getSql()), dataService, context).rowLimit(dataService.getRowLimit()).timeLimit(dataService.getTimeLimit()).logLevel(model.getLogLevel()).enableMetrics(enableMetrics).windowMode(model.getWindowMode()).windowSize(model.getWindowSize()).windowEvery(model.getWindowEvery()).windowLimit(model.getWindowLimit());
        } else {
            builder = new DataServiceExecutor.Builder(new SQL(model.getSql()), dataService, context).rowLimit(model.getMaxRows()).logLevel(model.getLogLevel()).enableMetrics(enableMetrics);
        }
        return builder.build();
    } catch (KettleException e) {
        model.setAlertMessage(e.getMessage());
        throw e;
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) DataServiceExecutor(org.pentaho.di.trans.dataservice.DataServiceExecutor) 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