[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:
@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user