Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, "%");

Check failure

Code scanning / CodeQL

Query built from user-controlled sources

This query depends on a [user-provided value](1).
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May I ask why KYUUBI is also true in isHive()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

KYUUBI use spark engine to query hive table by default, using HiveReader is better.

}

/**
Expand Down