This is an automated email from the ASF dual-hosted git repository.
xiangfu0 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pinot.git
The following commit(s) were added to refs/heads/master by this push:
new fa9151805cd Forward-index encoding: introduce Encoding SPI surface and
use it for raw vs dict checks (#18364)
fa9151805cd is described below
commit fa9151805cdbe571b155bd135091c97ccad9f94c
Author: Xiang Fu <[email protected]>
AuthorDate: Sun May 3 05:38:28 2026 -0700
Forward-index encoding: introduce Encoding SPI surface and use it for raw
vs dict checks (#18364)
Adds the SPI surface needed to track forward-index encoding (RAW vs
DICTIONARY) explicitly on ForwardIndexConfig and ColumnMetadata, alongside the
existing dictionary-presence signal. Today the two always agree; the new
accessors lay the SPI groundwork so a follow-up PR can decouple them (e.g. to
keep a dictionary for secondary indexes while the forward index stores RAW
values) without breaking ABI.
SPI additions
- ForwardIndexConfig: non-null FieldConfig.EncodingType.
Builder(EncodingType) is required; callers pass FieldConfig.getEncodingType().
getDefault(EncodingType) and getDisabled() helpers. Legacy JSON without
`encodingType` defaults to DICTIONARY for backward compatibility. Encoding
participates in equals/hashCode and round-trips through Jackson. Legacy
chunkCompressionType / dictIdCompressionType JSON properties keep deserializing
via the existing getActualCompressionCodec resolver.
- ColumnMetadata: new getForwardIndexEncoding() accessor (no default impl,
@JsonIgnore). Implementations read FORWARD_INDEX_ENCODING from segment
metadata, falling back to deriving from hasDictionary() for old segments.
- V1Constants.MetadataKeys.Column.FORWARD_INDEX_ENCODING constant;
ColumnMetadataImpl persists/reads it via getEnum.
Caller-side adoption
- ForwardIndexCreatorFactory branches on indexConfig.getEncodingType() ==
RAW. The dictionary-encoded branch uses `assert context.hasDictionary();` (no
overhead in production); ForwardIndexType.validate now rejects
encoding=DICTIONARY with no dictionary at table-config-load time so the assert
is provable.
- ForwardIndexReaderFactory reads via metadata.getForwardIndexEncoding() ==
DICTIONARY.
- ForwardIndexType.getFileExtension uses metadata.getForwardIndexEncoding()
to pick RAW vs SORTED/UNSORTED.
- ForwardIndexHandler / InvertedIndexAndDictionaryBasedForwardIndexCreator
write FORWARD_INDEX_ENCODING alongside HAS_DICTIONARY when metadata changes.
- ForwardIndexType.createDeserializerForLegacyConfigs propagates
fieldConfig.getEncodingType() into the Builder, and materializes RAW defaults
for columns whose dictionary is disabled but lack an explicit FieldConfig
forward block, so the framework's `fromIndexes` deserializer doesn't fall back
to a DICTIONARY default.
Tests
- ForwardIndexConfigTest: default encoding, builder retention,
copy-constructor preservation, equals/hashCode distinction, JSON round-trip,
explicit encodingType deserialization, and the empty-JSON backward-compat
default.
- ForwardIndexCreatorFactoryTest: RAW branch selection when a dictionary
exists, and dictionary branch selection for the default config.
- ColumnMetadataTest: encoding participates in equals/hashCode/toString.
- ForwardIndexHandlerTest: encoding metadata is written alongside
HAS_DICTIONARY when toggling dict.
- CrcUtilsTest and RealtimeSegmentConverterTest expected CRCs updated for
the new FORWARD_INDEX_ENCODING metadata key.
Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
---
.../org/apache/pinot/core/util/CrcUtilsTest.java | 8 +-
.../tests/OfflineClusterIntegrationTest.java | 16 ++-
.../segment/creator/impl/BaseSegmentCreator.java | 38 +++++--
.../segment/creator/impl/ColumnIndexCreators.java | 12 ++-
.../index/forward/ForwardIndexCreatorFactory.java | 7 +-
.../index/forward/ForwardIndexReaderFactory.java | 3 +-
.../segment/index/forward/ForwardIndexType.java | 119 +++++++++++++++++----
.../segment/index/loader/ForwardIndexHandler.java | 4 +
...IndexAndDictionaryBasedForwardIndexCreator.java | 7 +-
.../defaultcolumn/BaseDefaultColumnHandler.java | 12 ++-
.../segment/index/map/SimpleColumnMetadata.java | 6 ++
.../converter/RealtimeSegmentConverterTest.java | 25 +++--
.../local/segment/index/ColumnMetadataTest.java | 36 ++++++-
.../forward/ForwardIndexCreatorFactoryTest.java | 83 ++++++++++++++
.../index/forward/ForwardIndexTypeTest.java | 93 +++++++++++++---
.../index/loader/ForwardIndexHandlerTest.java | 5 +-
.../index/loader/IndexLoadingConfigTest.java | 2 +
.../index/loader/SegmentPreProcessorTest.java | 4 +-
.../apache/pinot/segment/spi/ColumnMetadata.java | 8 +-
.../org/apache/pinot/segment/spi/V1Constants.java | 4 +
.../segment/spi/index/ForwardIndexConfig.java | 84 +++++++++------
.../spi/index/metadata/ColumnMetadataImpl.java | 60 ++++++++---
.../segment/spi/index/ForwardIndexConfigTest.java | 83 ++++++++++++++
23 files changed, 595 insertions(+), 124 deletions(-)
diff --git
a/pinot-core/src/test/java/org/apache/pinot/core/util/CrcUtilsTest.java
b/pinot-core/src/test/java/org/apache/pinot/core/util/CrcUtilsTest.java
index 0b9e6a1688a..94019398200 100644
--- a/pinot-core/src/test/java/org/apache/pinot/core/util/CrcUtilsTest.java
+++ b/pinot-core/src/test/java/org/apache/pinot/core/util/CrcUtilsTest.java
@@ -105,10 +105,10 @@ public class CrcUtilsTest {
driver.build();
File indexDir = driver.getOutputDirectory();
- assertEquals(CrcUtils.computeCrc(indexDir), 1243018203L);
+ assertEquals(CrcUtils.computeCrc(indexDir), 2716945490L);
new SegmentV1V2ToV3FormatConverter().convert(indexDir);
- assertEquals(CrcUtils.computeCrc(indexDir), 2321393542L);
+ assertEquals(CrcUtils.computeCrc(indexDir), 1116143598L);
}
@Test
@@ -135,10 +135,10 @@ public class CrcUtilsTest {
driver.build();
File indexDir = driver.getOutputDirectory();
- assertEquals(CrcUtils.computeCrc(indexDir), 1921721469L);
+ assertEquals(CrcUtils.computeCrc(indexDir), 1019509989L);
new SegmentV1V2ToV3FormatConverter().convert(indexDir);
- assertEquals(CrcUtils.computeCrc(indexDir), 809891195L);
+ assertEquals(CrcUtils.computeCrc(indexDir), 237260274L);
}
@Test
diff --git
a/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/OfflineClusterIntegrationTest.java
b/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/OfflineClusterIntegrationTest.java
index ce7d04ea0e6..eda5859962a 100644
---
a/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/OfflineClusterIntegrationTest.java
+++
b/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/OfflineClusterIntegrationTest.java
@@ -1531,7 +1531,9 @@ public class OfflineClusterIntegrationTest extends
BaseClusterIntegrationTestSet
// Convert 'DestCityName' to v6 raw index (delta-encoded chunk header)
List<FieldConfig> fieldConfigs = tableConfig.getFieldConfigList();
assertNotNull(fieldConfigs);
- ForwardIndexConfig forwardIndexConfig = new
ForwardIndexConfig.Builder().withRawIndexWriterVersion(6).build();
+ ForwardIndexConfig forwardIndexConfig = new
ForwardIndexConfig.Builder(FieldConfig.EncodingType.RAW)
+ .withRawIndexWriterVersion(6)
+ .build();
ObjectNode indexes = JsonUtils.newObjectNode();
indexes.set("forward", forwardIndexConfig.toJsonNode());
FieldConfig fieldConfig =
@@ -1552,7 +1554,9 @@ public class OfflineClusterIntegrationTest extends
BaseClusterIntegrationTestSet
// Convert 'DestCityName' to v2 raw index by modifying existing FieldConfig
fieldConfigs = tableConfig.getFieldConfigList();
assertNotNull(fieldConfigs);
- forwardIndexConfig = new
ForwardIndexConfig.Builder().withRawIndexWriterVersion(2).build();
+ forwardIndexConfig = new
ForwardIndexConfig.Builder(FieldConfig.EncodingType.RAW)
+ .withRawIndexWriterVersion(2)
+ .build();
indexes = JsonUtils.newObjectNode();
indexes.set("forward", forwardIndexConfig.toJsonNode());
fieldConfig =
@@ -1567,7 +1571,9 @@ public class OfflineClusterIntegrationTest extends
BaseClusterIntegrationTestSet
assertTrue(v2RawIndexSize > v4rawIndexSize);
// Convert 'DestCityName' to SNAPPY compression
- forwardIndexConfig = new
ForwardIndexConfig.Builder().withCompressionCodec(CompressionCodec.SNAPPY).build();
+ forwardIndexConfig = new
ForwardIndexConfig.Builder(FieldConfig.EncodingType.RAW)
+ .withCompressionCodec(CompressionCodec.SNAPPY)
+ .build();
indexes.set("forward", forwardIndexConfig.toJsonNode());
fieldConfig =
new
FieldConfig.Builder(column).withEncodingType(FieldConfig.EncodingType.RAW).withIndexes(indexes).build();
@@ -1590,7 +1596,9 @@ public class OfflineClusterIntegrationTest extends
BaseClusterIntegrationTestSet
assertEquals(columnIndexSize.get(StandardIndexes.FORWARD_ID).asDouble(),
v4SnappyRawIndexSize);
// Adding 'LZ4' compression explicitly should trigger the conversion
- forwardIndexConfig = new
ForwardIndexConfig.Builder().withCompressionCodec(CompressionCodec.LZ4).build();
+ forwardIndexConfig = new
ForwardIndexConfig.Builder(FieldConfig.EncodingType.RAW)
+ .withCompressionCodec(CompressionCodec.LZ4)
+ .build();
indexes.set("forward", forwardIndexConfig.toJsonNode());
fieldConfig =
new
FieldConfig.Builder(column).withEncodingType(FieldConfig.EncodingType.RAW).withIndexes(indexes).build();
diff --git
a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/creator/impl/BaseSegmentCreator.java
b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/creator/impl/BaseSegmentCreator.java
index 6fafe69cca6..0a4e712ee51 100644
---
a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/creator/impl/BaseSegmentCreator.java
+++
b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/creator/impl/BaseSegmentCreator.java
@@ -75,6 +75,7 @@ import
org.apache.pinot.segment.spi.partition.PartitionFunction;
import org.apache.pinot.segment.spi.store.SegmentDirectory;
import org.apache.pinot.segment.spi.store.SegmentDirectoryPaths;
import org.apache.pinot.spi.config.instance.InstanceType;
+import org.apache.pinot.spi.config.table.FieldConfig;
import org.apache.pinot.spi.config.table.IndexConfig;
import org.apache.pinot.spi.config.table.SegmentZKPropsConfig;
import org.apache.pinot.spi.config.table.StarTreeIndexConfig;
@@ -148,7 +149,8 @@ public abstract class BaseSegmentCreator implements
SegmentCreator {
} else {
FieldSpec fieldSpec = _schema.getFieldSpecFor(columnName);
_colIndexes.put(columnName,
- new ColumnIndexCreators(columnName, fieldSpec, null, List.of(),
null));
+ new ColumnIndexCreators(columnName, fieldSpec,
+ _config.getIndexConfigsByColName().get(columnName), null,
List.of(), null));
}
}
}
@@ -172,7 +174,7 @@ public abstract class BaseSegmentCreator implements
SegmentCreator {
}
IndexCreationContext.Common context = getIndexCreationContext(fieldSpec,
dictEnabledColumn);
- FieldIndexConfigs config = adaptConfig(columnName, originalConfig,
columnStatistics, _config);
+ FieldIndexConfigs config = adaptConfig(columnName, originalConfig,
columnStatistics, _config, dictEnabledColumn);
SegmentDictionaryCreator dictionaryCreator = null;
if (dictEnabledColumn) {
@@ -181,7 +183,7 @@ public abstract class BaseSegmentCreator implements
SegmentCreator {
List<IndexCreator> indexCreators = getIndexCreatorsByColumn(fieldSpec,
context, config, dictEnabledColumn);
- return new ColumnIndexCreators(columnName, fieldSpec, dictionaryCreator,
+ return new ColumnIndexCreators(columnName, fieldSpec, config,
dictionaryCreator,
indexCreators, getNullValueCreator(fieldSpec));
}
@@ -307,7 +309,7 @@ public abstract class BaseSegmentCreator implements
SegmentCreator {
* Adapts field index configs based on column properties.
*/
private FieldIndexConfigs adaptConfig(String columnName, FieldIndexConfigs
config,
- ColumnStatistics columnStatistics, SegmentGeneratorConfig
segmentCreationSpec) {
+ ColumnStatistics columnStatistics, SegmentGeneratorConfig
segmentCreationSpec, boolean dictEnabledColumn) {
FieldIndexConfigs.Builder builder = new FieldIndexConfigs.Builder(config);
// Sorted columns treat the 'forwardIndexDisabled' flag as a no-op
ForwardIndexConfig fwdConfig = config.getConfig(StandardIndexes.forward());
@@ -315,6 +317,13 @@ public abstract class BaseSegmentCreator implements
SegmentCreator {
builder.add(StandardIndexes.forward(),
new
ForwardIndexConfig.Builder(fwdConfig).withLegacyProperties(segmentCreationSpec.getColumnProperties(),
columnName).build());
+ } else if (fwdConfig.isEnabled() && !dictEnabledColumn
+ && fwdConfig.getEncodingType() == FieldConfig.EncodingType.DICTIONARY)
{
+ // Segment-time dictionary optimizers (`optimizeDictionary` /
`optimizeDictionaryForMetrics`) can flip
+ // dictEnabledColumn=false for a column whose configured encoding is
DICTIONARY. Without a dictionary the
+ // forward index must be RAW, so reconcile here before the creator
factory branches on encoding.
+ builder.add(StandardIndexes.forward(),
+ new ForwardIndexConfig.Builder(fwdConfig,
FieldConfig.EncodingType.RAW).build());
}
// Initialize inverted index creator; skip creating inverted index if
sorted
if (columnStatistics.isSorted()) {
@@ -530,10 +539,16 @@ public abstract class BaseSegmentCreator implements
SegmentCreator {
for (Map.Entry<String, ColumnStatistics> entry :
_columnStatisticsMap.entrySet()) {
String column = entry.getKey();
ColumnStatistics columnStatistics = entry.getValue();
- SegmentDictionaryCreator dictionaryCreator =
_colIndexes.get(column).getDictionaryCreator();
- int dictionaryElementSize = (dictionaryCreator != null) ?
dictionaryCreator.getNumBytesPerEntry() : 0;
+ ColumnIndexCreators columnIndexCreators = _colIndexes.get(column);
+ SegmentDictionaryCreator dictionaryCreator =
columnIndexCreators.getDictionaryCreator();
+ boolean hasDictionary = dictionaryCreator != null;
+ int dictionaryElementSize = hasDictionary ?
dictionaryCreator.getNumBytesPerEntry() : 0;
+ // Use the adapted (post-`adaptConfig`) FieldIndexConfigs so the
persisted encoding matches what was actually
+ // built on disk (the dictionary optimizer may have flipped DICTIONARY
to RAW at segment-creation time).
+ ForwardIndexConfig fwdConfig =
+
columnIndexCreators.getIndexConfigs().getConfig(StandardIndexes.forward());
addColumnMetadataInfo(properties, column, columnStatistics, _totalDocs,
_schema.getFieldSpecFor(column),
- dictionaryCreator != null, dictionaryElementSize, false);
+ hasDictionary, dictionaryElementSize, fwdConfig.getEncodingType(),
false);
}
SegmentZKPropsConfig segmentZKPropsConfig =
_config.getSegmentZKPropsConfig();
@@ -544,17 +559,18 @@ public abstract class BaseSegmentCreator implements
SegmentCreator {
CommonsConfigurationUtils.saveToFile(properties, metadataFile);
}
- /**
- * Adds column metadata information to the properties configuration.
- */
+ /// Adds column metadata information to the properties configuration. The
`forwardIndexEncoding` is persisted under
+ /// [V1Constants.MetadataKeys.Column#FORWARD_INDEX_ENCODING]; readers
loading older segments that lack this key fall
+ /// back to inferring the encoding from `HAS_DICTIONARY`.
public static void addColumnMetadataInfo(PropertiesConfiguration properties,
String column,
ColumnStatistics columnStatistics, int totalDocs, FieldSpec fieldSpec,
boolean hasDictionary,
- int dictionaryElementSize, boolean autoGenerated) {
+ int dictionaryElementSize, FieldConfig.EncodingType
forwardIndexEncoding, boolean autoGenerated) {
addFieldSpec(properties, column, fieldSpec);
properties.setProperty(getKeyFor(column, TOTAL_DOCS),
String.valueOf(totalDocs));
int cardinality = columnStatistics.getCardinality();
properties.setProperty(getKeyFor(column, CARDINALITY),
String.valueOf(cardinality));
properties.setProperty(getKeyFor(column, HAS_DICTIONARY),
String.valueOf(hasDictionary));
+ properties.setProperty(getKeyFor(column, FORWARD_INDEX_ENCODING),
forwardIndexEncoding.name());
properties.setProperty(getKeyFor(column, IS_SORTED),
String.valueOf(columnStatistics.isSorted()));
DataType storedType = fieldSpec.getDataType().getStoredType();
if (!storedType.isFixedWidth()) {
diff --git
a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/creator/impl/ColumnIndexCreators.java
b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/creator/impl/ColumnIndexCreators.java
index 1fdaeefa5ae..0ef96b7b17b 100644
---
a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/creator/impl/ColumnIndexCreators.java
+++
b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/creator/impl/ColumnIndexCreators.java
@@ -25,6 +25,7 @@ import java.util.List;
import javax.annotation.Nullable;
import org.apache.pinot.common.utils.FileUtils;
import
org.apache.pinot.segment.local.segment.creator.impl.nullvalue.NullValueVectorCreator;
+import org.apache.pinot.segment.spi.index.FieldIndexConfigs;
import org.apache.pinot.segment.spi.index.IndexCreator;
import org.apache.pinot.spi.data.FieldSpec;
@@ -36,6 +37,7 @@ import org.apache.pinot.spi.data.FieldSpec;
public class ColumnIndexCreators implements Closeable {
private final String _columnName;
private final FieldSpec _fieldSpec;
+ private final FieldIndexConfigs _indexConfigs;
private final SegmentDictionaryCreator _dictionaryCreator; // null for raw
columns
// Indexes whose build lifecycle is not DURING_SEGMENT_CREATION are not
included
private final List<IndexCreator> _indexCreators;
@@ -44,12 +46,13 @@ public class ColumnIndexCreators implements Closeable {
private volatile boolean _isSealed = false;
private volatile boolean _isClosed = false;
- public ColumnIndexCreators(String columnName, FieldSpec fieldSpec,
+ public ColumnIndexCreators(String columnName, FieldSpec fieldSpec,
FieldIndexConfigs indexConfigs,
@Nullable SegmentDictionaryCreator dictionaryCreator,
List<IndexCreator> indexCreators,
@Nullable NullValueVectorCreator nullValueVectorCreator) {
_columnName = columnName;
_fieldSpec = fieldSpec;
+ _indexConfigs = indexConfigs;
_dictionaryCreator = dictionaryCreator;
_indexCreators = indexCreators;
_nullValueVectorCreator = nullValueVectorCreator;
@@ -82,6 +85,13 @@ public class ColumnIndexCreators implements Closeable {
return _isDictionaryEncoded;
}
+ /// Returns the per-column [FieldIndexConfigs] after
`BaseSegmentCreator.adaptConfig` ran. This is the source of
+ /// truth for what was actually built on disk (in particular, the
forward-index encoding may have been flipped to
+ /// RAW by the dictionary optimizer even though the original config said
DICTIONARY).
+ public FieldIndexConfigs getIndexConfigs() {
+ return _indexConfigs;
+ }
+
public void seal() throws IOException {
if (_isSealed) {
return;
diff --git
a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/forward/ForwardIndexCreatorFactory.java
b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/forward/ForwardIndexCreatorFactory.java
index 97ca0220d2a..28c06c2a3c3 100644
---
a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/forward/ForwardIndexCreatorFactory.java
+++
b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/forward/ForwardIndexCreatorFactory.java
@@ -52,8 +52,9 @@ public class ForwardIndexCreatorFactory {
String columnName = fieldSpec.getName();
int numTotalDocs = context.getTotalDocs();
- if (context.hasDictionary()) {
- // Dictionary enabled columns
+ if (indexConfig.getEncodingType() == FieldConfig.EncodingType.DICTIONARY) {
+ // Dictionary-encoded forward index requires a dictionary to translate
dict ids to values.
+ assert context.hasDictionary();
int cardinality = context.getCardinality();
if (fieldSpec.isSingleValueField()) {
if (context.isSorted()) {
@@ -70,7 +71,7 @@ public class ForwardIndexCreatorFactory {
}
}
} else {
- // Dictionary disabled columns
+ // Raw forward index
DataType storedType = fieldSpec.getDataType().getStoredType();
if (indexConfig.getCompressionCodec() ==
FieldConfig.CompressionCodec.CLP) {
// CLP (V1) uses hard-coded chunk compressor which is set to
`PassThrough`
diff --git
a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/forward/ForwardIndexReaderFactory.java
b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/forward/ForwardIndexReaderFactory.java
index 26ec28c4cf1..28615c02f21 100644
---
a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/forward/ForwardIndexReaderFactory.java
+++
b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/forward/ForwardIndexReaderFactory.java
@@ -47,6 +47,7 @@ import org.apache.pinot.segment.spi.index.IndexType;
import org.apache.pinot.segment.spi.index.StandardIndexes;
import org.apache.pinot.segment.spi.index.reader.ForwardIndexReader;
import org.apache.pinot.segment.spi.memory.PinotDataBuffer;
+import org.apache.pinot.spi.config.table.FieldConfig;
import org.apache.pinot.spi.data.FieldSpec.DataType;
@@ -74,7 +75,7 @@ public class ForwardIndexReaderFactory extends
IndexReaderFactory.Default<Forwar
}
public ForwardIndexReader createIndexReader(PinotDataBuffer dataBuffer,
ColumnMetadata metadata) {
- if (metadata.hasDictionary()) {
+ if (metadata.getForwardIndexEncoding() ==
FieldConfig.EncodingType.DICTIONARY) {
if (metadata.isSingleValue()) {
if (metadata.isSorted()) {
return new SortedIndexReaderImpl(dataBuffer,
metadata.getCardinality());
diff --git
a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/forward/ForwardIndexType.java
b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/forward/ForwardIndexType.java
index fa693c30fcc..8136a82297f 100644
---
a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/forward/ForwardIndexType.java
+++
b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/forward/ForwardIndexType.java
@@ -19,12 +19,18 @@
package org.apache.pinot.segment.local.segment.index.forward;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.base.Preconditions;
-import com.google.common.collect.Maps;
+import java.io.IOException;
+import java.io.UncheckedIOException;
import java.util.Collection;
import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import javax.annotation.Nullable;
import
org.apache.pinot.segment.local.realtime.impl.forward.CLPMutableForwardIndexV2;
import
org.apache.pinot.segment.local.realtime.impl.forward.FixedByteMVMutableForwardIndex;
@@ -58,6 +64,7 @@ import org.apache.pinot.spi.config.table.TableConfig;
import org.apache.pinot.spi.config.table.TableType;
import org.apache.pinot.spi.data.FieldSpec;
import org.apache.pinot.spi.data.Schema;
+import org.apache.pinot.spi.utils.JsonUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -92,7 +99,7 @@ public class ForwardIndexType extends
AbstractIndexType<ForwardIndexConfig, Forw
@Override
public ForwardIndexConfig getDefaultConfig() {
- return ForwardIndexConfig.getDefault();
+ return ForwardIndexConfig.getDefault(FieldConfig.EncodingType.DICTIONARY);
}
@Override
@@ -110,6 +117,11 @@ public class ForwardIndexType extends
AbstractIndexType<ForwardIndexConfig, Forw
String column = fieldSpec.getName();
CompressionCodec compressionCodec =
forwardIndexConfig.getCompressionCodec();
DictionaryIndexConfig dictionaryConfig =
indexConfigs.getConfig(StandardIndexes.dictionary());
+ // Dictionary-encoded forward index requires a dictionary to translate
dict ids back to values.
+ if (forwardIndexConfig.getEncodingType() ==
FieldConfig.EncodingType.DICTIONARY) {
+ Preconditions.checkState(dictionaryConfig.isEnabled(),
+ "Dictionary must be enabled for dictionary-encoded forward index
column: %s", column);
+ }
if (dictionaryConfig.isEnabled()) {
Preconditions.checkState(compressionCodec == null ||
compressionCodec.isApplicableToDictEncodedIndex(),
"Compression codec: %s is not applicable to dictionary encoded
column: %s", compressionCodec, column);
@@ -166,32 +178,97 @@ public class ForwardIndexType extends
AbstractIndexType<ForwardIndexConfig, Forw
return INDEX_DISPLAY_NAME;
}
+ /// Resolves per-column [ForwardIndexConfig] in a single pass over
[TableConfig], reconciling the legacy signals
+ /// (`indexingConfig.noDictionaryColumns`,
`indexingConfig.noDictionaryConfig`, `fieldConfig.encodingType`,
+ /// `fieldConfig.compressionCodec`) with the modern
`fieldConfig.indexes.forward` JSON block. The deserializer
+ /// fails fast on conflicting signals.
@Override
- protected ColumnConfigDeserializer<ForwardIndexConfig>
createDeserializerForLegacyConfigs() {
- // reads tableConfig.fieldConfigList and decides what to create using the
FieldConfig properties and encoding
+ protected ColumnConfigDeserializer<ForwardIndexConfig> createDeserializer() {
return (tableConfig, schema) -> {
- Map<String, DictionaryIndexConfig> dictConfigs =
StandardIndexes.dictionary().getConfig(tableConfig, schema);
+ Map<String, ForwardIndexConfig> result = new HashMap<>();
- Map<String, ForwardIndexConfig> fwdConfig =
- Maps.newHashMapWithExpectedSize(Math.max(dictConfigs.size(),
schema.size()));
+ // Legacy noDictionary signals — both indicate RAW forward index for the
listed columns.
+ IndexingConfig indexingConfig = tableConfig.getIndexingConfig();
+ Set<String> noDictionaryColumns = new HashSet<>();
+ if (indexingConfig.getNoDictionaryColumns() != null) {
+ noDictionaryColumns.addAll(indexingConfig.getNoDictionaryColumns());
+ }
+ Map<String, String> noDictionaryConfig =
indexingConfig.getNoDictionaryConfig();
+ if (noDictionaryConfig != null) {
+ noDictionaryColumns.addAll(noDictionaryConfig.keySet());
+ }
Collection<FieldConfig> fieldConfigs = tableConfig.getFieldConfigList();
if (fieldConfigs != null) {
for (FieldConfig fieldConfig : fieldConfigs) {
+ String column = fieldConfig.getName();
+ // Pop processed columns so the post-loop scan only emits defaults
for columns with no FieldConfig at all.
+ boolean inNoDictionaryList = noDictionaryColumns.remove(column);
+
+ // `forwardIndexDisabled` short-circuits everything else.
Map<String, String> properties = fieldConfig.getProperties();
if (properties != null && isDisabled(properties)) {
- fwdConfig.put(fieldConfig.getName(),
ForwardIndexConfig.getDisabled());
- } else {
- ForwardIndexConfig config =
createConfigFromFieldConfig(fieldConfig);
- if (!config.equals(ForwardIndexConfig.getDefault())) {
- fwdConfig.put(fieldConfig.getName(), config);
+ result.put(column, ForwardIndexConfig.getDisabled());
+ continue;
+ }
+
+ // Resolve the forward-index encoding. `FieldConfig.encodingType` is
never null (the FieldConfig constructor
+ // defaults it to DICTIONARY when unset), so the per-column override
here is the legacy
+ // `noDictionaryColumns` / `noDictionaryConfig` membership —
historically these may be set alongside a
+ // FieldConfig that left `encodingType` at the default DICTIONARY.
+ FieldConfig.CompressionCodec fcCodec =
fieldConfig.getCompressionCodec();
+ FieldConfig.EncodingType encodingType =
+ inNoDictionaryList ? FieldConfig.EncodingType.RAW :
fieldConfig.getEncodingType();
+
+ JsonNode forwardIndexNode =
fieldConfig.getIndexes().get(INDEX_DISPLAY_NAME);
+ if (forwardIndexNode != null) {
+ Preconditions.checkState(forwardIndexNode.isObject(), "Invalid
forward index config for column: %s",
+ column);
+
+ // Conflict: encodingType mismatch between resolved FieldConfig
encoding and indexes.forward.
+ JsonNode innerEncodingNode = forwardIndexNode.get("encodingType");
+ if (innerEncodingNode != null && !innerEncodingNode.isNull()) {
+ FieldConfig.EncodingType inner =
FieldConfig.EncodingType.valueOf(innerEncodingNode.asText());
+ Preconditions.checkState(inner == encodingType,
+ "Conflicting forward-index encoding for column: %s —
FieldConfig.encodingType=%s but "
+ + "indexes.forward.encodingType=%s", column,
encodingType, inner);
}
- // It is important to do not explicitly add the default value here
in order to avoid exclusive problems with
- // the default `fromIndexes` deserializer.
+
+ // Conflict: compressionCodec mismatch between FieldConfig and
indexes.forward.
+ JsonNode innerCodecNode = forwardIndexNode.get("compressionCodec");
+ if (innerCodecNode != null && !innerCodecNode.isNull() && fcCodec
!= null) {
+ FieldConfig.CompressionCodec inner =
FieldConfig.CompressionCodec.valueOf(innerCodecNode.asText());
+ Preconditions.checkState(inner == fcCodec,
+ "Conflicting forward-index compressionCodec for column: %s —
FieldConfig.compressionCodec=%s "
+ + "but indexes.forward.compressionCodec=%s", column,
fcCodec, inner);
+ }
+
+ // Inject the resolved encodingType / compressionCodec into the
JSON when absent so the resulting
+ // ForwardIndexConfig always matches the column-level signals.
+ ObjectNode configNode = (ObjectNode) forwardIndexNode.deepCopy();
+ if (innerEncodingNode == null || innerEncodingNode.isNull()) {
+ configNode.put("encodingType", encodingType.name());
+ }
+ if ((innerCodecNode == null || innerCodecNode.isNull()) && fcCodec
!= null) {
+ configNode.put("compressionCodec", fcCodec.name());
+ }
+ try {
+ result.put(column, JsonUtils.jsonNodeToObject(configNode,
ForwardIndexConfig.class));
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
+ }
+ } else {
+ result.put(column, createConfigFromFieldConfig(fieldConfig,
encodingType));
}
}
}
- return fwdConfig;
+
+ // Columns listed in noDictionaryColumns/noDictionaryConfig that have no
FieldConfig at all — emit a RAW default.
+ // (Columns with a FieldConfig were already removed from
`noDictionaryColumns` above.)
+ for (String column : noDictionaryColumns) {
+ result.put(column,
ForwardIndexConfig.getDefault(FieldConfig.EncodingType.RAW));
+ }
+ return result;
};
}
@@ -200,9 +277,10 @@ public class ForwardIndexType extends
AbstractIndexType<ForwardIndexConfig, Forw
props.getOrDefault(FieldConfig.FORWARD_INDEX_DISABLED,
FieldConfig.DEFAULT_FORWARD_INDEX_DISABLED));
}
- private ForwardIndexConfig createConfigFromFieldConfig(FieldConfig
fieldConfig) {
- ForwardIndexConfig.Builder builder = new ForwardIndexConfig.Builder();
- builder.withCompressionCodec(fieldConfig.getCompressionCodec());
+ private ForwardIndexConfig createConfigFromFieldConfig(FieldConfig
fieldConfig,
+ FieldConfig.EncodingType resolvedEncodingType) {
+ ForwardIndexConfig.Builder builder = new
ForwardIndexConfig.Builder(resolvedEncodingType)
+ .withCompressionCodec(fieldConfig.getCompressionCodec());
Map<String, String> properties = fieldConfig.getProperties();
if (properties != null) {
builder.withLegacyProperties(properties);
@@ -250,15 +328,16 @@ public class ForwardIndexType extends
AbstractIndexType<ForwardIndexConfig, Forw
}
public String getFileExtension(ColumnMetadata columnMetadata) {
+ boolean isRaw = columnMetadata.getForwardIndexEncoding() ==
FieldConfig.EncodingType.RAW;
if (columnMetadata.isSingleValue()) {
- if (!columnMetadata.hasDictionary()) {
+ if (isRaw) {
return V1Constants.Indexes.RAW_SV_FORWARD_INDEX_FILE_EXTENSION;
} else if (columnMetadata.isSorted()) {
return V1Constants.Indexes.SORTED_SV_FORWARD_INDEX_FILE_EXTENSION;
} else {
return V1Constants.Indexes.UNSORTED_SV_FORWARD_INDEX_FILE_EXTENSION;
}
- } else if (!columnMetadata.hasDictionary()) {
+ } else if (isRaw) {
return V1Constants.Indexes.RAW_MV_FORWARD_INDEX_FILE_EXTENSION;
} else {
return V1Constants.Indexes.UNSORTED_MV_FORWARD_INDEX_FILE_EXTENSION;
diff --git
a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/loader/ForwardIndexHandler.java
b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/loader/ForwardIndexHandler.java
index 2473399610f..4a7c7fb913c 100644
---
a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/loader/ForwardIndexHandler.java
+++
b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/loader/ForwardIndexHandler.java
@@ -68,6 +68,7 @@ import
org.apache.pinot.segment.spi.index.reader.ForwardIndexReader;
import org.apache.pinot.segment.spi.index.reader.ForwardIndexReaderContext;
import org.apache.pinot.segment.spi.store.SegmentDirectory;
import org.apache.pinot.segment.spi.utils.SegmentMetadataUtils;
+import org.apache.pinot.spi.config.table.FieldConfig;
import org.apache.pinot.spi.config.table.IndexingConfig;
import org.apache.pinot.spi.config.table.TableConfig;
import org.apache.pinot.spi.data.FieldSpec;
@@ -342,6 +343,7 @@ public class ForwardIndexHandler extends BaseIndexHandler {
segmentName, column);
Map<String, String> metadataProperties = new HashMap<>();
metadataProperties.put(getKeyFor(column, HAS_DICTIONARY),
String.valueOf(false));
+ metadataProperties.put(getKeyFor(column, FORWARD_INDEX_ENCODING),
FieldConfig.EncodingType.RAW.name());
metadataProperties.put(getKeyFor(column, DICTIONARY_ELEMENT_SIZE),
String.valueOf(0));
// TODO: See https://github.com/apache/pinot/pull/16921 for details
// metadataProperties.put(getKeyFor(column, BITS_PER_ELEMENT),
String.valueOf(-1));
@@ -898,6 +900,7 @@ public class ForwardIndexHandler extends BaseIndexHandler {
LOGGER.info("Created forwardIndex. Updating metadata properties for
segment={} and column={}", segmentName, column);
Map<String, String> metadataProperties = new HashMap<>();
metadataProperties.put(getKeyFor(column, HAS_DICTIONARY),
String.valueOf(true));
+ metadataProperties.put(getKeyFor(column, FORWARD_INDEX_ENCODING),
FieldConfig.EncodingType.DICTIONARY.name());
metadataProperties.put(getKeyFor(column, DICTIONARY_ELEMENT_SIZE),
String.valueOf(dictionaryCreator.getNumBytesPerEntry()));
// If realtime segments were completed when the column was RAW, the
cardinality value is populated as Integer
@@ -961,6 +964,7 @@ public class ForwardIndexHandler extends BaseIndexHandler {
column);
Map<String, String> metadataProperties = new HashMap<>();
metadataProperties.put(getKeyFor(column, HAS_DICTIONARY),
String.valueOf(false));
+ metadataProperties.put(getKeyFor(column, FORWARD_INDEX_ENCODING),
FieldConfig.EncodingType.RAW.name());
metadataProperties.put(getKeyFor(column, DICTIONARY_ELEMENT_SIZE),
String.valueOf(0));
// TODO: See https://github.com/apache/pinot/pull/16921 for details
// metadataProperties.put(getKeyFor(column, BITS_PER_ELEMENT),
String.valueOf(-1));
diff --git
a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/loader/InvertedIndexAndDictionaryBasedForwardIndexCreator.java
b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/loader/InvertedIndexAndDictionaryBasedForwardIndexCreator.java
index 3163f8c34fe..0c798691069 100644
---
a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/loader/InvertedIndexAndDictionaryBasedForwardIndexCreator.java
+++
b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/loader/InvertedIndexAndDictionaryBasedForwardIndexCreator.java
@@ -40,6 +40,7 @@ import org.apache.pinot.segment.spi.index.reader.Dictionary;
import org.apache.pinot.segment.spi.memory.PinotDataBuffer;
import org.apache.pinot.segment.spi.store.SegmentDirectory;
import org.apache.pinot.segment.spi.utils.SegmentMetadataUtils;
+import org.apache.pinot.spi.config.table.FieldConfig;
import org.apache.pinot.spi.data.FieldSpec;
import org.roaringbitmap.buffer.ImmutableRoaringBitmap;
import org.slf4j.Logger;
@@ -281,10 +282,12 @@ public class
InvertedIndexAndDictionaryBasedForwardIndexCreator implements AutoC
// Setup and return the metadata properties to update
if (_dictionaryEnabled) {
- return Map.of();
+ return Map.of(
+ getKeyFor(_columnName, FORWARD_INDEX_ENCODING),
FieldConfig.EncodingType.DICTIONARY.name());
} else {
return Map.of(
getKeyFor(_columnName, HAS_DICTIONARY), String.valueOf(false),
+ getKeyFor(_columnName, FORWARD_INDEX_ENCODING),
FieldConfig.EncodingType.RAW.name(),
getKeyFor(_columnName, DICTIONARY_ELEMENT_SIZE), String.valueOf(0)
// TODO: See https://github.com/apache/pinot/pull/16921 for details
// getKeyFor(_columnName, BITS_PER_ELEMENT), String.valueOf(-1)
@@ -376,6 +379,8 @@ public class
InvertedIndexAndDictionaryBasedForwardIndexCreator implements AutoC
metadataProperties.put(getKeyFor(_columnName, MAX_MULTI_VALUE_ELEMENTS),
String.valueOf(maxNumberOfMultiValues[0]));
metadataProperties.put(getKeyFor(_columnName, TOTAL_NUMBER_OF_ENTRIES),
String.valueOf(_nextValueId));
+ metadataProperties.put(getKeyFor(_columnName, FORWARD_INDEX_ENCODING),
+ (_dictionaryEnabled ? FieldConfig.EncodingType.DICTIONARY :
FieldConfig.EncodingType.RAW).name());
if (!_dictionaryEnabled) {
metadataProperties.put(getKeyFor(_columnName, HAS_DICTIONARY),
String.valueOf(false));
metadataProperties.put(getKeyFor(_columnName,
DICTIONARY_ELEMENT_SIZE), String.valueOf(0));
diff --git
a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/loader/defaultcolumn/BaseDefaultColumnHandler.java
b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/loader/defaultcolumn/BaseDefaultColumnHandler.java
index 8a0951f5575..891cc709574 100644
---
a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/loader/defaultcolumn/BaseDefaultColumnHandler.java
+++
b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/loader/defaultcolumn/BaseDefaultColumnHandler.java
@@ -75,6 +75,7 @@ import org.apache.pinot.segment.spi.index.reader.Dictionary;
import org.apache.pinot.segment.spi.index.reader.ForwardIndexReader;
import org.apache.pinot.segment.spi.store.SegmentDirectory;
import org.apache.pinot.segment.spi.utils.SegmentMetadataUtils;
+import org.apache.pinot.spi.config.table.FieldConfig;
import org.apache.pinot.spi.config.table.TableConfig;
import org.apache.pinot.spi.config.table.ingestion.IngestionConfig;
import org.apache.pinot.spi.config.table.ingestion.TransformConfig;
@@ -527,7 +528,7 @@ public abstract class BaseDefaultColumnHandler implements
DefaultColumnHandler {
// Add the column metadata information to the metadata properties.
BaseSegmentCreator.addColumnMetadataInfo(_segmentProperties, column,
columnStatistics, totalDocs, fieldSpec, true,
- dictionaryElementSize, true);
+ dictionaryElementSize, FieldConfig.EncodingType.DICTIONARY, true);
}
private boolean isNullable(FieldSpec fieldSpec) {
@@ -1112,7 +1113,7 @@ public abstract class BaseDefaultColumnHandler implements
DefaultColumnHandler {
}
// Add the column metadata
BaseSegmentCreator.addColumnMetadataInfo(_segmentProperties, column,
columnStatistics, numDocs, fieldSpec, true,
- dictionaryCreator.getNumBytesPerEntry(), true);
+ dictionaryCreator.getNumBytesPerEntry(),
FieldConfig.EncodingType.DICTIONARY, true);
}
}
}
@@ -1197,7 +1198,7 @@ public abstract class BaseDefaultColumnHandler implements
DefaultColumnHandler {
// Add the column metadata
BaseSegmentCreator.addColumnMetadataInfo(_segmentProperties, column,
columnStatistics, numDocs, fieldSpec, false,
- 0, true);
+ 0, FieldConfig.EncodingType.RAW, true);
}
private ForwardIndexCreator getForwardIndexCreator(FieldSpec fieldSpec,
ColumnStatistics columnStatistics,
@@ -1221,7 +1222,8 @@ public abstract class BaseDefaultColumnHandler implements
DefaultColumnHandler {
forwardIndexConfig =
fieldIndexConfig.getConfig(StandardIndexes.forward());
}
if (forwardIndexConfig == null) {
- forwardIndexConfig = new ForwardIndexConfig(false, null, null, null,
null, null, null);
+ forwardIndexConfig = ForwardIndexConfig.getDefault(
+ hasDictionary ? FieldConfig.EncodingType.DICTIONARY :
FieldConfig.EncodingType.RAW);
}
return StandardIndexes.forward().createIndexCreator(indexCreationContext,
forwardIndexConfig);
}
@@ -1237,7 +1239,7 @@ public abstract class BaseDefaultColumnHandler implements
DefaultColumnHandler {
IndexReaderFactory<ForwardIndexReader> readerFactory =
StandardIndexes.forward().getReaderFactory();
FieldIndexConfigs fieldIndexConfigs = new FieldIndexConfigs.Builder()
- .add(StandardIndexes.forward(), ForwardIndexConfig.getDefault())
+ .add(StandardIndexes.forward(),
ForwardIndexConfig.getDefault(columnMetadata.getForwardIndexEncoding()))
.build();
_forwardIndexReader = readerFactory.createIndexReader(_segmentWriter,
fieldIndexConfigs, columnMetadata);
if (columnMetadata.hasDictionary()) {
diff --git
a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/map/SimpleColumnMetadata.java
b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/map/SimpleColumnMetadata.java
index 7e5b519b5ce..067a22d78e8 100644
---
a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/map/SimpleColumnMetadata.java
+++
b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/map/SimpleColumnMetadata.java
@@ -23,6 +23,7 @@ import javax.annotation.Nullable;
import org.apache.pinot.segment.spi.ColumnMetadata;
import org.apache.pinot.segment.spi.index.IndexType;
import org.apache.pinot.segment.spi.partition.PartitionFunction;
+import org.apache.pinot.spi.config.table.FieldConfig;
import org.apache.pinot.spi.data.DimensionFieldSpec;
import org.apache.pinot.spi.data.FieldSpec;
import org.apache.pinot.spi.data.FieldSpec.DataType;
@@ -63,6 +64,11 @@ public class SimpleColumnMetadata implements ColumnMetadata {
return false;
}
+ @Override
+ public FieldConfig.EncodingType getForwardIndexEncoding() {
+ return FieldConfig.EncodingType.RAW;
+ }
+
@Override
public boolean isSorted() {
return false;
diff --git
a/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/realtime/converter/RealtimeSegmentConverterTest.java
b/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/realtime/converter/RealtimeSegmentConverterTest.java
index b8d1913cdae..b5b2d400a28 100644
---
a/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/realtime/converter/RealtimeSegmentConverterTest.java
+++
b/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/realtime/converter/RealtimeSegmentConverterTest.java
@@ -50,6 +50,7 @@ import
org.apache.pinot.segment.local.segment.virtualcolumn.VirtualColumnProvide
import org.apache.pinot.segment.spi.ColumnMetadata;
import org.apache.pinot.segment.spi.creator.SegmentVersion;
import org.apache.pinot.segment.spi.index.DictionaryIndexConfig;
+import org.apache.pinot.segment.spi.index.ForwardIndexConfig;
import org.apache.pinot.segment.spi.index.StandardIndexes;
import org.apache.pinot.segment.spi.index.TextIndexConfig;
import org.apache.pinot.segment.spi.index.column.ColumnIndexContainer;
@@ -166,6 +167,8 @@ public class RealtimeSegmentConverterTest implements
PinotBuffersAfterMethodChec
.setCapacity(1000)
.setAvgNumMultiValues(3)
.setIndex(Set.of(LONG_COLUMN2), StandardIndexes.dictionary(),
DictionaryIndexConfig.DISABLED)
+ .setIndex(Set.of(LONG_COLUMN2), StandardIndexes.forward(),
+ ForwardIndexConfig.getDefault(FieldConfig.EncodingType.RAW))
.setIndex(Set.of(STRING_COLUMN3), StandardIndexes.dictionary(), new
DictionaryIndexConfig(false, true))
.setIndex(Set.of(STRING_COLUMN1), StandardIndexes.inverted(),
IndexConfig.ENABLED)
.setSegmentZKMetadata(getSegmentZKMetadata(segmentName))
@@ -242,6 +245,8 @@ public class RealtimeSegmentConverterTest implements
PinotBuffersAfterMethodChec
.setCapacity(1000)
.setAvgNumMultiValues(3)
.setIndex(Set.of(LONG_COLUMN2), StandardIndexes.dictionary(),
DictionaryIndexConfig.DISABLED)
+ .setIndex(Set.of(LONG_COLUMN2), StandardIndexes.forward(),
+ ForwardIndexConfig.getDefault(FieldConfig.EncodingType.RAW))
.setIndex(Set.of(STRING_COLUMN3), StandardIndexes.dictionary(), new
DictionaryIndexConfig(false, true))
.setIndex(Set.of(STRING_COLUMN1, LONG_COLUMN1),
StandardIndexes.inverted(), IndexConfig.ENABLED)
.setSegmentZKMetadata(getSegmentZKMetadata(segmentName))
@@ -332,6 +337,8 @@ public class RealtimeSegmentConverterTest implements
PinotBuffersAfterMethodChec
.setCapacity(1000)
.setAvgNumMultiValues(3)
.setIndex(Set.of(LONG_COLUMN2), StandardIndexes.dictionary(),
DictionaryIndexConfig.DISABLED)
+ .setIndex(Set.of(LONG_COLUMN2), StandardIndexes.forward(),
+ ForwardIndexConfig.getDefault(FieldConfig.EncodingType.RAW))
.setIndex(Set.of(STRING_COLUMN3), StandardIndexes.dictionary(), new
DictionaryIndexConfig(false, true))
.setIndex(Set.of(STRING_COLUMN1), StandardIndexes.inverted(),
IndexConfig.ENABLED)
.setSegmentZKMetadata(getSegmentZKMetadata(segmentName))
@@ -408,6 +415,8 @@ public class RealtimeSegmentConverterTest implements
PinotBuffersAfterMethodChec
.setCapacity(1000)
.setAvgNumMultiValues(3)
.setIndex(Set.of(LONG_COLUMN2), StandardIndexes.dictionary(),
DictionaryIndexConfig.DISABLED)
+ .setIndex(Set.of(LONG_COLUMN2), StandardIndexes.forward(),
+ ForwardIndexConfig.getDefault(FieldConfig.EncodingType.RAW))
.setIndex(Set.of(STRING_COLUMN3), StandardIndexes.dictionary(), new
DictionaryIndexConfig(false, true))
.setIndex(Set.of(STRING_COLUMN1, LONG_COLUMN1),
StandardIndexes.inverted(), IndexConfig.ENABLED)
.setSegmentZKMetadata(getSegmentZKMetadata(segmentName))
@@ -495,10 +504,10 @@ public class RealtimeSegmentConverterTest implements
PinotBuffersAfterMethodChec
@DataProvider
public static Object[][] optimizeDictionaryTypeParams() {
- // Format: {optimizeDictionaryType, expectedCRC}, crc is used here to
check the correct dictionary type was used
+ // Format: {optimizeDictionaryType, expectedCRC}, crc is used here to
check the correct dictionary type was used.
return new Object[][]{
- {true, "3570313565"},
- {false, "4134511491"},
+ {true, "94495458"},
+ {false, "2028789000"},
};
}
@@ -648,7 +657,7 @@ public class RealtimeSegmentConverterTest implements
PinotBuffersAfterMethodChec
.withLuceneNRTCachingDirectoryMaxBufferSizeMB(luceneNRTCachingDirectoryMaxBufferSizeMB)
.withRawValueForTextIndex(rawValueForTextIndex)
.build();
- RealtimeSegmentConfig realtimeSegmentConfig = new
RealtimeSegmentConfig.Builder()
+ RealtimeSegmentConfig.Builder realtimeSegmentConfigBuilder = new
RealtimeSegmentConfig.Builder()
.setTableNameWithType(tableNameWithType)
.setSegmentName(segmentName)
.setStreamName(tableNameWithType)
@@ -662,8 +671,12 @@ public class RealtimeSegmentConverterTest implements
PinotBuffersAfterMethodChec
.setOffHeap(true)
.setMemoryManager(new DirectMemoryManager(segmentName))
.setStatsHistory(RealtimeSegmentStatsHistory.deserializeFrom(new
File(tmpDir, "stats")))
- .setConsumerDir(new File(tmpDir, "consumerDir").getAbsolutePath())
- .build();
+ .setConsumerDir(new File(tmpDir, "consumerDir").getAbsolutePath());
+ if (!dictionaryIndexConfig.isEnabled()) {
+ realtimeSegmentConfigBuilder.setIndex(Set.of(STRING_COLUMN1),
StandardIndexes.forward(),
+ ForwardIndexConfig.getDefault(FieldConfig.EncodingType.RAW));
+ }
+ RealtimeSegmentConfig realtimeSegmentConfig =
realtimeSegmentConfigBuilder.build();
// create mutable segment impl
RealtimeLuceneTextIndexSearcherPool.init(1);
diff --git
a/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/index/ColumnMetadataTest.java
b/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/index/ColumnMetadataTest.java
index b5b2d936378..b00c69b87b4 100644
---
a/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/index/ColumnMetadataTest.java
+++
b/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/index/ColumnMetadataTest.java
@@ -44,6 +44,7 @@ import
org.apache.pinot.segment.spi.index.metadata.ColumnMetadataImpl;
import org.apache.pinot.segment.spi.index.metadata.SegmentMetadataImpl;
import
org.apache.pinot.segment.spi.partition.BoundedColumnValuePartitionFunction;
import org.apache.pinot.spi.config.table.ColumnPartitionConfig;
+import org.apache.pinot.spi.config.table.FieldConfig;
import org.apache.pinot.spi.config.table.SegmentPartitionConfig;
import org.apache.pinot.spi.config.table.TableConfig;
import org.apache.pinot.spi.config.table.TableType;
@@ -54,6 +55,7 @@ import org.apache.pinot.spi.data.FieldSpec.DataType;
import org.apache.pinot.spi.data.Schema;
import org.apache.pinot.spi.data.readers.FileFormat;
import org.apache.pinot.spi.env.CommonsConfigurationUtils;
+import org.apache.pinot.spi.utils.JsonUtils;
import org.apache.pinot.spi.utils.TimeUtils;
import org.apache.pinot.spi.utils.builder.TableConfigBuilder;
import org.apache.pinot.util.TestUtils;
@@ -302,11 +304,43 @@ public class ColumnMetadataTest {
new DimensionFieldSpec("value", DataType.INT, true)));
PropertiesConfiguration config = new PropertiesConfiguration();
BaseSegmentCreator.addColumnMetadataInfo(config, "intMap",
mock(ColumnStatistics.class), 1, intMapFieldSpec, false,
- -1, false);
+ -1, FieldConfig.EncodingType.RAW, false);
ColumnMetadataImpl intMapColumnMetadata =
ColumnMetadataImpl.fromPropertiesConfiguration(config, 1, "intMap");
assertEquals(intMapColumnMetadata.getFieldSpec(), intMapFieldSpec);
}
+ @Test
+ public void testColumnMetadataEqualityIncludesForwardIndexEncoding() {
+ DimensionFieldSpec fieldSpec = new DimensionFieldSpec("col", DataType.INT,
true);
+ ColumnMetadataImpl dictForwardMetadata = new ColumnMetadataImpl.Builder()
+ .setFieldSpec(fieldSpec)
+ .setHasDictionary(true)
+ .setForwardIndexEncoding(FieldConfig.EncodingType.DICTIONARY)
+ .build();
+ ColumnMetadataImpl rawForwardMetadata = new ColumnMetadataImpl.Builder()
+ .setFieldSpec(fieldSpec)
+ .setHasDictionary(true)
+ .setForwardIndexEncoding(FieldConfig.EncodingType.RAW)
+ .build();
+
+ assertNotEquals(dictForwardMetadata, rawForwardMetadata);
+ assertNotEquals(dictForwardMetadata.hashCode(),
rawForwardMetadata.hashCode());
+
assertTrue(dictForwardMetadata.toString().contains("_forwardIndexEncoding=DICTIONARY"));
+ }
+
+ @Test
+ public void testForwardIndexEncodingIsExposedInJson()
+ throws Exception {
+ ColumnMetadataImpl rawMetadata = new ColumnMetadataImpl.Builder()
+ .setFieldSpec(new DimensionFieldSpec("col", DataType.INT, true))
+ .setHasDictionary(false)
+ .setForwardIndexEncoding(FieldConfig.EncodingType.RAW)
+ .build();
+ String json = JsonUtils.objectToString(rawMetadata);
+ assertTrue(json.contains("\"forwardIndexEncoding\":\"RAW\""),
+ "Expected forwardIndexEncoding in JSON output but got: " + json);
+ }
+
@Test
public void testSetAndCheckIndexSizes() {
ColumnMetadataImpl meta =
diff --git
a/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/index/forward/ForwardIndexCreatorFactoryTest.java
b/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/index/forward/ForwardIndexCreatorFactoryTest.java
new file mode 100644
index 00000000000..47bd8feee27
--- /dev/null
+++
b/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/index/forward/ForwardIndexCreatorFactoryTest.java
@@ -0,0 +1,83 @@
+/**
+ * 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.local.segment.index.forward;
+
+import java.io.File;
+import java.nio.file.Files;
+import org.apache.commons.io.FileUtils;
+import org.apache.pinot.segment.spi.creator.IndexCreationContext;
+import org.apache.pinot.segment.spi.index.ForwardIndexConfig;
+import org.apache.pinot.segment.spi.index.creator.ForwardIndexCreator;
+import org.apache.pinot.spi.config.table.FieldConfig;
+import org.apache.pinot.spi.data.DimensionFieldSpec;
+import org.apache.pinot.spi.data.FieldSpec;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+
+
+/**
+ * Tests {@link ForwardIndexCreatorFactory}'s forward-index encoding branch
selection. Each test uses an isolated
+ * temporary index directory and does not share mutable state.
+ */
+public class ForwardIndexCreatorFactoryTest {
+ private static final String COLUMN_NAME = "testCol";
+
+ @Test
+ public void testRawEncodingBuildsRawForwardIndexEvenWithDictionary()
+ throws Exception {
+ File indexDir =
Files.createTempDirectory("ForwardIndexCreatorFactoryTest").toFile();
+ try (ForwardIndexCreator creator =
ForwardIndexCreatorFactory.createIndexCreator(newContext(indexDir, true),
+ new ForwardIndexConfig.Builder(FieldConfig.EncodingType.RAW).build()))
{
+ assertFalse(creator.isDictionaryEncoded());
+ creator.putInt(1);
+ creator.seal();
+ } finally {
+ FileUtils.deleteQuietly(indexDir);
+ }
+ }
+
+ @Test
+ public void testDefaultEncodingBuildsDictionaryForwardIndex()
+ throws Exception {
+ File indexDir =
Files.createTempDirectory("ForwardIndexCreatorFactoryTest").toFile();
+ try (ForwardIndexCreator creator =
+ ForwardIndexCreatorFactory.createIndexCreator(newContext(indexDir,
true),
+
ForwardIndexConfig.getDefault(FieldConfig.EncodingType.DICTIONARY))) {
+ assertTrue(creator.isDictionaryEncoded());
+ creator.putDictId(0);
+ creator.seal();
+ } finally {
+ FileUtils.deleteQuietly(indexDir);
+ }
+ }
+
+ private static IndexCreationContext newContext(File indexDir, boolean
hasDictionary) {
+ FieldSpec fieldSpec = new DimensionFieldSpec(COLUMN_NAME,
FieldSpec.DataType.INT, true);
+ return IndexCreationContext.builder()
+ .withIndexDir(indexDir)
+ .withFieldSpec(fieldSpec)
+ .withDictionary(hasDictionary)
+ .withCardinality(2)
+ .withTotalDocs(1)
+ .build();
+ }
+}
diff --git
a/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/index/forward/ForwardIndexTypeTest.java
b/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/index/forward/ForwardIndexTypeTest.java
index 362c88a8a86..43fde236a76 100644
---
a/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/index/forward/ForwardIndexTypeTest.java
+++
b/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/index/forward/ForwardIndexTypeTest.java
@@ -39,6 +39,8 @@ import org.testng.annotations.Test;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertSame;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.expectThrows;
public class ForwardIndexTypeTest {
@@ -92,7 +94,7 @@ public class ForwardIndexTypeTest {
JsonUtils.stringToObject("[]", _fieldConfigListTypeRef)
);
- assertEquals(ForwardIndexConfig.getDefault());
+
assertEquals(ForwardIndexConfig.getDefault(FieldConfig.EncodingType.DICTIONARY));
}
@Test
@@ -120,7 +122,7 @@ public class ForwardIndexTypeTest {
+ " }"
);
- assertEquals(ForwardIndexConfig.getDefault());
+
assertEquals(ForwardIndexConfig.getDefault(FieldConfig.EncodingType.DICTIONARY));
}
@Test
@@ -139,7 +141,7 @@ public class ForwardIndexTypeTest {
);
assertEquals(
- new ForwardIndexConfig.Builder()
+ new ForwardIndexConfig.Builder(FieldConfig.EncodingType.RAW)
.withCompressionType(ChunkCompressionType.SNAPPY)
.withDeriveNumDocsPerChunk(false)
.build()
@@ -159,7 +161,7 @@ public class ForwardIndexTypeTest {
);
assertEquals(
- new ForwardIndexConfig.Builder()
+ new ForwardIndexConfig.Builder(FieldConfig.EncodingType.RAW)
.withCompressionType(ChunkCompressionType.SNAPPY)
.withDeriveNumDocsPerChunk(false)
.build()
@@ -175,7 +177,7 @@ public class ForwardIndexTypeTest {
+ " \"encodingType\": \"DICTIONARY\"\n"
+ " }"
);
- assertEquals(ForwardIndexConfig.getDefault());
+
assertEquals(ForwardIndexConfig.getDefault(FieldConfig.EncodingType.DICTIONARY));
}
@Test
@@ -189,7 +191,8 @@ public class ForwardIndexTypeTest {
+ "}"
);
assertEquals(
- new
ForwardIndexConfig.Builder().withDictIdCompressionType(DictIdCompressionType.MV_ENTRY_DICT).build());
+ new ForwardIndexConfig.Builder(FieldConfig.EncodingType.DICTIONARY)
+
.withDictIdCompressionType(DictIdCompressionType.MV_ENTRY_DICT).build());
}
@Test
@@ -202,7 +205,7 @@ public class ForwardIndexTypeTest {
+ " }"
);
- assertEquals(ForwardIndexConfig.getDefault());
+
assertEquals(ForwardIndexConfig.getDefault(FieldConfig.EncodingType.RAW));
}
@Test(dataProvider = "allCompressionCodec", dataProviderClass =
ForwardIndexTypeTest.class)
@@ -220,7 +223,7 @@ public class ForwardIndexTypeTest {
);
assertEquals(
- new ForwardIndexConfig.Builder()
+ new ForwardIndexConfig.Builder(FieldConfig.EncodingType.RAW)
.withCompressionCodec(compression == null ? null :
FieldConfig.CompressionCodec.valueOf(compression))
.withCompressionType(expectedChunkCompression)
.withDictIdCompressionType(expectedDictCompression)
@@ -243,7 +246,7 @@ public class ForwardIndexTypeTest {
+ " }"
);
- assertEquals(new ForwardIndexConfig.Builder()
+ assertEquals(new ForwardIndexConfig.Builder(FieldConfig.EncodingType.RAW)
.withCompressionType(null)
.withDeriveNumDocsPerChunk(true)
.withRawIndexWriterVersion(ForwardIndexConfig.getDefaultRawWriterVersion())
@@ -263,7 +266,7 @@ public class ForwardIndexTypeTest {
+ " }"
);
- assertEquals(new ForwardIndexConfig.Builder()
+ assertEquals(new ForwardIndexConfig.Builder(FieldConfig.EncodingType.RAW)
.withCompressionType(null)
.withDeriveNumDocsPerChunk(false)
.withRawIndexWriterVersion(3)
@@ -296,7 +299,7 @@ public class ForwardIndexTypeTest {
+ " }"
);
- assertEquals(ForwardIndexConfig.getDefault());
+
assertEquals(ForwardIndexConfig.getDefault(FieldConfig.EncodingType.DICTIONARY));
}
@Test
@@ -313,7 +316,8 @@ public class ForwardIndexTypeTest {
+ "}"
);
assertEquals(
- new
ForwardIndexConfig.Builder().withDictIdCompressionType(DictIdCompressionType.MV_ENTRY_DICT).build());
+ new ForwardIndexConfig.Builder(FieldConfig.EncodingType.DICTIONARY)
+
.withDictIdCompressionType(DictIdCompressionType.MV_ENTRY_DICT).build());
}
@Test(dataProvider = "allChunkCompression", dataProviderClass =
ForwardIndexTypeTest.class)
@@ -337,7 +341,7 @@ public class ForwardIndexTypeTest {
);
assertEquals(
- new ForwardIndexConfig.Builder()
+ new ForwardIndexConfig.Builder(FieldConfig.EncodingType.DICTIONARY)
.withCompressionType(expectedChunkCompression)
.withDictIdCompressionType(expectedDictCompression)
.withDeriveNumDocsPerChunk(true)
@@ -367,7 +371,7 @@ public class ForwardIndexTypeTest {
);
assertEquals(
- new ForwardIndexConfig.Builder()
+ new ForwardIndexConfig.Builder(FieldConfig.EncodingType.DICTIONARY)
.withCompressionCodec(compression == null ? null :
FieldConfig.CompressionCodec.valueOf(compression))
.withCompressionType(expectedChunkCompression)
.withDictIdCompressionType(expectedDictCompression)
@@ -398,7 +402,7 @@ public class ForwardIndexTypeTest {
);
assertEquals(
- new ForwardIndexConfig.Builder()
+ new ForwardIndexConfig.Builder(FieldConfig.EncodingType.DICTIONARY)
.withCompressionType(expectedChunkCompression)
.withDictIdCompressionType(expectedDictCompression)
.withDeriveNumDocsPerChunk(true)
@@ -425,6 +429,65 @@ public class ForwardIndexTypeTest {
.collect(Collectors.toList()).get(0);
assertNotNull(fieldConfig.getIndexes().get(ForwardIndexType.INDEX_DISPLAY_NAME));
}
+
+ @Test
+ public void
noDictionaryColumnsOverridesFieldConfigDictEncodingForForwardIndex()
+ throws IOException {
+ // Legacy pattern: column listed in noDictionaryColumns alongside a
FieldConfig with the default DICTIONARY
+ // encoding (e.g. for a TEXT index that uses the dictionary internally).
The forward index resolves to RAW.
+ _tableConfig.getIndexingConfig().setNoDictionaryColumns(
+ JsonUtils.stringToObject("[\"dimInt\"]", _stringListTypeRef));
+ addFieldIndexConfig("{\"name\": \"dimInt\", \"encodingType\":
\"DICTIONARY\"}");
+
assertEquals(ForwardIndexConfig.getDefault(FieldConfig.EncodingType.RAW));
+ }
+
+ @Test
+ public void
noDictionaryConfigOverridesFieldConfigDictEncodingForForwardIndex()
+ throws IOException {
+ _tableConfig.getIndexingConfig().setNoDictionaryConfig(
+ JsonUtils.stringToObject("{\"dimInt\": \"RAW\"}",
+ new TypeReference<Map<String, String>>() {
+ }));
+ addFieldIndexConfig("{\"name\": \"dimInt\", \"encodingType\":
\"DICTIONARY\"}");
+
assertEquals(ForwardIndexConfig.getDefault(FieldConfig.EncodingType.RAW));
+ }
+
+ @Test
+ public void conflictingFieldConfigEncodingVsIndexesForward()
+ throws IOException {
+ addFieldIndexConfig(""
+ + " {\n"
+ + " \"name\": \"dimInt\","
+ + " \"encodingType\": \"RAW\","
+ + " \"indexes\" : {"
+ + " \"forward\": { \"encodingType\": \"DICTIONARY\" }"
+ + " }\n"
+ + " }");
+ IllegalStateException ex = expectThrows(IllegalStateException.class,
+ () -> getActualConfig("dimInt", StandardIndexes.forward()));
+ assertTrue(ex.getMessage().contains("dimInt"), "message must name the
column: " + ex.getMessage());
+ assertTrue(ex.getMessage().contains("encoding"),
+ "message must identify encoding as the conflicting field: " +
ex.getMessage());
+ }
+
+ @Test
+ public void conflictingFieldConfigCompressionVsIndexesForward()
+ throws IOException {
+ addFieldIndexConfig(""
+ + " {\n"
+ + " \"name\": \"dimInt\","
+ + " \"encodingType\": \"RAW\","
+ + " \"compressionCodec\": \"SNAPPY\","
+ + " \"indexes\" : {"
+ + " \"forward\": { \"compressionCodec\": \"LZ4\" }"
+ + " }\n"
+ + " }");
+ IllegalStateException ex = expectThrows(IllegalStateException.class,
+ () -> getActualConfig("dimInt", StandardIndexes.forward()));
+ assertTrue(ex.getMessage().contains("dimInt"), "message must name the
column: " + ex.getMessage());
+ assertTrue(ex.getMessage().contains("compressionCodec"),
+ "message must identify compressionCodec as the conflicting field: "
+ ex.getMessage());
+ }
}
@Test
diff --git
a/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/index/loader/ForwardIndexHandlerTest.java
b/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/index/loader/ForwardIndexHandlerTest.java
index cf2db67716d..73a84049fd0 100644
---
a/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/index/loader/ForwardIndexHandlerTest.java
+++
b/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/index/loader/ForwardIndexHandlerTest.java
@@ -1040,7 +1040,7 @@ public class ForwardIndexHandlerTest {
_writer = writer;
existingSegmentMetadata = segmentDirectory.getSegmentMetadata();
- ForwardIndexConfig forwardIndexConfig = new
ForwardIndexConfig.Builder()
+ ForwardIndexConfig forwardIndexConfig = new
ForwardIndexConfig.Builder(FieldConfig.EncodingType.RAW)
.withCompressionCodec(CompressionCodec.LZ4)
.withRawIndexWriterVersion(4)
.build();
@@ -2136,7 +2136,8 @@ public class ForwardIndexHandlerTest {
FieldIndexConfigs.Builder builder = new FieldIndexConfigs.Builder();
// Add forward index config
- ForwardIndexConfig forwardIndexConfig = ForwardIndexConfig.getDefault();
+ ForwardIndexConfig forwardIndexConfig =
+
ForwardIndexConfig.getDefault(columnMetadata.getForwardIndexEncoding());
builder.add(StandardIndexes.forward(), forwardIndexConfig);
// Add dictionary config if the column has dictionary
diff --git
a/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/index/loader/IndexLoadingConfigTest.java
b/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/index/loader/IndexLoadingConfigTest.java
index 18ee15285ae..327c72215db 100644
---
a/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/index/loader/IndexLoadingConfigTest.java
+++
b/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/index/loader/IndexLoadingConfigTest.java
@@ -181,6 +181,7 @@ public class IndexLoadingConfigTest {
assertNotNull(indexConfigs);
ForwardIndexConfig forwardIndexConfig =
indexConfigs.getConfig(StandardIndexes.forward());
assertTrue(forwardIndexConfig.isEnabled());
+ assertEquals(forwardIndexConfig.getEncodingType(),
FieldConfig.EncodingType.RAW);
assertNull(forwardIndexConfig.getCompressionCodec());
assertFalse(forwardIndexConfig.isDeriveNumDocsPerChunk());
assertEquals(forwardIndexConfig.getRawIndexWriterVersion(),
ForwardIndexConfig.getDefaultRawWriterVersion());
@@ -214,6 +215,7 @@ public class IndexLoadingConfigTest {
assertNotNull(indexConfigs);
forwardIndexConfig = indexConfigs.getConfig(StandardIndexes.forward());
assertTrue(forwardIndexConfig.isEnabled());
+ assertEquals(forwardIndexConfig.getEncodingType(),
FieldConfig.EncodingType.RAW);
assertEquals(forwardIndexConfig.getCompressionCodec(),
FieldConfig.CompressionCodec.SNAPPY);
assertTrue(forwardIndexConfig.isDeriveNumDocsPerChunk());
assertEquals(forwardIndexConfig.getRawIndexWriterVersion(), 4);
diff --git
a/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/index/loader/SegmentPreProcessorTest.java
b/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/index/loader/SegmentPreProcessorTest.java
index a0fbc078ee7..a07b235c9c0 100644
---
a/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/index/loader/SegmentPreProcessorTest.java
+++
b/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/index/loader/SegmentPreProcessorTest.java
@@ -824,7 +824,9 @@ public class SegmentPreProcessorTest implements
PinotBuffersAfterClassCheckRule
assertFalse(hasDictionary);
IndexReaderFactory<ForwardIndexReader> readerFactory =
StandardIndexes.forward().getReaderFactory();
FieldIndexConfigs fieldIndexConfigs =
- new FieldIndexConfigs.Builder().add(StandardIndexes.forward(),
ForwardIndexConfig.getDefault()).build();
+ new FieldIndexConfigs.Builder()
+ .add(StandardIndexes.forward(),
ForwardIndexConfig.getDefault(columnMetadata.getForwardIndexEncoding()))
+ .build();
try (ForwardIndexReader fwdIndexReader =
readerFactory.createIndexReader(reader, fieldIndexConfigs,
columnMetadata)) {
ChunkCompressionType compressionType =
fwdIndexReader.getCompressionType();
diff --git
a/pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/ColumnMetadata.java
b/pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/ColumnMetadata.java
index 713a5801503..a5ea5c6fb58 100644
---
a/pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/ColumnMetadata.java
+++
b/pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/ColumnMetadata.java
@@ -25,6 +25,7 @@ import javax.annotation.Nullable;
import org.apache.pinot.segment.spi.index.IndexType;
import org.apache.pinot.segment.spi.partition.PartitionFunction;
import org.apache.pinot.spi.annotations.InterfaceAudience;
+import org.apache.pinot.spi.config.table.FieldConfig.EncodingType;
import org.apache.pinot.spi.data.FieldSpec;
import org.apache.pinot.spi.data.FieldSpec.DataType;
import org.apache.pinot.spi.data.FieldSpec.FieldType;
@@ -62,10 +63,15 @@ public interface ColumnMetadata {
/// [Constants#UNKNOWN_CARDINALITY].
int getCardinality();
- /// Returns `true` when the column is dictionary-encoded, `false` otherwise.
+ /// Returns `true` when the column has a dictionary, `false` otherwise.
@JsonProperty("hasDictionary")
boolean hasDictionary();
+ /// Returns the forward-index encoding for this column. The value is
persisted under
+ /// [V1Constants.MetadataKeys.Column#FORWARD_INDEX_ENCODING]; for old
segments that lack the key, implementations
+ /// derive it from [#hasDictionary()].
+ EncodingType getForwardIndexEncoding();
+
/// Returns `true` when all values in a SV column are sorted in ascending
order, `false` otherwise.
boolean isSorted();
diff --git
a/pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/V1Constants.java
b/pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/V1Constants.java
index fab40f3005a..7605c98c554 100644
---
a/pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/V1Constants.java
+++
b/pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/V1Constants.java
@@ -138,6 +138,10 @@ public class V1Constants {
public static final String CARDINALITY = "cardinality";
// Mandatory, treated as `true` when missing for backward compatibility
public static final String HAS_DICTIONARY = "hasDictionary";
+ // Mandatory for new segments. Records the forward-index encoding (RAW
or DICTIONARY). Old segments written
+ // before this key was introduced do not have it; readers fall back to
inferring the encoding from
+ // HAS_DICTIONARY in that case.
+ public static final String FORWARD_INDEX_ENCODING =
"forwardIndexEncoding";
// Mandatory, treated as `false` when missing for backward compatibility
public static final String IS_SORTED = "isSorted";
// Optional
diff --git
a/pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/index/ForwardIndexConfig.java
b/pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/index/ForwardIndexConfig.java
index a4324a40711..4752e8a8904 100644
---
a/pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/index/ForwardIndexConfig.java
+++
b/pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/index/ForwardIndexConfig.java
@@ -30,6 +30,7 @@ import
org.apache.pinot.segment.spi.compression.ChunkCompressionType;
import org.apache.pinot.segment.spi.compression.DictIdCompressionType;
import org.apache.pinot.spi.config.table.FieldConfig;
import org.apache.pinot.spi.config.table.FieldConfig.CompressionCodec;
+import org.apache.pinot.spi.config.table.FieldConfig.EncodingType;
import org.apache.pinot.spi.config.table.IndexConfig;
import org.apache.pinot.spi.utils.DataSizeUtils;
@@ -69,14 +70,15 @@ public class ForwardIndexConfig extends IndexConfig {
_defaultTargetDocsPerChunk = defaultTargetDocsPerChunk;
}
- public static ForwardIndexConfig getDefault() {
- return new Builder().build();
+ public static ForwardIndexConfig getDefault(EncodingType encodingType) {
+ return new Builder(encodingType).build();
}
public static ForwardIndexConfig getDisabled() {
- return new ForwardIndexConfig(true, null, null, null, null, null, null,
null, null);
+ return new Builder(EncodingType.DICTIONARY).withDisabled(true).build();
}
+ private final EncodingType _encodingType;
@Nullable
private final CompressionCodec _compressionCodec;
private final boolean _deriveNumDocsPerChunk;
@@ -92,22 +94,32 @@ public class ForwardIndexConfig extends IndexConfig {
@Nullable
private final Map<String, Object> _configs;
- public ForwardIndexConfig(@Nullable Boolean disabled, @Nullable
CompressionCodec compressionCodec,
- @Nullable Boolean deriveNumDocsPerChunk, @Nullable Integer
rawIndexWriterVersion,
- @Nullable String targetMaxChunkSize, @Nullable Integer
targetDocsPerChunk,
- @Nullable Map<String, Object> configs) {
+ @JsonCreator
+ private ForwardIndexConfig(@JsonProperty("disabled") @Nullable Boolean
disabled,
+ @JsonProperty("encodingType") @Nullable EncodingType encodingType,
+ @JsonProperty("compressionCodec") @Nullable CompressionCodec
compressionCodec,
+ @Deprecated @JsonProperty("chunkCompressionType") @Nullable
ChunkCompressionType chunkCompressionType,
+ @Deprecated @JsonProperty("dictIdCompressionType") @Nullable
DictIdCompressionType dictIdCompressionType,
+ @JsonProperty("deriveNumDocsPerChunk") @Nullable Boolean
deriveNumDocsPerChunk,
+ @JsonProperty("rawIndexWriterVersion") @Nullable Integer
rawIndexWriterVersion,
+ @JsonProperty("targetMaxChunkSize") @Nullable String targetMaxChunkSize,
+ @JsonProperty("targetDocsPerChunk") @Nullable Integer targetDocsPerChunk,
+ @JsonProperty("configs") @Nullable Map<String, Object> configs) {
super(disabled);
- _compressionCodec = compressionCodec;
+ // Backward-compat for legacy JSON that lacks `encodingType`: default to
DICTIONARY (matches the historical
+ // implicit behavior where ForwardIndexConfig had no encoding
distinction). Programmatic callers must use
+ // Builder(EncodingType) and pass an explicit value, typically from
FieldConfig.getEncodingType().
+ _encodingType = encodingType == null ? EncodingType.DICTIONARY :
encodingType;
+ _compressionCodec = getActualCompressionCodec(compressionCodec,
chunkCompressionType, dictIdCompressionType);
_deriveNumDocsPerChunk = Boolean.TRUE.equals(deriveNumDocsPerChunk);
-
_rawIndexWriterVersion = rawIndexWriterVersion == null ?
_defaultRawIndexWriterVersion : rawIndexWriterVersion;
_targetMaxChunkSize = targetMaxChunkSize == null ?
_defaultTargetMaxChunkSize : targetMaxChunkSize;
_targetMaxChunkSizeBytes =
targetMaxChunkSize == null ? _defaultTargetMaxChunkSizeBytes : (int)
DataSizeUtils.toBytes(targetMaxChunkSize);
_targetDocsPerChunk = targetDocsPerChunk == null ?
_defaultTargetDocsPerChunk : targetDocsPerChunk;
_configs = configs != null ? configs : new HashMap<>();
- if (compressionCodec != null) {
- switch (compressionCodec) {
+ if (_compressionCodec != null) {
+ switch (_compressionCodec) {
case PASS_THROUGH:
case CLP:
case CLPV2:
@@ -145,7 +157,7 @@ public class ForwardIndexConfig extends IndexConfig {
_chunkCompressionType = null;
break;
default:
- throw new IllegalStateException("Unsupported compression codec: " +
compressionCodec);
+ throw new IllegalStateException("Unsupported compression codec: " +
_compressionCodec);
}
} else {
_dictIdCompressionType = null;
@@ -153,20 +165,6 @@ public class ForwardIndexConfig extends IndexConfig {
}
}
- @JsonCreator
- public ForwardIndexConfig(@JsonProperty("disabled") @Nullable Boolean
disabled,
- @JsonProperty("compressionCodec") @Nullable CompressionCodec
compressionCodec,
- @Deprecated @JsonProperty("chunkCompressionType") @Nullable
ChunkCompressionType chunkCompressionType,
- @Deprecated @JsonProperty("dictIdCompressionType") @Nullable
DictIdCompressionType dictIdCompressionType,
- @JsonProperty("deriveNumDocsPerChunk") @Nullable Boolean
deriveNumDocsPerChunk,
- @JsonProperty("rawIndexWriterVersion") @Nullable Integer
rawIndexWriterVersion,
- @JsonProperty("targetMaxChunkSize") @Nullable String targetMaxChunkSize,
- @JsonProperty("targetDocsPerChunk") @Nullable Integer targetDocsPerChunk,
- @JsonProperty("configs") @Nullable Map<String, Object> configs) {
- this(disabled, getActualCompressionCodec(compressionCodec,
chunkCompressionType, dictIdCompressionType),
- deriveNumDocsPerChunk, rawIndexWriterVersion, targetMaxChunkSize,
targetDocsPerChunk, configs);
- }
-
public static CompressionCodec getActualCompressionCodec(@Nullable
CompressionCodec compressionCodec,
@Nullable ChunkCompressionType chunkCompressionType, @Nullable
DictIdCompressionType dictIdCompressionType) {
if (compressionCodec != null) {
@@ -248,6 +246,10 @@ public class ForwardIndexConfig extends IndexConfig {
return _configs;
}
+ public EncodingType getEncodingType() {
+ return _encodingType;
+ }
+
@Override
public boolean equals(Object o) {
if (this == o) {
@@ -262,16 +264,19 @@ public class ForwardIndexConfig extends IndexConfig {
ForwardIndexConfig that = (ForwardIndexConfig) o;
return _compressionCodec == that._compressionCodec &&
_deriveNumDocsPerChunk == that._deriveNumDocsPerChunk
&& _rawIndexWriterVersion == that._rawIndexWriterVersion &&
Objects.equals(_targetMaxChunkSize,
- that._targetMaxChunkSize) && _targetDocsPerChunk ==
that._targetDocsPerChunk;
+ that._targetMaxChunkSize) && _targetDocsPerChunk ==
that._targetDocsPerChunk
+ && _encodingType == that._encodingType;
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), _compressionCodec,
_deriveNumDocsPerChunk, _rawIndexWriterVersion,
- _targetMaxChunkSize, _targetDocsPerChunk);
+ _targetMaxChunkSize, _targetDocsPerChunk, _encodingType);
}
public static class Builder {
+ private boolean _disabled = false;
+ private final EncodingType _encodingType;
@Nullable
private CompressionCodec _compressionCodec;
private boolean _deriveNumDocsPerChunk = false;
@@ -280,10 +285,22 @@ public class ForwardIndexConfig extends IndexConfig {
private int _targetDocsPerChunk = _defaultTargetDocsPerChunk;
private Map<String, Object> _configs = new HashMap<>();
- public Builder() {
+ /// Constructs a builder with the given forward-index encoding. Callers
should pass `FieldConfig.getEncodingType()`
+ /// so the forward-index encoding stays consistent with the column-level
encoding.
+ public Builder(EncodingType encodingType) {
+ _encodingType = Preconditions.checkNotNull(encodingType, "encodingType
must not be null");
}
public Builder(ForwardIndexConfig other) {
+ this(other, other._encodingType);
+ }
+
+ /// Copies all fields from `other` but overrides the forward-index
encoding to `encodingType`.
+ /// Used at segment creation when an optimizer flips the column to RAW
after the configured encoding was
+ /// `DICTIONARY`.
+ public Builder(ForwardIndexConfig other, EncodingType encodingType) {
+ _disabled = other.isDisabled();
+ _encodingType = Preconditions.checkNotNull(encodingType, "encodingType
must not be null");
_compressionCodec = other._compressionCodec;
_deriveNumDocsPerChunk = other._deriveNumDocsPerChunk;
_rawIndexWriterVersion = other._rawIndexWriterVersion;
@@ -292,6 +309,11 @@ public class ForwardIndexConfig extends IndexConfig {
_configs = other._configs;
}
+ public Builder withDisabled(boolean disabled) {
+ _disabled = disabled;
+ return this;
+ }
+
public Builder withCompressionCodec(CompressionCodec compressionCodec) {
_compressionCodec = compressionCodec;
return this;
@@ -376,8 +398,8 @@ public class ForwardIndexConfig extends IndexConfig {
}
public ForwardIndexConfig build() {
- return new ForwardIndexConfig(false, _compressionCodec,
_deriveNumDocsPerChunk, _rawIndexWriterVersion,
- _targetMaxChunkSize, _targetDocsPerChunk, _configs);
+ return new ForwardIndexConfig(_disabled, _encodingType,
_compressionCodec, null, null, _deriveNumDocsPerChunk,
+ _rawIndexWriterVersion, _targetMaxChunkSize, _targetDocsPerChunk,
_configs);
}
}
}
diff --git
a/pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/index/metadata/ColumnMetadataImpl.java
b/pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/index/metadata/ColumnMetadataImpl.java
index d5fd242af57..8ce7d53f820 100644
---
a/pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/index/metadata/ColumnMetadataImpl.java
+++
b/pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/index/metadata/ColumnMetadataImpl.java
@@ -38,6 +38,7 @@ import org.apache.pinot.segment.spi.index.IndexType;
import org.apache.pinot.segment.spi.partition.PartitionFunction;
import org.apache.pinot.segment.spi.partition.PartitionFunctionFactory;
import org.apache.pinot.segment.spi.partition.metadata.ColumnPartitionMetadata;
+import org.apache.pinot.spi.config.table.FieldConfig.EncodingType;
import org.apache.pinot.spi.data.ComplexFieldSpec;
import org.apache.pinot.spi.data.DateTimeFieldSpec;
import org.apache.pinot.spi.data.DimensionFieldSpec;
@@ -59,6 +60,7 @@ public class ColumnMetadataImpl implements ColumnMetadata {
private final int _totalDocs;
private final int _cardinality;
private final boolean _hasDictionary;
+ private final EncodingType _forwardIndexEncoding;
private final boolean _sorted;
private final Comparable _minValue;
private final Comparable _maxValue;
@@ -80,15 +82,16 @@ public class ColumnMetadataImpl implements ColumnMetadata {
/// Use non-default size to save space for most columns
private final LongArrayList _indexTypeSizeList = new LongArrayList(2);
- private ColumnMetadataImpl(FieldSpec fieldSpec, int totalDocs, int
cardinality, boolean hasDictionary, boolean sorted,
- @Nullable Comparable minValue, @Nullable Comparable maxValue, boolean
minMaxValueInvalid,
- int lengthOfShortestElement, int lengthOfLongestElement, boolean
isAscii, int totalNumberOfEntries,
- int maxNumberOfMultiValues, int bitsPerElement, @Nullable
PartitionFunction partitionFunction,
- @Nullable Set<Integer> partitions, boolean autoGenerated) {
+ private ColumnMetadataImpl(FieldSpec fieldSpec, int totalDocs, int
cardinality, boolean hasDictionary,
+ EncodingType forwardIndexEncoding, boolean sorted, @Nullable Comparable
minValue, @Nullable Comparable maxValue,
+ boolean minMaxValueInvalid, int lengthOfShortestElement, int
lengthOfLongestElement, boolean isAscii,
+ int totalNumberOfEntries, int maxNumberOfMultiValues, int bitsPerElement,
+ @Nullable PartitionFunction partitionFunction, @Nullable Set<Integer>
partitions, boolean autoGenerated) {
_fieldSpec = fieldSpec;
_totalDocs = totalDocs;
_cardinality = cardinality;
_hasDictionary = hasDictionary;
+ _forwardIndexEncoding = forwardIndexEncoding;
_sorted = sorted;
_minValue = minValue;
_maxValue = maxValue;
@@ -124,6 +127,11 @@ public class ColumnMetadataImpl implements ColumnMetadata {
return _hasDictionary;
}
+ @Override
+ public EncodingType getForwardIndexEncoding() {
+ return _forwardIndexEncoding;
+ }
+
@Override
public boolean isSorted() {
return _sorted;
@@ -247,8 +255,8 @@ public class ColumnMetadataImpl implements ColumnMetadata {
}
ColumnMetadataImpl that = (ColumnMetadataImpl) o;
return _totalDocs == that._totalDocs && _cardinality == that._cardinality
&& _hasDictionary == that._hasDictionary
- && _sorted == that._sorted && _minMaxValueInvalid ==
that._minMaxValueInvalid
- && _lengthOfShortestElement == that._lengthOfShortestElement
+ && _forwardIndexEncoding == that._forwardIndexEncoding && _sorted ==
that._sorted
+ && _minMaxValueInvalid == that._minMaxValueInvalid &&
_lengthOfShortestElement == that._lengthOfShortestElement
&& _lengthOfLongestElement == that._lengthOfLongestElement && _isAscii
== that._isAscii
&& _totalNumberOfEntries == that._totalNumberOfEntries
&& _maxNumberOfMultiValues == that._maxNumberOfMultiValues &&
_bitsPerElement == that._bitsPerElement
@@ -260,17 +268,19 @@ public class ColumnMetadataImpl implements ColumnMetadata
{
@Override
public int hashCode() {
- return Objects.hash(_fieldSpec, _totalDocs, _cardinality, _hasDictionary,
_sorted, _minValue, _maxValue,
- _minMaxValueInvalid, _lengthOfShortestElement,
_lengthOfLongestElement, _isAscii, _totalNumberOfEntries,
- _maxNumberOfMultiValues, _bitsPerElement, _partitionFunction,
_partitions, _autoGenerated, _indexTypeSizeList);
+ return Objects.hash(_fieldSpec, _totalDocs, _cardinality, _hasDictionary,
_forwardIndexEncoding, _sorted,
+ _minValue, _maxValue, _minMaxValueInvalid, _lengthOfShortestElement,
_lengthOfLongestElement, _isAscii,
+ _totalNumberOfEntries, _maxNumberOfMultiValues, _bitsPerElement,
_partitionFunction, _partitions,
+ _autoGenerated, _indexTypeSizeList);
}
@Override
public String toString() {
return "ColumnMetadataImpl{" + "_fieldSpec=" + _fieldSpec + ",
_totalDocs=" + _totalDocs + ", _cardinality="
- + _cardinality + ", _hasDictionary=" + _hasDictionary + ", _sorted=" +
_sorted + ", _minValue=" + _minValue
- + ", _maxValue=" + _maxValue + ", _minMaxValueInvalid=" +
_minMaxValueInvalid + ", _lengthOfShortestElement="
- + _lengthOfShortestElement + ", _lengthOfLongestElement=" +
_lengthOfLongestElement + ", _isAscii=" + _isAscii
+ + _cardinality + ", _hasDictionary=" + _hasDictionary + ",
_forwardIndexEncoding=" + _forwardIndexEncoding
+ + ", _sorted=" + _sorted + ", _minValue=" + _minValue + ", _maxValue="
+ _maxValue
+ + ", _minMaxValueInvalid=" + _minMaxValueInvalid + ",
_lengthOfShortestElement=" + _lengthOfShortestElement
+ + ", _lengthOfLongestElement=" + _lengthOfLongestElement + ",
_isAscii=" + _isAscii
+ ", _totalNumberOfEntries=" + _totalNumberOfEntries + ",
_maxNumberOfMultiValues=" + _maxNumberOfMultiValues
+ ", _bitsPerElement=" + _bitsPerElement + ", _partitionFunction=" +
_partitionFunction + ", _partitions="
+ _partitions + ", _autoGenerated=" + _autoGenerated + ",
_indexTypeSizeList=" + _indexTypeSizeList + '}';
@@ -279,11 +289,16 @@ public class ColumnMetadataImpl implements ColumnMetadata
{
public static ColumnMetadataImpl
fromPropertiesConfiguration(PropertiesConfiguration config, int totalDocs,
String column) {
FieldSpec fieldSpec = generateFieldSpec(column, config);
+ boolean hasDictionary = config.getBoolean(Column.getKeyFor(column,
Column.HAS_DICTIONARY), true);
+ // Old segments may not have FORWARD_INDEX_ENCODING — derive from
HAS_DICTIONARY in that case.
+ EncodingType forwardIndexEncoding =
config.getEnum(Column.getKeyFor(column, Column.FORWARD_INDEX_ENCODING),
+ EncodingType.class, hasDictionary ? EncodingType.DICTIONARY :
EncodingType.RAW);
Builder builder = new Builder()
.setFieldSpec(fieldSpec)
.setTotalDocs(totalDocs)
.setCardinality(config.getInt(Column.getKeyFor(column,
Column.CARDINALITY)))
- .setHasDictionary(config.getBoolean(Column.getKeyFor(column,
Column.HAS_DICTIONARY), true))
+ .setHasDictionary(hasDictionary)
+ .setForwardIndexEncoding(forwardIndexEncoding)
.setSorted(config.getBoolean(Column.getKeyFor(column,
Column.IS_SORTED), false))
.setLengthOfShortestElement(
config.getInt(Column.getKeyFor(column,
Column.LENGTH_OF_SHORTEST_ELEMENT), UNAVAILABLE))
@@ -437,6 +452,7 @@ public class ColumnMetadataImpl implements ColumnMetadata {
private int _totalDocs;
private int _cardinality;
private boolean _hasDictionary;
+ private EncodingType _forwardIndexEncoding;
private boolean _sorted;
private Comparable<?> _minValue;
private Comparable<?> _maxValue;
@@ -472,6 +488,11 @@ public class ColumnMetadataImpl implements ColumnMetadata {
return this;
}
+ public Builder setForwardIndexEncoding(EncodingType forwardIndexEncoding) {
+ _forwardIndexEncoding = forwardIndexEncoding;
+ return this;
+ }
+
public Builder setSorted(boolean sorted) {
_sorted = sorted;
return this;
@@ -566,9 +587,14 @@ public class ColumnMetadataImpl implements ColumnMetadata {
_bitsPerElement = UNAVAILABLE;
}
- return new ColumnMetadataImpl(_fieldSpec, _totalDocs, _cardinality,
_hasDictionary, _sorted, _minValue, _maxValue,
- _minMaxValueInvalid, _lengthOfShortestElement,
_lengthOfLongestElement, _isAscii, _totalNumberOfEntries,
- _maxNumberOfMultiValues, _bitsPerElement, _partitionFunction,
_partitions, _autoGenerated);
+ if (_forwardIndexEncoding == null) {
+ _forwardIndexEncoding = _hasDictionary ? EncodingType.DICTIONARY :
EncodingType.RAW;
+ }
+
+ return new ColumnMetadataImpl(_fieldSpec, _totalDocs, _cardinality,
_hasDictionary, _forwardIndexEncoding,
+ _sorted, _minValue, _maxValue, _minMaxValueInvalid,
_lengthOfShortestElement, _lengthOfLongestElement,
+ _isAscii, _totalNumberOfEntries, _maxNumberOfMultiValues,
_bitsPerElement, _partitionFunction, _partitions,
+ _autoGenerated);
}
}
}
diff --git
a/pinot-segment-spi/src/test/java/org/apache/pinot/segment/spi/index/ForwardIndexConfigTest.java
b/pinot-segment-spi/src/test/java/org/apache/pinot/segment/spi/index/ForwardIndexConfigTest.java
index 33b1f61f208..d11bf97b937 100644
---
a/pinot-segment-spi/src/test/java/org/apache/pinot/segment/spi/index/ForwardIndexConfigTest.java
+++
b/pinot-segment-spi/src/test/java/org/apache/pinot/segment/spi/index/ForwardIndexConfigTest.java
@@ -19,7 +19,9 @@
package org.apache.pinot.segment.spi.index;
import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonNode;
import org.apache.pinot.segment.spi.compression.ChunkCompressionType;
+import org.apache.pinot.spi.config.table.FieldConfig;
import org.apache.pinot.spi.utils.JsonUtils;
import org.testng.annotations.Test;
@@ -39,6 +41,8 @@ public class ForwardIndexConfigTest {
assertFalse(config.isDeriveNumDocsPerChunk(), "Unexpected
deriveNumDocsPerChunk");
assertEquals(config.getRawIndexWriterVersion(),
ForwardIndexConfig.getDefaultRawWriterVersion(),
"Unexpected rawIndexWriterVersion");
+ assertEquals(config.getEncodingType(), FieldConfig.EncodingType.DICTIONARY,
+ "Missing encodingType should fall back to DICTIONARY for backward
compatibility");
}
@Test
@@ -108,4 +112,83 @@ public class ForwardIndexConfigTest {
assertEquals(config.getTargetMaxChunkSizeBytes(), 512 * 1024, "Unexpected
targetMaxChunkSizeBytes");
assertEquals(config.getTargetDocsPerChunk(), 2000, "Unexpected
defaultTargetDocsPerChunk");
}
+
+ @Test
+ public void defaultConfigUsesDictionaryEncoding() {
+ ForwardIndexConfig config =
ForwardIndexConfig.getDefault(FieldConfig.EncodingType.DICTIONARY);
+ assertEquals(config.getEncodingType(),
FieldConfig.EncodingType.DICTIONARY);
+ }
+
+ @Test
+ public void explicitEncodingIsSerialized() {
+ ForwardIndexConfig config = new
ForwardIndexConfig.Builder(FieldConfig.EncodingType.DICTIONARY)
+ .withRawIndexWriterVersion(6)
+ .build();
+ JsonNode json = config.toJsonNode();
+ assertTrue(json.has("encodingType"), "Resolved encodingType should always
be serialized");
+ assertEquals(json.get("encodingType").asText(),
FieldConfig.EncodingType.DICTIONARY.name());
+ }
+
+ @Test
+ public void explicitDictionaryEncodingIsSerialized() {
+ ForwardIndexConfig config = new
ForwardIndexConfig.Builder(FieldConfig.EncodingType.DICTIONARY)
+ .build();
+ JsonNode json = config.toJsonNode();
+ assertTrue(json.has("encodingType"), "Explicit encodingType should be
preserved even when it is the default value");
+ assertEquals(json.get("encodingType").asText(),
FieldConfig.EncodingType.DICTIONARY.name());
+ assertEquals(config.getEncodingType(),
FieldConfig.EncodingType.DICTIONARY);
+ }
+
+ @Test
+ public void builderRetainsExplicitlySetEncoding() {
+ ForwardIndexConfig config = new
ForwardIndexConfig.Builder(FieldConfig.EncodingType.RAW)
+ .build();
+ assertEquals(config.getEncodingType(), FieldConfig.EncodingType.RAW);
+ }
+
+ @Test
+ public void builderCopyConstructorPreservesEncoding() {
+ ForwardIndexConfig original = new
ForwardIndexConfig.Builder(FieldConfig.EncodingType.RAW)
+ .build();
+ ForwardIndexConfig copy = new ForwardIndexConfig.Builder(original).build();
+ assertEquals(copy.getEncodingType(), FieldConfig.EncodingType.RAW,
+ "Copy constructor must preserve encodingType");
+ }
+
+ @Test
+ public void builderCopyConstructorPreservesDisabledConfig() {
+ ForwardIndexConfig disabled = ForwardIndexConfig.getDisabled();
+ ForwardIndexConfig copy = new ForwardIndexConfig.Builder(disabled).build();
+ assertTrue(copy.isDisabled(), "Copy constructor must preserve disabled
config");
+ assertEquals(copy.getEncodingType(), FieldConfig.EncodingType.DICTIONARY);
+ }
+
+ @Test
+ public void equalsAndHashCodeDistinguishEncoding() {
+ ForwardIndexConfig dict = new
ForwardIndexConfig.Builder(FieldConfig.EncodingType.DICTIONARY)
+ .build();
+ ForwardIndexConfig raw = new
ForwardIndexConfig.Builder(FieldConfig.EncodingType.RAW)
+ .build();
+ assertNotEquals(dict, raw, "Configs differing only in encoding must not be
equal");
+ }
+
+ @Test
+ public void encodingRoundTripsThroughJson()
+ throws JsonProcessingException {
+ ForwardIndexConfig original = new
ForwardIndexConfig.Builder(FieldConfig.EncodingType.RAW)
+ .build();
+ String json = JsonUtils.objectToString(original);
+ ForwardIndexConfig restored = JsonUtils.stringToObject(json,
ForwardIndexConfig.class);
+ assertEquals(restored.getEncodingType(), FieldConfig.EncodingType.RAW,
+ "JSON serialize/deserialize must preserve encodingType");
+ assertEquals(restored, original, "Round-tripped config must equal the
original");
+ }
+
+ @Test
+ public void encodingDeserializesFromExplicitJsonField()
+ throws JsonProcessingException {
+ String confStr = "{\"encodingType\": \"RAW\"}";
+ ForwardIndexConfig config = JsonUtils.stringToObject(confStr,
ForwardIndexConfig.class);
+ assertEquals(config.getEncodingType(), FieldConfig.EncodingType.RAW);
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]