davidradl commented on code in PR #79:
URL:
https://github.com/apache/flink-connector-jdbc/pull/79#discussion_r1440284858
##########
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:
I am thinking that I should save the left right and operation in the
visitor. I hope to construct a list of simple binary predicates (each with left
right an operation) connected by any ORs. When this comes through to the
processing where I need to construct the query, I will then know to only do
character replacements in right hand sides (i.e not columns name or column name
expressions). I hope to put something in for review this week.
--
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]