snuyanzin commented on code in PR #79:
URL:
https://github.com/apache/flink-connector-jdbc/pull/79#discussion_r1443547398
##########
flink-connector-jdbc/src/main/java/org/apache/flink/connector/jdbc/table/ParameterizedPredicate.java:
##########
@@ -52,8 +69,26 @@ public void setPredicate(String predicate) {
}
public ParameterizedPredicate combine(String operator,
ParameterizedPredicate that) {
+ int paramIndex = String.format("(%s %s ", this.predicate,
operator).length();
+ if (!that.indexesOfPredicatePlaceHolders.isEmpty()) {
+ paramIndex = paramIndex +
that.indexesOfPredicatePlaceHolders.get(0);
+ }
+
this.predicate = String.format("(%s %s %s)", this.predicate, operator,
that.predicate);
this.parameters = ArrayUtils.addAll(this.parameters, that.parameters);
+
+ for (int i = 0; i < this.indexesOfPredicatePlaceHolders.size(); i++) {
+ // increment all the existing indexes to account for the new
additional first begin
+ // bracket
+ this.indexesOfPredicatePlaceHolders.set(
+ i, this.indexesOfPredicatePlaceHolders.get(i) + 1);
+ }
+ if (that.predicate.equals(
+
JdbcFilterPushdownPreparedStatementVisitor.PUSHDOWN_PREDICATE_PLACEHOLDER)
+ || (!that.indexesOfPredicatePlaceHolders.isEmpty())) {
+ // add index if that is a placeholder or has a placeholder.
+ this.indexesOfPredicatePlaceHolders.add(paramIndex);
+ }
Review Comment:
Also I tend to think that approach with indexes will not work because
between finding indexes and building `resolvedConditions` there is an optimizer
which could change SQL a bit
example of query where such change happens
```sql
"SELECT * FROM a left join d FOR SYSTEM_TIME AS OF a.proctime on ((d.age =
50 AND d.type = 0) OR (d.type = 1 AND d.age =40)) and a.ip = d.ip"
```
##########
flink-connector-jdbc/src/main/java/org/apache/flink/connector/jdbc/table/ParameterizedPredicate.java:
##########
@@ -52,8 +69,26 @@ public void setPredicate(String predicate) {
}
public ParameterizedPredicate combine(String operator,
ParameterizedPredicate that) {
+ int paramIndex = String.format("(%s %s ", this.predicate,
operator).length();
+ if (!that.indexesOfPredicatePlaceHolders.isEmpty()) {
+ paramIndex = paramIndex +
that.indexesOfPredicatePlaceHolders.get(0);
+ }
+
this.predicate = String.format("(%s %s %s)", this.predicate, operator,
that.predicate);
this.parameters = ArrayUtils.addAll(this.parameters, that.parameters);
+
+ for (int i = 0; i < this.indexesOfPredicatePlaceHolders.size(); i++) {
+ // increment all the existing indexes to account for the new
additional first begin
+ // bracket
+ this.indexesOfPredicatePlaceHolders.set(
+ i, this.indexesOfPredicatePlaceHolders.get(i) + 1);
+ }
+ if (that.predicate.equals(
+
JdbcFilterPushdownPreparedStatementVisitor.PUSHDOWN_PREDICATE_PLACEHOLDER)
+ || (!that.indexesOfPredicatePlaceHolders.isEmpty())) {
+ // add index if that is a placeholder or has a placeholder.
+ this.indexesOfPredicatePlaceHolders.add(paramIndex);
+ }
Review Comment:
Also I tend to think that approach with indexes will not work because
between finding indexes and building `resolvedConditions` there is an optimizer
which could change SQL a bit
example of query where such change happens
```sql
SELECT * FROM a left join d FOR SYSTEM_TIME AS OF a.proctime on ((d.age = 50
AND d.type = 0) OR (d.type = 1 AND d.age =40)) and a.ip = d.ip;
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]