use of org.teiid.query.sql.lang.Command in project teiid by teiid.
the class Block method addStatement.
public void addStatement(Statement statement, boolean exception) {
if (statement instanceof AssignmentStatement) {
AssignmentStatement stmt = (AssignmentStatement) statement;
Command cmd = stmt.getCommand();
if (cmd != null) {
internalAddStatement(new CommandStatement(cmd), exception);
stmt.setCommand(null);
stmt.setExpression(null);
if (stmt.getVariable().getShortName().equalsIgnoreCase(ProcedureReservedWords.ROWCOUNT) && stmt.getVariable().getGroupSymbol() != null && stmt.getVariable().getGroupSymbol().getName().equalsIgnoreCase(ProcedureReservedWords.VARIABLES)) {
return;
}
String fullName = ProcedureReservedWords.VARIABLES + Symbol.SEPARATOR + ProcedureReservedWords.ROWCOUNT;
stmt.setExpression(new ElementSymbol(fullName));
}
}
internalAddStatement(statement, exception);
}
use of org.teiid.query.sql.lang.Command in project teiid by teiid.
the class TestDependentJoins method testLargeSetInDepAccessWithAccessPattern.
@Test
public void testLargeSetInDepAccessWithAccessPattern() {
// $NON-NLS-1$
String sql = "SELECT a.e1, b.e1, b.e2 FROM pm4.g1 a INNER JOIN pm1.g1 b ON a.e1=b.e1 AND a.e2 = b.e2";
// Create expected results
List[] expected = new List[] { Arrays.asList(new Object[] { "aa ", "aa ", // $NON-NLS-1$ //$NON-NLS-2$
0 }), Arrays.asList(new Object[] { "bb ", "bb ", // $NON-NLS-1$ //$NON-NLS-2$
1 }), Arrays.asList(new Object[] { "cc ", "cc ", // $NON-NLS-1$ //$NON-NLS-2$
2 }) };
// Plan query
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
BasicSourceCapabilities depcaps = new BasicSourceCapabilities();
depcaps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
depcaps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, 1);
depcaps.setCapabilitySupport(Capability.CRITERIA_IN, true);
BasicSourceCapabilities caps = new BasicSourceCapabilities();
caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
// $NON-NLS-1$
capFinder.addCapabilities("pm4", depcaps);
// $NON-NLS-1$
capFinder.addCapabilities("pm1", caps);
QueryMetadataInterface fakeMetadata = RealMetadataFactory.example1Cached();
Command command = TestProcessor.helpParse(sql);
ProcessorPlan plan = TestProcessor.helpGetPlan(command, fakeMetadata, capFinder);
// Verify a dependent join (not merge join) was used
assertTrue(plan instanceof RelationalPlan);
RelationalPlan relationalPlan = (RelationalPlan) plan;
RelationalNode project = relationalPlan.getRootNode();
RelationalNode join = project.getChildren()[0];
// $NON-NLS-1$
assertTrue("Expected instance of JoinNode (for dep join) but got " + join.getClass(), join instanceof JoinNode);
// Construct data manager with data
FakeDataManager dataManager = new FakeDataManager();
TestProcessor.sampleData2b(dataManager, fakeMetadata);
// Run query
TestProcessor.helpProcess(plan, dataManager, expected);
}
use of org.teiid.query.sql.lang.Command in project teiid by teiid.
the class TestDependentJoins method testLargeSetInDepAccess.
/**
* SELECT pm1.g1.e1 FROM pm1.g1, pm6.g1 WHERE pm1.g1.e1=pm6.g1.e1 OPTION MAKEDEP pm6.g1
*/
@Test
public void testLargeSetInDepAccess() throws Exception {
// Create query
// $NON-NLS-1$
String sql = "SELECT pm1.g1.e1 FROM pm1.g1, pm6.g1 WHERE pm1.g1.e1=pm6.g1.e1 OPTION MAKEDEP pm6.g1";
// Construct data manager with data
FakeDataManager dataManager = new FakeDataManager();
sampleData4(dataManager);
// Slightly modify metadata to set max set size to just a few rows - this
// will allow us to test the dependent overflow case
QueryMetadataInterface fakeMetadata = RealMetadataFactory.example1Cached();
// Plan query
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
BasicSourceCapabilities depcaps = new BasicSourceCapabilities();
depcaps.setCapabilitySupport(Capability.CRITERIA_IN, true);
depcaps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, 1);
depcaps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
BasicSourceCapabilities caps = new BasicSourceCapabilities();
caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
// $NON-NLS-1$
capFinder.addCapabilities("pm1", caps);
// $NON-NLS-1$
capFinder.addCapabilities("pm6", depcaps);
List[] expected = new List[] { Arrays.asList(new Object[] { // $NON-NLS-1$
new String("b") }) };
Command command = TestProcessor.helpParse(sql);
ProcessorPlan plan = TestProcessor.helpGetPlan(command, fakeMetadata, capFinder);
// Run query
TestProcessor.helpProcess(plan, dataManager, expected);
}
use of org.teiid.query.sql.lang.Command in project teiid by teiid.
the class TestDependentJoins method testIndependentDupRemoval1.
@Test
public void testIndependentDupRemoval1() {
// Create query
// $NON-NLS-1$
String sql = "SELECT pm1.g1.e1, pm1.g1.e2, x.e2 FROM pm1.g1, pm2.g2, /*+ makeind */ (select distinct e1, e2 from pm2.g1) x WHERE x.e1=pm1.g1.e1 AND pm2.g2.e2=x.e2";
// Create expected results
List[] expected = new List[] { // $NON-NLS-1$
Arrays.asList(new Object[] { "a", 1, 1 }), // $NON-NLS-1$
Arrays.asList(new Object[] { "b", 1, 1 }) };
BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, false);
caps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, 1);
caps.setSourceProperty(Capability.MAX_DEPENDENT_PREDICATES, 1);
QueryMetadataInterface fakeMetadata = RealMetadataFactory.example1Cached();
Command command = TestProcessor.helpParse(sql);
ProcessorPlan plan = TestProcessor.helpGetPlan(command, fakeMetadata, new DefaultCapabilitiesFinder(caps));
HardcodedDataManager dataManager = new HardcodedDataManager();
dataManager.addData("SELECT DISTINCT g_0.e1, g_0.e2 FROM pm2.g1 AS g_0", new List<?>[] { Arrays.asList("b", 1), Arrays.asList("a", 1) });
dataManager.addData("SELECT g_0.e1 AS c_0, g_0.e2 AS c_1 FROM pm1.g1 AS g_0 WHERE g_0.e1 = 'b'", new List<?>[] { Arrays.asList("b", 1) });
dataManager.addData("SELECT g_0.e2 AS c_0 FROM pm2.g2 AS g_0 ORDER BY c_0", new List<?>[] { Arrays.asList(1), Arrays.asList(2), Arrays.asList(3) });
dataManager.addData("SELECT g_0.e1 AS c_0, g_0.e2 AS c_1 FROM pm1.g1 AS g_0 WHERE g_0.e1 = 'a'", new List<?>[] { Arrays.asList("a", 1) });
// Run query
TestProcessor.helpProcess(plan, dataManager, expected);
}
use of org.teiid.query.sql.lang.Command in project teiid by teiid.
the class TestDependentJoins method testIndependentDupRemoval.
@Test
public void testIndependentDupRemoval() {
// Create query
// $NON-NLS-1$
String sql = "SELECT pm1.g1.e1, pm1.g1.e2, pm2.g1.e2 FROM pm1.g1, pm2.g1 WHERE pm2.g1.e1=pm1.g1.e1 AND pm1.g1.e2<pm2.g1.e2 order by pm1.g1.e1 option makedep pm1.g1";
// Create expected results
List[] expected = new List[] { // $NON-NLS-1$
Arrays.asList(new Object[] { "a", 0, 3 }), // $NON-NLS-1$
Arrays.asList(new Object[] { "a", 0, 3 }) };
BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
caps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, 1);
caps.setSourceProperty(Capability.MAX_DEPENDENT_PREDICATES, 1);
caps.setCapabilitySupport(Capability.QUERY_ORDERBY, false);
QueryMetadataInterface fakeMetadata = RealMetadataFactory.example1Cached();
Command command = TestProcessor.helpParse(sql);
ProcessorPlan plan = TestProcessor.helpGetPlan(command, fakeMetadata, new DefaultCapabilitiesFinder(caps));
// Construct data manager with data
FakeDataManager dataManager = new FakeDataManager();
TestProcessor.sampleData1(dataManager);
// Run query
TestProcessor.helpProcess(plan, dataManager, expected);
}
Aggregations