@Test public void testLoadTableMetadata() throws SQLException { String tableName = "tb1"; String databaseName = "testdb"; ResultSet rs1 = mock(ResultSet.class); when(rs1.next()).thenReturn(true).thenReturn(false); when(rs1.getString("TABLE_TYPE")).thenReturn("TABLE"); ResultSet rs2 = mock(ResultSet.class); when(rs2.next()).thenReturn(true).thenReturn(true).thenReturn(true).thenReturn(false); when(rs2.getString("COLUMN_NAME")).thenReturn("COL1").thenReturn("COL2").thenReturn("COL3"); when(rs2.getInt("DATA_TYPE")).thenReturn(Types.VARCHAR).thenReturn(Types.INTEGER).thenReturn(Types.DECIMAL); when(rs2.getInt("COLUMN_SIZE")).thenReturn(128).thenReturn(10).thenReturn(19); when(rs2.getInt("DECIMAL_DIGITS")).thenReturn(0).thenReturn(0).thenReturn(4); when(rs2.getInt("ORDINAL_POSITION")).thenReturn(1).thenReturn(3).thenReturn(2); when(rs2.getString("REMARKS")).thenReturn("comment1").thenReturn("comment2").thenReturn("comment3"); when(jdbcMetadata.getTable(dbmd, databaseName, tableName)).thenReturn(rs1); when(jdbcMetadata.listColumns(dbmd, databaseName, tableName)).thenReturn(rs2); Pair<TableDesc, TableExtDesc> result = jdbcExplorer.loadTableMetadata(databaseName, tableName, "proj"); TableDesc tableDesc = result.getFirst(); ColumnDesc columnDesc = tableDesc.getColumns()[1]; Assert.assertEquals(databaseName.toUpperCase(Locale.ROOT), tableDesc.getDatabase()); Assert.assertEquals(3, tableDesc.getColumnCount()); Assert.assertEquals("TABLE", tableDesc.getTableType()); Assert.assertEquals("COL2", columnDesc.getName()); Assert.assertEquals("integer", columnDesc.getTypeName()); Assert.assertEquals("comment2", columnDesc.getComment()); Assert.assertEquals(databaseName.toUpperCase(Locale.ROOT) + "." + tableName.toUpperCase(Locale.ROOT), result.getSecond().getIdentity()); }
@Override public Pair<TableDesc, TableExtDesc> loadTableMetadata(String database, String table, String prj) throws SQLException { TableDesc tableDesc = new TableDesc(); tableDesc.setDatabase(database.toUpperCase(Locale.ROOT)); tableDesc.setName(table.toUpperCase(Locale.ROOT)); tableDesc.setUuid(RandomUtil.randomUUID().toString()); tableDesc.setLastModified(0); tableDesc.setSourceType(ISourceAware.ID_JDBC); Connection con = SqlUtil.getConnection(dbconf); DatabaseMetaData dbmd = con.getMetaData(); try (ResultSet rs = jdbcMetadataDialect.getTable(dbmd, database, table)) { String tableType = null; while (rs.next()) { tableType = rs.getString("TABLE_TYPE"); } if (tableType != null) { tableDesc.setTableType(tableType); } else { throw new RuntimeException( String.format(Locale.ROOT, "table %s not found in schema:%s", table, database)); } } try (ResultSet rs = jdbcMetadataDialect.listColumns(dbmd, database, table)) { tableDesc.setColumns(extractColumnFromMeta(rs)); } finally { DBUtils.closeQuietly(con); } TableExtDesc tableExtDesc = new TableExtDesc(); tableExtDesc.setIdentity(tableDesc.getIdentity()); tableExtDesc.setUuid(RandomUtil.randomUUID().toString()); tableExtDesc.setLastModified(0); tableExtDesc.init(prj); return Pair.newPair(tableDesc, tableExtDesc); }
JdbcExplorer implements ISourceMetadataExplorer, ISampleDataDeployer { @Override public Pair<TableDesc, TableExtDesc> loadTableMetadata(String database, String table, String prj) throws SQLException { TableDesc tableDesc = new TableDesc(); tableDesc.setDatabase(database.toUpperCase(Locale.ROOT)); tableDesc.setName(table.toUpperCase(Locale.ROOT)); tableDesc.setUuid(RandomUtil.randomUUID().toString()); tableDesc.setLastModified(0); tableDesc.setSourceType(ISourceAware.ID_JDBC); Connection con = SqlUtil.getConnection(dbconf); DatabaseMetaData dbmd = con.getMetaData(); try (ResultSet rs = jdbcMetadataDialect.getTable(dbmd, database, table)) { String tableType = null; while (rs.next()) { tableType = rs.getString("TABLE_TYPE"); } if (tableType != null) { tableDesc.setTableType(tableType); } else { throw new RuntimeException( String.format(Locale.ROOT, "table %s not found in schema:%s", table, database)); } } try (ResultSet rs = jdbcMetadataDialect.listColumns(dbmd, database, table)) { tableDesc.setColumns(extractColumnFromMeta(rs)); } finally { DBUtils.closeQuietly(con); } TableExtDesc tableExtDesc = new TableExtDesc(); tableExtDesc.setIdentity(tableDesc.getIdentity()); tableExtDesc.setUuid(RandomUtil.randomUUID().toString()); tableExtDesc.setLastModified(0); tableExtDesc.init(prj); return Pair.newPair(tableDesc, tableExtDesc); } }
JdbcExplorer implements ISourceMetadataExplorer, ISampleDataDeployer { @Override public Pair<TableDesc, TableExtDesc> loadTableMetadata(String database, String table, String prj) throws SQLException { TableDesc tableDesc = new TableDesc(); tableDesc.setDatabase(database.toUpperCase(Locale.ROOT)); tableDesc.setName(table.toUpperCase(Locale.ROOT)); tableDesc.setUuid(RandomUtil.randomUUID().toString()); tableDesc.setLastModified(0); tableDesc.setSourceType(ISourceAware.ID_JDBC); Connection con = SqlUtil.getConnection(dbconf); DatabaseMetaData dbmd = con.getMetaData(); try (ResultSet rs = jdbcMetadataDialect.getTable(dbmd, database, table)) { String tableType = null; while (rs.next()) { tableType = rs.getString("TABLE_TYPE"); } if (tableType != null) { tableDesc.setTableType(tableType); } else { throw new RuntimeException( String.format(Locale.ROOT, "table %s not found in schema:%s", table, database)); } } try (ResultSet rs = jdbcMetadataDialect.listColumns(dbmd, database, table)) { tableDesc.setColumns(extractColumnFromMeta(rs)); } finally { DBUtils.closeQuietly(con); } TableExtDesc tableExtDesc = new TableExtDesc(); tableExtDesc.setIdentity(tableDesc.getIdentity()); tableExtDesc.setUuid(RandomUtil.randomUUID().toString()); tableExtDesc.setLastModified(0); tableExtDesc.init(prj); return Pair.newPair(tableDesc, tableExtDesc); } @Deprecated  JdbcExplorer();  JdbcExplorer(KylinConfig config); }
JdbcExplorer implements ISourceMetadataExplorer, ISampleDataDeployer { @Override public Pair<TableDesc, TableExtDesc> loadTableMetadata(String database, String table, String prj) throws SQLException { TableDesc tableDesc = new TableDesc(); tableDesc.setDatabase(database.toUpperCase(Locale.ROOT)); tableDesc.setName(table.toUpperCase(Locale.ROOT)); tableDesc.setUuid(RandomUtil.randomUUID().toString()); tableDesc.setLastModified(0); tableDesc.setSourceType(ISourceAware.ID_JDBC); Connection con = SqlUtil.getConnection(dbconf); DatabaseMetaData dbmd = con.getMetaData(); try (ResultSet rs = jdbcMetadataDialect.getTable(dbmd, database, table)) { String tableType = null; while (rs.next()) { tableType = rs.getString("TABLE_TYPE"); } if (tableType != null) { tableDesc.setTableType(tableType); } else { throw new RuntimeException( String.format(Locale.ROOT, "table %s not found in schema:%s", table, database)); } } try (ResultSet rs = jdbcMetadataDialect.listColumns(dbmd, database, table)) { tableDesc.setColumns(extractColumnFromMeta(rs)); } finally { DBUtils.closeQuietly(con); } TableExtDesc tableExtDesc = new TableExtDesc(); tableExtDesc.setIdentity(tableDesc.getIdentity()); tableExtDesc.setUuid(RandomUtil.randomUUID().toString()); tableExtDesc.setLastModified(0); tableExtDesc.init(prj); return Pair.newPair(tableDesc, tableExtDesc); } @Deprecated  JdbcExplorer();  JdbcExplorer(KylinConfig config); @Override List<String> listDatabases(); @Override List<String> listTables(String schema); @Override Pair<TableDesc, TableExtDesc> loadTableMetadata(String database, String table, String prj); @Override void createSampleDatabase(String database); @Override void loadSampleData(String tableName, String tmpDataDir); @Override void createSampleTable(TableDesc table); @Override void createWrapperView(String origTableName, String viewName); @Override List<String> getRelatedKylinResources(TableDesc table); @Override ColumnDesc[] evalQueryMetadata(String query); @Override void validateSQL(String query); }
JdbcExplorer implements ISourceMetadataExplorer, ISampleDataDeployer { @Override public Pair<TableDesc, TableExtDesc> loadTableMetadata(String database, String table, String prj) throws SQLException { TableDesc tableDesc = new TableDesc(); tableDesc.setDatabase(database.toUpperCase(Locale.ROOT)); tableDesc.setName(table.toUpperCase(Locale.ROOT)); tableDesc.setUuid(RandomUtil.randomUUID().toString()); tableDesc.setLastModified(0); tableDesc.setSourceType(ISourceAware.ID_JDBC); Connection con = SqlUtil.getConnection(dbconf); DatabaseMetaData dbmd = con.getMetaData(); try (ResultSet rs = jdbcMetadataDialect.getTable(dbmd, database, table)) { String tableType = null; while (rs.next()) { tableType = rs.getString("TABLE_TYPE"); } if (tableType != null) { tableDesc.setTableType(tableType); } else { throw new RuntimeException( String.format(Locale.ROOT, "table %s not found in schema:%s", table, database)); } } try (ResultSet rs = jdbcMetadataDialect.listColumns(dbmd, database, table)) { tableDesc.setColumns(extractColumnFromMeta(rs)); } finally { DBUtils.closeQuietly(con); } TableExtDesc tableExtDesc = new TableExtDesc(); tableExtDesc.setIdentity(tableDesc.getIdentity()); tableExtDesc.setUuid(RandomUtil.randomUUID().toString()); tableExtDesc.setLastModified(0); tableExtDesc.init(prj); return Pair.newPair(tableDesc, tableExtDesc); } @Deprecated  JdbcExplorer();  JdbcExplorer(KylinConfig config); @Override List<String> listDatabases(); @Override List<String> listTables(String schema); @Override Pair<TableDesc, TableExtDesc> loadTableMetadata(String database, String table, String prj); @Override void createSampleDatabase(String database); @Override void loadSampleData(String tableName, String tmpDataDir); @Override void createSampleTable(TableDesc table); @Override void createWrapperView(String origTableName, String viewName); @Override List<String> getRelatedKylinResources(TableDesc table); @Override ColumnDesc[] evalQueryMetadata(String query); @Override void validateSQL(String query);  }