use of org.teiid.metadata.Schema 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);
}
use of org.teiid.metadata.Schema in project teiid by teiid.
the class FakeServer method deployVDB.
public void deployVDB(String vdbName, MetadataStore metadata, DeployVDBParameter parameterObject) {
VDBMetaData vdbMetaData = null;
try {
if (parameterObject.vdbResources != null && parameterObject.useVdbXml) {
VDBResource resource = parameterObject.vdbResources.get("/META-INF/vdb.xml");
if (resource != null) {
vdbMetaData = VDBMetadataParser.unmarshell(resource.openStream());
}
}
if (vdbMetaData == null) {
vdbMetaData = new VDBMetaData();
vdbMetaData.setName(vdbName);
for (Schema schema : metadata.getSchemas().values()) {
ModelMetaData model = addModel(vdbMetaData, schema);
if (parameterObject.metadataRepo != null) {
model.addAttchment(MetadataRepository.class, parameterObject.metadataRepo);
// fakeserver does not load through the repository framework, so call load after the fact here.
MetadataFactory mf = createMetadataFactory(vdbMetaData, metadata, model, parameterObject.vdbResources);
mf.setSchema(schema);
try {
parameterObject.metadataRepo.loadMetadata(mf, null, null);
} catch (TranslatorException e) {
throw new TeiidRuntimeException(e);
}
}
}
} else {
if (!parameterObject.useDataRoles) {
vdbMetaData.setDataPolicies(Collections.EMPTY_LIST);
}
cmr.createConnectorManagers(vdbMetaData, this);
}
UDFMetaData udfMetaData = null;
if (parameterObject.udfs != null) {
udfMetaData = new UDFMetaData();
for (Map.Entry<String, Collection<FunctionMethod>> entry : parameterObject.udfs.entrySet()) {
udfMetaData.addFunctions(entry.getKey(), entry.getValue());
}
}
if (parameterObject.vdbImports != null) {
for (VDBImportMetadata vdbImport : parameterObject.vdbImports) {
vdbMetaData.getVDBImports().add(vdbImport);
}
}
vdbMetaData.setStatus(VDB.Status.ACTIVE);
this.repo.addVDB(vdbMetaData, metadata, parameterObject.vdbResources, udfMetaData, cmr);
this.repo.finishDeployment(vdbMetaData.getName(), vdbMetaData.getVersion());
this.repo.getLiveVDB(vdbMetaData.getName(), vdbMetaData.getVersion()).setStatus(VDB.Status.ACTIVE);
} catch (VirtualDatabaseException e) {
throw new RuntimeException(e);
} catch (ConnectorManagerException e) {
throw new RuntimeException(e);
} catch (XMLStreamException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Aggregations