Search in sources :

Example 11 with MetadataFactory

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

the class TestSimpleDBSQLVisitor method testArrayCompare.

@Test
public void testArrayCompare() throws Exception {
    SimpleDBExecutionFactory translator = new SimpleDBExecutionFactory();
    translator.start();
    MetadataFactory mf = TestDDLParser.helpParse("create foreign table item (\"itemName()\" integer, attribute string[]);", "y");
    TransformationMetadata metadata = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "x", new FunctionTree("foo", new UDFSource(translator.getPushDownFunctions())));
    TranslationUtility tu = new TranslationUtility(metadata);
    Command c = tu.parseCommand("select * from item where attribute = ('1','2')");
    SimpleDBSQLVisitor visitor = new SimpleDBSQLVisitor();
    visitor.append(c);
    assertEquals("SELECT attribute FROM item WHERE attribute = '1' OR attribute = '2'", visitor.toString());
}
Also used : UDFSource(org.teiid.query.function.UDFSource) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) FunctionTree(org.teiid.query.function.FunctionTree) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) Command(org.teiid.language.Command) SimpleDBSQLVisitor(org.teiid.translator.simpledb.SimpleDBSQLVisitor) TranslationUtility(org.teiid.cdk.api.TranslationUtility) SimpleDBExecutionFactory(org.teiid.translator.simpledb.SimpleDBExecutionFactory) Test(org.junit.Test)

Example 12 with MetadataFactory

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

the class TestSimpleDBSQLVisitor method testEvery.

@Test
public void testEvery() throws Exception {
    SimpleDBExecutionFactory translator = new SimpleDBExecutionFactory();
    translator.start();
    MetadataFactory mf = TestDDLParser.helpParse("create foreign table item (\"itemName()\" integer, attribute string[]);", "y");
    TransformationMetadata metadata = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "x", new FunctionTree("foo", new UDFSource(translator.getPushDownFunctions())));
    TranslationUtility tu = new TranslationUtility(metadata);
    Command c = tu.parseCommand("select * from item where simpledb.every(attribute) = '1'");
    SimpleDBSQLVisitor visitor = new SimpleDBSQLVisitor();
    visitor.append(c);
    assertEquals("SELECT attribute FROM item WHERE SIMPLEDB.EVERY(attribute) = '1'", visitor.toString());
}
Also used : UDFSource(org.teiid.query.function.UDFSource) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) FunctionTree(org.teiid.query.function.FunctionTree) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) Command(org.teiid.language.Command) SimpleDBSQLVisitor(org.teiid.translator.simpledb.SimpleDBSQLVisitor) TranslationUtility(org.teiid.cdk.api.TranslationUtility) SimpleDBExecutionFactory(org.teiid.translator.simpledb.SimpleDBExecutionFactory) Test(org.junit.Test)

Example 13 with MetadataFactory

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

the class TestMongoDBQueryExecution method setUp.

@Before
public void setUp() throws Exception {
    this.translator = new MongoDBExecutionFactory();
    this.translator.setDatabaseVersion("2.6");
    this.translator.start();
    MetadataFactory mf = TestDDLParser.helpParse(ObjectConverterUtil.convertFileToString(UnitTestUtil.getTestDataFile("northwind.ddl")), "northwind");
    TransformationMetadata metadata = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "sakila", new FunctionTree("mongo", new UDFSource(translator.getPushDownFunctions())));
    ValidatorReport report = new MetadataValidator().validate(metadata.getVdbMetaData(), metadata.getMetadataStore());
    if (report.hasItems()) {
        throw new RuntimeException(report.getFailureMessage());
    }
    this.utility = new TranslationUtility(metadata);
}
Also used : UDFSource(org.teiid.query.function.UDFSource) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) FunctionTree(org.teiid.query.function.FunctionTree) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) TranslationUtility(org.teiid.cdk.api.TranslationUtility) MetadataValidator(org.teiid.query.metadata.MetadataValidator) ValidatorReport(org.teiid.query.validator.ValidatorReport) Before(org.junit.Before)

Example 14 with MetadataFactory

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

the class TestDataEntitySchemaBuilder method getNorthwindMetadataFromODataXML.

static TransformationMetadata getNorthwindMetadataFromODataXML() throws Exception {
    ModelMetaData model = new ModelMetaData();
    model.setName("nw");
    model.setModelType(Type.PHYSICAL);
    MetadataFactory mf = new MetadataFactory("northwind", 1, SystemMetadata.getInstance().getRuntimeTypeMap(), model);
    EdmDataServices edm = new EdmxFormatParser().parseMetadata(StaxUtil.newXMLEventReader(new FileReader(UnitTestUtil.getTestDataFile("northwind.xml"))));
    ODataMetadataProcessor metadataProcessor = new ODataMetadataProcessor();
    // $NON-NLS-1$
    PropertiesUtils.setBeanProperties(metadataProcessor, mf.getModelProperties(), "importer");
    metadataProcessor.getMetadata(mf, edm);
    String ddl = DDLStringVisitor.getDDLString(mf.getSchema(), null, null);
    TransformationMetadata metadata = RealMetadataFactory.fromDDL(ddl, "northwind", "nw");
    ValidatorReport report = new MetadataValidator().validate(metadata.getVdbMetaData(), metadata.getMetadataStore());
    if (report.hasItems()) {
        throw new RuntimeException(report.getFailureMessage());
    }
    return metadata;
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) EdmxFormatParser(org.odata4j.format.xml.EdmxFormatParser) FileReader(java.io.FileReader) MetadataValidator(org.teiid.query.metadata.MetadataValidator) ValidatorReport(org.teiid.query.validator.ValidatorReport) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData)

Example 15 with MetadataFactory

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

the class TestODataMetadataProcessor method testManytoManyAssosiation.

@Test
public void testManytoManyAssosiation() throws Exception {
    ODataMetadataProcessor processor = new ODataMetadataProcessor();
    MetadataFactory mf = new MetadataFactory("vdb", 1, "northwind", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), null);
    EdmEntityType.Builder g1Entity = entityType("g1");
    EdmEntityType.Builder g2Entity = entityType("g2");
    EdmAssociationEnd.Builder aend1 = EdmAssociationEnd.newBuilder().setRole("source").setType(g1Entity).setMultiplicity(EdmMultiplicity.MANY);
    EdmAssociationEnd.Builder aend2 = EdmAssociationEnd.newBuilder().setRole("target").setType(g2Entity).setMultiplicity(EdmMultiplicity.MANY);
    EdmAssociation.Builder assocition = EdmAssociation.newBuilder().setNamespace("namspace").setName("m_2_m").setEnds(aend2, aend1);
    EdmNavigationProperty.Builder navigation = EdmNavigationProperty.newBuilder("g1").setFromTo(aend2, aend1).setFromToName("source", "target").setRelationship(assocition);
    g2Entity.addNavigationProperties(navigation);
    EdmEntitySet g1Set = EdmEntitySet.newBuilder().setName("G1").setEntityType(g1Entity).build();
    EdmEntitySet g2Set = EdmEntitySet.newBuilder().setName("G2").setEntityType(g2Entity).build();
    processor.addEntitySetAsTable(mf, g1Set);
    processor.addEntitySetAsTable(mf, g2Set);
    processor.addNavigationRelations(mf, "G2", g2Entity.build());
    Table g1 = mf.getSchema().getTable("G1");
    Table g2 = mf.getSchema().getTable("G2");
    Table linkTable = mf.getSchema().getTable("m_2_m");
    assertEquals(1, linkTable.getColumns().size());
    assertEquals("e1", linkTable.getColumns().get(0).getName());
    assertNotNull(linkTable);
    assertEquals("G2,G1", linkTable.getProperty(ODataMetadataProcessor.LINK_TABLES, false));
    ForeignKey fk1 = linkTable.getForeignKeys().get(0);
    assertEquals("G2_FK", fk1.getName());
    assertNotNull(fk1.getColumnByName("e1"));
    ForeignKey fk2 = linkTable.getForeignKeys().get(1);
    assertEquals("G1_FK", fk2.getName());
    assertNotNull(fk2.getColumnByName("e1"));
}
Also used : EdmAssociationEnd(org.odata4j.edm.EdmAssociationEnd) Table(org.teiid.metadata.Table) EdmEntityType(org.odata4j.edm.EdmEntityType) EdmNavigationProperty(org.odata4j.edm.EdmNavigationProperty) Properties(java.util.Properties) ForeignKey(org.teiid.metadata.ForeignKey) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) EdmAssociation(org.odata4j.edm.EdmAssociation) EdmEntitySet(org.odata4j.edm.EdmEntitySet) Test(org.junit.Test)

Aggregations

MetadataFactory (org.teiid.metadata.MetadataFactory)159 Test (org.junit.Test)116 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)91 Properties (java.util.Properties)74 Table (org.teiid.metadata.Table)59 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)35 Procedure (org.teiid.metadata.Procedure)30 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)21 Column (org.teiid.metadata.Column)20 Connection (java.sql.Connection)18 FunctionTree (org.teiid.query.function.FunctionTree)15 UDFSource (org.teiid.query.function.UDFSource)14 CouchbaseMetadataProcessor (org.teiid.translator.couchbase.CouchbaseMetadataProcessor)14 Dimension (org.teiid.translator.couchbase.CouchbaseMetadataProcessor.Dimension)14 CouchbaseProperties (org.teiid.translator.couchbase.CouchbaseProperties)14 TranslationUtility (org.teiid.cdk.api.TranslationUtility)13 ValidatorReport (org.teiid.query.validator.ValidatorReport)13 XMLMetadata (org.apache.olingo.client.api.edm.xml.XMLMetadata)12 ClientCsdlXMLMetadata (org.apache.olingo.client.core.edm.ClientCsdlXMLMetadata)12 ForeignKey (org.teiid.metadata.ForeignKey)12