imply-cheddar commented on code in PR #13732:
URL: https://github.com/apache/druid/pull/13732#discussion_r1095447120


##########
processing/src/main/java/org/apache/druid/segment/virtual/NestedFieldVirtualColumn.java:
##########
@@ -233,20 +245,49 @@ public DimensionSelector makeDimensionSelector(
       ReadableOffset offset
   )
   {
-    final NestedDataComplexColumn column = 
NestedDataComplexColumn.fromColumnSelector(columnSelector, columnName);
-    if (column == null) {
-      // complex column itself didn't exist
-      return DimensionSelector.constant(null);
+    ColumnHolder holder = columnSelector.getColumnHolder(columnName);
+    if (holder == null) {
+      // column doesn't exist
+      return dimensionSpec.decorate(DimensionSelector.constant(null, 
dimensionSpec.getExtractionFn()));
     }
     if (hasNegativeArrayIndex) {
-      return new FieldDimensionSelector(
-          new RawFieldLiteralColumnValueSelector(
-              column.makeColumnValueSelector(offset),
-              parts
-          )
-      );
+      // if the path has negative array elements, then we have to use the 
'raw' processing of the FieldDimensionSelector
+      // created with the column selector factory instead of using the 
optimized nested field column, return null
+      // to fall through
+      return null;
     }
-    return column.makeDimensionSelector(parts, offset, 
dimensionSpec.getExtractionFn());
+
+    return dimensionSpec.decorate(makeDimensionSelectorUndecorated(holder, 
offset, dimensionSpec.getExtractionFn()));
+  }
+
+  private DimensionSelector makeDimensionSelectorUndecorated(
+      ColumnHolder holder,
+      ReadableOffset offset,
+      @Nullable ExtractionFn extractionFn
+  )
+  {
+    BaseColumn theColumn = holder.getColumn();
+    if (theColumn instanceof NestedDataComplexColumn) {
+      final NestedDataComplexColumn column = (NestedDataComplexColumn) 
theColumn;
+      return column.makeDimensionSelector(parts, offset, extractionFn);
+    }
+
+    // ok, so not a nested column, but we can still do stuff
+    if (!parts.isEmpty()) {
+      // we are being asked for a path that will never exist, so we are null 
selector
+      return DimensionSelector.constant(null, extractionFn);
+    }

Review Comment:
   I understand the want for less lines inside of a block, but my rule is that 
the fewest negations is always easier to read.



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