Search in sources :

Example 71 with MetadataStore

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

the class TestDynamicImportedMetaData method testUseScale.

@Test
public void testUseScale() throws Exception {
    MetadataFactory mf = createMetadataFactory("x", new Properties());
    Table dup = mf.addTable("x");
    Column c = mf.addColumn("x", DataTypeManager.DefaultDataTypes.BIG_DECIMAL, dup);
    c.setPrecision(10);
    c.setScale(2);
    MetadataStore ms = mf.asMetadataStore();
    server.deployVDB("test", ms);
    // $NON-NLS-1$
    Connection conn = server.createConnection("jdbc:teiid:test");
    Properties importProperties = new Properties();
    importProperties.setProperty("importer.useQualifiedName", Boolean.FALSE.toString());
    mf = getMetadata(importProperties, conn);
    Table t = mf.asMetadataStore().getSchemas().get("TEST").getTables().get("x");
    c = t.getColumnByName("x");
    assertEquals(10, c.getPrecision());
    assertEquals(2, c.getScale());
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) Table(org.teiid.metadata.Table) MetadataFactory(org.teiid.metadata.MetadataFactory) Column(org.teiid.metadata.Column) Connection(java.sql.Connection) Properties(java.util.Properties) Test(org.junit.Test)

Example 72 with MetadataStore

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

the class TestDynamicImportedMetaData method testDuplicateException.

@Test
public void testDuplicateException() throws Exception {
    MetadataFactory mf = createMetadataFactory("x", new Properties());
    MetadataFactory mf1 = createMetadataFactory("y", new Properties());
    Table dup = mf.addTable("dup");
    Table dup1 = mf1.addTable("dup");
    mf.addColumn("x", DataTypeManager.DefaultDataTypes.STRING, dup);
    mf1.addColumn("x", DataTypeManager.DefaultDataTypes.STRING, dup1);
    MetadataStore ms = mf.asMetadataStore();
    ms.addSchema(mf1.asMetadataStore().getSchemas().values().iterator().next());
    server.deployVDB("test", ms);
    // $NON-NLS-1$
    Connection conn = server.createConnection("jdbc:teiid:test");
    Properties importProperties = new Properties();
    mf = getMetadata(importProperties, conn);
    Table t = mf.asMetadataStore().getSchemas().get("TEST").getTables().get("TEST.X.DUP");
    assertEquals("\"test\".\"x\".\"dup\"", t.getNameInSource());
    importProperties.setProperty("importer.useFullSchemaName", Boolean.FALSE.toString());
    try {
        getMetadata(importProperties, conn);
        fail();
    } catch (DuplicateRecordException e) {
    }
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) DuplicateRecordException(org.teiid.metadata.DuplicateRecordException) Table(org.teiid.metadata.Table) MetadataFactory(org.teiid.metadata.MetadataFactory) Connection(java.sql.Connection) Properties(java.util.Properties) Test(org.junit.Test)

Example 73 with MetadataStore

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

the class TestCrossSourceStarJoin method testCrossSourceStarJoin.

@Test
public void testCrossSourceStarJoin() throws Exception {
    String sql = "select p.Description, sum(AMOUNT) from s3 p, s2 c, s1 b, o1 f " + "where p.PRODUCTID = f.PRODUCT and c.CurrencyCode = f.CURRENCY and b.BOOKID = f.BOOK and b.Name = 'xyz' and c.Name = 'abc' Group by p.Description";
    MetadataStore metadataStore = new MetadataStore();
    // $NON-NLS-1$
    Schema oracle = createPhysicalModel("oracle", metadataStore);
    // $NON-NLS-1$
    Schema sybase = createPhysicalModel("sybase", metadataStore);
    // Create physical groups
    // $NON-NLS-1$
    Table f = createPhysicalGroup("o1", oracle);
    f.setCardinality(5276965);
    // $NON-NLS-1$
    Table b = createPhysicalGroup("s1", sybase);
    b.setCardinality(141496);
    // $NON-NLS-1$
    Table c = createPhysicalGroup("s2", sybase);
    c.setCardinality(228);
    // $NON-NLS-1$
    Table p = createPhysicalGroup("s3", sybase);
    p.setCardinality(200);
    List<Column> f_cols = createElements(f, // $NON-NLS-1$
    new String[] { "PRODUCT", "CURRENCY", "BOOK", "AMOUNT" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.BIG_DECIMAL });
    f_cols.get(0).setDistinctValues(400);
    f_cols.get(1).setDistinctValues(228);
    f_cols.get(2).setDistinctValues(141496);
    createKey(KeyRecord.Type.Index, "idx_p", f, f_cols.subList(0, 1));
    createKey(KeyRecord.Type.Index, "idx_c", f, f_cols.subList(1, 2));
    createKey(KeyRecord.Type.Index, "idx_b", f, f_cols.subList(2, 3));
    List<Column> b_cols = createElements(b, // $NON-NLS-1$
    new String[] { "BOOKID", "Name" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.STRING });
    createKey(KeyRecord.Type.Primary, "pk", b, b_cols.subList(0, 1));
    b_cols.get(1).setDistinctValues(70000);
    // createKey(KeyRecord.Type.Unique, "uk", b, b_cols.subList(1, 2));
    List<Column> c_cols = createElements(c, // $NON-NLS-1$
    new String[] { "Name", "CurrencyCode" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER });
    createKey(KeyRecord.Type.Primary, "pk", c, c_cols.subList(1, 2));
    // createKey(KeyRecord.Type.Unique, "uk", c, c_cols.subList(0, 1));
    List<Column> p_cols = createElements(p, // $NON-NLS-1$
    new String[] { "PRODUCTID", "Description" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.STRING });
    createKey(KeyRecord.Type.Primary, "pk", p, p_cols.subList(0, 1));
    FakeCapabilitiesFinder finder = new FakeCapabilitiesFinder();
    // $NON-NLS-1$
    finder.addCapabilities("oracle", TestTPCR.oracleCapabilities());
    // $NON-NLS-1$
    finder.addCapabilities("sybase", TestTPCR.sqlServerCapabilities());
    TransformationMetadata metadata = RealMetadataFactory.createTransformationMetadata(metadataStore, "star");
    TestOptimizer.helpPlan(sql, metadata, new String[] { "SELECT g_0.CurrencyCode AS c_0 FROM sybase.s2 AS g_0 WHERE g_0.Name = 'abc' ORDER BY c_0", "SELECT g_0.BOOKID AS c_0 FROM sybase.s1 AS g_0 WHERE g_0.Name = 'xyz' ORDER BY c_0", "SELECT g_0.PRODUCTID AS c_0, g_0.Description AS c_1 FROM sybase.s3 AS g_0 ORDER BY c_0", "SELECT g_0.BOOK, g_0.PRODUCT, g_0.CURRENCY, SUM(g_0.AMOUNT) FROM oracle.o1 AS g_0 WHERE (g_0.BOOK IN (<dependent values>)) AND (g_0.PRODUCT IN (<dependent values>)) AND (g_0.CURRENCY IN (<dependent values>)) GROUP BY g_0.BOOK, g_0.PRODUCT, g_0.CURRENCY" }, finder, ComparisonMode.EXACT_COMMAND_STRING);
    // test that aggregate will not be staged
    f.setCardinality(527696);
    TestOptimizer.helpPlan(sql, metadata, new String[] { "SELECT g_0.CurrencyCode AS c_0 FROM sybase.s2 AS g_0 WHERE g_0.Name = 'abc' ORDER BY c_0", "SELECT g_0.BOOK, g_0.PRODUCT, g_0.CURRENCY, g_0.AMOUNT FROM oracle.o1 AS g_0 WHERE (g_0.BOOK IN (<dependent values>)) AND (g_0.CURRENCY IN (<dependent values>))", "SELECT g_0.PRODUCTID AS c_0, g_0.Description AS c_1 FROM sybase.s3 AS g_0 ORDER BY c_0", "SELECT g_0.BOOKID AS c_0 FROM sybase.s1 AS g_0 WHERE g_0.Name = 'xyz' ORDER BY c_0" }, finder, ComparisonMode.EXACT_COMMAND_STRING);
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) Table(org.teiid.metadata.Table) Column(org.teiid.metadata.Column) Schema(org.teiid.metadata.Schema) 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