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());
}
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());
}
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);
}
};
}
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());
}
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());
}
Aggregations