Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix-15668][Api]Fix data quality cannot get database/columns with kyuubi #15671

Closed
wants to merge 2 commits into from
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 @@
}

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 @@
}

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 High

This query depends on a
user-provided value
.
if (rs == null) {
throw new ServiceException(Status.DATASOURCE_CONNECT_FAILED);
}
Expand Down Expand Up @@ -585,7 +592,8 @@
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 @@
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 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
Loading