@Test public void testEvalQueryMetadata() { ColumnDesc[] columnDescs = explorer .evalQueryMetadata("select cal_dt, count(*) as cnt from DEFAULT.test_kylin_fact group by cal_dt"); Assert.assertNotNull(columnDescs); Assert.assertEquals(2, columnDescs.length); Assert.assertEquals("date", columnDescs[0].getDatatype()); Assert.assertEquals("CAL_DT", columnDescs[0].getName()); Assert.assertEquals("bigint", columnDescs[1].getDatatype()); Assert.assertEquals("CNT", columnDescs[1].getName()); }
@Override public ColumnDesc[] evalQueryMetadata(String query) { if (StringUtils.isEmpty(query)) { throw new RuntimeException("Evaluate query shall not be empty."); } try (Connection conn = dataSource.getConnection(); Statement state = conn.createStatement(); ResultSet rs = state.executeQuery(dataSource.convertSql(query))) { ResultSetMetaData rsMeta = rs.getMetaData(); ColumnDesc[] columnDescs = new ColumnDesc[rsMeta.getColumnCount()]; for (int i = 0; i < columnDescs.length; i++) { columnDescs[i] = new ColumnDesc(); columnDescs[i].setName(rsMeta.getColumnName(i + 1).toUpperCase(Locale.ROOT)); String kylinType = dataSource.toKylinTypeName(rsMeta.getColumnType(i + 1)); int precision = (SqlUtil.isPrecisionApplicable(kylinType) && rsMeta.getPrecision(i + 1) > 0) ? rsMeta.getPrecision(i + 1) : -1; int scale = (SqlUtil.isScaleApplicable(kylinType) && rsMeta.getScale(i + 1) > 0) ? rsMeta.getScale(i + 1) : -1; columnDescs[i].setDatatype(new DataType(kylinType, precision, scale).toString()); columnDescs[i].setId(String.valueOf(i + 1)); } return columnDescs; } catch (Exception e) { throw new RuntimeException("Cannot evaluate metadata of query: " + query, e); } }
JdbcExplorer implements ISourceMetadataExplorer, ISampleDataDeployer { @Override public ColumnDesc[] evalQueryMetadata(String query) { if (StringUtils.isEmpty(query)) { throw new RuntimeException("Evaluate query shall not be empty."); } try (Connection conn = dataSource.getConnection(); Statement state = conn.createStatement(); ResultSet rs = state.executeQuery(dataSource.convertSql(query))) { ResultSetMetaData rsMeta = rs.getMetaData(); ColumnDesc[] columnDescs = new ColumnDesc[rsMeta.getColumnCount()]; for (int i = 0; i < columnDescs.length; i++) { columnDescs[i] = new ColumnDesc(); columnDescs[i].setName(rsMeta.getColumnName(i + 1).toUpperCase(Locale.ROOT)); String kylinType = dataSource.toKylinTypeName(rsMeta.getColumnType(i + 1)); int precision = (SqlUtil.isPrecisionApplicable(kylinType) && rsMeta.getPrecision(i + 1) > 0) ? rsMeta.getPrecision(i + 1) : -1; int scale = (SqlUtil.isScaleApplicable(kylinType) && rsMeta.getScale(i + 1) > 0) ? rsMeta.getScale(i + 1) : -1; columnDescs[i].setDatatype(new DataType(kylinType, precision, scale).toString()); columnDescs[i].setId(String.valueOf(i + 1)); } return columnDescs; } catch (Exception e) { throw new RuntimeException("Cannot evaluate metadata of query: " + query, e); } } }
JdbcExplorer implements ISourceMetadataExplorer, ISampleDataDeployer { @Override public ColumnDesc[] evalQueryMetadata(String query) { if (StringUtils.isEmpty(query)) { throw new RuntimeException("Evaluate query shall not be empty."); } try (Connection conn = dataSource.getConnection(); Statement state = conn.createStatement(); ResultSet rs = state.executeQuery(dataSource.convertSql(query))) { ResultSetMetaData rsMeta = rs.getMetaData(); ColumnDesc[] columnDescs = new ColumnDesc[rsMeta.getColumnCount()]; for (int i = 0; i < columnDescs.length; i++) { columnDescs[i] = new ColumnDesc(); columnDescs[i].setName(rsMeta.getColumnName(i + 1).toUpperCase(Locale.ROOT)); String kylinType = dataSource.toKylinTypeName(rsMeta.getColumnType(i + 1)); int precision = (SqlUtil.isPrecisionApplicable(kylinType) && rsMeta.getPrecision(i + 1) > 0) ? rsMeta.getPrecision(i + 1) : -1; int scale = (SqlUtil.isScaleApplicable(kylinType) && rsMeta.getScale(i + 1) > 0) ? rsMeta.getScale(i + 1) : -1; columnDescs[i].setDatatype(new DataType(kylinType, precision, scale).toString()); columnDescs[i].setId(String.valueOf(i + 1)); } return columnDescs; } catch (Exception e) { throw new RuntimeException("Cannot evaluate metadata of query: " + query, e); } } JdbcExplorer(JdbcConnector dataSource); }
JdbcExplorer implements ISourceMetadataExplorer, ISampleDataDeployer { @Override public ColumnDesc[] evalQueryMetadata(String query) { if (StringUtils.isEmpty(query)) { throw new RuntimeException("Evaluate query shall not be empty."); } try (Connection conn = dataSource.getConnection(); Statement state = conn.createStatement(); ResultSet rs = state.executeQuery(dataSource.convertSql(query))) { ResultSetMetaData rsMeta = rs.getMetaData(); ColumnDesc[] columnDescs = new ColumnDesc[rsMeta.getColumnCount()]; for (int i = 0; i < columnDescs.length; i++) { columnDescs[i] = new ColumnDesc(); columnDescs[i].setName(rsMeta.getColumnName(i + 1).toUpperCase(Locale.ROOT)); String kylinType = dataSource.toKylinTypeName(rsMeta.getColumnType(i + 1)); int precision = (SqlUtil.isPrecisionApplicable(kylinType) && rsMeta.getPrecision(i + 1) > 0) ? rsMeta.getPrecision(i + 1) : -1; int scale = (SqlUtil.isScaleApplicable(kylinType) && rsMeta.getScale(i + 1) > 0) ? rsMeta.getScale(i + 1) : -1; columnDescs[i].setDatatype(new DataType(kylinType, precision, scale).toString()); columnDescs[i].setId(String.valueOf(i + 1)); } return columnDescs; } catch (Exception e) { throw new RuntimeException("Cannot evaluate metadata of query: " + query, e); } } JdbcExplorer(JdbcConnector dataSource); @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 ColumnDesc[] evalQueryMetadata(String query) { if (StringUtils.isEmpty(query)) { throw new RuntimeException("Evaluate query shall not be empty."); } try (Connection conn = dataSource.getConnection(); Statement state = conn.createStatement(); ResultSet rs = state.executeQuery(dataSource.convertSql(query))) { ResultSetMetaData rsMeta = rs.getMetaData(); ColumnDesc[] columnDescs = new ColumnDesc[rsMeta.getColumnCount()]; for (int i = 0; i < columnDescs.length; i++) { columnDescs[i] = new ColumnDesc(); columnDescs[i].setName(rsMeta.getColumnName(i + 1).toUpperCase(Locale.ROOT)); String kylinType = dataSource.toKylinTypeName(rsMeta.getColumnType(i + 1)); int precision = (SqlUtil.isPrecisionApplicable(kylinType) && rsMeta.getPrecision(i + 1) > 0) ? rsMeta.getPrecision(i + 1) : -1; int scale = (SqlUtil.isScaleApplicable(kylinType) && rsMeta.getScale(i + 1) > 0) ? rsMeta.getScale(i + 1) : -1; columnDescs[i].setDatatype(new DataType(kylinType, precision, scale).toString()); columnDescs[i].setId(String.valueOf(i + 1)); } return columnDescs; } catch (Exception e) { throw new RuntimeException("Cannot evaluate metadata of query: " + query, e); } } JdbcExplorer(JdbcConnector dataSource); @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);  }