-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat(columnar_map): SPI and data model for COLUMNAR_MAP index #18368
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
base: master
Are you sure you want to change the base?
Changes from all commits
33c616c
d4b23e3
d3a31e5
041abe2
3ef6d5e
16e05bd
15dcfbb
7b4006e
0539ded
af26975
a0e8451
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,28 +25,28 @@ | |
|
|
||
| public interface MapDataSource extends DataSource { | ||
|
|
||
| /** | ||
| * Get the map FieldSpec. | ||
| */ | ||
| /// Returns the map FieldSpec. | ||
| ComplexFieldSpec.MapFieldSpec getFieldSpec(); | ||
|
|
||
| /** | ||
| * Get the Data Source representation of a single key within this map column. | ||
| */ | ||
| /// Returns the DataSource for the given map key. For absent keys, returns a [NullDataSource] | ||
| /// that produces the column default value for every document. Callers need not null-check. | ||
| DataSource getKeyDataSource(String key); | ||
|
|
||
| /** | ||
| * Get the Data Source representation of all keys within this map column. | ||
| */ | ||
| /// Returns whether this segment MAY contain the given key. Implementations are allowed to return | ||
| /// `true` conservatively (i.e., when it is not possible to determine key presence without a | ||
| /// full scan). Callers must handle the case where the key is absent even when this returns | ||
| /// `true` — [#getKeyDataSource(String)] will return a DataSource for an absent key | ||
| /// (forward-index reads return the column default value; null-value bitmap marks all rows as null). | ||
| default boolean containsKey(String key) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (optional) This is probably not needed if we make
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. replied above.
|
||
| return getKeyDataSources().containsKey(key); | ||
| } | ||
|
|
||
| /// Returns DataSources for all keys present in this segment. | ||
| Map<String, DataSource> getKeyDataSources(); | ||
|
|
||
| /** | ||
| * Get the DataSourceMetadata of a single key within this map column. | ||
| */ | ||
| /// Returns the DataSourceMetadata for the given key. | ||
| DataSourceMetadata getKeyDataSourceMetadata(String key); | ||
|
|
||
| /** | ||
| * Get the IndexContainer of a single key within this map column. | ||
| */ | ||
| /// Returns the ColumnIndexContainer for the given key. | ||
| ColumnIndexContainer getKeyIndexContainer(String key); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |
| package org.apache.pinot.segment.spi.index; | ||
|
|
||
| import org.apache.pinot.segment.spi.index.creator.BloomFilterCreator; | ||
| import org.apache.pinot.segment.spi.index.creator.ColumnarMapIndexCreator; | ||
| import org.apache.pinot.segment.spi.index.creator.CombinedInvertedIndexCreator; | ||
| import org.apache.pinot.segment.spi.index.creator.DictionaryBasedInvertedIndexCreator; | ||
| import org.apache.pinot.segment.spi.index.creator.FSTIndexCreator; | ||
|
|
@@ -31,6 +32,7 @@ | |
| import org.apache.pinot.segment.spi.index.creator.VectorIndexConfig; | ||
| import org.apache.pinot.segment.spi.index.creator.VectorIndexCreator; | ||
| import org.apache.pinot.segment.spi.index.reader.BloomFilterReader; | ||
| import org.apache.pinot.segment.spi.index.reader.ColumnarMapIndexReader; | ||
| import org.apache.pinot.segment.spi.index.reader.Dictionary; | ||
| import org.apache.pinot.segment.spi.index.reader.ForwardIndexReader; | ||
| import org.apache.pinot.segment.spi.index.reader.H3IndexReader; | ||
|
|
@@ -41,6 +43,7 @@ | |
| import org.apache.pinot.segment.spi.index.reader.TextIndexReader; | ||
| import org.apache.pinot.segment.spi.index.reader.VectorIndexReader; | ||
| import org.apache.pinot.spi.config.table.BloomFilterConfig; | ||
| import org.apache.pinot.spi.config.table.ColumnarMapIndexConfig; | ||
| import org.apache.pinot.spi.config.table.IndexConfig; | ||
| import org.apache.pinot.spi.config.table.JsonIndexConfig; | ||
|
|
||
|
|
@@ -79,6 +82,7 @@ public class StandardIndexes { | |
| public static final String TEXT_ID = "text_index"; | ||
| public static final String H3_ID = "h3_index"; | ||
| public static final String VECTOR_ID = "vector_index"; | ||
| public static final String COLUMNAR_MAP_ID = "columnar_map"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we just call it
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's already a MAP concept in the codebase. The existing |
||
|
|
||
| private StandardIndexes() { | ||
| } | ||
|
|
@@ -142,4 +146,12 @@ public static IndexType<VectorIndexConfig, VectorIndexReader, VectorIndexCreator | |
| return (IndexType<VectorIndexConfig, VectorIndexReader, VectorIndexCreator>) | ||
| IndexService.getInstance().get(VECTOR_ID); | ||
| } | ||
|
|
||
| /// Returns the COLUMNAR_MAP index type, which materializes MAP column keys as virtual columns. | ||
| @SuppressWarnings("unchecked") | ||
| public static IndexType<ColumnarMapIndexConfig, ColumnarMapIndexReader, ColumnarMapIndexCreator> | ||
| columnarMap() { | ||
| return (IndexType<ColumnarMapIndexConfig, ColumnarMapIndexReader, ColumnarMapIndexCreator>) | ||
| IndexService.getInstance().get(COLUMNAR_MAP_ID); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| /** | ||
| * 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.pinot.segment.spi.index.creator; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Map; | ||
| import org.apache.commons.configuration2.PropertiesConfiguration; | ||
| import org.apache.pinot.segment.spi.index.IndexCreator; | ||
|
|
||
|
|
||
| /// Creator for the COLUMNAR_MAP index. Accepts one map per document during segment creation and | ||
| /// decomposes it into per-key columnar storage on `seal()`. | ||
| /// | ||
| /// Implementations are not thread-safe; callers must serialize `add` calls per creator instance. | ||
| /// | ||
| /// The inherited `add(Object, int)` method from `IndexCreator` treats the first argument as the | ||
| /// map and the second as the docId, matching the column-major creator path. | ||
| public interface ColumnarMapIndexCreator extends IndexCreator { | ||
|
|
||
| /// Adds one document's map. Keys are routed to per-key columnar storage; declared-type keys are | ||
| /// coerced to those types, others use the configured default value type. An empty map is valid. | ||
| /// Callers must pass an empty map rather than `null`. | ||
| /// | ||
| /// @param mapValue the document's map (non-null, may be empty) | ||
| /// @param docId document id, must be monotonically non-decreasing across calls | ||
| void add(Map<String, Object> mapValue, int docId) | ||
| throws IOException; | ||
|
|
||
| /// Returns metadata properties for the materialized columns this creator produced during `seal()`. | ||
| /// The framework merges the returned properties into the segment metadata. | ||
| /// Returns an empty map for creators that produce no materialized columns. Call after `seal()`. | ||
| default Map<String, PropertiesConfiguration> getMaterializedColumnMetadata() { | ||
| return Map.of(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| /** | ||
| * 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.pinot.segment.spi.index.reader; | ||
|
|
||
| import java.util.Map; | ||
| import java.util.Set; | ||
| import javax.annotation.Nullable; | ||
| import org.apache.pinot.segment.spi.index.IndexReader; | ||
| import org.apache.pinot.spi.data.FieldSpec.DataType; | ||
| import org.roaringbitmap.buffer.ImmutableRoaringBitmap; | ||
|
|
||
|
|
||
| /// Reader for the COLUMNAR_MAP index. Each indexed key is materialized as its own per-key | ||
| /// forward index plus a presence bitmap. | ||
| /// | ||
| /// Implementations must be safe for concurrent reads. Mutable implementations may impose | ||
| /// a single-writer constraint; refer to the concrete implementation's Javadoc for details. | ||
| /// | ||
| /// Per-key `DataSource` construction is the responsibility of the surrounding | ||
| /// `ColumnarMapDataSource` wrappers, not this reader. This interface exposes only | ||
| /// the primitives a wrapper needs (key set, type, presence bitmap, per-doc map view). | ||
| public interface ColumnarMapIndexReader extends IndexReader { | ||
|
|
||
| /// Returns the set of all indexed key names. Never null; empty if no keys are indexed. | ||
| Set<String> getKeys(); | ||
|
|
||
| /// Returns the value DataType for the given key, or null if the key is not indexed. | ||
| @Nullable | ||
| DataType getValueType(String key); | ||
|
|
||
| /// Returns the number of documents that have a non-null value for the given key. | ||
| /// Returns 0 if the key is not indexed. | ||
| int getNumDocsWithKey(String key); | ||
|
|
||
| /// Returns the presence bitmap for the given key (docIds with non-null values). | ||
| /// Returns an empty bitmap if the key is not indexed. The returned bitmap must not be mutated. | ||
| ImmutableRoaringBitmap getPresenceBitmap(String key); | ||
|
|
||
| /// Reconstructs the full map for a single document from per-key data. Only keys with a | ||
| /// non-null value at `docId` appear in the result. Returns an empty map if the document has | ||
| /// no values; behavior for an out-of-range `docId` is implementation-defined. | ||
| Map<String, Object> getMap(int docId); | ||
|
|
||
| /// Returns whether the given key has an inverted index available. False if the key is not indexed. | ||
| default boolean hasInvertedIndex(String key) { | ||
| return false; | ||
| } | ||
|
|
||
| /// Returns sorted distinct values for the key from the inverted index, or null if no | ||
| /// inverted index is available (or the key is not indexed). | ||
| @Nullable | ||
| default String[] getDistinctValuesForKey(String key) { | ||
| return null; | ||
| } | ||
| } |
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.
Not introduced in this PR, but let's rename it to:
It is very confusing now because the data source is for value, not key.
Suggest letting it return
@Nullableto represent key not existThere 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.
Agreed on the naming — getDataSource(key) is cleaner. I'll do the full getKeyXXX → getXXX rename across the SPI in a separate refactoring PR so it's one clean sweep rather than scattered across the stack. Will raise a new PR for this.
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.
For @nullable: I'd prefer to keep the current non-null contract backed by NullDataSource. The callers in ProjectionBlock and ItemTransformFunction dereference the result immediately without a null-check — NullDataSource lets them do that safely by returning the column's default value for every doc.
If we switch to @nullable, those two callers need null-guards, and so does any future caller. NullDataSource gives the same semantic (absent key → null/default for all rows) without pushing null-handling into every call site.
Happy to revisit this if you strognly feel we should add @nullable.
Let me know your thoughts.
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.
Updated the API names here - #18437