Search in sources :

Example 71 with Schema

use of org.teiid.metadata.Schema 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 });
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) Schema(org.teiid.metadata.Schema) FunctionMethod(org.teiid.metadata.FunctionMethod) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Example 72 with Schema

use of org.teiid.metadata.Schema 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) });
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) Schema(org.teiid.metadata.Schema) FunctionMethod(org.teiid.metadata.FunctionMethod) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Example 73 with Schema

use of org.teiid.metadata.Schema 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);
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) TempMetadataStore(org.teiid.query.metadata.TempMetadataStore) ProcedureParameter(org.teiid.metadata.ProcedureParameter) FakeDataManager(org.teiid.query.processor.FakeDataManager) QueryNode(org.teiid.query.mapping.relational.QueryNode) Schema(org.teiid.metadata.Schema) Procedure(org.teiid.metadata.Procedure) List(java.util.List) ArrayList(java.util.ArrayList) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) Test(org.junit.Test)

Example 74 with Schema

use of org.teiid.metadata.Schema in project teiid by teiid.

the class TestVirtualDepJoin method exampleVirtualDepJoin.

public static TransformationMetadata exampleVirtualDepJoin() {
    MetadataStore metadataStore = new MetadataStore();
    // $NON-NLS-1$
    Schema us = RealMetadataFactory.createPhysicalModel("US", metadataStore);
    // $NON-NLS-1$
    Table usAccts = RealMetadataFactory.createPhysicalGroup("Accounts", us);
    usAccts.setCardinality(1000000);
    List<Column> usAcctsElem = RealMetadataFactory.createElements(usAccts, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
    new String[] { "customer", "account", "txn", "txnid", "pennies" }, new String[] { DataTypeManager.DefaultDataTypes.LONG, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.INTEGER });
    setStats(usAcctsElem, // NDV per column
    new int[] { 1000, 1250, 4, 1000000, 800000 }, // NNV per column
    new int[] { 0, 0, 0, 0, 0 }, // min per column - use defaults //$NON-NLS-1$ //$NON-NLS-2$
    new String[] { "0", null, null, null, "-10" }, // max per column - use defaults //$NON-NLS-1$ //$NON-NLS-2$
    new String[] { "1000", null, null, null, "-5" });
    // $NON-NLS-1$
    Schema europe = RealMetadataFactory.createPhysicalModel("Europe", metadataStore);
    // $NON-NLS-1$
    Table euAccts = RealMetadataFactory.createPhysicalGroup("CustAccts", europe);
    euAccts.setCardinality(1000000);
    List<Column> euAcctsElem = RealMetadataFactory.createElements(euAccts, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    new String[] { "id", "accid", "type", "amount" }, new String[] { DataTypeManager.DefaultDataTypes.LONG, DataTypeManager.DefaultDataTypes.LONG, DataTypeManager.DefaultDataTypes.SHORT, DataTypeManager.DefaultDataTypes.BIG_DECIMAL });
    setStats(euAcctsElem, // NDV per column
    new int[] { 10000, 1000000, 4, 1000000, 750000 }, // NNV per column
    new int[] { 0, 0, 0, 0, 0 }, // min per column - use defaults
    null, // max per column - use defaults
    null);
    // $NON-NLS-1$
    Schema cust = RealMetadataFactory.createPhysicalModel("CustomerMaster", metadataStore);
    // $NON-NLS-1$
    Table customers = RealMetadataFactory.createPhysicalGroup("Customers", cust);
    customers.setCardinality(1000);
    List<Column> customersElem = RealMetadataFactory.createElements(customers, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    new String[] { "id", "first", "last", "birthday" }, new String[] { DataTypeManager.DefaultDataTypes.LONG, DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.DATE });
    setStats(customersElem, // NDV per column
    new int[] { 1000, 800, 800, 365 }, // NNV per column
    new int[] { 0, 0, 0, 0 }, // min per column - use defaults
    null, // max per column - use defaults
    null);
    // $NON-NLS-1$
    Table locations = RealMetadataFactory.createPhysicalGroup("Locations", cust);
    locations.setCardinality(1200);
    List<Column> locationsElem = RealMetadataFactory.createElements(locations, // $NON-NLS-1$ //$NON-NLS-2$
    new String[] { "id", "location" }, new String[] { DataTypeManager.DefaultDataTypes.LONG, DataTypeManager.DefaultDataTypes.STRING });
    setStats(locationsElem, // NDV per column
    new int[] { 1000, 2 }, // NNV per column
    new int[] { 0, 0, 0, 0 }, // min per column - use defaults
    null, // max per column - use defaults
    null);
    // $NON-NLS-1$
    Schema vAccts = RealMetadataFactory.createVirtualModel("Accounts", metadataStore);
    QueryNode accountsPlan = new QueryNode(// $NON-NLS-1$
    "SELECT customer as customer_id, convert(account, long) as account_id, convert(txnid, long) as transaction_id, case txn when 'DEP' then 1 when 'TFR' then 2 when 'WD' then 3 else -1 end as txn_type, (pennies + convert('0.00', bigdecimal)) / 100 as amount, 'US' as source FROM US.Accounts where txn != 'X'" + // $NON-NLS-1$
    "UNION ALL " + // $NON-NLS-1$
    "SELECT id, convert(accid / 10000, long), mod(accid, 10000), convert(\"type\", integer), amount, 'EU' from Europe.CustAccts");
    // $NON-NLS-1$
    Table accounts = RealMetadataFactory.createVirtualGroup("Accounts", vAccts, accountsPlan);
    RealMetadataFactory.createElements(accounts, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
    new String[] { "customer_id", "account_id", "transaction_id", "txn_type", "amount", "source" }, new String[] { DataTypeManager.DefaultDataTypes.LONG, DataTypeManager.DefaultDataTypes.LONG, DataTypeManager.DefaultDataTypes.LONG, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BIG_DECIMAL, DataTypeManager.DefaultDataTypes.STRING });
    // $NON-NLS-1$
    Schema master = RealMetadataFactory.createVirtualModel("Master", metadataStore);
    // $NON-NLS-1$
    QueryNode masterPlan = new QueryNode("select id as CustomerID, First, Last, a.account_id as AccountID, transaction_id as TransactionID, txn_type AS TxnCode, Amount from CustomerMaster.Customers c, Accounts.Accounts a where c.id=a.customer_id");
    // $NON-NLS-1$
    Table transactions = RealMetadataFactory.createVirtualGroup("Transactions", master, masterPlan);
    RealMetadataFactory.createElements(transactions, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
    new String[] { "CustomerID", "First", "Last", "AccountID", "TransactionID", "TxnCode", "Amount" }, new String[] { DataTypeManager.DefaultDataTypes.LONG, DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.LONG, DataTypeManager.DefaultDataTypes.LONG, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BIG_DECIMAL });
    return RealMetadataFactory.createTransformationMetadata(metadataStore, "virtualDepJoin");
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) Table(org.teiid.metadata.Table) Column(org.teiid.metadata.Column) QueryNode(org.teiid.query.mapping.relational.QueryNode) Schema(org.teiid.metadata.Schema)

Example 75 with Schema

use of org.teiid.metadata.Schema in project teiid by teiid.

the class TestSQLXMLProcessing method testXmlTableInView.

@Test
public void testXmlTableInView() throws Exception {
    // $NON-NLS-1$
    String sql = "select * from g1";
    List<?>[] expected = new List<?>[] { Arrays.asList(null, "first"), Arrays.asList("attr", "second") };
    MetadataStore metadataStore = new MetadataStore();
    // Create models
    // $NON-NLS-1$
    Schema vm1 = RealMetadataFactory.createVirtualModel("vm1", metadataStore);
    // $NON-NLS-1$ //$NON-NLS-2$
    QueryNode vm1g1n1 = new QueryNode("select * from xmltable('/a/b' passing convert('<a><b>first</b><b x=\"attr\">second</b></a>', xml) columns x string path '@x', val string path '/.') as x");
    // $NON-NLS-1$
    Table vm1g1 = RealMetadataFactory.createVirtualGroup("g1", vm1, vm1g1n1);
    RealMetadataFactory.createElements(vm1g1, // $NON-NLS-1$
    new String[] { "x", "val" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.STRING });
    // Create the facade from the store
    TransformationMetadata metadata = RealMetadataFactory.createTransformationMetadata(metadataStore, "example");
    ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata, new DefaultCapabilitiesFinder(), createCommandContext());
    helpProcess(plan, createCommandContext(), dataManager, expected);
    plan = helpGetPlan(helpParse(sql), metadata, new DefaultCapabilitiesFinder(), createCommandContext());
    doProcess(plan, dataManager, expected, createCommandContext());
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) Table(org.teiid.metadata.Table) QueryNode(org.teiid.query.mapping.relational.QueryNode) Schema(org.teiid.metadata.Schema) List(java.util.List) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Aggregations

Schema (org.teiid.metadata.Schema)92 MetadataStore (org.teiid.metadata.MetadataStore)47 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)37 Table (org.teiid.metadata.Table)35 Test (org.junit.Test)34 QueryNode (org.teiid.query.mapping.relational.QueryNode)20 FakeCapabilitiesFinder (org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder)19 Column (org.teiid.metadata.Column)18 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)18 Procedure (org.teiid.metadata.Procedure)16 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)11 List (java.util.List)10 ArrayList (java.util.ArrayList)9 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)8 ProcedureParameter (org.teiid.metadata.ProcedureParameter)8 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)7 FunctionMethod (org.teiid.metadata.FunctionMethod)6 TempMetadataStore (org.teiid.query.metadata.TempMetadataStore)6 CompositeMetadataStore (org.teiid.query.metadata.CompositeMetadataStore)5 DefaultCapabilitiesFinder (org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder)5