imply-cheddar commented on code in PR #13739: URL: https://github.com/apache/druid/pull/13739#discussion_r1095427829
########## 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: An old column might've needed an extraction function to be useful, while the new column does not. If we take and use the extraction function from the dimension spec that references the virtual column, then we will be blindly applying that across all columns, even if it's not needed. The approach here allows us to preserve the intentions of the end user without actually limiting expressiveness. -- 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]
