use of org.teiid.query.sql.lang.Command in project teiid by teiid.
the class TestVirtualDepJoin method testVirtualDepJoinPartialPushdown.
@Test
public void testVirtualDepJoinPartialPushdown() throws Exception {
// Create query
// $NON-NLS-1$
String sql = "SELECT * from Master.Transactions where last = 'Davis'";
// Create expected results
List[] expected = new List[] { // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15000), new Long(123), new Integer(1), new BigDecimal("100.00") }), // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15000), new Long(127), new Integer(2), new BigDecimal("250.00") }), // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15000), new Long(128), new Integer(3), new BigDecimal("1000.00") }), // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15001), new Long(134), new Integer(1), new BigDecimal("10.00") }), // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15001), new Long(201), new Integer(1), new BigDecimal("10.00") }), // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(540), new Long(1002), new Integer(1), new BigDecimal("7.20") }), // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(540), new Long(1003), new Integer(2), new BigDecimal("1000.00") }) };
// Construct data manager with data
QueryMetadataInterface metadata = exampleVirtualDepJoin();
FakeDataManager dataManager = new FakeDataManager();
sampleDataVirtualDepJoin(dataManager, metadata);
// Plan query
CommandContext context = TestProcessor.createCommandContext();
Command command = TestProcessor.helpParse(sql);
FakeCapabilitiesFinder finder = new FakeCapabilitiesFinder();
BasicSourceCapabilities caps1 = TestOptimizer.getTypicalCapabilities();
BasicSourceCapabilities caps2 = TestOptimizer.getTypicalCapabilities();
caps2.setCapabilitySupport(Capability.CRITERIA_IN, false);
// $NON-NLS-1$
finder.addCapabilities("US", caps1);
// $NON-NLS-1$
finder.addCapabilities("Europe", caps2);
// $NON-NLS-1$
finder.addCapabilities("CustomerMaster", caps1);
ProcessorPlan plan = TestProcessor.helpGetPlan(command, metadata, finder, context);
TestOptimizer.checkNodeTypes(plan, new int[] { // Access
2, // DependentAccess
1, // DependentSelect
0, // DependentProject
0, // DupRemove
0, // Grouping
0, // NestedLoopJoinStrategy
0, // MergeJoinStrategy
1, // Null
0, // PlanExecution
0, // Project
3, // Select
1, // Sort
0, // UnionAll
1 });
TestOptimizer.checkDependentJoinCount(plan, 1);
// Run query
TestProcessor.helpProcess(plan, context, dataManager, expected);
}
use of org.teiid.query.sql.lang.Command in project teiid by teiid.
the class TestVirtualDepJoin method testVirtualDepJoinNoValues.
@Test
public void testVirtualDepJoinNoValues() throws Exception {
// Create query
// $NON-NLS-1$
String sql = "select first, last, sum(amount) from Europe.CustAccts e join CustomerMaster.Customers c on c.id=e.id where c.first=-9999 group by c.id, first, last";
// Create expected results
List[] expected = new List[] {};
// Construct data manager with data
QueryMetadataInterface metadata = exampleVirtualDepJoin();
FakeDataManager dataManager = new FakeDataManager();
sampleDataVirtualDepJoin(dataManager, metadata);
// Plan query
CommandContext context = TestProcessor.createCommandContext();
Command command = TestProcessor.helpParse(sql);
FakeCapabilitiesFinder finder = new FakeCapabilitiesFinder();
BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, false);
// $NON-NLS-1$
finder.addCapabilities("Europe", caps);
// $NON-NLS-1$
finder.addCapabilities("CustomerMaster", caps);
ProcessorPlan plan = TestProcessor.helpGetPlan(command, metadata, finder, context);
TestOptimizer.checkDependentJoinCount(plan, 1);
// Run query
TestProcessor.helpProcess(plan, context, dataManager, expected);
// Second query *will not be run* as no values were passed and dependent side has always false criteria
// So, the list should contain only the first query
assertEquals(3, dataManager.getQueries().size());
}
use of org.teiid.query.sql.lang.Command in project teiid by teiid.
the class TestWithClauseProcessing method testSingleItemInOn.
@Test
public void testSingleItemInOn() {
// $NON-NLS-1$
String sql = "with a (x, y, z) as (select e1, e2, e3 from pm1.g1 limit 1) SELECT pm2.g1.e1 from pm2.g1 left outer join pm2.g2 on (pm2.g1.e2 = pm2.g2.e2 and pm2.g1.e1 = (select a.x from a))";
List[] expected = new List[] { Arrays.asList("a") };
HardcodedDataManager dataManager = new HardcodedDataManager() {
boolean block = true;
@Override
public TupleSource registerRequest(CommandContext context, Command command, String modelName, RegisterRequestParameter parameterObject) throws TeiidComponentException {
if (block) {
block = false;
throw BlockedException.INSTANCE;
}
return super.registerRequest(context, command, modelName, parameterObject);
}
};
dataManager.addData("SELECT g_0.e1 FROM pm1.g1 AS g_0", new List[] { Arrays.asList("a") });
dataManager.addData("SELECT g_0.e1 FROM pm2.g1 AS g_0 LEFT OUTER JOIN pm2.g2 AS g_1 ON g_0.e2 = g_1.e2 AND g_0.e1 = 'a'", new List[] { Arrays.asList("a") });
BasicSourceCapabilities bsc = TestOptimizer.getTypicalCapabilities();
bsc.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER, true);
bsc.setCapabilitySupport(Capability.CRITERIA_ON_SUBQUERY, true);
ProcessorPlan plan = helpGetPlan(helpParse(sql), RealMetadataFactory.example1Cached(), new DefaultCapabilitiesFinder(bsc));
helpProcess(plan, dataManager, expected);
}
use of org.teiid.query.sql.lang.Command in project teiid by teiid.
the class TestOrderByRewrite method getCommand.
private static Command getCommand(String sql) throws TeiidComponentException, TeiidProcessingException {
Command command = QueryParser.getQueryParser().parseCommand(sql);
QueryResolver.resolveCommand(command, RealMetadataFactory.example1Cached());
return QueryRewriter.rewrite(command, RealMetadataFactory.example1Cached(), null);
}
use of org.teiid.query.sql.lang.Command in project teiid by teiid.
the class TestJoinNode method testDupRemoveUnderJoin.
@Test
public void testDupRemoveUnderJoin() throws Exception {
// $NON-NLS-1$
String sql = "select a.e1, b.e2 from pm1.g1 as a, (select distinct 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<?>[1];
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<?>[1025];
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);
List<?>[] results = new List<?>[1025];
for (int i = 0; i < results.length; i++) {
results[i] = Arrays.asList("0", i);
}
TestProcessor.helpProcess(plan, context, hdm, results);
}
Aggregations