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