Search in sources :

Example 16 with MetadataStore

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

the class TestProcessor method createProjectErrorMetadata.

private TransformationMetadata createProjectErrorMetadata() {
    MetadataStore metadataStore = new MetadataStore();
    // $NON-NLS-1$
    Schema p1 = RealMetadataFactory.createPhysicalModel("p1", metadataStore);
    // $NON-NLS-1$
    Table t1 = RealMetadataFactory.createPhysicalGroup("t", p1);
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    RealMetadataFactory.createElements(t1, new String[] { "a", "b" }, new String[] { "string", "string" });
    // $NON-NLS-1$
    Schema v1 = RealMetadataFactory.createVirtualModel("v1", metadataStore);
    // $NON-NLS-1$ //$NON-NLS-2$
    QueryNode n1 = new QueryNode("SELECT convert(a, integer) as c, b FROM p1.t");
    // $NON-NLS-1$
    Table vt1 = RealMetadataFactory.createVirtualGroup("t1", v1, n1);
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    RealMetadataFactory.createElements(vt1, new String[] { "c", "b" }, new String[] { "integer", "string" });
    // $NON-NLS-1$ //$NON-NLS-2$
    QueryNode n3 = new QueryNode("SELECT c, b FROM v1.t1 UNION ALL SELECT c, b FROM v1.t1");
    // $NON-NLS-1$
    Table vu1 = RealMetadataFactory.createVirtualGroup("u1", v1, n3);
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    RealMetadataFactory.createElements(vu1, new String[] { "c", "b" }, new String[] { "integer", "string" });
    return RealMetadataFactory.createTransformationMetadata(metadataStore, "projectError");
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) TempMetadataStore(org.teiid.query.metadata.TempMetadataStore) Table(org.teiid.metadata.Table) QueryNode(org.teiid.query.mapping.relational.QueryNode) Schema(org.teiid.metadata.Schema)

Example 17 with MetadataStore

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

the class TestProcessor method testInsertTempTableCreation.

/*
     *  Prior to case 3994 testInsertTempTableCreation1 worked, but testInsertTempTableCreation did not.
     *  Now they should both pass
     * 
     */
@Test
public void testInsertTempTableCreation() {
    MetadataStore metadataStore = new MetadataStore();
    // $NON-NLS-1$
    Schema v1 = RealMetadataFactory.createVirtualModel("v1", metadataStore);
    // $NON-NLS-1$ //$NON-NLS-2$
    QueryNode n1 = new QueryNode("CREATE VIRTUAL PROCEDURE BEGIN insert into #temp (var1) values (1); select #temp.var1 from #temp; END");
    // $NON-NLS-1$ //$NON-NLS-2$
    ColumnSet<Procedure> rs = RealMetadataFactory.createResultSet("rs", new String[] { "var1" }, new String[] { DataTypeManager.DefaultDataTypes.INTEGER });
    // $NON-NLS-1$
    Procedure vp = RealMetadataFactory.createVirtualProcedure("vp", v1, null, n1);
    vp.setResultSet(rs);
    QueryMetadataInterface metadata = RealMetadataFactory.createTransformationMetadata(metadataStore, "foo");
    // $NON-NLS-1$
    ProcessorPlan plan = helpGetPlan("exec v1.vp()", metadata);
    List[] expected = new List[] { Arrays.asList(new Object[] { new Integer(1) }) };
    helpProcess(plan, new FakeDataManager(), expected);
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) TempMetadataStore(org.teiid.query.metadata.TempMetadataStore) BigInteger(java.math.BigInteger) QueryNode(org.teiid.query.mapping.relational.QueryNode) Schema(org.teiid.metadata.Schema) Procedure(org.teiid.metadata.Procedure) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Test(org.junit.Test)

Example 18 with MetadataStore

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

the class TestProcedureRelational method testIssue119.

/*
     * The following are tests that were removed from the validator.  We are no longer trying to validate a priori whether 
     * procedure input criteria is valid.  This can be addressed later more generally when we do up front validation of
     * access patterns and access patterns have a wider range of semantics.
     * 
    @Test public void testProcInVirtualGroupDefect14609_1() throws Exception{
        helpValidate("select ve3 from vm1.vgvp1 where ve1=1.1 and ve2='a'", new String[] {"ve1 = 1.1"}, RealMetadataFactory.example1Cached()); //$NON-NLS-1$ //$NON-NLS-2$
    }
   
    @Test public void testProcInVirtualGroupDefect14609_2() throws Exception{
        helpValidate("select ve3 from vm1.vgvp1 where convert(ve1, integer)=1 and ve2='a'", new String[] {"convert(ve1, integer) = 1" }, RealMetadataFactory.example1Cached()); //$NON-NLS-1$ //$NON-NLS-2$
    }
    
    @Test public void testProcInVirtualGroupDefect14609_3() throws Exception{
        helpValidate("select ve3 from vm1.vgvp1 where 1.1=ve1 and ve2='a'", new String[] {"1.1 = ve1" }, RealMetadataFactory.example1Cached()); //$NON-NLS-1$ //$NON-NLS-2$
    }
    
    @Test public void testProcInVirtualGroupDefect14609_4() throws Exception{
        helpValidate("select ve3 from vm1.vgvp1 where 1=convert(ve1, integer) and ve2='a'", new String[] {"1 = convert(ve1, integer)" }, RealMetadataFactory.example1Cached()); //$NON-NLS-1$ //$NON-NLS-2$
    }    

    @Test public void testDefect15861() throws Exception{
        helpValidate("select ve3 from vm1.vgvp1 where (ve1=1 or ve1=2) and ve2='a'", new String[] {"(ve1 = 1) OR (ve1 = 2)", "ve1 = 2"}, RealMetadataFactory.example1Cached()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    }

    @Test public void testProcInVirtualGroup1_Defect20164() {
        helpFailProcedure("select ve3 from vm1.vgvp2 where (ve1=1 and ve2='a') or ve3='c'", RealMetadataFactory.example1Cached()); //$NON-NLS-1$
    }

    @Test public void testProcInVirtualGroup2_Defect20164() {
        helpFailProcedure("select ve3 from vm1.vgvp2 where ve1=1 or ve2='a'", RealMetadataFactory.example1Cached()); //$NON-NLS-1$
    }

    @Test public void testProcInVirtualGroup3_Defect20164() {
        helpFailProcedure("select ve3 from vm1.vgvp2, pm1.g1 where ve1=pm1.g1.e2 and ve2='a'", RealMetadataFactory.example1Cached()); //$NON-NLS-1$
    }

    @Test public void testProcInVirtualGroup4_Defect20164() {
        helpValidate("select ve3 from vm1.vgvp2 where (ve1=1 and ve2='a') and (ve3='a' OR ve3='c')", new String[0], RealMetadataFactory.example1Cached()); //$NON-NLS-1$
    }

    @Test public void testProcInVirtualGroup5_Defect20164() {
        helpFailProcedure("select ve3 from vm1.vgvp2 where ve1=1 and NOT(ve2='a')", RealMetadataFactory.example1Cached()); //$NON-NLS-1$
    }

    @Test public void testProcInVirtualGroup6_Defect20164() {
        helpValidate("select ve3 from vm1.vgvp2 where ve1=1 and ve2 is null", new String[0], RealMetadataFactory.example1Cached()); //$NON-NLS-1$
    }

    @Test public void testProcInVirtualGroup7_Defect20164() {
        helpFailProcedure("select ve3 from vm1.vgvp2 where ve1=1 and ve2 is not null", RealMetadataFactory.example1Cached()); //$NON-NLS-1$
    }*/
/**
 * Ensures that dependent procedures are processed 1 at a time so that projected input values
 * are set correctly.
 */
@Test
public void testIssue119() throws Exception {
    MetadataStore metadataStore = new MetadataStore();
    // $NON-NLS-1$
    Schema v1 = RealMetadataFactory.createVirtualModel("v1", metadataStore);
    // $NON-NLS-1$
    Schema pm1 = RealMetadataFactory.createPhysicalModel("pm1", metadataStore);
    // $NON-NLS-1$
    ProcedureParameter in = RealMetadataFactory.createParameter("in1", SPParameter.IN, DataTypeManager.DefaultDataTypes.INTEGER);
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
    ColumnSet<Procedure> rs1 = RealMetadataFactory.createResultSet("v1.vp1.rs1", new String[] { "e1", "e2", "e3", "e4", "e5" }, new String[] { DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.INTEGER });
    // $NON-NLS-1$
    QueryNode n1 = new QueryNode("CREATE VIRTUAL PROCEDURE BEGIN SELECT vp1.in1 e1, x.in1 e2, x.e1 e3, y.in1 e4, y.e1 e5 FROM pm1.sp119 x, pm1.sp119 y where x.in1 = vp1.in1 and y.in1 = x.e1; END");
    // $NON-NLS-1$
    Procedure vt1 = RealMetadataFactory.createVirtualProcedure("vp1", v1, Arrays.asList(in), n1);
    vt1.setResultSet(rs1);
    // $NON-NLS-1$
    ProcedureParameter in1 = RealMetadataFactory.createParameter("in1", SPParameter.IN, DataTypeManager.DefaultDataTypes.INTEGER);
    // $NON-NLS-1$ //$NON-NLS-2$
    ColumnSet<Procedure> rs3 = RealMetadataFactory.createResultSet("pm1.sp119.rs1", new String[] { "e1" }, new String[] { DataTypeManager.DefaultDataTypes.INTEGER });
    // $NON-NLS-1$
    Procedure sp1 = RealMetadataFactory.createStoredProcedure("sp119", pm1, Arrays.asList(in1));
    sp1.setResultSet(rs3);
    // $NON-NLS-1$
    String sql = "select * from (exec v1.vp1(1)) foo order by e4, e5";
    List<?>[] expected = new List[] { Arrays.asList(1, 1, 3, 3, 5), Arrays.asList(1, 1, 3, 3, 8), Arrays.asList(1, 1, 6, 6, 8), Arrays.asList(1, 1, 6, 6, 11) };
    QueryMetadataInterface metadata = RealMetadataFactory.createTransformationMetadata(metadataStore, "foo");
    // Construct data manager with data
    // Plan query
    ProcessorPlan plan = TestProcedureProcessor.getProcedurePlan(sql, metadata);
    // Run query
    HardcodedDataManager dataManager = new HardcodedDataManager() {

        @Override
        public TupleSource registerRequest(CommandContext context, Command command, String modelName, RegisterRequestParameter parameterObject) throws TeiidComponentException {
            if (command instanceof StoredProcedure) {
                StoredProcedure proc = (StoredProcedure) command;
                List<SPParameter> params = proc.getInputParameters();
                assertEquals(1, params.size());
                int value = (Integer) ((Constant) params.get(0).getExpression()).getValue();
                return new FakeTupleSource(command.getProjectedSymbols(), new List[] { Arrays.asList(value + 2), Arrays.asList(value + 5) });
            }
            return super.registerRequest(context, command, modelName, parameterObject);
        }
    };
    TestProcedureProcessor.helpTestProcess(plan, expected, dataManager, metadata);
}
Also used : ProcedureParameter(org.teiid.metadata.ProcedureParameter) CommandContext(org.teiid.query.util.CommandContext) SPParameter(org.teiid.query.sql.lang.SPParameter) Schema(org.teiid.metadata.Schema) MetadataStore(org.teiid.metadata.MetadataStore) StoredProcedure(org.teiid.query.sql.lang.StoredProcedure) Command(org.teiid.query.sql.lang.Command) QueryNode(org.teiid.query.mapping.relational.QueryNode) StoredProcedure(org.teiid.query.sql.lang.StoredProcedure) Procedure(org.teiid.metadata.Procedure) List(java.util.List) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Test(org.junit.Test)

Example 19 with MetadataStore

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

the class TestAggregateProcessing method testUserDefined.

@Test
public void testUserDefined() throws Exception {
    MetadataStore ms = RealMetadataFactory.example1Store();
    Schema s = ms.getSchemas().get("PM1");
    AggregateAttributes aa = addAgg(s, "myagg", SumAll.class, DataTypeManager.DefaultDataTypes.INTEGER).getAggregateAttributes();
    addAgg(s, "myagg2", LongSumAll.class, DataTypeManager.DefaultDataTypes.LONG);
    TransformationMetadata metadata = RealMetadataFactory.createTransformationMetadata(ms, "test");
    Command c = TestResolver.helpResolve("select myagg2(distinct e2) from pm1.g1", metadata);
    assertEquals(DataTypeManager.DefaultDataClasses.LONG, c.getProjectedSymbols().get(0).getType());
    // must be in agg form
    TestValidator.helpValidate("SELECT myagg(e2) from pm1.g1", new String[] {}, metadata);
    // run validations over default AggregateAttributes
    TestValidator.helpValidate("SELECT myagg(distinct e2) from pm1.g1", new String[] { "myagg(DISTINCT e2)" }, metadata);
    TestValidator.helpValidate("SELECT myagg(e2 order by e1) from pm1.g1", new String[] { "myagg(ALL e2 ORDER BY e1)" }, metadata);
    TestValidator.helpValidate("SELECT myagg(ALL e2, e2) over () from pm1.g1", new String[] {}, metadata);
    aa.setAllowsDistinct(true);
    aa.setAllowsOrderBy(true);
    TestValidator.helpValidate("SELECT myagg(distinct e2) from pm1.g1", new String[] {}, metadata);
    TestValidator.helpValidate("SELECT myagg(e2 order by e1) from pm1.g1", new String[] {}, metadata);
    aa.setAnalytic(true);
    TestValidator.helpValidate("SELECT myagg(distinct e2) from pm1.g1", new String[] { "myagg(DISTINCT e2)" }, metadata);
    TestValidator.helpValidate("SELECT myagg(e2, e2) over () from pm1.g1", new String[] {}, metadata);
    aa.setAnalytic(false);
    // Create expected results
    List[] expected = new List[] { Arrays.asList(6, 6), Arrays.asList(8, 8) };
    // Construct data manager with data
    FakeDataManager dataManager = new FakeDataManager();
    sampleData1(dataManager);
    ProcessorPlan plan = helpGetPlan("select myagg(all e2, e2 order by e1), myagg(e2, e2) from pm1.g1 group by e3", metadata);
    helpProcess(plan, dataManager, expected);
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) Command(org.teiid.query.sql.lang.Command) Schema(org.teiid.metadata.Schema) ArrayList(java.util.ArrayList) List(java.util.List) AggregateAttributes(org.teiid.metadata.AggregateAttributes) Test(org.junit.Test)

Example 20 with MetadataStore

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

the class TestValidator method exampleMetadata4.

public static TransformationMetadata exampleMetadata4() {
    MetadataStore metadataStore = new MetadataStore();
    // Create metadata objects
    // $NON-NLS-1$
    Schema modelObj = RealMetadataFactory.createPhysicalModel("test", metadataStore);
    // $NON-NLS-1$
    Table groupObj = RealMetadataFactory.createPhysicalGroup("group", modelObj);
    // $NON-NLS-1$
    RealMetadataFactory.createElement("e0", groupObj, DataTypeManager.DefaultDataTypes.INTEGER);
    // $NON-NLS-1$
    RealMetadataFactory.createElement("e1", groupObj, DataTypeManager.DefaultDataTypes.STRING);
    // $NON-NLS-1$
    RealMetadataFactory.createElement("e2", groupObj, DataTypeManager.DefaultDataTypes.STRING);
    // $NON-NLS-1$
    Schema vModelObj = RealMetadataFactory.createVirtualModel("vTest", metadataStore);
    // $NON-NLS-1$ //$NON-NLS-2$
    QueryNode vNode = new QueryNode("SELECT * FROM test.group");
    // $NON-NLS-1$
    Table vGroupObj = RealMetadataFactory.createVirtualGroup("vGroup", vModelObj, vNode);
    // $NON-NLS-1$
    Column vElemObj0 = RealMetadataFactory.createElement("e0", vGroupObj, DataTypeManager.DefaultDataTypes.INTEGER);
    // $NON-NLS-1$
    Column vElemObj1 = RealMetadataFactory.createElement("e1", vGroupObj, DataTypeManager.DefaultDataTypes.STRING);
    // $NON-NLS-1$
    RealMetadataFactory.createElement("e2", vGroupObj, DataTypeManager.DefaultDataTypes.STRING);
    List<Column> elements = new ArrayList<Column>(2);
    elements.add(vElemObj0);
    elements.add(vElemObj1);
    // e1 //$NON-NLS-1$
    RealMetadataFactory.createAccessPattern("ap1", vGroupObj, elements);
    // $NON-NLS-1$ //$NON-NLS-2$
    QueryNode vNode2 = new QueryNode("SELECT * FROM vTest.vGroup");
    // $NON-NLS-1$
    Table vGroupObj2 = RealMetadataFactory.createVirtualGroup("vGroup2", vModelObj, vNode2);
    // $NON-NLS-1$
    Column vElemObj20 = RealMetadataFactory.createElement("e0", vGroupObj2, DataTypeManager.DefaultDataTypes.INTEGER);
    // $NON-NLS-1$
    Column vElemObj21 = RealMetadataFactory.createElement("e1", vGroupObj2, DataTypeManager.DefaultDataTypes.STRING);
    // $NON-NLS-1$
    RealMetadataFactory.createElement("e2", vGroupObj2, DataTypeManager.DefaultDataTypes.STRING);
    elements = new ArrayList<Column>(2);
    elements.add(vElemObj20);
    elements.add(vElemObj21);
    // e1 //$NON-NLS-1$
    RealMetadataFactory.createAccessPattern("vTest.vGroup2.ap1", vGroupObj2, elements);
    return RealMetadataFactory.createTransformationMetadata(metadataStore, "example4");
}
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) ArrayList(java.util.ArrayList)

Aggregations

MetadataStore (org.teiid.metadata.MetadataStore)73 Schema (org.teiid.metadata.Schema)47 Test (org.junit.Test)38 Table (org.teiid.metadata.Table)37 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)22 QueryNode (org.teiid.query.mapping.relational.QueryNode)19 Column (org.teiid.metadata.Column)17 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)15 Properties (java.util.Properties)12 MetadataFactory (org.teiid.metadata.MetadataFactory)12 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)12 Procedure (org.teiid.metadata.Procedure)11 List (java.util.List)9 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)9 Connection (java.sql.Connection)8 ConnectorManagerRepository (org.teiid.dqp.internal.datamgr.ConnectorManagerRepository)8 ArrayList (java.util.ArrayList)7 ProcedureParameter (org.teiid.metadata.ProcedureParameter)7 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)7 TempMetadataStore (org.teiid.query.metadata.TempMetadataStore)6