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());
}
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) {
}
}
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);
}
Aggregations