use of org.teiid.metadata.MetadataStore in project teiid by teiid.
the class TestProcedureRelational method testParameterPassing.
/**
* test for defect 22376
*/
@Test
public void testParameterPassing() throws Exception {
MetadataStore metadataStore = new MetadataStore();
// $NON-NLS-1$
Schema v1 = RealMetadataFactory.createVirtualModel("v1", metadataStore);
// $NON-NLS-1$ //$NON-NLS-2$
ColumnSet<Procedure> rs1 = RealMetadataFactory.createResultSet("v1.rs1", new String[] { "e1" }, new String[] { DataTypeManager.DefaultDataTypes.STRING });
// $NON-NLS-1$
QueryNode n1 = new QueryNode("CREATE VIRTUAL PROCEDURE BEGIN declare string VARIABLES.x = '1'; SELECT e1 FROM v1.vp2 where v1.vp2.in = VARIABLES.x; END");
// $NON-NLS-1$
Procedure vt1 = RealMetadataFactory.createVirtualProcedure("vp1", v1, null, n1);
vt1.setResultSet(rs1);
// $NON-NLS-1$
ProcedureParameter p1 = RealMetadataFactory.createParameter("in", ParameterInfo.IN, DataTypeManager.DefaultDataTypes.STRING);
// $NON-NLS-1$
QueryNode n2 = new QueryNode("CREATE VIRTUAL PROCEDURE BEGIN declare string VARIABLES.x; declare string VARIABLES.y; VARIABLES.x = '2'; VARIABLES.y = v1.vp2.in; select VARIABLES.y; end");
// $NON-NLS-1$
Procedure vt2 = RealMetadataFactory.createVirtualProcedure("vp2", v1, Arrays.asList(p1), n2);
vt2.setResultSet(RealMetadataFactory.createResultSet("v1.rs1", new String[] { "e1" }, new String[] { DataTypeManager.DefaultDataTypes.STRING }));
// $NON-NLS-1$
String sql = "select * from (exec v1.vp1()) foo";
List<?>[] expected = new List[] { // $NON-NLS-1$
Arrays.asList(new Object[] { "1" }) };
QueryMetadataInterface metadata = RealMetadataFactory.createTransformationMetadata(metadataStore, "foo");
// Construct data manager with data
// Plan query
ProcessorPlan plan = TestProcedureProcessor.getProcedurePlan(sql, metadata);
// Run query
TestProcedureProcessor.helpTestProcess(plan, expected, new FakeDataManager(), metadata);
}
use of org.teiid.metadata.MetadataStore in project teiid by teiid.
the class TestAggregateProcessing method testNullDependentAggParitioned.
@Test
public void testNullDependentAggParitioned() throws Exception {
MetadataStore ms = RealMetadataFactory.example1Store();
Schema s = ms.getSchemas().get("PM1");
FunctionMethod fm = addAgg(s, "myagg", SumAll.class, DataTypeManager.DefaultDataTypes.INTEGER);
fm.setNullOnNull(false);
fm.getAggregateAttributes().setDecomposable(true);
TransformationMetadata metadata = RealMetadataFactory.createTransformationMetadata(ms, "test");
// $NON-NLS-1$
final String userSql = "SELECT myagg(e2), source_name FROM (select e2, 'a' as source_name from pm1.g1 union all select e2, 'b' from pm2.g1) x group by source_name";
BasicSourceCapabilities caps = TestAggregatePushdown.getAggregateCapabilities();
caps.setFunctionSupport("myagg", true);
ProcessorPlan plan = TestOptimizer.helpPlan(userSql, metadata, new String[] { "SELECT myagg(ALL v_0.c_1), v_0.c_0 FROM (SELECT 'a' AS c_0, g_0.e2 AS c_1 FROM pm1.g1 AS g_0) AS v_0 GROUP BY v_0.c_0", "SELECT myagg(ALL v_0.c_1), v_0.c_0 FROM (SELECT 'b' AS c_0, g_0.e2 AS c_1 FROM pm2.g1 AS g_0) AS v_0 GROUP BY v_0.c_0" }, new DefaultCapabilitiesFinder(caps), ComparisonMode.EXACT_COMMAND_STRING);
TestOptimizer.checkNodeTypes(plan, new int[] { // Access
2, // DependentAccess
0, // DependentSelect
0, // DependentProject
0, // DupRemove
0, // Grouping
0, // NestedLoopJoinStrategy
0, // MergeJoinStrategy
0, // Null
0, // PlanExecution
0, // Project
1, // Select
0, // Sort
0, // UnionAll
1 });
}
use of org.teiid.metadata.MetadataStore in project teiid by teiid.
the class TestAggregateProcessing method testNullDependentAgg.
@Test
public void testNullDependentAgg() throws Exception {
MetadataStore ms = RealMetadataFactory.example1Store();
Schema s = ms.getSchemas().get("PM1");
FunctionMethod fm = addAgg(s, "myagg", SumAll.class, DataTypeManager.DefaultDataTypes.INTEGER);
fm.setNullOnNull(false);
fm.getAggregateAttributes().setDecomposable(true);
TransformationMetadata metadata = RealMetadataFactory.createTransformationMetadata(ms, "test");
// $NON-NLS-1$
final String userSql = "SELECT myagg(e2) FROM (select e2, e1 as source_name from pm1.g1 union all select e2, e1 from pm2.g1) x";
BasicSourceCapabilities caps = TestAggregatePushdown.getAggregateCapabilities();
caps.setFunctionSupport("myagg", true);
ProcessorPlan plan = TestOptimizer.helpPlan(userSql, metadata, new String[] { "SELECT myagg(ALL g_0.e2) FROM pm1.g1 AS g_0 HAVING COUNT(*) > 0", "SELECT myagg(ALL g_0.e2) FROM pm2.g1 AS g_0 HAVING COUNT(*) > 0" }, new DefaultCapabilitiesFinder(caps), ComparisonMode.EXACT_COMMAND_STRING);
TestOptimizer.checkNodeTypes(plan, new int[] { // Access
2, // DependentAccess
0, // DependentSelect
0, // DependentProject
0, // DupRemove
0, // Grouping
1, // NestedLoopJoinStrategy
0, // MergeJoinStrategy
0, // Null
0, // PlanExecution
0, // Project
1, // Select
0, // Sort
0, // UnionAll
1 });
}
use of org.teiid.metadata.MetadataStore in project teiid by teiid.
the class TestAggregateProcessing method testNullDependentAgg1.
@Test
public void testNullDependentAgg1() throws Exception {
MetadataStore ms = RealMetadataFactory.example1Store();
Schema s = ms.getSchemas().get("PM1");
FunctionMethod fm = addAgg(s, "myagg", CustomSum.class, DataTypeManager.DefaultDataTypes.STRING);
fm.setNullOnNull(false);
fm.getAggregateAttributes().setDecomposable(true);
TransformationMetadata metadata = RealMetadataFactory.createTransformationMetadata(ms, "test");
// $NON-NLS-1$
final String userSql = "SELECT myagg(e2) FROM (select e2, e1 as source_name from pm1.g1 union all select e2, e1 from pm2.g1) x";
BasicSourceCapabilities caps = TestAggregatePushdown.getAggregateCapabilities();
caps.setFunctionSupport("myagg", true);
caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_ORDERED, false);
ProcessorPlan plan = TestOptimizer.helpPlan(userSql, metadata, new String[] { "SELECT COUNT(*), myagg(ALL g_0.e2) FROM pm2.g1 AS g_0", "SELECT COUNT(*), myagg(ALL g_0.e2) FROM pm1.g1 AS g_0" }, new DefaultCapabilitiesFinder(caps), ComparisonMode.EXACT_COMMAND_STRING);
TestOptimizer.checkNodeTypes(plan, new int[] { // Access
2, // DependentAccess
0, // DependentSelect
0, // DependentProject
0, // DupRemove
0, // Grouping
1, // NestedLoopJoinStrategy
0, // MergeJoinStrategy
0, // Null
0, // PlanExecution
0, // Project
3, // Select
2, // Sort
0, // UnionAll
1 });
HardcodedDataManager dataManager = new HardcodedDataManager();
dataManager.addData("SELECT COUNT(*), myagg(ALL g_0.e2) FROM pm1.g1 AS g_0", new List<?>[] { Arrays.asList(0, null) });
dataManager.addData("SELECT COUNT(*), myagg(ALL g_0.e2) FROM pm2.g1 AS g_0", new List<?>[] { Arrays.asList(0, null) });
// if we don't filter the nulls, then we'd get 0
helpProcess(plan, dataManager, new List[] { Collections.singletonList(null) });
}
use of org.teiid.metadata.MetadataStore in project teiid by teiid.
the class TestProcedureProcessor method testFunctionInput.
/**
* defect 23975
*/
@Test
public void testFunctionInput() throws Exception {
MetadataStore metadataStore = new MetadataStore();
// $NON-NLS-1$
Schema v1 = RealMetadataFactory.createVirtualModel("v1", metadataStore);
// $NON-NLS-1$
ProcedureParameter p1 = RealMetadataFactory.createParameter("in", ParameterInfo.IN, DataTypeManager.DefaultDataTypes.STRING);
// $NON-NLS-1$ //$NON-NLS-2$
ColumnSet<Procedure> rs1 = RealMetadataFactory.createResultSet("v1.rs1", new String[] { "e1" }, new String[] { DataTypeManager.DefaultDataTypes.STRING });
// $NON-NLS-1$ //$NON-NLS-2$
QueryNode n1 = new QueryNode("CREATE VIRTUAL PROCEDURE BEGIN declare string VARIABLES.x = '1'; exec v1.vp2(concat(x, v1.vp1.in)); END");
// $NON-NLS-1$
Procedure vt1 = RealMetadataFactory.createVirtualProcedure("vp1", v1, Arrays.asList(p1), n1);
vt1.setResultSet(rs1);
// $NON-NLS-1$
ProcedureParameter p2 = RealMetadataFactory.createParameter("in", ParameterInfo.IN, DataTypeManager.DefaultDataTypes.STRING);
// $NON-NLS-1$ //$NON-NLS-2$
QueryNode n2 = new QueryNode("CREATE VIRTUAL PROCEDURE BEGIN select v1.vp2.in; end");
// $NON-NLS-1$
Procedure vt2 = RealMetadataFactory.createVirtualProcedure("vp2", v1, Arrays.asList(p2), n2);
// $NON-NLS-1$ //$NON-NLS-2$
vt2.setResultSet(RealMetadataFactory.createResultSet("v1.rs1", new String[] { "e1" }, new String[] { DataTypeManager.DefaultDataTypes.STRING }));
// $NON-NLS-1$
String sql = "exec v1.vp1('1')";
List[] expected = new List[] { // $NON-NLS-1$
Arrays.asList(new Object[] { "11" }) };
QueryMetadataInterface metadata = RealMetadataFactory.createTransformationMetadata(metadataStore, "foo");
// Construct data manager with data
// Plan query
ProcessorPlan plan = getProcedurePlan(sql, metadata);
// Run query
helpTestProcess(plan, expected, new FakeDataManager(), metadata);
}
Aggregations