gianm commented on code in PR #18965:
URL: https://github.com/apache/druid/pull/18965#discussion_r2748096316


##########
sql/src/main/java/org/apache/druid/sql/calcite/expression/Expressions.java:
##########
@@ -831,25 +831,43 @@ private static DimFilter toSimpleLeafFilter(
 
   /**
    * Translates to an "expression" type leaf filter. Used as a fallback if we 
can't use a simple leaf filter.
+   * If the expression contains specialized nodes (e.g. JSON_VALUE), a virtual 
column is created to benefit
+   * from specialization. Otherwise, the expression is inlined directly.
    */
   @Nullable
   private static DimFilter toExpressionLeafFilter(
       final PlannerContext plannerContext,
       final RowSignature rowSignature,
+      @Nullable final VirtualColumnRegistry virtualColumnRegistry,
       final RexNode rexNode
   )
   {
     final DruidExpression druidExpression = toDruidExpression(plannerContext, 
rowSignature, rexNode);
 
-    if (druidExpression != null) {
+    if (druidExpression == null) {
+      return null;
+    }
+
+    if (virtualColumnRegistry != null && 
druidExpression.containsSpecializedNodes()) {
+      // Use a virtual column so we can take advantage of specialization.
+      final String virtualColumnName = 
virtualColumnRegistry.getOrCreateVirtualColumnForExpression(
+          druidExpression,
+          ColumnType.LONG
+      );
+      final String vcExpression = "\"" + virtualColumnName + "\"";

Review Comment:
   I did think about using an `equals` filter in this case (like, `equals` with 
`1L` value) but decided against it because of the fancy coercing that the 
`expression` does.



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


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

Reply via email to