clintropolis commented on code in PR #13732:
URL: https://github.com/apache/druid/pull/13732#discussion_r1095433036
##########
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:
>Is this because parts.isEmpty() means that we are looking for the root? And
if we are not looking for the root then it's impossible to have something?
yep, exactly, will try to clarify comments
>If so, can we move the stuff that's after this if to be inside of the if
(to eliminate the negation) and adjust the comments to explain the relationship
between parts.isEmpty() and the "real world/query"?
hah, i originally had it flipped and decided last minute to do this way so
less stuff inside the if which seemed slightly more pleasing, but will switch
back because is all the same.
--
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]