Search in sources :

Example 46 with MetadataFactory

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

the class TestSchemaToProtobufProcessor method testConverstion.

@SuppressWarnings("rawtypes")
@Test
public void testConverstion() throws Exception {
    SchemaToProtobufProcessor tool = new SchemaToProtobufProcessor();
    // tool.setIndexMessages(true);
    MetadataFactory mf = TestProtobufMetadataProcessor.protoMatadata("tables.proto");
    InfinispanConnection conn = Mockito.mock(InfinispanConnection.class);
    BasicCache cache = Mockito.mock(BasicCache.class);
    Mockito.stub(cache.getName()).toReturn("default");
    Mockito.stub(conn.getCache()).toReturn(cache);
    ProtobufResource resource = tool.process(mf, conn);
    String expected = "package model;\n" + "\n" + "/* @Indexed @Cache(name=foo) */\n" + "message G1 {\n" + "    /* @Id @IndexedField(index=true, store=false) */\n" + "    required int32 e1 = 1;\n" + "    /* @IndexedField */\n" + "    required string e2 = 2;\n" + "    optional float e3 = 3;\n" + "    /* @IndexedField(index=true, store=false) */\n" + "    repeated string e4 = 4;\n" + "    repeated string e5 = 5;\n" + "}\n" + "\n" + "/* @Indexed */\n" + "message G2 {\n" + "    /* @Id */\n" + "    required int32 e1 = 1;\n" + "    required string e2 = 2;\n" + "    optional G3 g3 = 5;\n" + "    /* @IndexedField(index=false) */\n" + "    optional bytes e5 = 7;\n" + "    /* @Teiid(type=long) */\n" + "    optional fixed64 e6 = 8;\n" + "    repeated G4 g4 = 6;\n" + "}\n" + "\n" + "/* @Indexed */\n" + "message G4 {\n" + "    required int32 e1 = 1;\n" + "    required string e2 = 2;\n" + "    optional int32 e1 = 3;\n" + "}\n" + "\n" + "/* @Indexed */\n" + "message G5 {\n" + "    /* @Id */\n" + "    required int32 e1 = 1;\n" + "    required string e2 = 2;\n" + "    optional double e3 = 3;\n" + "    optional float e4 = 4;\n" + "    /* @Teiid(type=short) */\n" + "    optional int32 e5 = 5;\n" + "    /* @Teiid(type=byte) */\n" + "    optional int32 e6 = 6;\n" + "    /* @Teiid(type=char, length=1) */\n" + "    optional string e7 = 7;\n" + "    optional int64 e8 = 8;\n" + "    /* @Teiid(type=bigdecimal) */\n" + "    optional string e9 = 9;\n" + "    /* @Teiid(type=biginteger) */\n" + "    optional string e10 = 10;\n" + "    /* @Teiid(type=time) */\n" + "    optional int64 e11 = 11;\n" + "    /* @Teiid(type=timestamp) */\n" + "    optional int64 e12 = 12;\n" + "    /* @Teiid(type=date) */\n" + "    optional int64 e13 = 13;\n" + "    /* @Teiid(type=object) */\n" + "    optional bytes e14 = 14;\n" + "    /* @Teiid(type=blob) */\n" + "    optional bytes e15 = 15;\n" + "    /* @Teiid(type=clob) */\n" + "    optional bytes e16 = 16;\n" + "    /* @Teiid(type=xml) */\n" + "    optional bytes e17 = 17;\n" + "    /* @Teiid(type=geometry) */\n" + "    optional bytes e18 = 18;\n" + "}\n" + "\n" + "message pm1.G3 {\n" + "    required int32 e1 = 1;\n" + "    required string e2 = 2;\n" + "}";
    assertEquals(expected, resource.getContents());
}
Also used : MetadataFactory(org.teiid.metadata.MetadataFactory) BasicCache(org.infinispan.commons.api.BasicCache) InfinispanConnection(org.teiid.infinispan.api.InfinispanConnection) ProtobufResource(org.teiid.infinispan.api.ProtobufResource) Test(org.junit.Test)

Example 47 with MetadataFactory

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

the class TestHiveExecutionFactory method testQuoting.

@Test
public void testQuoting() throws Exception {
    HiveMetadataProcessor hmp = new HiveMetadataProcessor();
    Connection c = Mockito.mock(Connection.class);
    MetadataFactory mf = Mockito.mock(MetadataFactory.class);
    Table table = new Table();
    Mockito.stub(mf.addTable("x")).toReturn(table);
    Column col = new Column();
    col.setName("y");
    Mockito.stub(mf.addColumn("y", "string", table)).toReturn(col);
    Statement stmt = Mockito.mock(Statement.class);
    Mockito.stub(c.createStatement()).toReturn(stmt);
    ResultSet rs = Mockito.mock(ResultSet.class);
    Mockito.stub(stmt.executeQuery("SHOW TABLES")).toReturn(rs);
    Mockito.stub(rs.next()).toReturn(true).toReturn(false);
    Mockito.stub(rs.getString(1)).toReturn("x");
    ResultSet rs1 = Mockito.mock(ResultSet.class);
    Mockito.stub(stmt.executeQuery("DESCRIBE x")).toReturn(rs1);
    Mockito.stub(rs1.next()).toReturn(true).toReturn(false);
    Mockito.stub(rs1.getString(1)).toReturn("y");
    Mockito.stub(rs1.getString(2)).toReturn("string");
    hmp.process(mf, c);
    assertEquals("`x`", table.getNameInSource());
    assertEquals("`y`", col.getNameInSource());
}
Also used : Table(org.teiid.metadata.Table) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) Column(org.teiid.metadata.Column) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) Test(org.junit.Test)

Example 48 with MetadataFactory

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

the class MySQLExecutionFactory method getMetadataProcessor.

@Override
public MetadataProcessor<Connection> getMetadataProcessor() {
    return new JDBCMetadataProcessor() {

        @Override
        protected String getRuntimeType(int type, String typeName, int precision) {
            // mysql will otherwise report a 0/null type for geometry
            if ("geometry".equalsIgnoreCase(typeName)) {
                // $NON-NLS-1$
                return TypeFacility.RUNTIME_NAMES.GEOMETRY;
            }
            return super.getRuntimeType(type, typeName, precision);
        }

        @Override
        protected Column addColumn(ResultSet columns, Table table, MetadataFactory metadataFactory, int rsColumns) throws SQLException {
            Column c = super.addColumn(columns, table, metadataFactory, rsColumns);
            if (c.getPrecision() == 0 && "bit".equalsIgnoreCase(c.getNativeType())) {
                // $NON-NLS-1$
                c.setNativeType(TINYINT);
            }
            return c;
        }

        @Override
        protected void getTableStatistics(Connection conn, String catalog, String schema, String name, Table table) throws SQLException {
            PreparedStatement stmt = null;
            ResultSet rs = null;
            try {
                // $NON-NLS-1$
                stmt = conn.prepareStatement("SELECT cardinality FROM INFORMATION_SCHEMA.STATISTICS WHERE table_schema = ? AND table_name = ?");
                if (catalog != null && schema == null) {
                    // mysql jdbc reports the schema as the catalog
                    stmt.setString(1, catalog);
                } else {
                    stmt.setString(1, schema);
                }
                stmt.setString(2, name);
                rs = stmt.executeQuery();
                if (rs.next()) {
                    int cardinality = rs.getInt(1);
                    if (!rs.wasNull()) {
                        table.setCardinality(cardinality);
                    }
                }
            } finally {
                if (rs != null) {
                    rs.close();
                }
                if (stmt != null) {
                    stmt.close();
                }
            }
        }

        @Override
        protected boolean isUnsignedTypeName(String name) {
            if (!name.contains("UNSIGNED")) {
                // $NON-NLS-1$
                return false;
            }
            return super.isUnsignedTypeName(name);
        }
    };
}
Also used : Table(org.teiid.metadata.Table) MetadataFactory(org.teiid.metadata.MetadataFactory) JDBCMetadataProcessor(org.teiid.translator.jdbc.JDBCMetadataProcessor) Column(org.teiid.metadata.Column) ResultSet(java.sql.ResultSet) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Example 49 with MetadataFactory

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

the class TestDynamicImportedMetaData method testUseCatalog.

@Test
public void testUseCatalog() throws Exception {
    MetadataFactory mf = createMetadataFactory("x", new Properties());
    Table dup = mf.addTable("dup");
    mf.addColumn("x", DataTypeManager.DefaultDataTypes.STRING, dup);
    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.useCatalogName", Boolean.FALSE.toString());
    mf = getMetadata(importProperties, conn);
    Table t = mf.asMetadataStore().getSchemas().get("TEST").getTables().get("X.DUP");
    assertEquals("\"x\".\"dup\"", t.getNameInSource());
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) Table(org.teiid.metadata.Table) MetadataFactory(org.teiid.metadata.MetadataFactory) Connection(java.sql.Connection) Properties(java.util.Properties) Test(org.junit.Test)

Example 50 with MetadataFactory

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

the class TestDynamicImportedMetaData method testUseQualified.

@Test
public void testUseQualified() throws Exception {
    MetadataFactory mf = createMetadataFactory("x", new Properties());
    Table dup = mf.addTable("dup");
    mf.addColumn("x", DataTypeManager.DefaultDataTypes.STRING, dup);
    MetadataStore ms = mf.asMetadataStore();
    server.deployVDB("test", ms);
    // $NON-NLS-1$
    Connection conn = server.createConnection("jdbc:teiid:test");
    // neither the name nor name in source should be qualified
    Properties importProperties = new Properties();
    importProperties.setProperty("importer.useQualifiedName", Boolean.FALSE.toString());
    mf = getMetadata(importProperties, conn);
    Table t = mf.asMetadataStore().getSchemas().get("TEST").getTables().get("DUP");
    assertEquals("\"dup\"", t.getNameInSource());
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) Table(org.teiid.metadata.Table) MetadataFactory(org.teiid.metadata.MetadataFactory) Connection(java.sql.Connection) Properties(java.util.Properties) 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