Search in sources :

Example 66 with Schema

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

the class TestInsertProcessing method testSelectInto_Case5412b.

@Test
public void testSelectInto_Case5412b() {
    MetadataStore metadataStore = new MetadataStore();
    // test setting BULK_INSERT capability to false
    // $NON-NLS-1$
    Schema pm1 = RealMetadataFactory.createPhysicalModel("pm1", metadataStore);
    // $NON-NLS-1$
    Table pm1g1 = RealMetadataFactory.createPhysicalGroup("g1", pm1);
    FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
    BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
    caps.setCapabilitySupport(Capability.BULK_UPDATE, false);
    // $NON-NLS-1$
    capFinder.addCapabilities("pm1", caps);
    caps.setFunctionSupport(SourceSystemFunctions.CONVERT, true);
    RealMetadataFactory.createElements(pm1g1, // $NON-NLS-1$ //$NON-NLS-2$
    new String[] { "e1", "e2" }, new String[] { DataTypeManager.DefaultDataTypes.BIG_INTEGER, DataTypeManager.DefaultDataTypes.FLOAT });
    QueryMetadataInterface metadata = RealMetadataFactory.createTransformationMetadata(metadataStore, "foo");
    HardcodedDataManager dataManager = new HardcodedDataManager();
    // $NON-NLS-1$
    dataManager.addData(// $NON-NLS-1$
    "INSERT INTO pm1.g1 (e1, e2) VALUES (1, 1.0)", new List[] { Arrays.asList(new Object[] { new Integer(1) }) });
    // $NON-NLS-1$
    String sql = "SELECT 1, convert(1, float) INTO pm1.g1";
    Command command = helpParse(sql);
    ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
    List<?>[] expected = new List[] { Arrays.asList(new Object[] { new Integer(1) }) };
    helpProcess(plan, dataManager, expected);
    Insert insert = (Insert) dataManager.getCommandHistory().iterator().next();
    Constant value0 = (Constant) insert.getValues().get(0);
    Constant value1 = (Constant) insert.getValues().get(1);
    assertEquals(DataTypeManager.DefaultDataClasses.BIG_INTEGER, value0.getValue().getClass());
    assertEquals(DataTypeManager.DefaultDataClasses.FLOAT, value1.getValue().getClass());
}
Also used : FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) Table(org.teiid.metadata.Table) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) Constant(org.teiid.query.sql.symbol.Constant) Schema(org.teiid.metadata.Schema) Insert(org.teiid.query.sql.lang.Insert) MetadataStore(org.teiid.metadata.MetadataStore) Command(org.teiid.query.sql.lang.Command) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand) List(java.util.List) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Test(org.junit.Test)

Example 67 with Schema

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

the class TestInsertProcessing method testSelectIntoWithTypeConversion.

@Test
public void testSelectIntoWithTypeConversion() {
    MetadataStore metadataStore = new MetadataStore();
    // $NON-NLS-1$
    Schema pm1 = RealMetadataFactory.createPhysicalModel("pm1", metadataStore);
    // $NON-NLS-1$
    Table pm1g1 = RealMetadataFactory.createPhysicalGroup("g1", pm1);
    FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
    BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
    caps.setCapabilitySupport(Capability.BATCHED_UPDATES, true);
    caps.setFunctionSupport(SourceSystemFunctions.CONVERT, true);
    // $NON-NLS-1$
    capFinder.addCapabilities("pm1", caps);
    RealMetadataFactory.createElements(pm1g1, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    new String[] { "e1", "e2", "e3" }, new String[] { DataTypeManager.DefaultDataTypes.BIG_INTEGER, DataTypeManager.DefaultDataTypes.FLOAT, DataTypeManager.DefaultDataTypes.FLOAT });
    QueryMetadataInterface metadata = RealMetadataFactory.createTransformationMetadata(metadataStore, "foo");
    HardcodedDataManager dataManager = new HardcodedDataManager();
    // $NON-NLS-1$
    dataManager.addData(// $NON-NLS-1$
    "BatchedUpdate{I}", new List[] { Arrays.asList(new Object[] { new Integer(1) }) });
    // $NON-NLS-1$
    String sql = "SELECT 1, convert(1, float), convert(1, float) INTO pm1.g1";
    Command command = helpParse(sql);
    ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
    List<?>[] expected = new List[] { Arrays.asList(new Object[] { new Integer(1) }) };
    helpProcess(plan, dataManager, expected);
    BatchedUpdateCommand buc = (BatchedUpdateCommand) dataManager.getCommandHistory().iterator().next();
    Insert insert = (Insert) buc.getUpdateCommands().get(0);
    Constant value0 = (Constant) insert.getValues().get(0);
    Constant value1 = (Constant) insert.getValues().get(1);
    assertEquals(DataTypeManager.DefaultDataClasses.BIG_INTEGER, value0.getValue().getClass());
    assertEquals(DataTypeManager.DefaultDataClasses.FLOAT, value1.getValue().getClass());
}
Also used : FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) Table(org.teiid.metadata.Table) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) Constant(org.teiid.query.sql.symbol.Constant) Schema(org.teiid.metadata.Schema) Insert(org.teiid.query.sql.lang.Insert) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand) MetadataStore(org.teiid.metadata.MetadataStore) Command(org.teiid.query.sql.lang.Command) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand) List(java.util.List) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Test(org.junit.Test)

Example 68 with Schema

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

the class TestInsertProcessing method testSelectInto_Case5412a.

@Test
public void testSelectInto_Case5412a() {
    MetadataStore metadataStore = new MetadataStore();
    // test setting BULK_INSERT capability to true
    // $NON-NLS-1$
    Schema pm1 = RealMetadataFactory.createPhysicalModel("pm1", metadataStore);
    // $NON-NLS-1$
    Table pm1g1 = RealMetadataFactory.createPhysicalGroup("g1", pm1);
    FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
    BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
    caps.setCapabilitySupport(Capability.INSERT_WITH_ITERATOR, true);
    caps.setFunctionSupport(SourceSystemFunctions.CONVERT, true);
    // $NON-NLS-1$
    capFinder.addCapabilities("pm1", caps);
    RealMetadataFactory.createElements(pm1g1, // $NON-NLS-1$ //$NON-NLS-2$
    new String[] { "e1", "e2" }, new String[] { DataTypeManager.DefaultDataTypes.BIG_INTEGER, DataTypeManager.DefaultDataTypes.FLOAT });
    QueryMetadataInterface metadata = RealMetadataFactory.createTransformationMetadata(metadataStore, "foo");
    HardcodedDataManager dataManager = new HardcodedDataManager();
    // $NON-NLS-1$
    dataManager.addData(// $NON-NLS-1$
    "INSERT INTO pm1.g1 (e1, e2) VALUES (...)", new List[] { Arrays.asList(new Object[] { new Integer(1) }) });
    // $NON-NLS-1$
    String sql = "SELECT 1, convert(1, float) INTO pm1.g1";
    Command command = helpParse(sql);
    ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
    List<?>[] expected = new List[] { Arrays.asList(new Object[] { new Integer(1) }) };
    helpProcess(plan, dataManager, expected);
}
Also used : FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) Table(org.teiid.metadata.Table) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) Schema(org.teiid.metadata.Schema) MetadataStore(org.teiid.metadata.MetadataStore) Command(org.teiid.query.sql.lang.Command) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand) List(java.util.List) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Test(org.junit.Test)

Example 69 with Schema

use of org.teiid.metadata.Schema 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);
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) ProcedureParameter(org.teiid.metadata.ProcedureParameter) QueryNode(org.teiid.query.mapping.relational.QueryNode) Schema(org.teiid.metadata.Schema) 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 70 with Schema

use of org.teiid.metadata.Schema 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 });
}
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)

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