snuyanzin commented on code in PR #79:
URL: 
https://github.com/apache/flink-connector-jdbc/pull/79#discussion_r1443523454


##########
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:
   This will not work for cases when constant on the left side e.g.
   ```sql
       @Test
       public void test123() {
           util.verifyExecPlan(
                   "SELECT * FROM a left join d FOR SYSTEM_TIME AS OF 
a.proctime on (50 = d.age OR 1 = d.type)  and a.ip = d.ip");
       }
   ```
   this test will fail with 
   ```
   Caused by: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
        at java.util.ArrayList.rangeCheck(ArrayList.java:659)
        at java.util.ArrayList.get(ArrayList.java:435)
        at 
org.apache.flink.connector.jdbc.table.JdbcDynamicTableSource.getResolvedConditions(JdbcDynamicTableSource.java:157)
        at 
org.apache.flink.connector.jdbc.table.JdbcDynamicTableSource.getLookupRuntimeProvider(JdbcDynamicTableSource.java:120)
        at 
org.apache.flink.table.planner.plan.utils.LookupJoinUtil.createLookupRuntimeProvider(LookupJoinUtil.java:626)
        at 
org.apache.flink.table.planner.plan.utils.LookupJoinUtil.isAsyncLookup(LookupJoinUtil.java:413)
   ```
   



-- 
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: issues-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to