davidradl commented on code in PR #79:
URL:
https://github.com/apache/flink-connector-jdbc/pull/79#discussion_r1438684576
##########
flink-connector-jdbc/src/main/java/org/apache/flink/connector/jdbc/table/JdbcDynamicTableSource.java:
##########
@@ -96,28 +97,115 @@ public JdbcDynamicTableSource(
public LookupRuntimeProvider getLookupRuntimeProvider(LookupContext
context) {
// JDBC only support 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();
+
+ String[] conditions = null;
+
+ if (this.resolvedPredicates != null) {
+ conditions = new String[this.resolvedPredicates.size()];
+ int processedPushdownParamsIndex = 0;
+ for (int i = 0; i < this.resolvedPredicates.size(); i++) {
+ String resolvedPredicate = this.resolvedPredicates.get(i);
+
+ /*
+ * This replace seems like it should be using a Flink class to
resolve the parameter. It does not
+ * effect the dialects as the placeholder comes from
JdbcFilterPushdownPreparedStatementVisitor.
+ *
+ * Here is what has been considered as alternatives.
+ *
+ * We cannot use the way this is done in
getScanRuntimeProvider, as the index we have is the index
+ * into the filters, but it needs the index into the fields.
For example one lookup key and one filter
+ * would both have an index of 0, which the subsequent code
would incorrectly resolve to the first
+ * field.
+ * We cannot use the PreparedStatement as we have not got
access to the statement here.
+ * We cannot use ParameterizedPredicate as it takes the filter
expression as input (e.g EQUALS(...)
+ * not the form we have here an example would be ('field1'= ?).
+ *
+ * An entry in the resolvedPredicates list may have more than
one associated pushdown parameter, for example
+ * a query like this : ... on e.type = 2 and (e.age = 50 OR
height > 90) and a.ip = e.ip;
+ * will have 2 resolvedPredicates and 3 pushdownParams. The
2nd and 3rd pushdownParams will be for the second
+ * resolvedPredicate.
+ *
+ */
+ ArrayList<String> paramsForThisPredicate = new ArrayList();
+ char placeholderChar =
+
JdbcFilterPushdownPreparedStatementVisitor.PUSHDOWN_PREDICATE_PLACEHOLDER
+ .charAt(0);
+
+ int count =
+ (int) resolvedPredicate.chars().filter(ch -> ch ==
placeholderChar).count();
+
+ for (int j = processedPushdownParamsIndex;
+ j < processedPushdownParamsIndex + count;
+ j++) {
+
paramsForThisPredicate.add(this.pushdownParams[j].toString());
+ }
+ processedPushdownParamsIndex = processedPushdownParamsIndex +
count;
Review Comment:
@snuyanzin Yes I had not thought of that. I have reviewed this. I see 2
options I am looking to explore:
1. amend the string processing to cope with the scenario you have
highlighted. This is tricky as I will need to parse the string looking for
simple binary operators and OR operators that link many simple expressions,
when there might be quote in the column names. This seems overly complicated
and fragile.
2. Investigate whether I can change how `this.pushdownParams` and
`this.resolvedPredicates` are populated or add more instance variables - so
they can be simply processed without complex string logic.
3. remove the pushdown capability from this connector to enable the release.
I think this is looking more attractive as the pragmatic approach, given what
we are seeing.
I hope 2. will be fruitful.
--
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]