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.

(improvement)(headless)Optimize compatibility and robustness in ontology query translation.
  • Loading branch information
jerryjzhang committed Mar 5, 2025
1 parent efddf4c commit e0dc3fb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ public List<Expression> parserFilter(ComparisonOperator comparisonOperator, Stri
}

ExpressionList<?> leftFunctionParams = leftFunction.getParameters();
if (CollectionUtils.isEmpty(leftFunctionParams)) {
if (CollectionUtils.isEmpty(leftFunctionParams)
|| !(leftFunctionParams.get(0) instanceof Column)) {
return result;
}

Expand Down
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 e0dc3fb

Please sign in to comment.