clintropolis commented on a change in pull request #9487: Convert 
array_contains() and array_overlaps() into native filters if possible
URL: https://github.com/apache/druid/pull/9487#discussion_r389969227
 
 

 ##########
 File path: 
sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ArrayOverlapOperatorConversion.java
 ##########
 @@ -51,4 +67,66 @@ public ArrayOverlapOperatorConversion()
   {
     super(SQL_FUNCTION, EXPR_FUNCTION);
   }
+
+  @Nullable
+  @Override
+  public DimFilter toDruidFilter(
+      final PlannerContext plannerContext,
+      RowSignature rowSignature,
+      @Nullable VirtualColumnRegistry virtualColumnRegistry,
+      final RexNode rexNode
+  )
+  {
+    final List<RexNode> operands = ((RexCall) rexNode).getOperands();
+    final List<DruidExpression> druidExpressions = 
Expressions.toDruidExpressions(
+        plannerContext,
+        rowSignature,
+        operands
+    );
+    if (druidExpressions == null) {
+      return null;
+    }
+
+    // Converts array_overlaps() function into an OR of Selector filters if 
possible.
+    final boolean leftSimpleExtractionExpr = 
druidExpressions.get(0).isSimpleExtraction();
+    final boolean rightSimpleExtractionExpr = 
druidExpressions.get(1).isSimpleExtraction();
+    final DruidExpression simpleExtractionExpr;
+    final DruidExpression complexExpr;
+
+    if (leftSimpleExtractionExpr ^ rightSimpleExtractionExpr) {
+      if (leftSimpleExtractionExpr) {
+        simpleExtractionExpr = druidExpressions.get(0);
+        complexExpr = druidExpressions.get(1);
+      } else {
+        simpleExtractionExpr = druidExpressions.get(1);
+        complexExpr = druidExpressions.get(0);
+      }
+    } else {
+      return toExpressionFilter(plannerContext, getDruidFunctionName(), 
druidExpressions);
+    }
+
+    Expr expr = Parser.parse(complexExpr.getExpression(), 
plannerContext.getExprMacroTable());
+    if (expr.isLiteral()) {
 
 Review comment:
   nit: is it worth splitting this out into a static method on one of these 
classes (or a utility method somewhere) since this block looks basically shared 
with `array_contains`?

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to