Skip to content

Commit

Permalink
(improvement)(headless)Optimize compatibility and robustness in ontol…
Browse files Browse the repository at this point in the history
…ogy query translation.
  • Loading branch information
jerryjzhang committed Mar 5, 2025
1 parent efddf4c commit f764236
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ public static SqlNode parse(String expression, SqlValidatorScope scope, EngineTy
scope.getValidator().getCatalogReader().getRootSchema(), engineType);
if (Configuration.getSqlAdvisor(sqlValidatorWithHints, engineType).getReservedAndKeyWords()
.contains(expression.toUpperCase())) {
if (engineType == EngineType.HANADB || engineType == EngineType.PRESTO || engineType == EngineType.TRINO) {
if (engineType == EngineType.HANADB || engineType == EngineType.PRESTO
|| engineType == EngineType.TRINO) {
expression = String.format("\"%s\"", expression);
} else {
expression = String.format("`%s`", expression);
Expand Down Expand Up @@ -166,9 +167,9 @@ public static SqlNode getTable(SqlNode sqlNode) {
if (sqlNode instanceof SqlBasicCall) {
SqlBasicCall sqlBasicCall = (SqlBasicCall) sqlNode;
if (sqlBasicCall.getOperator().getKind().equals(SqlKind.AS)) {
if (sqlBasicCall.getOperandList().get(0) instanceof SqlSelect) {
SqlSelect table = (SqlSelect) sqlBasicCall.getOperandList().get(0);
return table;
SqlNode innerQuery = sqlBasicCall.getOperandList().get(0);
if (innerQuery instanceof SqlCall) {
return innerQuery;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,13 @@ public String buildOntologySql(QueryStatement queryStatement) throws Exception {
SqlNode parserNode = tableView.build();
DatabaseResp database = queryStatement.getOntology().getDatabase();
EngineType engineType = EngineType.fromString(database.getType());
parserNode = optimizeParseNode(parserNode, engineType);
try {
parserNode = optimizeParseNode(parserNode, engineType);
} catch (Exception e) {
// failure in optimization phase doesn't affect the query result,
// just ignore it
log.error("optimizeParseNode error", e);
}
return SemanticNode.getSql(parserNode, engineType);
}

Expand Down

0 comments on commit f764236

Please sign in to comment.