Skip to content

Commit

Permalink
add version check
Browse files Browse the repository at this point in the history
  • Loading branch information
cdmikechen committed Oct 29, 2024
1 parent 1f04cb7 commit 3b241e6
Showing 1 changed file with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ public ResultSet getTables(String catalog, String schemaPattern, String tableNam
buildFilters(sql, filters);
sql.append("\nORDER BY table_type, table_catalog, table_schema, table_name");

if (types == null || types.length == 0 || Arrays.stream(types).allMatch(t -> t.equalsIgnoreCase("VIEW"))) {
if (checkVersionAddView() && types != null && Arrays.stream(types).allMatch(t -> t.equalsIgnoreCase("VIEW"))) {
// add view
sql.append("\n union all ");
sql.append("\nselect database TABLE_CAT, database TABLE_SCHEM, name TABLE_NAME, 'VIEW' TABLE_TYPE, null REMARKS, ");
Expand All @@ -899,6 +899,24 @@ public ResultSet getTables(String catalog, String schemaPattern, String tableNam
return select(sql.toString());
}

// This handles bug that existed a while, views were not included in information_schema.tables
// https://github.com/datafuselabs/databend/issues/16039
private boolean checkVersionAddView() throws SQLException {
// the same fix for python-sdk
// https://github.com/databendlabs/databend-sqlalchemy/blob/3226f10e0f8b6aa85185208583977037b33ec99f/databend_sqlalchemy/databend_dialect.py#L819
String version = getDatabaseProductVersion();
Pattern pattern = Pattern.compile("v(\\d+)\\.(\\d+)\\.(\\d+)");
Matcher matcher = pattern.matcher(version);
if (matcher.find()) {
// > 1.2.410 and <= 1.2.566
if (Integer.parseInt(matcher.group(1)) != 1) return false;
if (Integer.parseInt(matcher.group(2)) != 2) return false;
int minorVersion = Integer.parseInt(matcher.group(3));
return minorVersion > 410 && minorVersion <= 566;
}
return false;
}

@Override
public ResultSet getSchemas()
throws SQLException {
Expand Down

0 comments on commit 3b241e6

Please sign in to comment.