You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by "imply-cheddar (via GitHub)" <gi...@apache.org> on 2023/02/02 07:29:17 UTC

[GitHub] [druid] imply-cheddar opened a new pull request, #13739: Fallback virtual column

imply-cheddar opened a new pull request, #13739:
URL: https://github.com/apache/druid/pull/13739

   This virtual columns enables falling back to another column if the original column doesn't exist.  This is useful when doing column migrations and you have some old data with column X, new data with column Y and you want to use Y if it exists, X otherwise so that you can run a consistent query against all of the data.
   
   This PR has:
   
   - [x] been self-reviewed.
   - [x] added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
   - [x] added unit tests or modified existing tests to cover new code paths, ensuring the threshold for [code coverage](https://github.com/apache/druid/blob/master/dev/code-review/code-coverage.md) is met.


-- 
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: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] cheddar merged pull request #13739: Fallback virtual column

Posted by "cheddar (via GitHub)" <gi...@apache.org>.
cheddar merged PR #13739:
URL: https://github.com/apache/druid/pull/13739


-- 
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: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] clintropolis commented on a diff in pull request #13739: Fallback virtual column

Posted by "clintropolis (via GitHub)" <gi...@apache.org>.
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: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] imply-cheddar commented on a diff in pull request #13739: Fallback virtual column

Posted by "imply-cheddar (via GitHub)" <gi...@apache.org>.
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: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] imply-cheddar commented on a diff in pull request #13739: Fallback virtual column

Posted by "imply-cheddar (via GitHub)" <gi...@apache.org>.
imply-cheddar commented on code in PR #13739:
URL: https://github.com/apache/druid/pull/13739#discussion_r1095428678


##########
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:
   Yeah...  probably.  I didn't know exactly how I was going to use the thing as I threw these methods on it, but looking back at how it is used, that would've worked for the usage.  🤷   It's a test class whose API can be plenty fluid, we can make it better when next we come to it.



-- 
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: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org