use of org.teiid.query.processor.relational.RelationalNode in project teiid by teiid.
the class TestProcessor method testComplexJoinExpressionsUsingDependentJoinWithAccessPattern.
/**
* RLM Case 2077
* @throws Exception
*/
@Test
public void testComplexJoinExpressionsUsingDependentJoinWithAccessPattern() throws Exception {
// $NON-NLS-1$
String sql = "SELECT a.e1, b.e1, b.e2 FROM pm4.g1 a, pm2.g1 b where rtrim(a.e1)=(b.e1 || b.e1)";
// Create expected results
List[] expected = new List[] { // $NON-NLS-1$ //$NON-NLS-2$
Arrays.asList(new Object[] { "bb ", "b", new Integer(0) }) };
// Plan query
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
BasicSourceCapabilities caps = new BasicSourceCapabilities();
caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
caps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, new Integer(1));
// $NON-NLS-1$
caps.setFunctionSupport("||", true);
// $NON-NLS-1$
caps.setFunctionSupport("rtrim", true);
// $NON-NLS-1$
capFinder.addCapabilities("pm4", caps);
// $NON-NLS-1$
capFinder.addCapabilities("pm2", caps);
QueryMetadataInterface metadata = RealMetadataFactory.example1();
RealMetadataFactory.setCardinality("pm4.g1", RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000, metadata);
RealMetadataFactory.setCardinality("pm2.g1", RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY - 1, metadata);
// Construct data manager with data
FakeDataManager dataManager = new FakeDataManager();
sampleData2b(dataManager, metadata);
Command command = helpParse(sql);
CommandContext context = createCommandContext();
context.setMetadata(metadata);
ProcessorPlan plan = helpGetPlan(command, metadata, capFinder, context);
// 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);
// Run query
helpProcess(plan, context, dataManager, expected);
}
use of org.teiid.query.processor.relational.RelationalNode in project teiid by teiid.
the class TestProcessor method testComplexJoinExpressionsUsingDependentJoin.
/**
* RLM Case 2077
* @throws Exception
*/
@Test
public void testComplexJoinExpressionsUsingDependentJoin() throws Exception {
// $NON-NLS-1$
String sql = "SELECT a.e1, b.e1, b.e2 FROM pm1.g1 a, pm2.g1 b where rtrim(a.e1)=(b.e1 || b.e1)";
// Create expected results
List[] expected = new List[] { // $NON-NLS-1$ //$NON-NLS-2$
Arrays.asList(new Object[] { "bb ", "b", new Integer(0) }) };
// Plan query
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
BasicSourceCapabilities caps = new BasicSourceCapabilities();
caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
caps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, new Integer(1000));
// $NON-NLS-1$
caps.setFunctionSupport("||", true);
// $NON-NLS-1$
caps.setFunctionSupport("rtrim", true);
// $NON-NLS-1$
capFinder.addCapabilities("pm1", caps);
// $NON-NLS-1$
capFinder.addCapabilities("pm2", caps);
QueryMetadataInterface metadata = RealMetadataFactory.example1();
RealMetadataFactory.setCardinality("pm1.g1", RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000, metadata);
RealMetadataFactory.setCardinality("pm2.g1", RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY - 1, metadata);
// Construct data manager with data
FakeDataManager dataManager = new FakeDataManager();
sampleData2b(dataManager, metadata);
Command command = helpParse(sql);
CommandContext context = createCommandContext();
context.setMetadata(metadata);
ProcessorPlan plan = helpGetPlan(command, metadata, capFinder, context);
// 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);
// Run query
helpProcess(plan, context, dataManager, expected);
}
use of org.teiid.query.processor.relational.RelationalNode in project teiid by teiid.
the class TestDependentJoins method helpTestDepAccessCausingSortNodeInsert.
public void helpTestDepAccessCausingSortNodeInsert(boolean accessNodeHandlesAliases) {
// $NON-NLS-1$
String sql = "SELECT a.e1, b.e1, b.e2 FROM pm4.g1 a INNER JOIN pm1.g1 b ON a.e2=b.e2 AND a.e1 = b.e1 OPTION MAKEDEP a";
// Create expected results
List[] expected = new List[] { // $NON-NLS-1$ //$NON-NLS-2$
Arrays.asList(new Object[] { "aa ", "aa ", 0 }), // $NON-NLS-1$ //$NON-NLS-2$
Arrays.asList(new Object[] { "bb ", "bb ", 1 }), // $NON-NLS-1$ //$NON-NLS-2$
Arrays.asList(new Object[] { "cc ", "cc ", 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);
if (accessNodeHandlesAliases) {
depcaps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, 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);
// 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();
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.processor.relational.RelationalNode in project teiid by teiid.
the class TestEnginePerformance method helpTestLargeSort.
private void helpTestLargeSort(int iterations, int threads, final int rows) throws InterruptedException, Exception {
final List<ElementSymbol> elems = new ArrayList<ElementSymbol>();
final int cols = 50;
for (int i = 0; i < cols; i++) {
ElementSymbol elem1 = new ElementSymbol("e" + i);
elem1.setType(DataTypeManager.DefaultDataClasses.STRING);
elems.add(elem1);
}
final List<ElementSymbol> sortElements = Arrays.asList(elems.get(0));
final Task task = new Task() {
@Override
public Void call() throws Exception {
// $NON-NLS-1$ //$NON-NLS-2$
CommandContext context = new CommandContext("pid", "test", null, null, 1);
SortNode sortNode = new SortNode(1);
sortNode.setSortElements(new OrderBy(sortElements).getOrderByItems());
sortNode.setMode(Mode.SORT);
sortNode.setElements(elems);
RelationalNode rn = new RelationalNode(2) {
int blockingPeriod = 3;
int count = 0;
int batches = 0;
@Override
protected TupleBatch nextBatchDirect() throws BlockedException, TeiidComponentException, TeiidProcessingException {
if (count++ % blockingPeriod == 0) {
throw BlockedException.INSTANCE;
}
int batchSize = this.getBatchSize();
int batchRows = batchSize;
boolean done = false;
int start = batches++ * batchSize;
if (start + batchSize >= rows) {
done = true;
batchRows = rows - start;
}
ArrayList<List<?>> batch = new ArrayList<List<?>>(batchRows);
for (int i = 0; i < batchRows; i++) {
ArrayList<Object> row = new ArrayList<Object>();
for (int j = 0; j < cols; j++) {
if (j == 0) {
row.add(String.valueOf((i * 279470273) % 4294967291l));
} else {
row.add(i + "abcdefghijklmnop" + j);
}
}
batch.add(row);
}
TupleBatch result = new TupleBatch(start + 1, batch);
if (done) {
result.setTerminationFlag(true);
}
return result;
}
@Override
public Object clone() {
return null;
}
};
rn.setElements(elems);
sortNode.addChild(rn);
sortNode.initialize(context, bm, null);
rn.initialize(context, bm, null);
process(sortNode, rows);
return null;
}
};
runTask(iterations, threads, task);
}
Aggregations