snuyanzin commented on code in PR #79: URL: https://github.com/apache/flink-connector-jdbc/pull/79#discussion_r1443526792
########## flink-connector-jdbc/src/main/java/org/apache/flink/connector/jdbc/table/JdbcDynamicTableSource.java: ########## @@ -94,30 +97,76 @@ public JdbcDynamicTableSource( @Override public LookupRuntimeProvider getLookupRuntimeProvider(LookupContext context) { - // JDBC only support non-nested look up keys + // JDBC only supports non-nested look up keys String[] keyNames = new String[context.getKeys().length]; + for (int i = 0; i < keyNames.length; i++) { int[] innerKeyArr = context.getKeys()[i]; Preconditions.checkArgument( innerKeyArr.length == 1, "JDBC only support non-nested look up keys"); keyNames[i] = DataType.getFieldNames(physicalRowDataType).get(innerKeyArr[0]); } + final RowType rowType = (RowType) physicalRowDataType.getLogicalType(); + JdbcRowDataLookupFunction lookupFunction = new JdbcRowDataLookupFunction( options, lookupMaxRetryTimes, DataType.getFieldNames(physicalRowDataType).toArray(new String[0]), DataType.getFieldDataTypes(physicalRowDataType).toArray(new DataType[0]), keyNames, - rowType); + rowType, + getResolvedConditions(this.pushdownParameterizedPredicates)); if (cache != null) { return PartialCachingLookupProvider.of(lookupFunction, cache); } else { return LookupFunctionProvider.of(lookupFunction); } } + @VisibleForTesting + protected String[] getResolvedConditions(List<ParameterizedPredicate> parameterizedPredicates) { + String[] conditions = null; + if (parameterizedPredicates != null) { + conditions = new String[parameterizedPredicates.size()]; + + for (int predicateIndex = 0; + predicateIndex < parameterizedPredicates.size(); + predicateIndex++) { + ParameterizedPredicate pushdownParameterizedPredicate = + parameterizedPredicates.get(predicateIndex); + String predicate = pushdownParameterizedPredicate.getPredicate(); + Serializable[] parameters = pushdownParameterizedPredicate.getParameters(); + ArrayList<Integer> indexesOfPredicatePlaceHolders = + pushdownParameterizedPredicate.getIndexesOfPredicatePlaceHolders(); + // build up the resolved condition. + StringBuilder resolvedCondition = new StringBuilder(); + if (parameters == null || parameters.length == 0) { + // no parameter values to resolve (for example when there is a unary + // operation) + resolvedCondition.append(predicate); + } else { + int processingIndex = 0; + for (int parameterIndex = 0; + parameterIndex < parameters.length; + parameterIndex++) { + resolvedCondition.append( + predicate.substring( + processingIndex, + indexesOfPredicatePlaceHolders.get(parameterIndex))); + resolvedCondition.append(parameters[parameterIndex]); + processingIndex = indexesOfPredicatePlaceHolders.get(parameterIndex) + 1; + } + resolvedCondition.append( + predicate.substring(processingIndex, predicate.length())); Review Comment: ```suggestion resolvedCondition.append( predicate.substring(processingIndex)); ``` no need to specify last index if it is end of string -- 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