jon-wei commented on a change in pull request #7588: multi-value string column 
support for expressions
URL: https://github.com/apache/incubator-druid/pull/7588#discussion_r290972700
 
 

 ##########
 File path: 
processing/src/main/java/org/apache/druid/segment/virtual/ExpressionSelectors.java
 ##########
 @@ -155,15 +164,54 @@ public void inspectRuntimeShape(RuntimeShapeInspector 
inspector)
       }
     }
 
-    final Expr.ObjectBinding bindings = createBindings(expression, 
columnSelectorFactory);
+    final Set<String> actualArrays = new HashSet<>();
+    final Set<String> unknownIfArrays = new HashSet<>();
+    for (String column : columns) {
+      final ColumnCapabilities capabilities = 
columnSelectorFactory.getColumnCapabilities(column);
+      if (capabilities != null) {
+        if (capabilities.hasMultipleValues()) {
+          actualArrays.add(column);
+        } else if (
+            !capabilities.isComplete() &&
+            capabilities.getType().equals(ValueType.STRING) &&
+            !exprDetails.getArrayVariables().contains(column)
+        ) {
+          unknownIfArrays.add(column);
+        }
+      } else {
+        unknownIfArrays.add(column);
+      }
+    }
+
+    final List<String> needsApplied =
+        columns.stream()
+               .filter(c -> actualArrays.contains(c) && 
!exprDetails.getArrayVariables().contains(c))
+               .collect(Collectors.toList());
+    final Expr finalExpr;
+    if (needsApplied.size() > 0) {
+      finalExpr = Parser.applyUnappliedIdentifiers(expression, exprDetails, 
needsApplied);
+    } else {
+      finalExpr = expression;
+    }
+
+
+    final Expr.ObjectBinding bindings = createBindings(exprDetails, 
columnSelectorFactory);
 
     if (bindings.equals(ExprUtils.nilBindings())) {
       // Optimization for constant expressions.
       return new ConstantExprEvalSelector(expression.eval(bindings));
     }
 
+    if (unknownIfArrays.size() > 0) {
+      return new OpportunisticMultiValueStringExpressionColumnValueSelector(
+          finalExpr,
+          exprDetails,
+          bindings,
+          unknownIfArrays
+      );
+    }
     // No special optimization.
-    return new ExpressionColumnValueSelector(expression, bindings);
+    return new ExpressionColumnValueSelector(finalExpr, bindings);
 
 Review comment:
   I think the `// No special optimization.` comment above should be adjusted, 
since the case where all the array columns are known is the more "optimized" one

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