use of org.teiid.metadata.Schema in project teiid by teiid.
the class TestOptimizer method testUnnamedAggInView.
@Test
public void testUnnamedAggInView() throws Exception {
MetadataStore metadataStore = new MetadataStore();
// $NON-NLS-1$
Schema bqt1 = RealMetadataFactory.createPhysicalModel("BQT1", metadataStore);
// $NON-NLS-1$
Schema vqt = RealMetadataFactory.createVirtualModel("VQT", metadataStore);
// $NON-NLS-1$
Table bqt1SmallA = RealMetadataFactory.createPhysicalGroup("SmallA", bqt1);
RealMetadataFactory.createElement("col", bqt1SmallA, DataTypeManager.DefaultDataTypes.STRING);
Table agg3 = RealMetadataFactory.createVirtualGroup("Agg3", vqt, new QueryNode("select count(*) from smalla"));
RealMetadataFactory.createElement("count", agg3, DataTypeManager.DefaultDataTypes.INTEGER);
TransformationMetadata metadata = RealMetadataFactory.createTransformationMetadata(metadataStore, "x");
BasicSourceCapabilities bac = getTypicalCapabilities();
bac.setCapabilitySupport(Capability.QUERY_FROM_INLINE_VIEWS, true);
bac.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT_STAR, true);
bac.setCapabilitySupport(Capability.QUERY_GROUP_BY, true);
helpPlan("select count(*) from agg3", metadata, new String[] {}, new DefaultCapabilitiesFinder(bac), ComparisonMode.EXACT_COMMAND_STRING);
}
use of org.teiid.metadata.Schema in project teiid by teiid.
the class TestDDLStringVisitor method testFunction.
@Test
public void testFunction() throws Exception {
Schema s = new Schema();
s.addFunction(MetadataFactory.createFunctionFromMethod("x", TestDDLStringVisitor.class.getMethod("someMethod", int.class)));
String metadataDDL = DDLStringVisitor.getDDLString(s, null, null);
assertEquals("CREATE VIRTUAL FUNCTION x(param1 integer) RETURNS string[]" + "\nOPTIONS (NAMEINSOURCE 'x', JAVA_CLASS 'org.teiid.query.metadata.TestDDLStringVisitor', JAVA_METHOD 'someMethod');", metadataDDL);
}
use of org.teiid.metadata.Schema in project teiid by teiid.
the class TestDDLStringVisitor method helpTest.
private void helpTest(String ddl, String expected) {
Schema s = TestDDLParser.helpParse(ddl, "model").getSchema();
String metadataDDL = DDLStringVisitor.getDDLString(s, null, null);
assertEquals(expected, metadataDDL);
}
use of org.teiid.metadata.Schema in project teiid by teiid.
the class TestDDLStringVisitor method testSchema.
@Test
public void testSchema() throws Exception {
Database db = new Database("foo", "2");
DataWrapper dw = new DataWrapper("orcle");
db.addDataWrapper(dw);
Server s = new Server("testing");
s.setDataWrapper(dw.getName());
s.setJndiName("java://test-server");
s.setType("orcl");
db.addServer(s);
String table = "CREATE FOREIGN TABLE G1( e1 integer, e2 varchar)";
Table t = TestDDLParser.helpParse(table, "SchemaA").getSchema().getTable("G1");
Schema schema = new Schema();
schema.setName("SchemaA");
schema.addTable(t);
schema.addServer(s);
db.addSchema(schema);
String metadataDDL = DDLStringVisitor.getDDLString(db);
String expected = "\n" + "/*\n" + "###########################################\n" + "# START DATABASE foo\n" + "###########################################\n" + "*/\n" + "CREATE DATABASE foo VERSION '2';\n" + "USE DATABASE foo VERSION '2';" + "\n" + "\n--############ Translators ############\n" + "CREATE FOREIGN DATA WRAPPER orcle;\n" + "\n" + "\n--############ Servers ############\n" + "CREATE SERVER testing TYPE 'orcl' FOREIGN DATA WRAPPER orcle OPTIONS (\"jndi-name\" 'java://test-server');\n" + "\n" + "\n--############ Schemas ############\n" + "CREATE SCHEMA SchemaA SERVER testing;\n\n" + "\n--############ Schema:SchemaA ############\n" + "SET SCHEMA SchemaA;\n" + "\n" + "CREATE FOREIGN TABLE G1 (\n" + "\te1 integer,\n" + "\te2 string\n" + ");\n" + "/*\n" + "###########################################\n" + "# END DATABASE foo\n" + "###########################################\n" + "*/\n" + "\n";
assertEquals(expected, metadataDDL);
}
use of org.teiid.metadata.Schema in project teiid by teiid.
the class InfinispanExecutionFactory method getMetadata.
@Override
public void getMetadata(MetadataFactory metadataFactory, InfinispanConnection conn) throws TranslatorException {
ProtobufMetadataProcessor metadataProcessor = (ProtobufMetadataProcessor) getMetadataProcessor();
// $NON-NLS-1$
PropertiesUtils.setBeanProperties(metadataProcessor, metadataFactory.getModelProperties(), "importer");
// This block is only invoked when NATIVE metadata is defined, by the time code got here if we have
// tables already in schema, then user defined through other metadata repositories. In this case,
// a .proto file need to be generated based on schema, then use that to generate final metadata and
// register the .proto with the Infinispan
Schema schema = metadataFactory.getSchema();
ProtobufResource resource = null;
ArrayList<Table> removedTables = new ArrayList<>();
if (schema.getTables() != null && !schema.getTables().isEmpty()) {
SchemaToProtobufProcessor stpp = new SchemaToProtobufProcessor();
stpp.setIndexMessages(true);
resource = stpp.process(metadataFactory, conn);
metadataProcessor.setProtobufResource(resource);
ArrayList<Table> tables = new ArrayList<>(schema.getTables().values());
for (Table t : tables) {
// remove the previous tables, as we want to introduce them with necessary
// extension metadata generated with generated .proto file. As some of the default
// extension metadata can be added.
removedTables.add(schema.removeTable(t.getName()));
}
}
metadataProcessor.process(metadataFactory, conn);
// may be not carried forward, we need to make sure we copy those back.
for (Table oldT : removedTables) {
Table newT = schema.getTable(oldT.getName());
Map<String, String> properties = oldT.getProperties();
for (Map.Entry<String, String> entry : properties.entrySet()) {
newT.setProperty(entry.getKey(), entry.getValue());
}
newT.setSupportsUpdate(oldT.supportsUpdate());
if (oldT.getAnnotation() != null) {
newT.setAnnotation(oldT.getAnnotation());
}
List<Column> columns = oldT.getColumns();
for (Column c : columns) {
Column newCol = newT.getColumnByName(c.getName());
if (newCol != null) {
Map<String, String> colProperties = c.getProperties();
for (Map.Entry<String, String> entry : colProperties.entrySet()) {
newCol.setProperty(entry.getKey(), entry.getValue());
}
newCol.setUpdatable(c.isUpdatable());
if (c.getAnnotation() != null) {
newCol.setAnnotation(c.getAnnotation());
}
}
}
}
resource = metadataProcessor.getProtobufResource();
if (resource == null) {
SchemaToProtobufProcessor stpp = new SchemaToProtobufProcessor();
resource = stpp.process(metadataFactory, conn);
}
// register protobuf
if (resource != null) {
conn.registerProtobufFile(resource);
}
}
Aggregations