clintropolis commented on code in PR #13739:
URL: https://github.com/apache/druid/pull/13739#discussion_r1095416713


##########
processing/src/main/java/org/apache/druid/segment/virtual/FallbackVirtualColumn.java:
##########
@@ -0,0 +1,227 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.segment.virtual;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.apache.druid.java.util.common.IAE;
+import org.apache.druid.java.util.common.Pair;
+import org.apache.druid.query.cache.CacheKeyBuilder;
+import org.apache.druid.query.dimension.DimensionSpec;
+import org.apache.druid.segment.ColumnInspector;
+import org.apache.druid.segment.ColumnSelector;
+import org.apache.druid.segment.ColumnSelectorFactory;
+import org.apache.druid.segment.ColumnValueSelector;
+import org.apache.druid.segment.DimensionSelector;
+import org.apache.druid.segment.VirtualColumn;
+import org.apache.druid.segment.column.ColumnCapabilities;
+import org.apache.druid.segment.column.ColumnCapabilitiesImpl;
+import org.apache.druid.segment.column.ColumnHolder;
+import org.apache.druid.segment.column.ColumnIndexSupplier;
+import org.apache.druid.segment.vector.MultiValueDimensionVectorSelector;
+import org.apache.druid.segment.vector.SingleValueDimensionVectorSelector;
+import org.apache.druid.segment.vector.VectorColumnSelectorFactory;
+import org.apache.druid.segment.vector.VectorObjectSelector;
+import org.apache.druid.segment.vector.VectorValueSelector;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * A virtual column that picks one column or another based on whether they 
exist.  It walks through an array of
+ * DimensionSpecs finding and using the first column that actually exists.  If 
it believes that none of them exist
+ * it YOLOs it with the first entry from the list.
+ * <p>
+ * If you are using this virtual column and want to have a 
decorator/extraction function on your DimensionSpec,
+ * it is expected that you will put it on the specs in the list rather than on 
the spec that references this
+ * virtual column.  That is, when this virtual column resolves a dimension, it 
ignores the decoration from the
+ * spec that it was given and instead uses the spec as defined in the list 
as-is to delegate to the column that
+ * it chose.
+ */
+public class FallbackVirtualColumn implements VirtualColumn
+{
+  private final String name;
+  private final ArrayList<DimensionSpec> columns;
+
+  @JsonCreator
+  public FallbackVirtualColumn(
+      @JsonProperty("name") String name,
+      @JsonProperty("columns") ArrayList<DimensionSpec> columns

Review Comment:
   is there much difference of doing the decorate/extractionFn this way 
compared to if we just passed an array of string column names in here and then 
use the spec of whatever is referencing this column?
   
   I guess a reason we could be in favor of doing this this way is if we wanted 
to add checking that the type of the dimension spec matches the column 
capabilities of the column we are looking for or something?



##########
processing/src/test/java/org/apache/druid/segment/vector/TestVectorColumnSelectorFactory.java:
##########
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.segment.vector;
+
+import org.apache.druid.java.util.common.UOE;
+import org.apache.druid.query.dimension.DimensionSpec;
+import org.apache.druid.segment.column.ColumnCapabilities;
+
+import javax.annotation.Nullable;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+public class TestVectorColumnSelectorFactory implements 
VectorColumnSelectorFactory
+{
+  private ReadableVectorInspector inspector = null;
+
+  private final Map<String, SingleValueDimensionVectorSelector> 
singleValDimSelectors = new LinkedHashMap<>();
+  private final Map<String, MultiValueDimensionVectorSelector> 
multiValDimSelectors = new LinkedHashMap<>();
+  private final Map<String, VectorValueSelector> vectorValueSelectors = new 
LinkedHashMap<>();
+  private final Map<String, VectorObjectSelector> vectorObjectSelectors = new 
LinkedHashMap<>();
+  private final Map<String, ColumnCapabilities> capabilitiesMap = new 
LinkedHashMap<>();
+
+  public TestVectorColumnSelectorFactory addSVDVS(String col, 
SingleValueDimensionVectorSelector selector)

Review Comment:
   maybe nice to allow setting both selector and capabilities in same call so 
you don't have to add stuff twice?



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