godfreyhe commented on a change in pull request #12866:
URL: https://github.com/apache/flink/pull/12866#discussion_r455672711



##########
File path: 
flink-table/flink-table-planner-blink/src/test/java/org/apache/flink/table/planner/factories/TestValuesTableFactory.java
##########
@@ -448,6 +478,127 @@ public void applyProjection(int[][] projectedFields) {
                        this.projectedFields = 
Arrays.stream(projectedFields).mapToInt(f -> f[0]).toArray();
                }
 
+               @Override
+               public Result applyFilters(List<ResolvedExpression> filters) {
+                       List<ResolvedExpression> acceptedFilters = new 
ArrayList<>();
+                       List<ResolvedExpression> remainingFilters = new 
ArrayList<>();
+                       for (ResolvedExpression expr : filters) {
+                               if (shouldPushDown(expr)) {
+                                       acceptedFilters.add(expr);
+                               } else {
+                                       remainingFilters.add(expr);
+                               }
+                       }
+                       this.filterPredicates = acceptedFilters;
+                       return Result.of(acceptedFilters, remainingFilters);
+               }
+
+               private boolean shouldPushDown(Expression expr) {
+                       if (expr instanceof CallExpression && 
expr.getChildren().size() == 2) {
+                               return 
shouldPushDownUnaryExpression(expr.getChildren().get(0))
+                                       && 
shouldPushDownUnaryExpression(expr.getChildren().get(1));
+                       }
+                       return false;
+               }
+
+               private boolean shouldPushDownUnaryExpression(Expression expr) {
+                       if (expr instanceof FieldReferenceExpression) {
+                               if 
(filterableFields.contains(((FieldReferenceExpression) expr).getName())) {
+                                       return true;
+                               }
+                       }
+
+                       if (expr instanceof ValueLiteralExpression) {
+                               // validate that literal is comparable
+                               Optional value = ((ValueLiteralExpression) 
expr).getValueAs(((ValueLiteralExpression) 
expr).getOutputDataType().getConversionClass());

Review comment:
       we should also consider whether the type of `FieldReferenceExpression ` 
is comparable, consider the following pattern:
   the `filterableFields` is `a` and `b` and the pushed pattern `a > b`




----------------------------------------------------------------
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.

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


Reply via email to