Search in sources :

Example 41 with MetadataStore

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

the class TestLimit method exampleMetadata.

private static TransformationMetadata exampleMetadata() {
    MetadataStore metadataStore = new MetadataStore();
    // Create models
    // $NON-NLS-1$
    Schema pm1 = RealMetadataFactory.createPhysicalModel("pm1", metadataStore);
    // $NON-NLS-1$
    Schema vm1 = RealMetadataFactory.createVirtualModel("vm1", metadataStore);
    // Create physical groups
    // $NON-NLS-1$
    Table pm1g1 = RealMetadataFactory.createPhysicalGroup("g1", pm1);
    // $NON-NLS-1$
    Table pm1g2 = RealMetadataFactory.createPhysicalGroup("g2", pm1);
    // $NON-NLS-1$
    Table pm1g3 = RealMetadataFactory.createPhysicalGroup("g3", pm1);
    // $NON-NLS-1$
    Table pm1g4 = RealMetadataFactory.createPhysicalGroup("g4", pm1);
    // $NON-NLS-1$
    Table pm1g5 = RealMetadataFactory.createPhysicalGroup("g5", pm1);
    // $NON-NLS-1$
    Table pm1g6 = RealMetadataFactory.createPhysicalGroup("g6", pm1);
    // Create physical elements
    RealMetadataFactory.createElements(pm1g1, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    new String[] { "e1", "e2", "e3", "e4" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
    RealMetadataFactory.createElements(pm1g2, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    new String[] { "e1", "e2", "e3", "e4" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
    RealMetadataFactory.createElements(pm1g3, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    new String[] { "e1", "e2", "e3", "e4" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
    List<Column> pm1g4e = RealMetadataFactory.createElements(pm1g4, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    new String[] { "e1", "e2", "e3", "e4" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
    pm1g4e.get(1).setSelectable(false);
    pm1g4e.get(3).setSelectable(false);
    List<Column> pm1g5e = RealMetadataFactory.createElements(pm1g5, // $NON-NLS-1$
    new String[] { "e1" }, new String[] { DataTypeManager.DefaultDataTypes.STRING });
    pm1g5e.get(0).setSelectable(false);
    RealMetadataFactory.createElements(pm1g6, // $NON-NLS-1$ //$NON-NLS-2$
    new String[] { "in", "in3" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.STRING });
    // Create virtual groups
    // $NON-NLS-1$ //$NON-NLS-2$
    QueryNode vm1g1n1 = new QueryNode("SELECT * FROM pm1.g1 LIMIT 100");
    // $NON-NLS-1$
    Table vm1g1 = RealMetadataFactory.createVirtualGroup("g1", vm1, vm1g1n1);
    // Create virtual elements
    RealMetadataFactory.createElements(vm1g1, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    new String[] { "e1", "e2", "e3", "e4" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
    // $NON-NLS-1$ //$NON-NLS-2$
    QueryNode vm1g2n1 = new QueryNode("SELECT * FROM vm1.g1 ORDER BY e1");
    // $NON-NLS-1$
    Table vm1g2 = RealMetadataFactory.createVirtualGroup("g2", vm1, vm1g2n1);
    // Create virtual elements
    RealMetadataFactory.createElements(vm1g2, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    new String[] { "e1", "e2", "e3", "e4" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
    return RealMetadataFactory.createTransformationMetadata(metadataStore, "example");
}
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 42 with MetadataStore

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

the class TestFunctionPushdown method testDDLMetadata.

@Test
public void testDDLMetadata() throws Exception {
    String ddl = "CREATE VIRTUAL FUNCTION SourceFunc(msg varchar) RETURNS varchar " + "OPTIONS(CATEGORY 'misc', DETERMINISM 'DETERMINISTIC', " + "\"NULL-ON-NULL\" 'true', JAVA_CLASS '" + TestFunctionPushdown.class.getName() + "', JAVA_METHOD 'sourceFunc');" + "CREATE VIEW X (Y varchar) as SELECT e1 from pm1.g1;";
    MetadataFactory mf = TestDDLParser.helpParse(ddl, "model");
    mf.getSchema().setPhysical(false);
    MetadataStore ms = mf.asMetadataStore();
    ms.merge(RealMetadataFactory.example1Cached().getMetadataStore());
    QueryMetadataInterface metadata = RealMetadataFactory.createTransformationMetadata(ms, "example1");
    FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
    BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
    caps.setFunctionSupport("model.SourceFunc", true);
    // $NON-NLS-1$
    capFinder.addCapabilities("pm1", caps);
    helpPlan("select sourceFunc(y) from x", metadata, null, capFinder, new String[] { "SELECT sourceFunc(g_0.e1) FROM pm1.g1 AS g_0" }, // $NON-NLS-1$
    ComparisonMode.EXACT_COMMAND_STRING);
    caps.setFunctionSupport("model.SourceFunc", false);
    helpPlan("select sourceFunc(y) from x", metadata, null, capFinder, new String[] { "SELECT g_0.e1 FROM pm1.g1 AS g_0" }, // $NON-NLS-1$
    ComparisonMode.EXACT_COMMAND_STRING);
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Test(org.junit.Test)

Example 43 with MetadataStore

use of org.teiid.metadata.MetadataStore 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 44 with MetadataStore

use of org.teiid.metadata.MetadataStore 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 45 with MetadataStore

use of org.teiid.metadata.MetadataStore 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)

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