Search in sources :

Example 61 with MetadataFactory

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

the class TestMetadataProcessor method testRemoveColumns.

@Test
public void testRemoveColumns() throws Exception {
    GoogleSpreadsheetConnection conn = Mockito.mock(GoogleSpreadsheetConnection.class);
    SpreadsheetInfo people = new SpreadsheetInfo("People");
    Worksheet worksheet = people.createWorksheet("PeopleList");
    worksheet.setHeaderEnabled(true);
    for (int i = 1; i <= 3; i++) {
        Column newCol = new Column();
        newCol.setAlphaName(Util.convertColumnIDtoString(i));
        newCol.setLabel("c" + i);
        if (i == 1) {
            newCol.setDataType(SpreadsheetColumnType.DATETIME);
        }
        worksheet.addColumn(newCol.getAlphaName(), newCol);
    }
    Column newCol = new Column();
    newCol.setAlphaName("empty");
    worksheet.addColumn(null, newCol);
    Mockito.stub(conn.getSpreadsheetInfo()).toReturn(people);
    MetadataFactory factory = new MetadataFactory("", 1, "", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), "");
    GoogleMetadataProcessor processor = new GoogleMetadataProcessor();
    processor.process(factory, conn);
    Table t = factory.getSchema().getTables().get("PeopleList");
    assertTrue(t.supportsUpdate());
    assertEquals(3, t.getColumns().size());
    assertTrue(t.getColumns().get(0).isUpdatable());
    processor.setAllTypesUpdatable(false);
    factory = new MetadataFactory("", 1, "", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), "");
    processor.process(factory, conn);
    t = factory.getSchema().getTables().get("PeopleList");
    assertFalse(t.getColumns().get(0).isUpdatable());
}
Also used : Table(org.teiid.metadata.Table) MetadataFactory(org.teiid.metadata.MetadataFactory) SpreadsheetInfo(org.teiid.translator.google.api.metadata.SpreadsheetInfo) Column(org.teiid.translator.google.api.metadata.Column) Worksheet(org.teiid.translator.google.api.metadata.Worksheet) Properties(java.util.Properties) GoogleSpreadsheetConnection(org.teiid.translator.google.api.GoogleSpreadsheetConnection) Test(org.junit.Test)

Example 62 with MetadataFactory

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

the class TestSQLtoSpreadsheetQuery method dummySpreadsheetMetadata.

private QueryMetadataInterface dummySpreadsheetMetadata() throws Exception {
    GoogleSpreadsheetConnection conn = Mockito.mock(GoogleSpreadsheetConnection.class);
    Mockito.stub(conn.getSpreadsheetInfo()).toReturn(people);
    MetadataFactory factory = new MetadataFactory("", 1, "", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), "");
    GoogleMetadataProcessor processor = new GoogleMetadataProcessor();
    processor.process(factory, conn);
    return new TransformationMetadata(null, new CompositeMetadataStore(factory.asMetadataStore()), null, RealMetadataFactory.SFM.getSystemFunctions(), null);
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) CompositeMetadataStore(org.teiid.query.metadata.CompositeMetadataStore) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) Properties(java.util.Properties) GoogleSpreadsheetConnection(org.teiid.translator.google.api.GoogleSpreadsheetConnection)

Example 63 with MetadataFactory

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

the class TestVisitor method queryMetadataInterface.

private static TransformationMetadata queryMetadataInterface() {
    try {
        ModelMetaData mmd = new ModelMetaData();
        mmd.setName("couchbase");
        CouchbaseMetadataProcessor mp = new CouchbaseMetadataProcessor();
        MetadataFactory mf = new MetadataFactory("couchbase", 1, SystemMetadata.getInstance().getRuntimeTypeMap(), mmd);
        Table customer = createTable(mf, KEYSPACE, "Customer");
        mp.scanRow(KEYSPACE, KEYSPACE_SOURCE, formCustomer(), mf, customer, customer.getName(), false, new Dimension());
        Table order = createTable(mf, KEYSPACE, "Oder");
        mp.scanRow(KEYSPACE, KEYSPACE_SOURCE, formOder(), mf, order, order.getName(), false, new Dimension());
        Table t2 = createTable(mf, "T2", "T2");
        mp.scanRow("T2", "`T2`", formDataTypeJson(), mf, t2, t2.getName(), false, new Dimension());
        Table t3 = createTable(mf, "T3", "T3");
        mp.scanRow("T3", "`T3`", nestedJson(), mf, t3, t3.getName(), false, new Dimension());
        mp.scanRow("T3", "`T3`", nestedArray(), mf, t3, t3.getName(), false, new Dimension());
        mp.addProcedures(mf, null);
        TransformationMetadata tm = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "x");
        ValidatorReport report = new MetadataValidator().validate(tm.getVdbMetaData(), tm.getMetadataStore());
        if (report.hasItems()) {
            throw new RuntimeException(report.getFailureMessage());
        }
        return tm;
    } catch (MetadataException e) {
        throw new RuntimeException(e);
    }
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) Table(org.teiid.metadata.Table) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) TestCouchbaseMetadataProcessor(org.teiid.translator.couchbase.TestCouchbaseMetadataProcessor) MetadataValidator(org.teiid.query.metadata.MetadataValidator) Dimension(org.teiid.translator.couchbase.CouchbaseMetadataProcessor.Dimension) ValidatorReport(org.teiid.query.validator.ValidatorReport) MetadataException(org.teiid.metadata.MetadataException) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData)

Example 64 with MetadataFactory

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

the class TestMongoDBMetadataProcessor method testExclusion.

@Test
public void testExclusion() throws TranslatorException {
    MongoDBMetadataProcessor mp = new MongoDBMetadataProcessor();
    mp.setExcludeTables("e.*");
    MetadataFactory mf = new MetadataFactory("vdb", 1, "mongodb", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), null);
    MongoDBConnection conn = Mockito.mock(MongoDBConnection.class);
    DBCollection tableDBCollection = Mockito.mock(DBCollection.class);
    DBCollection embeddedDBCollection = Mockito.mock(DBCollection.class);
    DBCollection emptyDBCollection = Mockito.mock(DBCollection.class);
    DBCollection emptyFirstDBCollection = Mockito.mock(DBCollection.class);
    LinkedHashSet<String> tables = new LinkedHashSet<String>();
    tables.add("table");
    tables.add("embedded");
    tables.add("empty");
    tables.add("emptyFirst");
    DB db = Mockito.mock(DB.class);
    BasicDBList array = new BasicDBList();
    array.add("one");
    array.add("two");
    BasicDBObject row = new BasicDBObject();
    row.append("_id", new Integer(1));
    row.append("col2", new Double(2.0));
    row.append("col3", new Long(3L));
    row.append("col5", Boolean.TRUE);
    row.append("col6", new Date(0L));
    row.append("col6", new DBRef(db.getName(), "ns", "one"));
    row.append("col7", array);
    row.append("col8", new Binary("binary".getBytes()));
    BasicDBObject child = new BasicDBObject();
    child.append("col1", "one");
    child.append("col2", "two");
    row.append("child", child);
    BasicDBObject emptyFirstRow = new BasicDBObject();
    emptyFirstRow.append("_id", new ObjectId("5835a598944716c40d2f26ae"));
    emptyFirstRow.append("col2", new Double(2.0));
    emptyFirstRow.append("col3", new Long(3L));
    BasicDBObject embedded = new BasicDBObject();
    embedded.append("col1", "one");
    embedded.append("col2", "two");
    row.append("embedded", embedded);
    Mockito.stub(db.getCollectionNames()).toReturn(tables);
    Mockito.stub(db.getCollection(Mockito.eq("table"))).toReturn(tableDBCollection);
    Mockito.stub(db.getCollection(Mockito.eq("embedded"))).toReturn(embeddedDBCollection);
    Mockito.stub(db.getCollection(Mockito.eq("empty"))).toReturn(emptyDBCollection);
    Mockito.stub(db.getCollection(Mockito.eq("emptyFirst"))).toReturn(emptyFirstDBCollection);
    DBCursor tableCursor = Mockito.mock(DBCursor.class);
    Mockito.when(tableCursor.hasNext()).thenReturn(true).thenReturn(false);
    Mockito.when(tableCursor.next()).thenReturn(row);
    Mockito.when(tableDBCollection.find()).thenReturn(tableCursor);
    DBCursor embeddedCursor = Mockito.mock(DBCursor.class);
    Mockito.when(embeddedCursor.hasNext()).thenReturn(true).thenReturn(false);
    Mockito.when(embeddedCursor.next()).thenReturn(child);
    Mockito.when(embeddedDBCollection.find()).thenReturn(embeddedCursor);
    DBCursor emptyFirstCursor = Mockito.mock(DBCursor.class);
    Mockito.when(emptyFirstCursor.hasNext()).thenReturn(true).thenReturn(true).thenReturn(false);
    Mockito.when(emptyFirstCursor.next()).thenReturn(null).thenReturn(emptyFirstRow);
    Mockito.when(emptyFirstDBCollection.find()).thenReturn(emptyFirstCursor);
    DBCursor emptyCursor = Mockito.mock(DBCursor.class);
    Mockito.when(emptyCursor.hasNext()).thenReturn(true).thenReturn(false);
    Mockito.when(emptyCursor.next()).thenReturn(null);
    Mockito.when(emptyDBCollection.find()).thenReturn(emptyCursor);
    Mockito.stub(conn.getDatabase()).toReturn(db);
    mp.process(mf, conn);
    String metadataDDL = DDLStringVisitor.getDDLString(mf.getSchema(), null, null);
    String expected = "SET NAMESPACE 'http://www.teiid.org/ext/relational/2012' AS teiid_rel;\n" + "SET NAMESPACE 'http://www.teiid.org/translator/mongodb/2013' AS teiid_mongo;\n" + "\n" + "CREATE FOREIGN TABLE \"table\" (\n" + "    \"_id\" integer,\n" + "    col2 double,\n" + "    col3 long,\n" + "    col5 boolean,\n" + "    col6 string,\n" + "    col7 object[] OPTIONS (SEARCHABLE 'Unsearchable'),\n" + "    col8 varbinary OPTIONS (NATIVE_TYPE 'org.bson.types.Binary'),\n" + "    CONSTRAINT PK0 PRIMARY KEY(\"_id\"),\n" + "    CONSTRAINT FK_col6 FOREIGN KEY(col6) REFERENCES ns \n" + ") OPTIONS (UPDATABLE TRUE, \"teiid_rel:fqn\" 'collection=table');\n" + "\n" + "CREATE FOREIGN TABLE child (\n" + "    col1 string,\n" + "    col2 string,\n" + "    \"_id\" integer OPTIONS (UPDATABLE FALSE),\n" + "    CONSTRAINT PK0 PRIMARY KEY(\"_id\"),\n" + "    FOREIGN KEY(\"_id\") REFERENCES \"table\" \n" + ") OPTIONS (UPDATABLE TRUE, \"teiid_rel:fqn\" 'collection=table/embedded=child', \"teiid_mongo:MERGE\" 'table');\n" + "\n" + "CREATE FOREIGN TABLE embedded (\n" + "    col1 string,\n" + "    col2 string,\n" + "    \"_id\" integer OPTIONS (UPDATABLE FALSE),\n" + "    CONSTRAINT PK0 PRIMARY KEY(\"_id\"),\n" + "    FOREIGN KEY(\"_id\") REFERENCES \"table\" \n" + ") OPTIONS (UPDATABLE TRUE, \"teiid_rel:fqn\" 'collection=table/embedded=embedded', \"teiid_mongo:MERGE\" 'table');";
    assertEquals(expected, metadataDDL.replace("\t", "    "));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ObjectId(org.bson.types.ObjectId) DBRef(com.mongodb.DBRef) Properties(java.util.Properties) Date(java.sql.Date) DBCollection(com.mongodb.DBCollection) BasicDBList(com.mongodb.BasicDBList) BasicDBObject(com.mongodb.BasicDBObject) DBCursor(com.mongodb.DBCursor) MetadataFactory(org.teiid.metadata.MetadataFactory) MongoDBConnection(org.teiid.mongodb.MongoDBConnection) Binary(org.bson.types.Binary) DB(com.mongodb.DB) Test(org.junit.Test)

Example 65 with MetadataFactory

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

the class TestPhoenixUtil method queryMetadataInterface.

public static TransformationMetadata queryMetadataInterface() {
    try {
        ModelMetaData mmd = new ModelMetaData();
        mmd.setName("HBaseModel");
        MetadataFactory mf = new MetadataFactory("hbase", 1, SystemMetadata.getInstance().getRuntimeTypeMap(), mmd);
        mf.setParser(new QueryParser());
        mf.parse(new FileReader(UnitTestUtil.getTestDataFile("customer.ddl")));
        TransformationMetadata tm = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "x");
        ValidatorReport report = new MetadataValidator().validate(tm.getVdbMetaData(), tm.getMetadataStore());
        if (report.hasItems()) {
            throw new RuntimeException(report.getFailureMessage());
        }
        return tm;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : QueryParser(org.teiid.query.parser.QueryParser) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) MetadataFactory(org.teiid.metadata.MetadataFactory) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) FileReader(java.io.FileReader) MetadataValidator(org.teiid.query.metadata.MetadataValidator) ValidatorReport(org.teiid.query.validator.ValidatorReport) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData)

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