[bug](jdbc) fix trino date/datetime filter (#20443)

When querying Trino's JDBC catalog, if our WHERE filter condition is k1 >= '2022-01-01', this format is incorrect. 
In Trino, the correct format should be k1 >= date '2022-01-01' or k1 >= timestamp '2022-01-01 00:00:00'. 
Therefore, the date string in the WHERE condition needs to be converted to the date or timestamp format supported by Trino.
This commit is contained in:
zy-kkk
2023-06-06 11:20:42 +08:00
committed by GitHub
parent 2fc1141c5f
commit c56eddbfa9

View File

@ -85,6 +85,25 @@ public class OdbcScanNode extends ExternalScanNode {
return filter;
}
}
if (tableType.equals(TOdbcTableType.TRINO) && expr.contains(DateLiteral.class)
&& (expr instanceof BinaryPredicate)) {
ArrayList<Expr> children = expr.getChildren();
if (children.get(1).isConstant() && (children.get(1).getType().isDate()) || children
.get(1).getType().isDateV2()) {
String filter = children.get(0).toSql();
filter += ((BinaryPredicate) expr).getOp().toString();
filter += "date '" + children.get(1).getStringValue() + "'";
return filter;
}
if (children.get(1).isConstant() && (children.get(1).getType().isDatetime() || children
.get(1).getType().isDatetimeV2())) {
String filter = children.get(0).toSql();
filter += ((BinaryPredicate) expr).getOp().toString();
filter += "timestamp '" + children.get(1).getStringValue() + "'";
return filter;
}
}
return expr.toMySql();
}