@Test public void testTableWithoutColumns() throws TranslatorException { MongoDBMetadataProcessor mp = new MongoDBMetadataProcessor(); 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); LinkedHashSet<String> tables = new LinkedHashSet<String>(); tables.add("table"); DB db = Mockito.mock(DB.class); BasicDBObject row = new BasicDBObject(); row.append("col", new BasicDBObject()); Mockito.stub(db.getCollectionNames()).toReturn(tables); Mockito.stub(db.getCollection(Mockito.eq("table"))).toReturn(tableDBCollection); 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); Mockito.stub(conn.getDatabase()).toReturn(db); mp.process(mf, conn); String metadataDDL = DDLStringVisitor.getDDLString(mf.getSchema(), null, null); String expected = ""; assertEquals(expected, metadataDDL); }
@Override public void process(MetadataFactory metadataFactory, MongoDBConnection connection) throws TranslatorException { DB db = connection.getDatabase(); for (String tableName:db.getCollectionNames()) { if (getExcludeTables() != null && shouldExclude(tableName)) { continue; } if (getIncludeTables() != null && !shouldInclude(tableName)) { continue; } try { DBCollection collection = db.getCollection(tableName); DBCursor cursor = collection.find(); while(cursor.hasNext()) { BasicDBObject row = (BasicDBObject)cursor.next(); if (row == null) { continue; } Table table = addTable(metadataFactory, tableName, row, null); if (table != null) { table.setProperty(TOP_LEVEL_DOC, String.valueOf(Boolean.TRUE)); } if (cursor.numSeen() >= sampleSize) { break; } } cursor.close(); } catch (MongoException e) { LogManager.logWarning(LogConstants.CTX_CONNECTOR, MongoDBPlugin.Util.gs(MongoDBPlugin.Event.TEIID18037, e)); } } for (Table table:metadataFactory.getSchema().getTables().values()) { String merge = table.getProperty(MERGE, false); if (merge != null) { addForeignKey(metadataFactory, table, metadataFactory.getSchema().getTable(merge)); } } for (Table table:metadataFactory.getSchema().getTables().values()) { String top = table.getProperty(TOP_LEVEL_DOC, false); String merge = table.getProperty(MERGE, false); if ( top != null) { table.setProperty(TOP_LEVEL_DOC, null); if (merge != null) { table.setProperty(MERGE, null); table.setProperty(EMBEDDABLE, "true"); } } } for (Table table : new HashSet<Table>(metadataFactory.getSchema().getTables().values())) { if (table.isPhysical() && (table.getColumns() == null || table.getColumns().isEmpty())) { metadataFactory.getSchema().removeTable(table.getName()); } } }
MongoDBMetadataProcessor implements MetadataProcessor<MongoDBConnection> { @Override public void process(MetadataFactory metadataFactory, MongoDBConnection connection) throws TranslatorException { DB db = connection.getDatabase(); for (String tableName:db.getCollectionNames()) { if (getExcludeTables() != null && shouldExclude(tableName)) { continue; } if (getIncludeTables() != null && !shouldInclude(tableName)) { continue; } try { DBCollection collection = db.getCollection(tableName); DBCursor cursor = collection.find(); while(cursor.hasNext()) { BasicDBObject row = (BasicDBObject)cursor.next(); if (row == null) { continue; } Table table = addTable(metadataFactory, tableName, row, null); if (table != null) { table.setProperty(TOP_LEVEL_DOC, String.valueOf(Boolean.TRUE)); } if (cursor.numSeen() >= sampleSize) { break; } } cursor.close(); } catch (MongoException e) { LogManager.logWarning(LogConstants.CTX_CONNECTOR, MongoDBPlugin.Util.gs(MongoDBPlugin.Event.TEIID18037, e)); } } for (Table table:metadataFactory.getSchema().getTables().values()) { String merge = table.getProperty(MERGE, false); if (merge != null) { addForeignKey(metadataFactory, table, metadataFactory.getSchema().getTable(merge)); } } for (Table table:metadataFactory.getSchema().getTables().values()) { String top = table.getProperty(TOP_LEVEL_DOC, false); String merge = table.getProperty(MERGE, false); if ( top != null) { table.setProperty(TOP_LEVEL_DOC, null); if (merge != null) { table.setProperty(MERGE, null); table.setProperty(EMBEDDABLE, "true"); } } } for (Table table : new HashSet<Table>(metadataFactory.getSchema().getTables().values())) { if (table.isPhysical() && (table.getColumns() == null || table.getColumns().isEmpty())) { metadataFactory.getSchema().removeTable(table.getName()); } } } }
MongoDBMetadataProcessor implements MetadataProcessor<MongoDBConnection> { @Override public void process(MetadataFactory metadataFactory, MongoDBConnection connection) throws TranslatorException { DB db = connection.getDatabase(); for (String tableName:db.getCollectionNames()) { if (getExcludeTables() != null && shouldExclude(tableName)) { continue; } if (getIncludeTables() != null && !shouldInclude(tableName)) { continue; } try { DBCollection collection = db.getCollection(tableName); DBCursor cursor = collection.find(); while(cursor.hasNext()) { BasicDBObject row = (BasicDBObject)cursor.next(); if (row == null) { continue; } Table table = addTable(metadataFactory, tableName, row, null); if (table != null) { table.setProperty(TOP_LEVEL_DOC, String.valueOf(Boolean.TRUE)); } if (cursor.numSeen() >= sampleSize) { break; } } cursor.close(); } catch (MongoException e) { LogManager.logWarning(LogConstants.CTX_CONNECTOR, MongoDBPlugin.Util.gs(MongoDBPlugin.Event.TEIID18037, e)); } } for (Table table:metadataFactory.getSchema().getTables().values()) { String merge = table.getProperty(MERGE, false); if (merge != null) { addForeignKey(metadataFactory, table, metadataFactory.getSchema().getTable(merge)); } } for (Table table:metadataFactory.getSchema().getTables().values()) { String top = table.getProperty(TOP_LEVEL_DOC, false); String merge = table.getProperty(MERGE, false); if ( top != null) { table.setProperty(TOP_LEVEL_DOC, null); if (merge != null) { table.setProperty(MERGE, null); table.setProperty(EMBEDDABLE, "true"); } } } for (Table table : new HashSet<Table>(metadataFactory.getSchema().getTables().values())) { if (table.isPhysical() && (table.getColumns() == null || table.getColumns().isEmpty())) { metadataFactory.getSchema().removeTable(table.getName()); } } }  }
MongoDBMetadataProcessor implements MetadataProcessor<MongoDBConnection> { @Override public void process(MetadataFactory metadataFactory, MongoDBConnection connection) throws TranslatorException { DB db = connection.getDatabase(); for (String tableName:db.getCollectionNames()) { if (getExcludeTables() != null && shouldExclude(tableName)) { continue; } if (getIncludeTables() != null && !shouldInclude(tableName)) { continue; } try { DBCollection collection = db.getCollection(tableName); DBCursor cursor = collection.find(); while(cursor.hasNext()) { BasicDBObject row = (BasicDBObject)cursor.next(); if (row == null) { continue; } Table table = addTable(metadataFactory, tableName, row, null); if (table != null) { table.setProperty(TOP_LEVEL_DOC, String.valueOf(Boolean.TRUE)); } if (cursor.numSeen() >= sampleSize) { break; } } cursor.close(); } catch (MongoException e) { LogManager.logWarning(LogConstants.CTX_CONNECTOR, MongoDBPlugin.Util.gs(MongoDBPlugin.Event.TEIID18037, e)); } } for (Table table:metadataFactory.getSchema().getTables().values()) { String merge = table.getProperty(MERGE, false); if (merge != null) { addForeignKey(metadataFactory, table, metadataFactory.getSchema().getTable(merge)); } } for (Table table:metadataFactory.getSchema().getTables().values()) { String top = table.getProperty(TOP_LEVEL_DOC, false); String merge = table.getProperty(MERGE, false); if ( top != null) { table.setProperty(TOP_LEVEL_DOC, null); if (merge != null) { table.setProperty(MERGE, null); table.setProperty(EMBEDDABLE, "true"); } } } for (Table table : new HashSet<Table>(metadataFactory.getSchema().getTables().values())) { if (table.isPhysical() && (table.getColumns() == null || table.getColumns().isEmpty())) { metadataFactory.getSchema().removeTable(table.getName()); } } }  @Override void process(MetadataFactory metadataFactory, MongoDBConnection connection); @TranslatorProperty(display="Exclude Tables", category=PropertyType.IMPORT, description="A case-insensitive regular expression that when matched against a fully qualified Teiid table name will exclude it from import. Applied after table names are retrieved. Use a negative look-ahead (?!<inclusion pattern>).* to act as an inclusion filter.") String getExcludeTables(); void setExcludeTables(String excludeTables); @TranslatorProperty(display="Include Tables", category=PropertyType.IMPORT, description="A case-insensitive regular expression that when matched against a fully qualified Teiid table name will include it from import. Applied after table names are retrieved. Use a negative look-ahead (?!<inclusion pattern>).* to act as an exclusion filter") String getIncludeTables(); void setIncludeTables(String tableNamePattern); @TranslatorProperty(display="Sample Size", category=PropertyType.IMPORT, description="The number of top level documents of a given collection name to sample.") int getSampleSize(); void setSampleSize(int sampleSize); @TranslatorProperty(display="Full Embedded Names", category=PropertyType.IMPORT, description="Whether to prefix embedded table names with their parents, e.g. parent_embedded") boolean isFullEmbeddedNames(); void setFullEmbeddedNames(boolean fullEmbeddedNames); }
MongoDBMetadataProcessor implements MetadataProcessor<MongoDBConnection> { @Override public void process(MetadataFactory metadataFactory, MongoDBConnection connection) throws TranslatorException { DB db = connection.getDatabase(); for (String tableName:db.getCollectionNames()) { if (getExcludeTables() != null && shouldExclude(tableName)) { continue; } if (getIncludeTables() != null && !shouldInclude(tableName)) { continue; } try { DBCollection collection = db.getCollection(tableName); DBCursor cursor = collection.find(); while(cursor.hasNext()) { BasicDBObject row = (BasicDBObject)cursor.next(); if (row == null) { continue; } Table table = addTable(metadataFactory, tableName, row, null); if (table != null) { table.setProperty(TOP_LEVEL_DOC, String.valueOf(Boolean.TRUE)); } if (cursor.numSeen() >= sampleSize) { break; } } cursor.close(); } catch (MongoException e) { LogManager.logWarning(LogConstants.CTX_CONNECTOR, MongoDBPlugin.Util.gs(MongoDBPlugin.Event.TEIID18037, e)); } } for (Table table:metadataFactory.getSchema().getTables().values()) { String merge = table.getProperty(MERGE, false); if (merge != null) { addForeignKey(metadataFactory, table, metadataFactory.getSchema().getTable(merge)); } } for (Table table:metadataFactory.getSchema().getTables().values()) { String top = table.getProperty(TOP_LEVEL_DOC, false); String merge = table.getProperty(MERGE, false); if ( top != null) { table.setProperty(TOP_LEVEL_DOC, null); if (merge != null) { table.setProperty(MERGE, null); table.setProperty(EMBEDDABLE, "true"); } } } for (Table table : new HashSet<Table>(metadataFactory.getSchema().getTables().values())) { if (table.isPhysical() && (table.getColumns() == null || table.getColumns().isEmpty())) { metadataFactory.getSchema().removeTable(table.getName()); } } }  @Override void process(MetadataFactory metadataFactory, MongoDBConnection connection); @TranslatorProperty(display="Exclude Tables", category=PropertyType.IMPORT, description="A case-insensitive regular expression that when matched against a fully qualified Teiid table name will exclude it from import. Applied after table names are retrieved. Use a negative look-ahead (?!<inclusion pattern>).* to act as an inclusion filter.") String getExcludeTables(); void setExcludeTables(String excludeTables); @TranslatorProperty(display="Include Tables", category=PropertyType.IMPORT, description="A case-insensitive regular expression that when matched against a fully qualified Teiid table name will include it from import. Applied after table names are retrieved. Use a negative look-ahead (?!<inclusion pattern>).* to act as an exclusion filter") String getIncludeTables(); void setIncludeTables(String tableNamePattern); @TranslatorProperty(display="Sample Size", category=PropertyType.IMPORT, description="The number of top level documents of a given collection name to sample.") int getSampleSize(); void setSampleSize(int sampleSize); @TranslatorProperty(display="Full Embedded Names", category=PropertyType.IMPORT, description="Whether to prefix embedded table names with their parents, e.g. parent_embedded") boolean isFullEmbeddedNames(); void setFullEmbeddedNames(boolean fullEmbeddedNames); @ExtensionMetadataProperty(applicable=Table.class, datatype=String.class, display="Merge Into Table", description="Declare the name of table that this table needs to be merged into. No separate copy maintained")
    static final String MERGE; @ExtensionMetadataProperty(applicable=Table.class, datatype=String.class, display="Embedded Into Table", description="Declare the name of table that this table needs to be embedded into. A separate copy is also maintained")
    static final String EMBEDDABLE; }