use of org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder in project teiid by teiid.
the class TestProcessor method testUpdateCompensation.
@Test
public void testUpdateCompensation() {
// $NON-NLS-1$
String sql = "update pm1.g1 set e4 = null where e1 = 'a' and exists (select 1 from pm1.g2 where e2 = pm1.g1.e2)";
List[] expected = new List[] { Arrays.asList(3) };
FakeDataManager dataManager = new FakeDataManager();
sampleData1(dataManager);
BasicSourceCapabilities caps = getTypicalCapabilities();
caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, false);
ProcessorPlan plan = helpGetPlan(sql, RealMetadataFactory.example4(), new DefaultCapabilitiesFinder(caps));
helpProcess(plan, dataManager, expected);
}
use of org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder 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.optimizer.capabilities.DefaultCapabilitiesFinder in project teiid by teiid.
the class TestProcessor method testUpdateNonDeterministic.
@Test
public void testUpdateNonDeterministic() {
String sql = "update pm1.g2 set e1 = (with u (id) as (select uuid()) select id from u) where e1 = 'xxxx'";
FakeDataManager dataManager = new FakeDataManager();
sampleData1(dataManager);
BasicSourceCapabilities caps = getTypicalCapabilities();
ProcessorPlan plan = helpGetPlan(sql, RealMetadataFactory.example1Cached(), new DefaultCapabilitiesFinder(caps));
helpProcess(plan, dataManager, new List[] { Arrays.asList(0) });
// same as above
sql = "update pm1.g2 set e1 = (select uuid()) where e1 = 'xxxx'";
plan = helpGetPlan(sql, RealMetadataFactory.example1Cached(), new DefaultCapabilitiesFinder(caps));
helpProcess(plan, dataManager, new List[] { Arrays.asList(0) });
sql = "update pm1.g2 set e1 = uuid() where e1 = 'xxxx'";
try {
helpGetPlan(helpParse(sql), RealMetadataFactory.example1Cached(), new DefaultCapabilitiesFinder(caps), createCommandContext());
fail();
} catch (TeiidException e) {
// no primary key
}
}
use of org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder in project teiid by teiid.
the class TestProcessor method testCase6193_2.
/**
* Here a merge join will be used since there is at least one equi join predicate.
*/
@Test
public void testCase6193_2() throws Exception {
// Create query
// $NON-NLS-1$
String sql = "select a.e2, b.e2 from pm1.g1 a LEFT OUTER JOIN pm1.g2 b on a.e4=b.e4 and (a.e2+b.e2)=4 order by a.e2";
// Create expected results
List[] expected = new List[] { Arrays.asList(new Object[] { new Integer(0), null }), Arrays.asList(new Object[] { new Integer(0), null }), Arrays.asList(new Object[] { new Integer(1), null }), Arrays.asList(new Object[] { new Integer(1), null }), Arrays.asList(new Object[] { new Integer(2), new Integer(2) }), Arrays.asList(new Object[] { new Integer(3), null }) };
// Construct data manager with data
FakeDataManager dataManager = new FakeDataManager();
sampleData1(dataManager);
// Plan query
ProcessorPlan plan = TestOptimizer.helpPlan(sql, RealMetadataFactory.example1Cached(), new String[] { "SELECT a.e4, a.e2 FROM pm1.g1 AS a", "SELECT b.e4, b.e2 FROM pm1.g2 AS b" }, new DefaultCapabilitiesFinder(), // $NON-NLS-1$ //$NON-NLS-2$
ComparisonMode.CORRECTED_COMMAND_STRING);
TestOptimizer.checkNodeTypes(plan, new int[] { // Access
2, // DependentAccess
0, // DependentSelect
0, // DependentProject
0, // DupRemove
0, // Grouping
0, // NestedLoopJoinStrategy
0, // MergeJoinStrategy
1, // Null
0, // PlanExecution
0, // Project
1, // Select
0, // Sort
1, // UnionAll
0 });
// Run query
helpProcess(plan, dataManager, expected);
}
use of org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder in project teiid by teiid.
the class TestProcessor method testMixedAnsiLateralJoinsWithConstantProjection.
@Test
public void testMixedAnsiLateralJoinsWithConstantProjection() throws Exception {
TransformationMetadata metadata = RealMetadataFactory.fromDDL("CREATE VIRTUAL PROCEDURE pr0(arg1 string) returns (res1 string) AS\n" + " BEGIN\n" + " SELECT '2017-01-01';\n" + " END;" + "create foreign table test_t1(col_t1 varchar) options (cardinality 1)", "x", "y");
String sql = "SELECT d.*,x.*,xxx.*,dl.*\n" + " FROM (SELECT 'League' AS type, 1 AS arg0) xxx, test_t1 dl, table(CALL pr0(arg0)) x\n" + " JOIN test_t1 d ON d.col_t1 = 'str_val'";
BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_LATERAL, true);
ProcessorPlan plan = TestProcessor.helpGetPlan(sql, metadata, new DefaultCapabilitiesFinder(caps));
HardcodedDataManager dataManager = new HardcodedDataManager();
dataManager.addData("SELECT g_0.col_t1 FROM y.test_t1 AS g_0 WHERE g_0.col_t1 = 'str_val'", Arrays.asList("str_val"));
dataManager.addData("SELECT g_0.col_t1 FROM y.test_t1 AS g_0", Arrays.asList("str_val"));
TestProcessor.helpProcess(plan, dataManager, new List<?>[] { Arrays.asList("str_val", "2017-01-01", "League", 1, "str_val") });
}
Aggregations