use of org.teiid.query.util.CommandContext in project teiid by teiid.
the class TestProcessor method testNonDeterministicPushdown.
@Test
public void testNonDeterministicPushdown() throws Exception {
// Create query
// $NON-NLS-1$
String sql = "SELECT RAND(), lookup('pm1.g1', 'e1', 'e2', 1) FROM pm1.g1 limit 2";
List[] expected = new List[] { Arrays.asList(new Double(0.1), "a"), Arrays.asList(new Double(0.2), "a") };
// Construct data manager with data
HardcodedDataManager hdm = new HardcodedDataManager();
hdm.addData("SELECT RAND() FROM pm1.g1", new List[] { Arrays.asList(.1), Arrays.asList(.2) });
hdm.addData("SELECT pm1.g1.e2, pm1.g1.e1 FROM pm1.g1", new List<?>[] { Arrays.asList(1, "a") });
BasicSourceCapabilities bsc = new BasicSourceCapabilities();
bsc.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
bsc.setFunctionSupport(SourceSystemFunctions.RAND, true);
// Plan query
CommandContext cc = createCommandContext();
ProcessorPlan plan = helpGetPlan(helpParse(sql), RealMetadataFactory.example1Cached(), new DefaultCapabilitiesFinder(bsc), cc);
helpProcess(plan, cc, hdm, expected);
bsc.setFunctionSupport(SourceSystemFunctions.RAND, false);
plan = helpGetPlan(helpParse(sql), RealMetadataFactory.example1Cached(), new DefaultCapabilitiesFinder(bsc), cc);
hdm = new HardcodedDataManager();
hdm.addData("SELECT 'a' FROM pm1.g1", new List[] { Arrays.asList("a"), Arrays.asList("a") });
hdm.addData("SELECT pm1.g1.e2, pm1.g1.e1 FROM pm1.g1", new List<?>[] { Arrays.asList(1, "a") });
Random r = new Random(0);
r.nextDouble();
expected = new List[] { Arrays.asList(r.nextDouble(), "a"), Arrays.asList(r.nextDouble(), "a") };
helpProcess(plan, cc, hdm, expected);
}
use of org.teiid.query.util.CommandContext in project teiid by teiid.
the class TestProcessor method testSortedFullOuterJoin.
@Test
public void testSortedFullOuterJoin() throws Exception {
// Create query
// $NON-NLS-1$
String sql = "SELECT pm1.g1.e2, pm2.g1.e2 FROM pm1.g1 FULL OUTER JOIN pm2.g1 ON pm1.g1.e2=pm2.g1.e2 and pm1.g1.e2 > 3";
// Create expected results
List[] expected = new List[] { // $NON-NLS-1$
Arrays.asList(new Object[] { null, 2 }), // $NON-NLS-1$ //$NON-NLS-2$
Arrays.asList(new Object[] { 3, null }), // $NON-NLS-1$
Arrays.asList(new Object[] { null, 3 }), // $NON-NLS-1$
Arrays.asList(new Object[] { null, 4 }) };
HardcodedDataManager hdm = new HardcodedDataManager();
hdm.addData("SELECT g_0.e2 AS c_0 FROM pm1.g1 AS g_0 ORDER BY c_0", new List[] { Arrays.asList(3) });
hdm.addData("SELECT g_0.e2 AS c_0 FROM pm2.g1 AS g_0 ORDER BY c_0", new List[] { Arrays.asList(2), Arrays.asList(3), Arrays.asList(4) });
ProcessorPlan plan = helpGetPlan(helpParse(sql), RealMetadataFactory.example1Cached(), TestOptimizer.getGenericFinder());
CommandContext cc = createCommandContext();
cc.setProcessorBatchSize(2);
helpProcess(plan, cc, hdm, expected);
}
use of org.teiid.query.util.CommandContext in project teiid by teiid.
the class TestProcessor method helpProcessException.
private void helpProcessException(ProcessorPlan plan, ProcessorDataManager dataManager, String expectedErrorMessage) {
TupleBuffer tsId = null;
BufferManager bufferMgr = null;
try {
bufferMgr = BufferManagerFactory.getStandaloneBufferManager();
// $NON-NLS-1$ //$NON-NLS-2$
CommandContext context = new CommandContext("0", "test", null, null, 1);
QueryProcessor processor = new QueryProcessor(plan, context, bufferMgr, dataManager);
processor.setNonBlocking(true);
BatchCollector collector = processor.createBatchCollector();
tsId = collector.collectTuples();
// $NON-NLS-1$
fail("Expected error during processing, but got none.");
} catch (TeiidException e) {
// ignore - this is expected
if (expectedErrorMessage != null) {
assertEquals(expectedErrorMessage, e.getMessage());
}
} finally {
if (tsId != null) {
tsId.remove();
}
}
}
use of org.teiid.query.util.CommandContext in project teiid by teiid.
the class TestTextTable method testTextAggGroupBy.
@Test
public void testTextAggGroupBy() throws Exception {
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
BasicSourceCapabilities caps = getTypicalCapabilities();
// $NON-NLS-1$
capFinder.addCapabilities("pm1", caps);
ProcessorPlan plan = helpPlan(// $NON-NLS-1$
"select convert(to_chars(textagg(pm1.g1.e1 order by pm1.g1.e1), 'UTF-8'), string) as x from pm1.g1 group by e2", // $NON-NLS-1$
metadata, // $NON-NLS-1$
null, // $NON-NLS-1$
capFinder, new String[] { "SELECT g_0.e2, g_0.e1 FROM pm1.g1 AS g_0" }, // $NON-NLS-1$
ComparisonMode.EXACT_COMMAND_STRING);
HardcodedDataManager hdm = new HardcodedDataManager();
hdm.addData("SELECT g_0.e2, g_0.e1 FROM pm1.g1 AS g_0", new List<?>[] { Arrays.asList(2, "z"), Arrays.asList(1, "b"), Arrays.asList(2, "z"), Arrays.asList(1, "b"), Arrays.asList(2, "c"), Arrays.asList(2, "a") });
hdm.setBlockOnce(true);
String nl = System.getProperty("line.separator");
ArrayList<Object> list = new ArrayList<Object>();
list.add("\"b\"" + nl + "\"b\"" + nl);
ArrayList<Object> list1 = new ArrayList<Object>();
list1.add("\"a\"" + nl + "\"c\"" + nl + "\"z\"" + nl + "\"z\"" + nl);
List<?>[] expected = new List<?>[] { list, list1 };
CommandContext context = createCommandContext();
context.setBufferManager(BufferManagerFactory.getTestBufferManager(0, 2));
helpProcess(plan, context, hdm, expected);
}
use of org.teiid.query.util.CommandContext in project teiid by teiid.
the class TestTriggerActions method testInsert.
@Test
public void testInsert() throws Exception {
TransformationMetadata metadata = TestUpdateValidator.example1();
TestUpdateValidator.createView("select 1 as x, 2 as y", metadata, GX);
Table t = metadata.getMetadataStore().getSchemas().get(VM1).getTables().get(GX);
t.setDeletePlan("");
t.setUpdatePlan("");
t.setInsertPlan("FOR EACH ROW BEGIN insert into pm1.g1 (e1) values (new.x); END");
String sql = "insert into gx (x, y) values (1, 2)";
FakeDataManager dm = new FakeDataManager();
FakeDataStore.addTable("pm1.g1", dm, metadata);
CommandContext context = createCommandContext();
BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
ProcessorPlan plan = TestProcessor.helpGetPlan(TestResolver.helpResolve(sql, metadata), metadata, new DefaultCapabilitiesFinder(caps), context);
List<?>[] expected = new List[] { Arrays.asList(1) };
helpProcess(plan, context, dm, expected);
}
Aggregations