snuyanzin commented on code in PR #79:
URL:
https://github.com/apache/flink-connector-jdbc/pull/79#discussion_r1443527603
##########
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)));
Review Comment:
no need to do substring since `append` could append only a part of string
based on provided boundaries e.g.
```java
resolvedCondition.append(
predicate, processingIndex,
indexesOfPredicatePlaceHolders.get(parameterIndex));
```
--
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]