use of org.teiid.query.sql.lang.Command in project teiid by teiid.
the class TestJoinNode method testPrefetchDistinct.
@Test
public void testPrefetchDistinct() throws Exception {
// $NON-NLS-1$
String sql = "select a.e1, b.e2 from pm1.g1 as a, (select e1, e2 from pm2.g2 union select e1, e2 from pm2.g2) as b";
ProcessorPlan plan = TestProcessor.helpGetPlan(sql, RealMetadataFactory.example1Cached());
HardcodedDataManager hdm = new HardcodedDataManager() {
public TupleSource registerRequest(CommandContext context, Command command, String modelName, RegisterRequestParameter parameterObject) throws TeiidComponentException {
final TupleSource source = super.registerRequest(context, command, modelName, parameterObject);
return new TupleSource() {
private int block;
@Override
public List<?> nextTuple() throws TeiidComponentException, TeiidProcessingException {
if (block++ % 2 == 0) {
throw BlockedException.INSTANCE;
}
return source.nextTuple();
}
@Override
public void closeSource() {
source.closeSource();
}
};
}
};
List<?>[] rows = new List<?>[2];
for (int i = 0; i < rows.length; i++) {
rows[i] = Arrays.asList(String.valueOf(i));
}
hdm.addData("SELECT pm1.g1.e1 FROM pm1.g1", rows);
rows = new List<?>[2];
for (int i = 0; i < rows.length; i++) {
rows[i] = Arrays.asList(String.valueOf(i), i);
}
hdm.addData("SELECT pm2.g2.e1, pm2.g2.e2 FROM pm2.g2", rows);
BufferManagerImpl mgr = BufferManagerFactory.getTestBufferManager(1, 2);
mgr.setTargetBytesPerRow(100);
// $NON-NLS-1$ //$NON-NLS-2$
CommandContext context = new CommandContext("pid", "test", null, null, 1);
context.setBufferManager(mgr);
TestProcessor.helpProcess(plan, context, hdm, new List<?>[] { Arrays.asList("0", 0), Arrays.asList("0", 1), Arrays.asList("1", 0), Arrays.asList("1", 1) });
}
use of org.teiid.query.sql.lang.Command in project teiid by teiid.
the class TestProcessor method helpGetPlan.
public static ProcessorPlan helpGetPlan(String sql, QueryMetadataInterface metadata, CapabilitiesFinder finder) {
// $NON-NLS-1$
if (DEBUG)
System.out.println("\n####################################\n" + sql);
Command command = helpParse(sql);
ProcessorPlan process = helpGetPlan(command, metadata, finder);
return process;
}
use of org.teiid.query.sql.lang.Command in project teiid by teiid.
the class TestProcessor method testPushdownLiteralInSelectWithOrderBy.
@Test
public void testPushdownLiteralInSelectWithOrderBy() {
String sql = // $NON-NLS-1$
"SELECT 1, concat('a', 'b' ) AS X FROM BQT1.SmallA where intkey = 0 " + // $NON-NLS-1$
"UNION ALL " + // $NON-NLS-1$
"select 2, 'Hello2' from BQT1.SmallA where intkey = 1 order by X desc";
// Create expected results - would expect these to be:
// 1, "ab"
// 2, "Hello2"
// but our fake tuple source is too dumb to return anything reasonable, so instead get:
List[] expected = new List[] { Arrays.asList(new Object[] { null, null }) };
// Construct data manager with data
FakeDataManager dataManager = new FakeDataManager();
sampleDataBQTSmall(dataManager);
// Plan query
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
BasicSourceCapabilities caps = new BasicSourceCapabilities();
caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
caps.setCapabilitySupport(Capability.QUERY_UNION, true);
caps.setCapabilitySupport(Capability.QUERY_SET_ORDER_BY, true);
caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
// $NON-NLS-1$
capFinder.addCapabilities("BQT1", caps);
QueryMetadataInterface metadata = RealMetadataFactory.exampleBQTCached();
Command command = helpParse(sql);
ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
// Run query
helpProcess(plan, dataManager, expected);
}
use of org.teiid.query.sql.lang.Command in project teiid by teiid.
the class TestProcessor method testCase5413.
@Test
public void testCase5413() throws Exception {
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
BasicSourceCapabilities caps = new BasicSourceCapabilities();
caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
// $NON-NLS-1$
capFinder.addCapabilities("pm1", caps);
// Plan query
// $NON-NLS-1$
String sql = "SELECT e1 FROM pm1.g2 WHERE LOOKUP('pm1.g1','e1', 'e2', 0) = e1";
QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
Command command = TestProcessor.helpParse(sql);
CommandContext context = createCommandContext();
ProcessorPlan plan = helpGetPlan(command, metadata, capFinder, context);
// Run query
List[] expected = new List[] { // $NON-NLS-1$
Arrays.asList(new Object[] { "a" }) };
FakeDataManager dataManager = new FakeDataManager();
FakeDataStore.sampleData2(dataManager);
helpProcess(plan, context, dataManager, expected);
}
use of org.teiid.query.sql.lang.Command in project teiid by teiid.
the class TestProcedureResolving method testDefect13029_CorrectlySetUpdateProcedureTempGroupIDs.
@Test
public void testDefect13029_CorrectlySetUpdateProcedureTempGroupIDs() throws Exception {
StringBuffer proc = // $NON-NLS-1$
new StringBuffer("FOR EACH ROW").append(// $NON-NLS-1$
"\nBEGIN").append(// $NON-NLS-1$
"\nDECLARE string var1;").append(// $NON-NLS-1$
"\nvar1 = '';").append(// $NON-NLS-1$
"\n LOOP ON (SELECT pm1.g1.e1 FROM pm1.g1) AS loopCursor").append(// $NON-NLS-1$
"\n BEGIN").append(// $NON-NLS-1$
"\n LOOP ON (SELECT pm1.g2.e1 FROM pm1.g2 WHERE loopCursor.e1 = pm1.g2.e1) AS loopCursor2").append(// $NON-NLS-1$
"\n BEGIN").append(// $NON-NLS-1$
"\n var1 = CONCAT(var1, CONCAT(' ', loopCursor2.e1));").append(// $NON-NLS-1$
"\n END").append(// $NON-NLS-1$
"\n END").append(// $NON-NLS-1$
"\nEND");
// $NON-NLS-1$
String userUpdateStr = "UPDATE vm1.g1 SET e1='x'";
Command command = helpResolveUpdateProcedure(proc.toString(), userUpdateStr, Table.TriggerEvent.UPDATE);
Map<String, TempMetadataID> tempIDs = command.getTemporaryMetadata().getData();
assertNotNull(tempIDs);
// $NON-NLS-1$
assertNull(tempIDs.get("LOOPCURSOR"));
// $NON-NLS-1$
assertNull(tempIDs.get("LOOPCURSOR2"));
Command subCommand = CommandCollectorVisitor.getCommands(command).get(0);
tempIDs = subCommand.getTemporaryMetadata().getData();
assertNotNull(tempIDs);
// $NON-NLS-1$
assertNull(tempIDs.get("LOOPCURSOR"));
// $NON-NLS-1$
assertNull(tempIDs.get("LOOPCURSOR2"));
subCommand = CommandCollectorVisitor.getCommands(command).get(1);
tempIDs = subCommand.getTemporaryMetadata().getData();
assertNotNull(tempIDs);
// $NON-NLS-1$
assertNotNull(tempIDs.get("LOOPCURSOR"));
// $NON-NLS-1$
assertNull(tempIDs.get("LOOPCURSOR2"));
}
Aggregations