-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Configurable index disabling for virtual columns #19004
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
nozjkoitop
wants to merge
2
commits into
apache:master
from
deep-bi:feature-auto-disablinig-vc-bitmap-indexing
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
...ing/src/main/java/org/apache/druid/segment/VirtualColumnBitmapDisablingIndexSelector.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| /* | ||
| * 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; | ||
|
|
||
| import org.apache.druid.collections.bitmap.BitmapFactory; | ||
| import org.apache.druid.query.filter.ColumnIndexSelector; | ||
| import org.apache.druid.segment.column.ColumnCapabilities; | ||
| import org.apache.druid.segment.column.ColumnHolder; | ||
| import org.apache.druid.segment.column.ColumnIndexSupplier; | ||
| import org.apache.druid.segment.column.SelectableColumn; | ||
| import org.apache.druid.segment.selector.settable.SettableColumnValueSelector; | ||
| import org.apache.druid.segment.serde.NoIndexesColumnIndexSupplier; | ||
|
|
||
| import javax.annotation.Nullable; | ||
| import java.util.Objects; | ||
|
|
||
| public final class VirtualColumnBitmapDisablingIndexSelector implements ColumnIndexSelector | ||
| { | ||
| private static final ColumnIndexSupplier NO_INDEXES = NoIndexesColumnIndexSupplier.getInstance(); | ||
| private final ColumnIndexSelector delegate; | ||
| private final VirtualColumns virtualColumns; | ||
|
|
||
|
|
||
| public VirtualColumnBitmapDisablingIndexSelector( | ||
| final ColumnIndexSelector delegate, | ||
| final VirtualColumns virtualColumns | ||
| ) | ||
| { | ||
| this.delegate = Objects.requireNonNull(delegate, "delegate"); | ||
| this.virtualColumns = Objects.requireNonNull(virtualColumns, "virtualColumns"); | ||
| } | ||
|
|
||
| @Override | ||
| public int getNumRows() | ||
| { | ||
| return delegate.getNumRows(); | ||
| } | ||
|
|
||
| @Override | ||
| public BitmapFactory getBitmapFactory() | ||
| { | ||
| return delegate.getBitmapFactory(); | ||
| } | ||
|
|
||
| @Override | ||
| @Nullable | ||
| public ColumnHolder getColumnHolder(final String columnName) | ||
| { | ||
| final ColumnHolder holder = delegate.getColumnHolder(columnName); | ||
| if (holder == null || !isVirtual(columnName)) { | ||
| return holder; | ||
| } | ||
|
|
||
| // force no indexes even if callers go via getColumnHolder(). | ||
| return new ColumnHolder() | ||
| { | ||
| @Override | ||
| public ColumnCapabilities getCapabilities() | ||
| { | ||
| return holder.getCapabilities(); | ||
| } | ||
|
|
||
| @Override | ||
| public int getLength() | ||
| { | ||
| return holder.getLength(); | ||
| } | ||
|
|
||
| @Override | ||
| public SelectableColumn getColumn() | ||
| { | ||
| return holder.getColumn(); | ||
| } | ||
|
|
||
| @Override | ||
| public ColumnIndexSupplier getIndexSupplier() | ||
| { | ||
| return NO_INDEXES; | ||
| } | ||
|
|
||
| @Override | ||
| public SettableColumnValueSelector makeNewSettableColumnValueSelector() | ||
| { | ||
| return holder.makeNewSettableColumnValueSelector(); | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| @Override | ||
| @Nullable | ||
| public ColumnIndexSupplier getIndexSupplier(final String column) | ||
| { | ||
| if (column.isEmpty()) { | ||
| return null; | ||
| } | ||
|
|
||
| // Only disable indexes for virtual columns | ||
| if (isVirtual(column)) { | ||
| return NO_INDEXES; | ||
| } | ||
| return delegate.getIndexSupplier(column); | ||
| } | ||
|
|
||
|
|
||
| private boolean isVirtual(final String columnName) | ||
| { | ||
| return virtualColumns.getVirtualColumn(columnName) != null; | ||
| } | ||
| } |
108 changes: 108 additions & 0 deletions
108
...src/test/java/org/apache/druid/segment/filter/FilterBundleVCBitmapIndexDisablingTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| /* | ||
| * 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.filter; | ||
|
|
||
| import com.google.common.collect.ImmutableList; | ||
| import org.apache.druid.collections.bitmap.BitmapFactory; | ||
| import org.apache.druid.java.util.common.io.Closer; | ||
| import org.apache.druid.math.expr.ExprMacroTable; | ||
| import org.apache.druid.query.DefaultBitmapResultFactory; | ||
| import org.apache.druid.query.filter.ColumnIndexSelector; | ||
| import org.apache.druid.query.filter.EqualityFilter; | ||
| import org.apache.druid.query.filter.Filter; | ||
| import org.apache.druid.query.filter.FilterBundle; | ||
| import org.apache.druid.segment.ColumnCache; | ||
| import org.apache.druid.segment.QueryableIndex; | ||
| import org.apache.druid.segment.TestIndex; | ||
| import org.apache.druid.segment.VirtualColumnBitmapDisablingIndexSelector; | ||
| import org.apache.druid.segment.VirtualColumns; | ||
| import org.apache.druid.segment.column.ColumnType; | ||
| import org.apache.druid.segment.virtual.ExpressionVirtualColumn; | ||
| import org.apache.druid.testing.InitializedNullHandlingTest; | ||
| import org.junit.Assert; | ||
| import org.junit.Test; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| public class FilterBundleVCBitmapIndexDisablingTest extends InitializedNullHandlingTest | ||
| { | ||
|
|
||
| @Test | ||
| public void testVCBitmapIndexEnabled() | ||
| { | ||
| final VirtualColumns virtualColumns = VirtualColumns.create(ImmutableList.of( | ||
| new ExpressionVirtualColumn("v1", | ||
| "countryName", ColumnType.STRING, | ||
| ExprMacroTable.nil() | ||
| ) | ||
| )); | ||
| final QueryableIndex index = TestIndex.getMMappedWikipediaIndex(); | ||
| BitmapFactory bitmapFactory = index.getBitmapFactoryForDimensions(); | ||
|
|
||
| try (Closer closer = Closer.create()) { | ||
| ColumnCache columnCache = new ColumnCache(index, virtualColumns, closer); | ||
| VirtualColumnBitmapDisablingIndexSelector selector = new VirtualColumnBitmapDisablingIndexSelector(columnCache, | ||
| virtualColumns | ||
| ); | ||
|
|
||
| final FilterBundle filterBundleIndexEnabled = makeFilterBundle(new AndFilter(ImmutableList.of( | ||
| new EqualityFilter("v1", ColumnType.STRING, "United States", null), | ||
| new EqualityFilter("countryName", | ||
| ColumnType.STRING, | ||
| "United States", | ||
| null | ||
| ) | ||
| )), columnCache, bitmapFactory); | ||
|
|
||
| final FilterBundle filterBundleIndexDisabled = makeFilterBundle(new AndFilter(ImmutableList.of( | ||
| new EqualityFilter("v1", ColumnType.STRING, "United States", null), | ||
| new EqualityFilter("countryName", | ||
| ColumnType.STRING, | ||
| "United States", | ||
| null | ||
| ) | ||
| )), selector, bitmapFactory); | ||
|
|
||
| Assert.assertEquals(2, filterBundleIndexEnabled.getIndex().getIndexInfo().getIndexes().size()); | ||
| Assert.assertEquals("v1 = United States", filterBundleIndexEnabled.getIndex().getIndexInfo().getIndexes().get(0).getFilter()); | ||
| Assert.assertEquals("countryName = United States", filterBundleIndexEnabled.getIndex().getIndexInfo().getIndexes().get(1).getFilter()); | ||
|
|
||
| Assert.assertNull(filterBundleIndexDisabled.getIndex().getIndexInfo().getIndexes()); | ||
| Assert.assertEquals("countryName = United States", filterBundleIndexDisabled.getIndex().getIndexInfo().getFilter()); | ||
| } | ||
| catch (IOException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| protected FilterBundle makeFilterBundle( | ||
| final Filter filter, | ||
| ColumnIndexSelector selector, | ||
| BitmapFactory bitmapFactory | ||
| ) | ||
| { | ||
| return new FilterBundle.Builder(filter, selector, false).build(new DefaultBitmapResultFactory(bitmapFactory), | ||
| selector.getNumRows(), | ||
| selector.getNumRows(), | ||
| false | ||
| ); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P2] Search queries still bypass this virtual-column index guard
This only wraps the selector used by cursor filter bundles, but
SearchQueryhas a separate index-only path inUseIndexesStrategythat still constructs plainColumnCacheselectors forpartitionDimensionList,makeTimeFilteredBitmap, andIndexOnlyExecutor. A search query withmaxVirtualColumnsForBitmapIndexingset low and a virtual search dimension or virtual-column filter can still choose and execute the bitmap-index plan, so the new query context is not honored for one of the query types that accepts virtual columns. Please apply the same disabling selector in the search index strategy, or document/limit the parameter to cursor-backed query paths.