Skip to content

Commit

Permalink
Merge f8fa69f into e984300
Browse files Browse the repository at this point in the history
  • Loading branch information
liuchunhua committed Mar 6, 2024
2 parents e984300 + f8fa69f commit d0bb720
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,8 @@ public List<ParamsOptions> getTables(Integer datasourceId, String database) {
}

tables = metaData.getTables(
database,
getDbSchemaPattern(dataSource.getType(), schema, connectionParam),
getCatalog(dataSource.getType(), database),
getDbSchemaPattern(dataSource.getType(), database, schema, connectionParam),
"%", TABLE_TYPES);
if (null == tables) {
log.error("Get datasource tables error, datasourceId:{}.", datasourceId);
Expand Down Expand Up @@ -499,11 +499,18 @@ public List<ParamsOptions> getTableColumns(Integer datasourceId, String database
}

DatabaseMetaData metaData = connection.getMetaData();

if (dataSource.getType() == DbType.ORACLE) {
database = null;
String schema = null;
try {
schema = metaData.getConnection().getSchema();
} catch (SQLException e) {
log.error("Cant not get the schema, datasourceId:{}.", datasourceId, e);
throw new ServiceException(Status.GET_DATASOURCE_TABLES_ERROR);
}
rs = metaData.getColumns(database, null, tableName, "%");

rs = metaData.getColumns(
getCatalog(dataSource.getType(), database),
getDbSchemaPattern(dataSource.getType(), database, schema, connectionParam),
tableName, "%");
if (rs == null) {
throw new ServiceException(Status.DATASOURCE_CONNECT_FAILED);
}
Expand Down Expand Up @@ -585,7 +592,8 @@ private List<ParamsOptions> getParamsOptions(List<String> columnList) {
return options;
}

private String getDbSchemaPattern(DbType dbType, String schema, BaseConnectionParam connectionParam) {
private String getDbSchemaPattern(DbType dbType, String database, String schema,
BaseConnectionParam connectionParam) {
if (dbType == null) {
return null;
}
Expand All @@ -594,6 +602,9 @@ private String getDbSchemaPattern(DbType dbType, String schema, BaseConnectionPa
case HIVE:
schemaPattern = connectionParam.getDatabase();
break;
case KYUUBI:
schemaPattern = database;
break;
case ORACLE:
schemaPattern = connectionParam.getUser();
if (null != schemaPattern) {
Expand Down Expand Up @@ -636,4 +647,16 @@ private static void closeResult(ResultSet rs) {
}
}

private String getCatalog(DbType dbType, String database) {
String catalog = null;
switch (dbType) {
case KYUUBI:
catalog = "spark_catalog";
break;
default:
catalog = database;
}
return catalog;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public String getDescp() {
}

public boolean isHive() {
return this == DbType.HIVE;
return this == DbType.HIVE || this == DbType.KYUUBI;
}

/**
Expand Down

0 comments on commit d0bb720

Please sign in to comment.