You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by ja...@apache.org on 2026/04/23 07:01:42 UTC
(pinot) branch master updated: Refactor ColumnMetadata SPI and simplify MapIndexReader (#18280)
This is an automated email from the ASF dual-hosted git repository.
Jackie-Jiang 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 d36c9f3f578 Refactor ColumnMetadata SPI and simplify MapIndexReader (#18280)
d36c9f3f578 is described below
commit d36c9f3f5781098e0437867dcf682ff9d538898e
Author: Xiaotian (Jackie) Jiang <17...@users.noreply.github.com>
AuthorDate: Thu Apr 23 00:01:36 2026 -0700
Refactor ColumnMetadata SPI and simplify MapIndexReader (#18280)
---
.../org/apache/pinot/core/util/CrcUtilsTest.java | 8 +-
.../pinot/perf/BenchmarkOfflineIndexReader.java | 2 +-
.../segment/creator/impl/BaseSegmentCreator.java | 150 +++---
.../index/dictionary/DictionaryIndexType.java | 6 +-
.../segment/index/loader/ForwardIndexHandler.java | 2 +-
.../ColumnMinMaxValueGenerator.java | 6 +-
.../local/segment/index/map/BaseMapDataSource.java | 4 +-
.../segment/index/map/ImmutableMapDataSource.java | 8 +-
.../segment/index/map/MapIndexReaderWrapper.java | 121 +----
.../segment/index/map/MutableMapDataSource.java | 2 +-
.../segment/index/map/SimpleColumnMetadata.java | 154 ++++++
.../converter/RealtimeSegmentConverterTest.java | 4 +-
.../impl/ColumnarSegmentBuildingTestBase.java | 2 +-
.../stats/MapColumnPreIndexStatsCollectorTest.java | 59 +--
.../local/segment/index/ColumnMetadataTest.java | 92 ++--
.../index/loader/ForwardIndexHandlerTest.java | 546 ++++++---------------
.../index/loader/SegmentPreProcessorTest.java | 444 +++++++++--------
.../apache/pinot/segment/spi/ColumnMetadata.java | 98 ++--
.../org/apache/pinot/segment/spi/V1Constants.java | 76 ++-
.../spi/index/metadata/ColumnMetadataImpl.java | 360 ++++++++------
.../spi/index/metadata/SegmentMetadataImpl.java | 37 +-
.../segment/spi/index/reader/MapIndexReader.java | 26 +-
.../metadata/ColumnPartitionMetadata.java | 23 +-
.../pinot/server/api/resources/TablesResource.java | 20 +-
.../apache/pinot/server/api/BaseResourceTest.java | 38 +-
.../pinot/server/api/TableSizeResourceTest.java | 14 +-
.../pinot/server/api/TableTierResourceTest.java | 27 +-
.../pinot/server/api/TablesResourceTest.java | 286 +++++------
.../java/org/apache/pinot/spi/data/FieldSpec.java | 24 +
29 files changed, 1257 insertions(+), 1382 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 defd4d8193d..0b9e6a1688a 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), 2102337593L);
+ assertEquals(CrcUtils.computeCrc(indexDir), 1243018203L);
new SegmentV1V2ToV3FormatConverter().convert(indexDir);
- assertEquals(CrcUtils.computeCrc(indexDir), 3362640853L);
+ assertEquals(CrcUtils.computeCrc(indexDir), 2321393542L);
}
@Test
@@ -135,10 +135,10 @@ public class CrcUtilsTest {
driver.build();
File indexDir = driver.getOutputDirectory();
- assertEquals(CrcUtils.computeCrc(indexDir), 2627227852L);
+ assertEquals(CrcUtils.computeCrc(indexDir), 1921721469L);
new SegmentV1V2ToV3FormatConverter().convert(indexDir);
- assertEquals(CrcUtils.computeCrc(indexDir), 1229791705L);
+ assertEquals(CrcUtils.computeCrc(indexDir), 809891195L);
}
@Test
diff --git a/pinot-perf/src/main/java/org/apache/pinot/perf/BenchmarkOfflineIndexReader.java b/pinot-perf/src/main/java/org/apache/pinot/perf/BenchmarkOfflineIndexReader.java
index aca52847be7..e4550408763 100644
--- a/pinot-perf/src/main/java/org/apache/pinot/perf/BenchmarkOfflineIndexReader.java
+++ b/pinot-perf/src/main/java/org/apache/pinot/perf/BenchmarkOfflineIndexReader.java
@@ -154,7 +154,7 @@ public class BenchmarkOfflineIndexReader {
ColumnMetadata stringColumnMetadata = segmentMetadata.getColumnMetadataFor(STRING_COLUMN_NAME);
_stringDictionary =
new StringDictionary(segmentReader.getIndexFor(STRING_COLUMN_NAME, StandardIndexes.dictionary()),
- stringColumnMetadata.getCardinality(), stringColumnMetadata.getColumnMaxLength());
+ stringColumnMetadata.getCardinality(), stringColumnMetadata.getLengthOfLongestElement());
}
@Benchmark
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 faeccb592e8..6fafe69cca6 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
@@ -85,6 +85,7 @@ import org.apache.pinot.spi.data.DateTimeFormatSpec;
import org.apache.pinot.spi.data.FieldSpec;
import org.apache.pinot.spi.data.FieldSpec.DataType;
import org.apache.pinot.spi.data.FieldSpec.FieldType;
+import org.apache.pinot.spi.data.FieldSpec.MaxLengthExceedStrategy;
import org.apache.pinot.spi.data.Schema;
import org.apache.pinot.spi.env.CommonsConfigurationUtils;
import org.apache.pinot.spi.env.PinotConfiguration;
@@ -549,11 +550,29 @@ public abstract class BaseSegmentCreator implements SegmentCreator {
public static void addColumnMetadataInfo(PropertiesConfiguration properties, String column,
ColumnStatistics columnStatistics, int totalDocs, FieldSpec fieldSpec, boolean hasDictionary,
int dictionaryElementSize, 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, TOTAL_DOCS), String.valueOf(totalDocs));
- DataType dataType = fieldSpec.getDataType();
- properties.setProperty(getKeyFor(column, DATA_TYPE), String.valueOf(dataType));
+ properties.setProperty(getKeyFor(column, HAS_DICTIONARY), String.valueOf(hasDictionary));
+ properties.setProperty(getKeyFor(column, IS_SORTED), String.valueOf(columnStatistics.isSorted()));
+ DataType storedType = fieldSpec.getDataType().getStoredType();
+ if (!storedType.isFixedWidth()) {
+ properties.setProperty(getKeyFor(column, LENGTH_OF_SHORTEST_ELEMENT),
+ String.valueOf(columnStatistics.getLengthOfShortestElement()));
+ int lengthOfLongestElement = columnStatistics.getLengthOfLongestElement();
+ properties.setProperty(getKeyFor(column, LENGTH_OF_LONGEST_ELEMENT), String.valueOf(lengthOfLongestElement));
+ if (hasDictionary) {
+ // Ensure length of longest element matches dictionary element size
+ Preconditions.checkState(lengthOfLongestElement == dictionaryElementSize,
+ "Length of longest element: %s doesn't match dictionary element size: %s for column: %s",
+ lengthOfLongestElement, dictionaryElementSize, column);
+ }
+ if (storedType == DataType.STRING) {
+ properties.setProperty(getKeyFor(column, IS_ASCII), String.valueOf(columnStatistics.isAscii()));
+ }
+ }
+ properties.setProperty(getKeyFor(column, DICTIONARY_ELEMENT_SIZE), String.valueOf(dictionaryElementSize));
// TODO: When the column is raw (no dictionary), we should set BITS_PER_ELEMENT to -1 (invalid). Currently we set
// it regardless of whether dictionary is created or not for backward compatibility because
// ForwardIndexHandler doesn't update this value when converting a raw column to dictionary encoded.
@@ -561,51 +580,16 @@ public abstract class BaseSegmentCreator implements SegmentCreator {
// See https://github.com/apache/pinot/pull/16921 for details
properties.setProperty(getKeyFor(column, BITS_PER_ELEMENT),
String.valueOf(PinotDataBitSet.getNumBitsPerValue(cardinality - 1)));
- FieldType fieldType = fieldSpec.getFieldType();
- properties.setProperty(getKeyFor(column, DICTIONARY_ELEMENT_SIZE), String.valueOf(dictionaryElementSize));
- properties.setProperty(getKeyFor(column, COLUMN_TYPE), String.valueOf(fieldType));
- properties.setProperty(getKeyFor(column, IS_SORTED), String.valueOf(columnStatistics.isSorted()));
- properties.setProperty(getKeyFor(column, HAS_DICTIONARY), String.valueOf(hasDictionary));
- properties.setProperty(getKeyFor(column, IS_SINGLE_VALUED), String.valueOf(fieldSpec.isSingleValueField()));
- properties.setProperty(getKeyFor(column, MAX_MULTI_VALUE_ELEMENTS),
- String.valueOf(columnStatistics.getMaxNumberOfMultiValues()));
properties.setProperty(getKeyFor(column, TOTAL_NUMBER_OF_ENTRIES),
String.valueOf(columnStatistics.getTotalNumberOfEntries()));
- properties.setProperty(getKeyFor(column, IS_AUTO_GENERATED), String.valueOf(autoGenerated));
- DataType storedType = dataType.getStoredType();
- if (storedType == DataType.STRING || storedType == DataType.BYTES) {
- properties.setProperty(getKeyFor(column, SCHEMA_MAX_LENGTH), fieldSpec.getEffectiveMaxLength());
- // TODO let's revisit writing effective maxLengthStrategy into metadata, as changing it right now may affect
- // segment's CRC value
- FieldSpec.MaxLengthExceedStrategy maxLengthStrategy = fieldSpec.getMaxLengthExceedStrategy();
- if (maxLengthStrategy != null) {
- properties.setProperty(getKeyFor(column, SCHEMA_MAX_LENGTH_EXCEED_STRATEGY),
- fieldSpec.getMaxLengthExceedStrategy());
- }
- }
-
- PartitionFunction partitionFunction = columnStatistics.getPartitionFunction();
- if (partitionFunction != null) {
- properties.setProperty(getKeyFor(column, PARTITION_FUNCTION), partitionFunction.getName());
- properties.setProperty(getKeyFor(column, NUM_PARTITIONS), partitionFunction.getNumPartitions());
- properties.setProperty(getKeyFor(column, PARTITION_VALUES), columnStatistics.getPartitions());
- Map<String, String> partitionFunctionConfig = partitionFunction.getFunctionConfig();
- if (partitionFunctionConfig != null) {
- for (Map.Entry<String, String> entry : partitionFunctionConfig.entrySet()) {
- properties.setProperty(getKeyFor(column, String.format("%s.%s", PARTITION_FUNCTION_CONFIG, entry.getKey())),
- entry.getValue());
- }
- }
- }
-
- // Datetime field
- if (fieldType == FieldType.DATE_TIME) {
- DateTimeFieldSpec dateTimeFieldSpec = (DateTimeFieldSpec) fieldSpec;
- properties.setProperty(getKeyFor(column, DATETIME_FORMAT), dateTimeFieldSpec.getFormat());
- properties.setProperty(getKeyFor(column, DATETIME_GRANULARITY), dateTimeFieldSpec.getGranularity());
+ properties.setProperty(getKeyFor(column, MAX_MULTI_VALUE_ELEMENTS),
+ String.valueOf(columnStatistics.getMaxNumberOfMultiValues()));
+ if (autoGenerated) {
+ properties.setProperty(getKeyFor(column, IS_AUTO_GENERATED), "true");
}
- if (fieldType != FieldType.COMPLEX) {
+ // Min/max value
+ if (fieldSpec.getFieldType() != FieldType.COMPLEX) {
// Regular (non-complex) field
if (totalDocs > 0) {
Object min = columnStatistics.getMinValue();
@@ -618,25 +602,21 @@ public abstract class BaseSegmentCreator implements SegmentCreator {
addColumnMinMaxValueInfo(properties, column, min, max, storedType);
}
}
- } else {
- // Complex field
- ComplexFieldSpec complexFieldSpec = (ComplexFieldSpec) fieldSpec;
- properties.setProperty(getKeyFor(column, COMPLEX_CHILD_FIELD_NAMES),
- new ArrayList<>(complexFieldSpec.getChildFieldSpecs().keySet()));
- for (Map.Entry<String, FieldSpec> entry : complexFieldSpec.getChildFieldSpecs().entrySet()) {
- addFieldSpec(properties, ComplexFieldSpec.getFullChildName(column, entry.getKey()), entry.getValue());
- }
}
- // TODO: Revisit whether we should set default null value for complex field
- String defaultNullValueStr = fieldSpec.getDefaultNullValueString();
- if (storedType == DataType.STRING) {
- // NOTE: Do not limit length of default null value because we need exact value to determine whether the default
- // null value changes
- defaultNullValueStr = CommonsConfigurationUtils.replaceSpecialCharacterInPropertyValue(defaultNullValueStr);
- }
- if (defaultNullValueStr != null) {
- properties.setProperty(getKeyFor(column, DEFAULT_NULL_VALUE), defaultNullValueStr);
+ // Partition function
+ PartitionFunction partitionFunction = columnStatistics.getPartitionFunction();
+ if (partitionFunction != null) {
+ properties.setProperty(getKeyFor(column, PARTITION_FUNCTION), partitionFunction.getName());
+ properties.setProperty(getKeyFor(column, NUM_PARTITIONS), partitionFunction.getNumPartitions());
+ properties.setProperty(getKeyFor(column, PARTITION_VALUES), columnStatistics.getPartitions());
+ Map<String, String> partitionFunctionConfig = partitionFunction.getFunctionConfig();
+ if (partitionFunctionConfig != null) {
+ for (Map.Entry<String, String> entry : partitionFunctionConfig.entrySet()) {
+ properties.setProperty(getKeyFor(column, String.format("%s.%s", PARTITION_FUNCTION_CONFIG, entry.getKey())),
+ entry.getValue());
+ }
+ }
}
}
@@ -656,34 +636,46 @@ public abstract class BaseSegmentCreator implements SegmentCreator {
* column.intMap$$value.isSingleValued = true
*/
public static void addFieldSpec(PropertiesConfiguration properties, String column, FieldSpec fieldSpec) {
- properties.setProperty(getKeyFor(column, COLUMN_TYPE), String.valueOf(fieldSpec.getFieldType()));
- if (!column.equals(fieldSpec.getName())) {
- properties.setProperty(getKeyFor(column, COLUMN_NAME), String.valueOf(fieldSpec.getName()));
+ String fieldName = fieldSpec.getName();
+ if (!column.equals(fieldName)) {
+ properties.setProperty(getKeyFor(column, COLUMN_NAME), String.valueOf(fieldName));
}
+ FieldType fieldType = fieldSpec.getFieldType();
+ properties.setProperty(getKeyFor(column, COLUMN_TYPE), String.valueOf(fieldType));
DataType dataType = fieldSpec.getDataType();
properties.setProperty(getKeyFor(column, DATA_TYPE), String.valueOf(dataType));
properties.setProperty(getKeyFor(column, IS_SINGLE_VALUED), String.valueOf(fieldSpec.isSingleValueField()));
- if (dataType.equals(DataType.STRING) || dataType.equals(DataType.BYTES) || dataType.equals(DataType.JSON)) {
- properties.setProperty(getKeyFor(column, SCHEMA_MAX_LENGTH), fieldSpec.getEffectiveMaxLength());
- FieldSpec.MaxLengthExceedStrategy maxLengthExceedStrategy = fieldSpec.getEffectiveMaxLengthExceedStrategy();
- if (maxLengthExceedStrategy != null) {
- properties.setProperty(getKeyFor(column, SCHEMA_MAX_LENGTH_EXCEED_STRATEGY), maxLengthExceedStrategy);
+ DataType storedType = dataType.getStoredType();
+ String defaultNullValueStr = fieldSpec.getDefaultNullValueString();
+ if (storedType == DataType.STRING) {
+ // NOTE: Do not limit length of default null value because we need exact value to determine whether the default
+ // null value changes
+ defaultNullValueStr = CommonsConfigurationUtils.replaceSpecialCharacterInPropertyValue(defaultNullValueStr);
+ }
+ if (defaultNullValueStr != null) {
+ properties.setProperty(getKeyFor(column, DEFAULT_NULL_VALUE), defaultNullValueStr);
+ }
+ if (storedType == DataType.STRING || storedType == DataType.BYTES) {
+ Integer nonDefaultMaxLength = fieldSpec.getNonDefaultMaxLength();
+ if (nonDefaultMaxLength != null) {
+ properties.setProperty(getKeyFor(column, SCHEMA_MAX_LENGTH), nonDefaultMaxLength);
+ }
+ MaxLengthExceedStrategy nonDefaultMaxLengthExceedStrategy = fieldSpec.getNonDefaultMaxLengthExceedStrategy();
+ if (nonDefaultMaxLengthExceedStrategy != null) {
+ properties.setProperty(getKeyFor(column, SCHEMA_MAX_LENGTH_EXCEED_STRATEGY), nonDefaultMaxLengthExceedStrategy);
}
}
-
- // datetime field
- if (fieldSpec.getFieldType() == FieldType.DATE_TIME) {
+ if (fieldType == FieldType.DATE_TIME) {
+ // DATE_TIME field
DateTimeFieldSpec dateTimeFieldSpec = (DateTimeFieldSpec) fieldSpec;
properties.setProperty(getKeyFor(column, DATETIME_FORMAT), dateTimeFieldSpec.getFormat());
properties.setProperty(getKeyFor(column, DATETIME_GRANULARITY), dateTimeFieldSpec.getGranularity());
- }
-
- // complex field
- if (fieldSpec.getFieldType() == FieldType.COMPLEX) {
+ } else if (fieldType == FieldType.COMPLEX) {
+ // COMPLEX field
ComplexFieldSpec complexFieldSpec = (ComplexFieldSpec) fieldSpec;
- properties.setProperty(getKeyFor(column, COMPLEX_CHILD_FIELD_NAMES),
- new ArrayList<>(complexFieldSpec.getChildFieldSpecs().keySet()));
- for (Map.Entry<String, FieldSpec> entry : complexFieldSpec.getChildFieldSpecs().entrySet()) {
+ Map<String, FieldSpec> childFieldSpecs = complexFieldSpec.getChildFieldSpecs();
+ properties.setProperty(getKeyFor(column, COMPLEX_CHILD_FIELD_NAMES), new ArrayList<>(childFieldSpecs.keySet()));
+ for (Map.Entry<String, FieldSpec> entry : childFieldSpecs.entrySet()) {
addFieldSpec(properties, ComplexFieldSpec.getFullChildName(column, entry.getKey()), entry.getValue());
}
}
diff --git a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/dictionary/DictionaryIndexType.java b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/dictionary/DictionaryIndexType.java
index 34db3effca0..87376a30a40 100644
--- a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/dictionary/DictionaryIndexType.java
+++ b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/dictionary/DictionaryIndexType.java
@@ -326,15 +326,15 @@ public class DictionaryIndexType
return loadOnHeap ? new OnHeapDoubleDictionary(dataBuffer, length)
: new DoubleDictionary(dataBuffer, length);
case BIG_DECIMAL:
- int numBytesPerValue = metadata.getColumnMaxLength();
+ int numBytesPerValue = metadata.getLengthOfLongestElement();
return loadOnHeap ? new OnHeapBigDecimalDictionary(dataBuffer, length, numBytesPerValue)
: new BigDecimalDictionary(dataBuffer, length, numBytesPerValue);
case STRING:
- numBytesPerValue = metadata.getColumnMaxLength();
+ numBytesPerValue = metadata.getLengthOfLongestElement();
return loadOnHeap ? new OnHeapStringDictionary(dataBuffer, length, numBytesPerValue, strInterner, byteInterner)
: new StringDictionary(dataBuffer, length, numBytesPerValue);
case BYTES:
- numBytesPerValue = metadata.getColumnMaxLength();
+ numBytesPerValue = metadata.getLengthOfLongestElement();
return loadOnHeap ? new OnHeapBytesDictionary(dataBuffer, length, numBytesPerValue, byteInterner)
: new BytesDictionary(dataBuffer, length, numBytesPerValue);
default:
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 eb55d3769f3..7095d2740a3 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
@@ -983,7 +983,7 @@ public class ForwardIndexHandler extends BaseIndexHandler {
if (!columnMetadata.getDataType().getStoredType().isFixedWidth()) {
if (columnMetadata.isSingleValue()) {
// lengthOfLongestEntry is available for dict columns from metadata.
- builder.withLengthOfLongestEntry(columnMetadata.getColumnMaxLength());
+ builder.withLengthOfLongestEntry(columnMetadata.getLengthOfLongestElement());
} else {
// maxRowLength can only be determined by scanning the column.
builder.withMaxRowLengthInBytes(getMaxRowLength(columnMetadata, reader, dictionary));
diff --git a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/loader/columnminmaxvalue/ColumnMinMaxValueGenerator.java b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/loader/columnminmaxvalue/ColumnMinMaxValueGenerator.java
index b8800233fe4..6c9d70c1f81 100644
--- a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/loader/columnminmaxvalue/ColumnMinMaxValueGenerator.java
+++ b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/loader/columnminmaxvalue/ColumnMinMaxValueGenerator.java
@@ -186,11 +186,11 @@ public class ColumnMinMaxValueGenerator {
case DOUBLE:
return new DoubleDictionary(dictionaryBuffer, length);
case BIG_DECIMAL:
- return new BigDecimalDictionary(dictionaryBuffer, length, columnMetadata.getColumnMaxLength());
+ return new BigDecimalDictionary(dictionaryBuffer, length, columnMetadata.getLengthOfLongestElement());
case STRING:
- return new StringDictionary(dictionaryBuffer, length, columnMetadata.getColumnMaxLength());
+ return new StringDictionary(dictionaryBuffer, length, columnMetadata.getLengthOfLongestElement());
case BYTES:
- return new BytesDictionary(dictionaryBuffer, length, columnMetadata.getColumnMaxLength());
+ return new BytesDictionary(dictionaryBuffer, length, columnMetadata.getLengthOfLongestElement());
default:
throw new IllegalStateException("Unsupported data type: " + dataType + " for column: " + columnName);
}
diff --git a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/map/BaseMapDataSource.java b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/map/BaseMapDataSource.java
index 16ab6925b95..bbfe36a5ca2 100644
--- a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/map/BaseMapDataSource.java
+++ b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/map/BaseMapDataSource.java
@@ -72,7 +72,7 @@ public abstract class BaseMapDataSource extends BaseDataSource implements MapDat
if (_keyDataSources.containsKey(key)) {
return _keyDataSources.get(key);
}
- Map<IndexType, IndexReader> indexes = getMapIndexReader().getKeyIndexes(key);
+ Map<IndexType, IndexReader> indexes = getMapIndexReader().getIndexes(key);
if (indexes == null) {
// The key does not exist in the map
@@ -80,7 +80,7 @@ public abstract class BaseMapDataSource extends BaseDataSource implements MapDat
}
try (ColumnIndexContainer indexContainer = new ColumnIndexContainer.FromMap(indexes)) {
- ColumnMetadata keyMeta = getMapIndexReader().getKeyMetadata(key);
+ ColumnMetadata keyMeta = getMapIndexReader().getColumnMetadata(key);
ImmutableDataSource dataSource = new ImmutableDataSource(keyMeta, indexContainer);
_keyDataSources.put(key, dataSource);
return dataSource;
diff --git a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/map/ImmutableMapDataSource.java b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/map/ImmutableMapDataSource.java
index 0ffe5e0a2d8..8592b41dc43 100644
--- a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/map/ImmutableMapDataSource.java
+++ b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/map/ImmutableMapDataSource.java
@@ -23,20 +23,16 @@ import java.util.Set;
import javax.annotation.Nullable;
import org.apache.pinot.segment.spi.ColumnMetadata;
import org.apache.pinot.segment.spi.datasource.DataSourceMetadata;
-import org.apache.pinot.segment.spi.index.IndexReader;
import org.apache.pinot.segment.spi.index.column.ColumnIndexContainer;
import org.apache.pinot.segment.spi.index.reader.ForwardIndexReader;
import org.apache.pinot.segment.spi.index.reader.ForwardIndexReaderContext;
import org.apache.pinot.segment.spi.index.reader.MapIndexReader;
import org.apache.pinot.segment.spi.partition.PartitionFunction;
import org.apache.pinot.spi.data.FieldSpec;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
@SuppressWarnings("rawtypes")
public class ImmutableMapDataSource extends BaseMapDataSource {
- private static final Logger LOGGER = LoggerFactory.getLogger(ImmutableMapDataSource.class);
private final MapIndexReader _mapIndexReader;
public ImmutableMapDataSource(ColumnMetadata columnMetadata, ColumnIndexContainer columnIndexContainer) {
@@ -46,13 +42,13 @@ public class ImmutableMapDataSource extends BaseMapDataSource {
if (forwardIndex instanceof MapIndexReader) {
mapIndexReader = (MapIndexReader) forwardIndex;
} else {
- mapIndexReader = new MapIndexReaderWrapper(forwardIndex, getFieldSpec());
+ mapIndexReader = new MapIndexReaderWrapper(forwardIndex, getFieldSpec(), columnMetadata.getTotalDocs());
}
_mapIndexReader = mapIndexReader;
}
@Override
- public MapIndexReader<ForwardIndexReaderContext, IndexReader> getMapIndexReader() {
+ public MapIndexReader<ForwardIndexReaderContext> getMapIndexReader() {
return _mapIndexReader;
}
diff --git a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/map/MapIndexReaderWrapper.java b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/map/MapIndexReaderWrapper.java
index 6d446fe105f..bf78a726a40 100644
--- a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/map/MapIndexReaderWrapper.java
+++ b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/map/MapIndexReaderWrapper.java
@@ -21,24 +21,27 @@ package org.apache.pinot.segment.local.segment.index.map;
import java.io.IOException;
import java.util.Map;
import java.util.Set;
-import javax.annotation.Nullable;
import org.apache.pinot.segment.spi.ColumnMetadata;
import org.apache.pinot.segment.spi.index.IndexReader;
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.partition.PartitionFunction;
-import org.apache.pinot.spi.data.ComplexFieldSpec;
+import org.apache.pinot.segment.spi.index.reader.MapIndexReader;
+import org.apache.pinot.spi.data.ComplexFieldSpec.MapFieldSpec;
import org.apache.pinot.spi.data.FieldSpec;
+import org.apache.pinot.spi.data.FieldSpec.DataType;
-public class MapIndexReaderWrapper implements org.apache.pinot.segment.spi.index.reader.MapIndexReader {
+@SuppressWarnings("rawtypes")
+public class MapIndexReaderWrapper implements MapIndexReader {
private final ForwardIndexReader _forwardIndexReader;
- private final ComplexFieldSpec.MapFieldSpec _mapFieldSpec;
+ private final FieldSpec _valueFieldSpec;
+ private final int _totalDocs;
- public MapIndexReaderWrapper(ForwardIndexReader forwardIndexReader, ComplexFieldSpec.MapFieldSpec mapFieldSpec) {
+ public MapIndexReaderWrapper(ForwardIndexReader forwardIndexReader, MapFieldSpec mapFieldSpec, int totalDocs) {
_forwardIndexReader = forwardIndexReader;
- _mapFieldSpec = mapFieldSpec;
+ _valueFieldSpec = mapFieldSpec.getValueFieldSpec();
+ _totalDocs = totalDocs;
}
@Override
@@ -47,105 +50,13 @@ public class MapIndexReaderWrapper implements org.apache.pinot.segment.spi.index
}
@Override
- public Map<IndexType, IndexReader> getKeyIndexes(String key) {
- return Map.of(StandardIndexes.forward(), new MapKeyIndexReader(_forwardIndexReader, key, getKeyFieldSpec(key)));
+ public Map<IndexType, IndexReader> getIndexes(String key) {
+ return Map.of(StandardIndexes.forward(), new MapKeyIndexReader(_forwardIndexReader, key, _valueFieldSpec));
}
@Override
- public FieldSpec getKeyFieldSpec(String key) {
- return _mapFieldSpec.getValueFieldSpec();
- }
-
- @Override
- public FieldSpec.DataType getKeyStoredType(String key) {
- return _mapFieldSpec.getValueFieldSpec().getDataType().getStoredType();
- }
-
- @Override
- public ColumnMetadata getKeyMetadata(String key) {
- return new ColumnMetadata() {
- @Override
- public FieldSpec getFieldSpec() {
- return _mapFieldSpec.getValueFieldSpec();
- }
-
- @Override
- public int getTotalDocs() {
- return 0;
- }
-
- @Override
- public int getCardinality() {
- return 0;
- }
-
- @Override
- public boolean isSorted() {
- return false;
- }
-
- @Override
- public Comparable getMinValue() {
- return null;
- }
-
- @Override
- public Comparable getMaxValue() {
- return null;
- }
-
- @Override
- public boolean hasDictionary() {
- return false;
- }
-
- @Override
- public int getColumnMaxLength() {
- return 0;
- }
-
- @Override
- public int getBitsPerElement() {
- return 0;
- }
-
- @Override
- public int getMaxNumberOfMultiValues() {
- return 0;
- }
-
- @Override
- public int getTotalNumberOfEntries() {
- return 0;
- }
-
- @Nullable
- @Override
- public PartitionFunction getPartitionFunction() {
- return null;
- }
-
- @Nullable
- @Override
- public Set<Integer> getPartitions() {
- return null;
- }
-
- @Override
- public Map<IndexType<?, ?, ?>, Long> getIndexSizeMap() {
- return Map.of();
- }
-
- @Override
- public boolean isAutoGenerated() {
- return false;
- }
- };
- }
-
- @Override
- public IndexReader getKeyReader(String key, IndexType indexType) {
- return getKeyIndexes(key).get(indexType);
+ public ColumnMetadata getColumnMetadata(String key) {
+ return new SimpleColumnMetadata(_valueFieldSpec, _totalDocs);
}
@Override
@@ -159,8 +70,8 @@ public class MapIndexReaderWrapper implements org.apache.pinot.segment.spi.index
}
@Override
- public FieldSpec.DataType getStoredType() {
- return FieldSpec.DataType.MAP;
+ public DataType getStoredType() {
+ return DataType.MAP;
}
@Override
diff --git a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/map/MutableMapDataSource.java b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/map/MutableMapDataSource.java
index b0459ff3aed..b1387b09beb 100644
--- a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/map/MutableMapDataSource.java
+++ b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/map/MutableMapDataSource.java
@@ -61,7 +61,7 @@ public class MutableMapDataSource extends BaseMapDataSource {
if (forwardIndex instanceof MapIndexReader) {
mapIndexReader = (MapIndexReader) forwardIndex;
} else {
- mapIndexReader = new MapIndexReaderWrapper(forwardIndex, getFieldSpec());
+ mapIndexReader = new MapIndexReaderWrapper(forwardIndex, getFieldSpec(), numDocs);
}
_mapIndexReader = mapIndexReader;
}
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
new file mode 100644
index 00000000000..7e5b519b5ce
--- /dev/null
+++ b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/map/SimpleColumnMetadata.java
@@ -0,0 +1,154 @@
+/**
+ * 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.map;
+
+import java.util.Set;
+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.data.DimensionFieldSpec;
+import org.apache.pinot.spi.data.FieldSpec;
+import org.apache.pinot.spi.data.FieldSpec.DataType;
+
+
+// TODO: THIS IS A HACK with all stats UNAVAILABLE. Revisit to fill the actual stats for the column.
+@SuppressWarnings("rawtypes")
+public class SimpleColumnMetadata implements ColumnMetadata {
+ private final FieldSpec _fieldSpec;
+ private final int _totalDocs;
+
+ public SimpleColumnMetadata(FieldSpec fieldSpec, int totalDocs) {
+ _fieldSpec = fieldSpec;
+ _totalDocs = totalDocs;
+ }
+
+ public SimpleColumnMetadata(String columnName, DataType dataType, int totalDocs) {
+ this(new DimensionFieldSpec(columnName, dataType, true), totalDocs);
+ }
+
+ @Override
+ public FieldSpec getFieldSpec() {
+ return _fieldSpec;
+ }
+
+ @Override
+ public int getTotalDocs() {
+ return _totalDocs;
+ }
+
+ @Override
+ public int getCardinality() {
+ return UNAVAILABLE;
+ }
+
+ @Override
+ public boolean hasDictionary() {
+ return false;
+ }
+
+ @Override
+ public boolean isSorted() {
+ return false;
+ }
+
+ @Nullable
+ @Override
+ public Comparable getMinValue() {
+ return null;
+ }
+
+ @Nullable
+ @Override
+ public Comparable getMaxValue() {
+ return null;
+ }
+
+ @Override
+ public boolean isMinMaxValueInvalid() {
+ return true;
+ }
+
+ @Override
+ public int getLengthOfShortestElement() {
+ return UNAVAILABLE;
+ }
+
+ @Override
+ public int getLengthOfLongestElement() {
+ return UNAVAILABLE;
+ }
+
+ @Override
+ public boolean isAscii() {
+ return false;
+ }
+
+ @Override
+ public int getTotalNumberOfEntries() {
+ return UNAVAILABLE;
+ }
+
+ @Override
+ public int getMaxNumberOfMultiValues() {
+ return UNAVAILABLE;
+ }
+
+ @Override
+ public int getBitsPerElement() {
+ return UNAVAILABLE;
+ }
+
+ @Nullable
+ @Override
+ public PartitionFunction getPartitionFunction() {
+ return null;
+ }
+
+ @Nullable
+ @Override
+ public Set<Integer> getPartitions() {
+ return null;
+ }
+
+ @Override
+ public boolean isAutoGenerated() {
+ return false;
+ }
+
+ @Override
+ public int getNumIndexes() {
+ return 0;
+ }
+
+ @Override
+ public short getIndexType(int position) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public long getIndexSize(int position) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public long getIndexSizeFor(IndexType type) {
+ return UNAVAILABLE;
+ }
+}
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 d0d34ef6f90..b8d1913cdae 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
@@ -497,8 +497,8 @@ public class RealtimeSegmentConverterTest implements PinotBuffersAfterMethodChec
public static Object[][] optimizeDictionaryTypeParams() {
// Format: {optimizeDictionaryType, expectedCRC}, crc is used here to check the correct dictionary type was used
return new Object[][]{
- {true, "2653526366"},
- {false, "2948830084"},
+ {true, "3570313565"},
+ {false, "4134511491"},
};
}
diff --git a/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/creator/impl/ColumnarSegmentBuildingTestBase.java b/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/creator/impl/ColumnarSegmentBuildingTestBase.java
index 82dd9181244..81f51f98e43 100644
--- a/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/creator/impl/ColumnarSegmentBuildingTestBase.java
+++ b/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/creator/impl/ColumnarSegmentBuildingTestBase.java
@@ -372,7 +372,7 @@ public abstract class ColumnarSegmentBuildingTestBase {
"Cardinality mismatch for column " + columnName);
Assert.assertEquals(metadata1.hasDictionary(), metadata2.hasDictionary(),
"Dictionary flag mismatch for column " + columnName);
- Assert.assertEquals(metadata1.getColumnMaxLength(), metadata2.getColumnMaxLength(),
+ Assert.assertEquals(metadata1.getLengthOfLongestElement(), metadata2.getLengthOfLongestElement(),
"Column max length mismatch for column " + columnName);
// Validate sorting and indexing properties
diff --git a/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/creator/impl/stats/MapColumnPreIndexStatsCollectorTest.java b/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/creator/impl/stats/MapColumnPreIndexStatsCollectorTest.java
index 0c09fda42f2..d1de8887bfe 100644
--- a/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/creator/impl/stats/MapColumnPreIndexStatsCollectorTest.java
+++ b/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/creator/impl/stats/MapColumnPreIndexStatsCollectorTest.java
@@ -24,10 +24,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
-import org.apache.pinot.segment.local.segment.index.map.MapIndexReaderWrapper;
-import org.apache.pinot.segment.local.segment.index.map.MapKeyIndexReader;
import org.apache.pinot.segment.spi.creator.StatsCollectorConfig;
-import org.apache.pinot.segment.spi.index.reader.ForwardIndexReader;
import org.apache.pinot.segment.spi.partition.PartitionFunction;
import org.apache.pinot.spi.config.table.ColumnPartitionConfig;
import org.apache.pinot.spi.config.table.SegmentPartitionConfig;
@@ -35,12 +32,12 @@ import org.apache.pinot.spi.config.table.TableConfig;
import org.apache.pinot.spi.data.ComplexFieldSpec;
import org.apache.pinot.spi.data.DimensionFieldSpec;
import org.apache.pinot.spi.data.FieldSpec;
+import org.apache.pinot.spi.data.FieldSpec.DataType;
import org.apache.pinot.spi.data.Schema;
import org.apache.pinot.spi.utils.ByteArray;
import org.apache.pinot.spi.utils.builder.TableConfigBuilder;
import org.testng.annotations.Test;
-import static org.mockito.Mockito.mock;
import static org.testng.Assert.*;
@@ -56,11 +53,11 @@ public class MapColumnPreIndexStatsCollectorTest {
.build();
Map<String, FieldSpec> children = new HashMap<>();
- children.put("key", new DimensionFieldSpec("key", FieldSpec.DataType.STRING, true));
+ children.put("key", new DimensionFieldSpec("key", DataType.STRING, true));
// Values of heterogeneous types will drive per-key collectors of different types
- children.put("value", new DimensionFieldSpec("value", FieldSpec.DataType.STRING, true));
+ children.put("value", new DimensionFieldSpec("value", DataType.STRING, true));
Schema schema = new Schema();
- schema.addField(new ComplexFieldSpec("col", FieldSpec.DataType.MAP, true, children));
+ schema.addField(new ComplexFieldSpec("col", DataType.MAP, true, children));
return new StatsCollectorConfig(tableConfig, schema,
tableConfig.getIndexingConfig().getSegmentPartitionConfig());
}
@@ -562,52 +559,4 @@ public class MapColumnPreIndexStatsCollectorTest {
assertTrue(col.getKeyStatistics("kInt") instanceof NoDictColumnStatisticsCollector);
assertTrue(col.getKeyStatistics("kStr") instanceof NoDictColumnStatisticsCollector);
}
-
- private static MapIndexReaderWrapper mapReaderWithValueType(FieldSpec.DataType valueType) {
- FieldSpec keySpec = new DimensionFieldSpec("key", FieldSpec.DataType.STRING, true);
- FieldSpec valueSpec = new DimensionFieldSpec("value", valueType, true);
- ComplexFieldSpec complexFieldSpec = new ComplexFieldSpec("testMap", FieldSpec.DataType.MAP, true,
- Map.of(ComplexFieldSpec.KEY_FIELD, keySpec, ComplexFieldSpec.VALUE_FIELD, valueSpec));
- return new MapIndexReaderWrapper(mock(ForwardIndexReader.class), ComplexFieldSpec.toMapFieldSpec(complexFieldSpec));
- }
-
- @Test
- public void testGetKeyStoredTypeReturnsPrimitiveStoredTypes() {
- for (FieldSpec.DataType type : new FieldSpec.DataType[]{
- FieldSpec.DataType.INT, FieldSpec.DataType.LONG, FieldSpec.DataType.FLOAT, FieldSpec.DataType.DOUBLE,
- FieldSpec.DataType.STRING, FieldSpec.DataType.BYTES
- }) {
- assertEquals(mapReaderWithValueType(type).getKeyStoredType("k"), type, "Stored type mismatch for: " + type);
- }
- }
-
- @Test
- public void testGetKeyStoredTypeForBooleanIsInt() {
- assertEquals(mapReaderWithValueType(FieldSpec.DataType.BOOLEAN).getKeyStoredType("k"), FieldSpec.DataType.INT);
- }
-
- @Test
- public void testGetKeyStoredTypeForTimestampIsLong() {
- assertEquals(mapReaderWithValueType(FieldSpec.DataType.TIMESTAMP).getKeyStoredType("k"), FieldSpec.DataType.LONG);
- }
-
- @Test
- public void testGetKeyStoredTypeForJsonIsString() {
- assertEquals(mapReaderWithValueType(FieldSpec.DataType.JSON).getKeyStoredType("k"), FieldSpec.DataType.STRING);
- }
-
- @Test
- public void testGetStoredTypeIsAlwaysMap() {
- assertEquals(mapReaderWithValueType(FieldSpec.DataType.STRING).getStoredType(), FieldSpec.DataType.MAP);
- }
-
- @Test
- public void testMapKeyIndexReaderGetStoredTypeReturnsStoredType() {
- assertEquals(new MapKeyIndexReader(mock(ForwardIndexReader.class), "k",
- new DimensionFieldSpec("k", FieldSpec.DataType.BOOLEAN, true)).getStoredType(), FieldSpec.DataType.INT);
- assertEquals(new MapKeyIndexReader(mock(ForwardIndexReader.class), "k",
- new DimensionFieldSpec("k", FieldSpec.DataType.TIMESTAMP, true)).getStoredType(), FieldSpec.DataType.LONG);
- assertEquals(new MapKeyIndexReader(mock(ForwardIndexReader.class), "k",
- new DimensionFieldSpec("k", FieldSpec.DataType.JSON, true)).getStoredType(), FieldSpec.DataType.STRING);
- }
}
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 e46060c12d3..b5b2d936378 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
@@ -50,7 +50,6 @@ import org.apache.pinot.spi.config.table.TableType;
import org.apache.pinot.spi.data.ComplexFieldSpec;
import org.apache.pinot.spi.data.DateTimeFieldSpec;
import org.apache.pinot.spi.data.DimensionFieldSpec;
-import org.apache.pinot.spi.data.FieldSpec;
import org.apache.pinot.spi.data.FieldSpec.DataType;
import org.apache.pinot.spi.data.Schema;
import org.apache.pinot.spi.data.readers.FileFormat;
@@ -113,71 +112,93 @@ public class ColumnMetadataTest {
public void verifySegmentAfterLoading(SegmentMetadata segmentMetadata) {
// Single-value dictionary-encoded string dimension column
ColumnMetadata col3Meta = segmentMetadata.getColumnMetadataFor("column3");
- assertEquals(col3Meta.getFieldSpec(),
- new DimensionFieldSpec("column3", DataType.STRING, true, FieldSpec.DEFAULT_MAX_LENGTH, null));
- assertEquals(col3Meta.getCardinality(), 5);
+ assertEquals(col3Meta.getFieldSpec(), new DimensionFieldSpec("column3", DataType.STRING, true));
assertEquals(col3Meta.getTotalDocs(), 100000);
- assertEquals(col3Meta.getBitsPerElement(), 3);
- assertEquals(col3Meta.getColumnMaxLength(), 4);
- assertFalse(col3Meta.isSorted());
+ assertEquals(col3Meta.getCardinality(), 5);
assertTrue(col3Meta.hasDictionary());
- assertEquals(col3Meta.getMaxNumberOfMultiValues(), 0);
+ assertFalse(col3Meta.isSorted());
+ assertEquals(col3Meta.getMinValue(), "");
+ assertEquals(col3Meta.getMaxValue(), "w");
+ assertFalse(col3Meta.isMinMaxValueInvalid());
+ assertEquals(col3Meta.getLengthOfShortestElement(), 0);
+ assertEquals(col3Meta.getLengthOfLongestElement(), 4);
+ assertTrue(col3Meta.isAscii());
assertEquals(col3Meta.getTotalNumberOfEntries(), 100000);
+ assertEquals(col3Meta.getMaxNumberOfMultiValues(), 0);
+ assertEquals(col3Meta.getBitsPerElement(), 3);
assertFalse(col3Meta.isAutoGenerated());
// Single-value raw string dimension column
ColumnMetadata col4Meta = segmentMetadata.getColumnMetadataFor("column4");
- assertEquals(col4Meta.getFieldSpec(),
- new DimensionFieldSpec("column4", DataType.STRING, true, FieldSpec.DEFAULT_MAX_LENGTH, null));
- assertEquals(col4Meta.getCardinality(), 5);
+ assertEquals(col4Meta.getFieldSpec(), new DimensionFieldSpec("column4", DataType.STRING, true));
assertEquals(col4Meta.getTotalDocs(), 100000);
- assertEquals(col4Meta.getBitsPerElement(), 3);
- assertEquals(col4Meta.getColumnMaxLength(), 0);
- assertFalse(col4Meta.isSorted());
+ assertEquals(col4Meta.getCardinality(), 5);
assertFalse(col4Meta.hasDictionary());
- assertEquals(col4Meta.getMaxNumberOfMultiValues(), 0);
+ assertFalse(col4Meta.isSorted());
+ assertEquals(col4Meta.getMinValue(), "");
+ assertEquals(col4Meta.getMaxValue(), "w");
+ assertFalse(col4Meta.isMinMaxValueInvalid());
+ assertEquals(col4Meta.getLengthOfShortestElement(), 0);
+ assertEquals(col4Meta.getLengthOfLongestElement(), 4);
+ assertTrue(col4Meta.isAscii());
assertEquals(col4Meta.getTotalNumberOfEntries(), 100000);
+ assertEquals(col4Meta.getMaxNumberOfMultiValues(), 0);
+ assertEquals(col4Meta.getBitsPerElement(), -1);
assertFalse(col4Meta.isAutoGenerated());
// Multi-value dictionary-encoded int dimension column
ColumnMetadata col6Meta = segmentMetadata.getColumnMetadataFor("column6");
assertEquals(col6Meta.getFieldSpec(), new DimensionFieldSpec("column6", DataType.INT, false));
- assertEquals(col6Meta.getCardinality(), 18499);
assertEquals(col6Meta.getTotalDocs(), 100000);
- assertEquals(col6Meta.getBitsPerElement(), 15);
- assertEquals(col6Meta.getColumnMaxLength(), 0);
- assertFalse(col6Meta.isSorted());
+ assertEquals(col6Meta.getCardinality(), 18499);
assertTrue(col6Meta.hasDictionary());
- assertEquals(col6Meta.getMaxNumberOfMultiValues(), 13);
+ assertFalse(col6Meta.isSorted());
+ assertEquals(col6Meta.getMinValue(), 1001);
+ assertEquals(col6Meta.getMaxValue(), 2147483647);
+ assertFalse(col6Meta.isMinMaxValueInvalid());
+ assertEquals(col6Meta.getLengthOfShortestElement(), 4);
+ assertEquals(col6Meta.getLengthOfLongestElement(), 4);
+ assertFalse(col6Meta.isAscii());
assertEquals(col6Meta.getTotalNumberOfEntries(), 106688);
+ assertEquals(col6Meta.getMaxNumberOfMultiValues(), 13);
+ assertEquals(col6Meta.getBitsPerElement(), 15);
assertFalse(col6Meta.isAutoGenerated());
// Multi-value raw int dimension column
ColumnMetadata col7Meta = segmentMetadata.getColumnMetadataFor("column7");
assertEquals(col7Meta.getFieldSpec(), new DimensionFieldSpec("column7", DataType.INT, false));
- assertEquals(col7Meta.getCardinality(), 359);
assertEquals(col7Meta.getTotalDocs(), 100000);
- assertEquals(col7Meta.getBitsPerElement(), 9);
- assertEquals(col7Meta.getColumnMaxLength(), 0);
- assertFalse(col7Meta.isSorted());
+ assertEquals(col7Meta.getCardinality(), 359);
assertFalse(col7Meta.hasDictionary());
- assertEquals(col7Meta.getMaxNumberOfMultiValues(), 24);
+ assertFalse(col7Meta.isSorted());
+ assertEquals(col7Meta.getMinValue(), 201);
+ assertEquals(col7Meta.getMaxValue(), 2147483647);
+ assertFalse(col7Meta.isMinMaxValueInvalid());
+ assertEquals(col7Meta.getLengthOfShortestElement(), 4);
+ assertEquals(col7Meta.getLengthOfLongestElement(), 4);
+ assertFalse(col7Meta.isAscii());
assertEquals(col7Meta.getTotalNumberOfEntries(), 134090);
+ assertEquals(col7Meta.getMaxNumberOfMultiValues(), 24);
+ assertEquals(col7Meta.getBitsPerElement(), -1);
assertFalse(col7Meta.isAutoGenerated());
// Date-time column
ColumnMetadata timeColumn = segmentMetadata.getColumnMetadataFor("daysSinceEpoch");
assertEquals(timeColumn.getFieldSpec(),
new DateTimeFieldSpec("daysSinceEpoch", DataType.INT, "EPOCH|HOURS", "1:HOURS"));
- assertEquals(timeColumn.getColumnName(), "daysSinceEpoch");
- assertEquals(timeColumn.getCardinality(), 1);
assertEquals(timeColumn.getTotalDocs(), 100000);
- assertEquals(timeColumn.getBitsPerElement(), 1);
- assertEquals(timeColumn.getColumnMaxLength(), 0);
- assertTrue(timeColumn.isSorted());
+ assertEquals(timeColumn.getCardinality(), 1);
assertTrue(timeColumn.hasDictionary());
- assertEquals(timeColumn.getMaxNumberOfMultiValues(), 0);
+ assertTrue(timeColumn.isSorted());
+ assertEquals(timeColumn.getMinValue(), 1756015683);
+ assertEquals(timeColumn.getMaxValue(), 1756015683);
+ assertFalse(timeColumn.isMinMaxValueInvalid());
+ assertEquals(timeColumn.getLengthOfShortestElement(), 4);
+ assertEquals(timeColumn.getLengthOfLongestElement(), 4);
+ assertFalse(timeColumn.isAscii());
assertEquals(timeColumn.getTotalNumberOfEntries(), 100000);
+ assertEquals(timeColumn.getMaxNumberOfMultiValues(), 0);
+ assertEquals(timeColumn.getBitsPerElement(), 1);
assertFalse(timeColumn.isAutoGenerated());
}
@@ -269,7 +290,7 @@ public class ColumnMetadataTest {
File metadataFile = new File(resource.getFile());
PropertiesConfiguration propertiesConfiguration = CommonsConfigurationUtils.fromFile(metadataFile);
ColumnMetadataImpl installationOutput =
- ColumnMetadataImpl.fromPropertiesConfiguration("installation_output", propertiesConfiguration);
+ ColumnMetadataImpl.fromPropertiesConfiguration(propertiesConfiguration, 6478, "installation_output");
assertEquals(installationOutput.getMinValue(),
"\r\n\r\n utils em::C:\\dir\\utils\r\nPSParentPath : Mi");
}
@@ -282,13 +303,14 @@ public class ColumnMetadataTest {
PropertiesConfiguration config = new PropertiesConfiguration();
BaseSegmentCreator.addColumnMetadataInfo(config, "intMap", mock(ColumnStatistics.class), 1, intMapFieldSpec, false,
-1, false);
- ColumnMetadataImpl intMapColumnMetadata = ColumnMetadataImpl.fromPropertiesConfiguration("intMap", config);
+ ColumnMetadataImpl intMapColumnMetadata = ColumnMetadataImpl.fromPropertiesConfiguration(config, 1, "intMap");
assertEquals(intMapColumnMetadata.getFieldSpec(), intMapFieldSpec);
}
@Test
public void testSetAndCheckIndexSizes() {
- ColumnMetadataImpl meta = new ColumnMetadataImpl.Builder().build();
+ ColumnMetadataImpl meta =
+ new ColumnMetadataImpl.Builder().setFieldSpec(new DimensionFieldSpec("col", DataType.STRING, true)).build();
meta.addIndexSize(IndexService.getInstance().getNumericId(StandardIndexes.json()), 12345L);
meta.addIndexSize(IndexService.getInstance().getNumericId(StandardIndexes.h3()), 0xffffffffffffL);
meta.addIndexSize(IndexService.getInstance().getNumericId(StandardIndexes.vector()), 0);
@@ -297,7 +319,7 @@ public class ColumnMetadataTest {
assertEquals(meta.getIndexSizeFor(StandardIndexes.json()), 12345L);
assertEquals(meta.getIndexSizeFor(StandardIndexes.h3()), 0xffffffffffffL);
assertEquals(meta.getIndexSizeFor(StandardIndexes.vector()), 0);
- assertEquals(meta.getIndexSizeFor(StandardIndexes.inverted()), ColumnMetadata.INDEX_NOT_FOUND);
+ assertEquals(meta.getIndexSizeFor(StandardIndexes.inverted()), ColumnMetadata.UNAVAILABLE);
try {
meta.addIndexSize(IndexService.getInstance().getNumericId(StandardIndexes.fst()), -1);
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 f8dc1d01d1f..cf2db67716d 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
@@ -37,6 +37,7 @@ import javax.annotation.Nullable;
import org.apache.commons.configuration2.ex.ConfigurationException;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
+import org.apache.pinot.segment.local.io.util.PinotDataBitSet;
import org.apache.pinot.segment.local.segment.creator.impl.SegmentIndexCreationDriverImpl;
import org.apache.pinot.segment.local.segment.index.dictionary.DictionaryIndexType;
import org.apache.pinot.segment.local.segment.index.loader.invertedindex.RangeIndexHandler;
@@ -63,7 +64,6 @@ import org.apache.pinot.spi.config.table.FieldConfig;
import org.apache.pinot.spi.config.table.FieldConfig.CompressionCodec;
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.FieldSpec.DataType;
import org.apache.pinot.spi.data.Schema;
import org.apache.pinot.spi.data.readers.GenericRow;
@@ -77,6 +77,7 @@ import org.testng.annotations.Test;
import static org.testng.Assert.*;
+@SuppressWarnings("rawtypes")
public class ForwardIndexHandlerTest {
private static final String RAW_TABLE_NAME = "testTable";
private static final String SEGMENT_NAME = "testSegment";
@@ -230,9 +231,9 @@ public class ForwardIndexHandlerTest {
private static final List<String> FORWARD_INDEX_DISABLED_RAW_COLUMNS =
List.of(DIM_RAW_SV_FORWARD_INDEX_DISABLED_INTEGER, DIM_RAW_MV_FORWARD_INDEX_DISABLED_INTEGER);
- private static final List<CompressionCodec> RAW_COMPRESSION_TYPES =
- Arrays.stream(CompressionCodec.values()).filter(CompressionCodec::isApplicableToRawIndex)
- .collect(Collectors.toList());
+ private static final List<CompressionCodec> RAW_COMPRESSION_TYPES = Arrays.stream(CompressionCodec.values())
+ .filter(CompressionCodec::isApplicableToRawIndex)
+ .collect(Collectors.toList());
//@formatter:off
private static final Schema SCHEMA = new Schema.SchemaBuilder().setSchemaName(RAW_TABLE_NAME)
@@ -298,8 +299,6 @@ public class ForwardIndexHandlerTest {
//@formatter:on
private static final Random RANDOM = new Random();
- private static int _cardinalityOfSvEntries;
- private static int _cardinalityOfMvEntries;
private static final List<GenericRow> TEST_DATA;
@@ -328,8 +327,6 @@ public class ForwardIndexHandlerTest {
Long[][] tempMVLongRowsForwardIndexDisabled = new Long[numRows][maxNumberOfMVEntries];
byte[][][] tempMVByteRowsForwardIndexDisabled = new byte[numRows][maxNumberOfMVEntries][];
- _cardinalityOfSvEntries = 1; // Start with 1 to account for static "testRow" entry
- _cardinalityOfMvEntries = maxNumberOfMVEntries + 1; // Add 1 to account for static "testRow" entry
for (int i = 0; i < numRows; i++) {
// Adding a fixed value to check for filter queries
if (i % 10 == 0) {
@@ -355,7 +352,6 @@ public class ForwardIndexHandlerTest {
tempLongRows[i] = (long) i;
tempBytesRows[i] = str.getBytes();
tempBigDecimalRows[i] = BigDecimal.valueOf(i);
- _cardinalityOfSvEntries += 1;
// Avoid creating empty arrays.
// To test total cardinality, for atleast 1 row, have the number of MV entries = maxNumberOfMVEntries
@@ -1023,11 +1019,7 @@ public class ForwardIndexHandlerTest {
// Validate metadata properties. Nothing should change when a forwardIndex is rewritten for compressionType
// change.
- validateMetadataProperties(column, metadata.hasDictionary(), metadata.getColumnMaxLength(),
- metadata.getCardinality(), metadata.getTotalDocs(), metadata.getDataType(), metadata.getFieldType(),
- metadata.isSorted(), metadata.isSingleValue(), metadata.getMaxNumberOfMultiValues(),
- metadata.getTotalNumberOfEntries(), metadata.isAutoGenerated(), metadata.getMinValue(),
- metadata.getMaxValue(), false);
+ validateMetadataProperties(new SegmentMetadataImpl(INDEX_DIR).getColumnMetadataFor(column), metadata);
}
}
}
@@ -1048,9 +1040,10 @@ public class ForwardIndexHandlerTest {
_writer = writer;
existingSegmentMetadata = segmentDirectory.getSegmentMetadata();
- ForwardIndexConfig forwardIndexConfig =
- new ForwardIndexConfig.Builder().withCompressionCodec(CompressionCodec.LZ4).withRawIndexWriterVersion(4)
- .build();
+ ForwardIndexConfig forwardIndexConfig = new ForwardIndexConfig.Builder()
+ .withCompressionCodec(CompressionCodec.LZ4)
+ .withRawIndexWriterVersion(4)
+ .build();
ObjectNode indexes = JsonUtils.newObjectNode();
indexes.set("forward", forwardIndexConfig.toJsonNode());
FieldConfig fieldConfig =
@@ -1072,11 +1065,7 @@ public class ForwardIndexHandlerTest {
// Validate metadata properties. Nothing should change when a forwardIndex is rewritten for compressionType
// change.
- validateMetadataProperties(column, metadata.hasDictionary(), metadata.getColumnMaxLength(),
- metadata.getCardinality(), metadata.getTotalDocs(), metadata.getDataType(), metadata.getFieldType(),
- metadata.isSorted(), metadata.isSingleValue(), metadata.getMaxNumberOfMultiValues(),
- metadata.getTotalNumberOfEntries(), metadata.isAutoGenerated(), metadata.getMinValue(),
- metadata.getMaxValue(), false);
+ validateMetadataProperties(new SegmentMetadataImpl(INDEX_DIR).getColumnMetadataFor(column), metadata);
// Convert it back
try (SegmentDirectory segmentDirectory = new SegmentLocalFSDirectory(INDEX_DIR, ReadMode.mmap);
@@ -1099,11 +1088,7 @@ public class ForwardIndexHandlerTest {
// Validate metadata properties. Nothing should change when a forwardIndex is rewritten for compressionType
// change.
- validateMetadataProperties(column, metadata.hasDictionary(), metadata.getColumnMaxLength(),
- metadata.getCardinality(), metadata.getTotalDocs(), metadata.getDataType(), metadata.getFieldType(),
- metadata.isSorted(), metadata.isSingleValue(), metadata.getMaxNumberOfMultiValues(),
- metadata.getTotalNumberOfEntries(), metadata.isAutoGenerated(), metadata.getMinValue(),
- metadata.getMaxValue(), false);
+ validateMetadataProperties(new SegmentMetadataImpl(INDEX_DIR).getColumnMetadataFor(column), metadata);
}
}
@@ -1194,27 +1179,16 @@ public class ForwardIndexHandlerTest {
// Tear down before validation. Because columns.psf and index map cleanup happens at segmentDirectory.close()
}
- ColumnMetadata metadata = existingSegmentMetadata.getColumnMetadataFor(column1);
- testIndexExists(column1, StandardIndexes.forward());
- validateIndexMap(column1, false, false);
- validateForwardIndex(column1, newCompressionType, metadata.isSorted());
- // Validate metadata properties. Nothing should change when a forwardIndex is rewritten for compressionType
- // change.
- validateMetadataProperties(column1, metadata.hasDictionary(), metadata.getColumnMaxLength(),
- metadata.getCardinality(), metadata.getTotalDocs(), metadata.getDataType(), metadata.getFieldType(),
- metadata.isSorted(), metadata.isSingleValue(), metadata.getMaxNumberOfMultiValues(),
- metadata.getTotalNumberOfEntries(), metadata.isAutoGenerated(), metadata.getMinValue(), metadata.getMaxValue(),
- false);
-
- metadata = existingSegmentMetadata.getColumnMetadataFor(column2);
- testIndexExists(column2, StandardIndexes.forward());
- validateIndexMap(column2, false, false);
- validateForwardIndex(column2, newCompressionType, metadata.isSorted());
- validateMetadataProperties(column2, metadata.hasDictionary(), metadata.getColumnMaxLength(),
- metadata.getCardinality(), metadata.getTotalDocs(), metadata.getDataType(), metadata.getFieldType(),
- metadata.isSorted(), metadata.isSingleValue(), metadata.getMaxNumberOfMultiValues(),
- metadata.getTotalNumberOfEntries(), metadata.isAutoGenerated(), metadata.getMinValue(), metadata.getMaxValue(),
- false);
+ SegmentMetadataImpl newSegmentMetadata = new SegmentMetadataImpl(INDEX_DIR);
+ for (String column : List.of(column1, column2)) {
+ ColumnMetadata metadata = existingSegmentMetadata.getColumnMetadataFor(column);
+ testIndexExists(column, StandardIndexes.forward());
+ validateIndexMap(column, false, false);
+ validateForwardIndex(column, newCompressionType, metadata.isSorted());
+ // Validate metadata properties. Nothing should change when a forwardIndex is rewritten for compressionType
+ // change.
+ validateMetadataProperties(newSegmentMetadata.getColumnMetadataFor(column), metadata);
+ }
}
@Test
@@ -1240,23 +1214,8 @@ public class ForwardIndexHandlerTest {
validateIndexMap(column, true, false);
validateForwardIndex(column, null, metadata.isSorted());
- // In column metadata, nothing other than hasDictionary and dictionaryElementSize should change.
- int dictionaryElementSize = 0;
- DataType dataType = metadata.getDataType();
- if (dataType == DataType.STRING || dataType == DataType.BYTES) {
- // This value is based on the rows in createTestData().
- dictionaryElementSize = 7;
- } else if (dataType == DataType.BIG_DECIMAL) {
- dictionaryElementSize = 4;
- }
- int expectedCardinality = column.equals(DIM_MV_PASS_THROUGH_INTEGER) || column.equals(DIM_MV_PASS_THROUGH_LONG)
- ? _cardinalityOfMvEntries : _cardinalityOfSvEntries;
- // DIM_RAW_SORTED_INTEGER has all unique values
- expectedCardinality = column.equals(DIM_RAW_SORTED_INTEGER) ? TEST_DATA.size() : expectedCardinality;
- validateMetadataProperties(column, true, dictionaryElementSize, expectedCardinality,
- metadata.getTotalDocs(), dataType, metadata.getFieldType(), metadata.isSorted(), metadata.isSingleValue(),
- metadata.getMaxNumberOfMultiValues(), metadata.getTotalNumberOfEntries(), metadata.isAutoGenerated(),
- metadata.getMinValue(), metadata.getMaxValue(), false);
+ // In column metadata, nothing other than hasDictionary and bitsPerElement should change.
+ validateMetadataProperties(new SegmentMetadataImpl(INDEX_DIR).getColumnMetadataFor(column), metadata, true);
}
}
@@ -1280,53 +1239,16 @@ public class ForwardIndexHandlerTest {
// Tear down before validation. Because columns.psf and index map cleanup happens at segmentDirectory.close()
}
- // Col1 validation.
- ColumnMetadata metadata = existingSegmentMetadata.getColumnMetadataFor(column1);
- testIndexExists(column1, StandardIndexes.forward());
- testIndexExists(column1, StandardIndexes.dictionary());
- validateIndexMap(column1, true, false);
- validateForwardIndex(column1, null, metadata.isSorted());
- // In column metadata, nothing other than hasDictionary and dictionaryElementSize should change.
- int dictionaryElementSize = 0;
- DataType dataType = metadata.getDataType();
- if (dataType == DataType.STRING || dataType == DataType.BYTES) {
- // This value is based on the rows in createTestData().
- dictionaryElementSize = 7;
- } else if (dataType == DataType.BIG_DECIMAL) {
- dictionaryElementSize = 4;
- }
- int expectedCardinality = column1.equals(DIM_MV_PASS_THROUGH_INTEGER) || column1.equals(DIM_MV_PASS_THROUGH_LONG)
- ? _cardinalityOfMvEntries : _cardinalityOfSvEntries;
- // DIM_RAW_SORTED_INTEGER has all unique values
- expectedCardinality = column1.equals(DIM_RAW_SORTED_INTEGER) ? TEST_DATA.size() : expectedCardinality;
- validateMetadataProperties(column1, true, dictionaryElementSize, expectedCardinality, metadata.getTotalDocs(),
- dataType, metadata.getFieldType(), metadata.isSorted(), metadata.isSingleValue(),
- metadata.getMaxNumberOfMultiValues(), metadata.getTotalNumberOfEntries(), metadata.isAutoGenerated(),
- metadata.getMinValue(), metadata.getMaxValue(), false);
-
- // Col2 validation.
- metadata = existingSegmentMetadata.getColumnMetadataFor(column2);
- testIndexExists(column2, StandardIndexes.forward());
- testIndexExists(column2, StandardIndexes.dictionary());
- validateIndexMap(column2, true, false);
- validateForwardIndex(column2, null, metadata.isSorted());
- // In column metadata, nothing other than hasDictionary and dictionaryElementSize should change.
- dictionaryElementSize = 0;
- dataType = metadata.getDataType();
- if (dataType == DataType.STRING || dataType == DataType.BYTES) {
- // This value is based on the rows in createTestData().
- dictionaryElementSize = 7;
- } else if (dataType == DataType.BIG_DECIMAL) {
- dictionaryElementSize = 4;
- }
- expectedCardinality = column2.equals(DIM_MV_PASS_THROUGH_INTEGER) || column2.equals(DIM_MV_PASS_THROUGH_LONG)
- ? _cardinalityOfMvEntries : _cardinalityOfSvEntries;
- // DIM_RAW_SORTED_INTEGER has all unique values
- expectedCardinality = column2.equals(DIM_RAW_SORTED_INTEGER) ? TEST_DATA.size() : expectedCardinality;
- validateMetadataProperties(column2, true, dictionaryElementSize, expectedCardinality, metadata.getTotalDocs(),
- dataType, metadata.getFieldType(), metadata.isSorted(), metadata.isSingleValue(),
- metadata.getMaxNumberOfMultiValues(), metadata.getTotalNumberOfEntries(), metadata.isAutoGenerated(),
- metadata.getMinValue(), metadata.getMaxValue(), false);
+ SegmentMetadataImpl newSegmentMetadata = new SegmentMetadataImpl(INDEX_DIR);
+ for (String column : List.of(column1, column2)) {
+ ColumnMetadata metadata = existingSegmentMetadata.getColumnMetadataFor(column);
+ testIndexExists(column, StandardIndexes.forward());
+ testIndexExists(column, StandardIndexes.dictionary());
+ validateIndexMap(column, true, false);
+ validateForwardIndex(column, null, metadata.isSorted());
+ // In column metadata, nothing other than hasDictionary and bitsPerElement should change.
+ validateMetadataProperties(newSegmentMetadata.getColumnMetadataFor(column), metadata, true);
+ }
}
@Test
@@ -1350,12 +1272,8 @@ public class ForwardIndexHandlerTest {
validateIndexesForForwardIndexDisabledColumns(column);
// In column metadata, nothing should change.
- ColumnMetadata metadata = existingSegmentMetadata.getColumnMetadataFor(column);
- validateMetadataProperties(column, metadata.hasDictionary(), metadata.getColumnMaxLength(),
- metadata.getCardinality(), metadata.getTotalDocs(), metadata.getDataType(), metadata.getFieldType(),
- metadata.isSorted(), metadata.isSingleValue(), metadata.getMaxNumberOfMultiValues(),
- metadata.getTotalNumberOfEntries(), metadata.isAutoGenerated(), metadata.getMinValue(),
- metadata.getMaxValue(), false);
+ validateMetadataProperties(new SegmentMetadataImpl(INDEX_DIR).getColumnMetadataFor(column),
+ existingSegmentMetadata.getColumnMetadataFor(column));
}
}
@@ -1381,27 +1299,14 @@ public class ForwardIndexHandlerTest {
// Tear down before validation. Because columns.psf and index map cleanup happens at segmentDirectory.close()
}
- // Col1 validation.
- validateIndexMap(column1, true, true);
- validateIndexesForForwardIndexDisabledColumns(column1);
- // In column metadata, nothing should change.
- ColumnMetadata metadata = existingSegmentMetadata.getColumnMetadataFor(column1);
- validateMetadataProperties(column1, metadata.hasDictionary(), metadata.getColumnMaxLength(),
- metadata.getCardinality(), metadata.getTotalDocs(), metadata.getDataType(), metadata.getFieldType(),
- metadata.isSorted(), metadata.isSingleValue(), metadata.getMaxNumberOfMultiValues(),
- metadata.getTotalNumberOfEntries(), metadata.isAutoGenerated(), metadata.getMinValue(), metadata.getMaxValue(),
- false);
-
- // Col2 validation.
- validateIndexMap(column2, true, true);
- validateIndexesForForwardIndexDisabledColumns(column2);
- // In column metadata, nothing should change.
- metadata = existingSegmentMetadata.getColumnMetadataFor(column2);
- validateMetadataProperties(column2, metadata.hasDictionary(), metadata.getColumnMaxLength(),
- metadata.getCardinality(), metadata.getTotalDocs(), metadata.getDataType(), metadata.getFieldType(),
- metadata.isSorted(), metadata.isSingleValue(), metadata.getMaxNumberOfMultiValues(),
- metadata.getTotalNumberOfEntries(), metadata.isAutoGenerated(), metadata.getMinValue(), metadata.getMaxValue(),
- false);
+ SegmentMetadataImpl newSegmentMetadata = new SegmentMetadataImpl(INDEX_DIR);
+ for (String column : List.of(column1, column2)) {
+ validateIndexMap(column, true, true);
+ validateIndexesForForwardIndexDisabledColumns(column);
+ // In column metadata, nothing should change.
+ validateMetadataProperties(newSegmentMetadata.getColumnMetadataFor(column),
+ existingSegmentMetadata.getColumnMetadataFor(column));
+ }
}
@Test
@@ -1426,11 +1331,8 @@ public class ForwardIndexHandlerTest {
// All the columns are dimensions. So default compression type is LZ4.
validateForwardIndex(column, CompressionCodec.LZ4, metadata.isSorted());
- // In column metadata, nothing other than hasDictionary and dictionaryElementSize should change.
- validateMetadataProperties(column, false, 0, metadata.getCardinality(), metadata.getTotalDocs(),
- metadata.getDataType(), metadata.getFieldType(), metadata.isSorted(), metadata.isSingleValue(),
- metadata.getMaxNumberOfMultiValues(), metadata.getTotalNumberOfEntries(), metadata.isAutoGenerated(),
- metadata.getMinValue(), metadata.getMaxValue(), false);
+ // In column metadata, nothing other than hasDictionary and bitsPerElement should change.
+ validateMetadataProperties(new SegmentMetadataImpl(INDEX_DIR).getColumnMetadataFor(column), metadata, false);
}
}
@@ -1456,10 +1358,8 @@ public class ForwardIndexHandlerTest {
testIndexExists(DIM_RAW_SORTED_INTEGER, StandardIndexes.dictionary());
validateIndexMap(DIM_RAW_SORTED_INTEGER, true, false);
validateForwardIndex(DIM_RAW_SORTED_INTEGER, null, true);
- validateMetadataProperties(DIM_RAW_SORTED_INTEGER, true, 0, TEST_DATA.size(), dictMetadata.getTotalDocs(),
- dictMetadata.getDataType(), dictMetadata.getFieldType(), true, dictMetadata.isSingleValue(),
- dictMetadata.getMaxNumberOfMultiValues(), dictMetadata.getTotalNumberOfEntries(),
- dictMetadata.isAutoGenerated(), dictMetadata.getMinValue(), dictMetadata.getMaxValue(), false);
+ validateMetadataProperties(new SegmentMetadataImpl(INDEX_DIR).getColumnMetadataFor(DIM_RAW_SORTED_INTEGER),
+ dictMetadata, true);
// Step 2: Disable dictionary for the sorted column again (convert back to raw).
SegmentMetadataImpl existingSegmentMetadata;
@@ -1482,10 +1382,8 @@ public class ForwardIndexHandlerTest {
testIndexExists(DIM_RAW_SORTED_INTEGER, StandardIndexes.forward());
validateIndexMap(DIM_RAW_SORTED_INTEGER, false, false);
validateForwardIndex(DIM_RAW_SORTED_INTEGER, CompressionCodec.SNAPPY, true);
- validateMetadataProperties(DIM_RAW_SORTED_INTEGER, false, 0, TEST_DATA.size(), metadata.getTotalDocs(),
- metadata.getDataType(), metadata.getFieldType(), true, metadata.isSingleValue(),
- metadata.getMaxNumberOfMultiValues(), metadata.getTotalNumberOfEntries(), metadata.isAutoGenerated(),
- metadata.getMinValue(), metadata.getMaxValue(), false);
+ validateMetadataProperties(new SegmentMetadataImpl(INDEX_DIR).getColumnMetadataFor(DIM_RAW_SORTED_INTEGER),
+ metadata, false);
}
@Test
@@ -1508,31 +1406,16 @@ public class ForwardIndexHandlerTest {
// Tear down before validation. Because columns.psf and index map cleanup happens at segmentDirectory.close()
}
- // Column1 validation.
- ColumnMetadata metadata = existingSegmentMetadata.getColumnMetadataFor(column1);
- testIndexExists(column1, StandardIndexes.forward());
- validateIndexMap(column1, false, false);
- // All the columns are dimensions. So default compression type is LZ4.
- validateForwardIndex(column1, CompressionCodec.LZ4, metadata.isSorted());
-
- // In column metadata, nothing other than hasDictionary and dictionaryElementSize should change.
- validateMetadataProperties(column1, false, 0, metadata.getCardinality(), metadata.getTotalDocs(),
- metadata.getDataType(), metadata.getFieldType(), metadata.isSorted(), metadata.isSingleValue(),
- metadata.getMaxNumberOfMultiValues(), metadata.getTotalNumberOfEntries(), metadata.isAutoGenerated(),
- metadata.getMinValue(), metadata.getMaxValue(), false);
-
- // Column2 validation.
- metadata = existingSegmentMetadata.getColumnMetadataFor(column2);
- testIndexExists(column2, StandardIndexes.forward());
- validateIndexMap(column2, false, false);
- // All the columns are dimensions. So default compression type is LZ4.
- validateForwardIndex(column2, CompressionCodec.LZ4, metadata.isSorted());
-
- // In column metadata, nothing other than hasDictionary and dictionaryElementSize should change.
- validateMetadataProperties(column2, false, 0, metadata.getCardinality(), metadata.getTotalDocs(),
- metadata.getDataType(), metadata.getFieldType(), metadata.isSorted(), metadata.isSingleValue(),
- metadata.getMaxNumberOfMultiValues(), metadata.getTotalNumberOfEntries(), metadata.isAutoGenerated(),
- metadata.getMinValue(), metadata.getMaxValue(), false);
+ SegmentMetadataImpl newSegmentMetadata = new SegmentMetadataImpl(INDEX_DIR);
+ for (String column : List.of(column1, column2)) {
+ ColumnMetadata metadata = existingSegmentMetadata.getColumnMetadataFor(column);
+ testIndexExists(column, StandardIndexes.forward());
+ validateIndexMap(column, false, false);
+ // All the columns are dimensions. So default compression type is LZ4.
+ validateForwardIndex(column, CompressionCodec.LZ4, metadata.isSorted());
+ // In column metadata, nothing other than hasDictionary and bitsPerElement should change.
+ validateMetadataProperties(newSegmentMetadata.getColumnMetadataFor(column), metadata, false);
+ }
}
@Test
@@ -1562,22 +1445,9 @@ public class ForwardIndexHandlerTest {
validateIndexMap(column, true, true);
validateIndexesForForwardIndexDisabledColumns(column);
- // In column metadata, nothing other than hasDictionary and dictionaryElementSize should change.
- int dictionaryElementSize = 0;
- ColumnMetadata metadata = existingSegmentMetadata.getColumnMetadataFor(column);
- DataType dataType = metadata.getDataType();
- if (dataType == DataType.STRING || dataType == DataType.BYTES) {
- // This value is based on the rows in createTestData().
- dictionaryElementSize = 7;
- } else if (dataType == DataType.BIG_DECIMAL) {
- dictionaryElementSize = 4;
- }
- int expectedCardinality = column.equals(DIM_MV_PASS_THROUGH_INTEGER) || column.equals(DIM_MV_PASS_THROUGH_LONG)
- ? _cardinalityOfMvEntries : _cardinalityOfSvEntries;
- validateMetadataProperties(column, true, dictionaryElementSize, expectedCardinality,
- metadata.getTotalDocs(), dataType, metadata.getFieldType(), metadata.isSorted(), metadata.isSingleValue(),
- metadata.getMaxNumberOfMultiValues(), metadata.getTotalNumberOfEntries(), metadata.isAutoGenerated(),
- metadata.getMinValue(), metadata.getMaxValue(), false);
+ // In column metadata, nothing other than hasDictionary and bitsPerElement should change.
+ validateMetadataProperties(new SegmentMetadataImpl(INDEX_DIR).getColumnMetadataFor(column),
+ existingSegmentMetadata.getColumnMetadataFor(column), true);
}
}
@@ -1607,45 +1477,14 @@ public class ForwardIndexHandlerTest {
// Tear down before validation. Because columns.psf and index map cleanup happens at segmentDirectory.close()
}
- // Col1 validation.
- validateIndexMap(column1, true, true);
- validateIndexesForForwardIndexDisabledColumns(column1);
- // In column metadata, nothing other than hasDictionary and dictionaryElementSize should change.
- int dictionaryElementSize = 0;
- ColumnMetadata metadata = existingSegmentMetadata.getColumnMetadataFor(column1);
- DataType dataType = metadata.getDataType();
- if (dataType == DataType.STRING || dataType == DataType.BYTES) {
- // This value is based on the rows in createTestData().
- dictionaryElementSize = 7;
- } else if (dataType == DataType.BIG_DECIMAL) {
- dictionaryElementSize = 4;
- }
- int expectedCardinality = column1.equals(DIM_MV_PASS_THROUGH_INTEGER) || column1.equals(DIM_MV_PASS_THROUGH_LONG)
- ? _cardinalityOfMvEntries : _cardinalityOfSvEntries;
- validateMetadataProperties(column1, true, dictionaryElementSize, expectedCardinality, metadata.getTotalDocs(),
- dataType, metadata.getFieldType(), metadata.isSorted(), metadata.isSingleValue(),
- metadata.getMaxNumberOfMultiValues(), metadata.getTotalNumberOfEntries(), metadata.isAutoGenerated(),
- metadata.getMinValue(), metadata.getMaxValue(), false);
-
- // Col2 validation.
- validateIndexMap(column2, true, true);
- validateIndexesForForwardIndexDisabledColumns(column2);
- // In column metadata, nothing other than hasDictionary and dictionaryElementSize should change.
- dictionaryElementSize = 0;
- metadata = existingSegmentMetadata.getColumnMetadataFor(column2);
- dataType = metadata.getDataType();
- if (dataType == DataType.STRING || dataType == DataType.BYTES) {
- // This value is based on the rows in createTestData().
- dictionaryElementSize = 7;
- } else if (dataType == DataType.BIG_DECIMAL) {
- dictionaryElementSize = 4;
- }
- expectedCardinality = column2.equals(DIM_MV_PASS_THROUGH_INTEGER) || column2.equals(DIM_MV_PASS_THROUGH_LONG)
- ? _cardinalityOfMvEntries : _cardinalityOfSvEntries;
- validateMetadataProperties(column2, true, dictionaryElementSize, expectedCardinality, metadata.getTotalDocs(),
- dataType, metadata.getFieldType(), metadata.isSorted(), metadata.isSingleValue(),
- metadata.getMaxNumberOfMultiValues(), metadata.getTotalNumberOfEntries(), metadata.isAutoGenerated(),
- metadata.getMinValue(), metadata.getMaxValue(), false);
+ SegmentMetadataImpl newSegmentMetadata = new SegmentMetadataImpl(INDEX_DIR);
+ for (String column : List.of(column1, column2)) {
+ validateIndexMap(column, true, true);
+ validateIndexesForForwardIndexDisabledColumns(column);
+ // In column metadata, nothing other than hasDictionary and bitsPerElement should change.
+ validateMetadataProperties(newSegmentMetadata.getColumnMetadataFor(column),
+ existingSegmentMetadata.getColumnMetadataFor(column), true);
+ }
}
@Test
@@ -1672,13 +1511,9 @@ public class ForwardIndexHandlerTest {
validateIndexMap(column, false, true);
validateIndexesForForwardIndexDisabledColumns(column);
- // In column metadata, nothing other than hasDictionary and dictionaryElementSize should change.
- ColumnMetadata metadata = existingSegmentMetadata.getColumnMetadataFor(column);
- DataType dataType = metadata.getDataType();
- validateMetadataProperties(column, false, 0, metadata.getCardinality(), metadata.getTotalDocs(), dataType,
- metadata.getFieldType(), metadata.isSorted(), metadata.isSingleValue(), metadata.getMaxNumberOfMultiValues(),
- metadata.getTotalNumberOfEntries(), metadata.isAutoGenerated(), metadata.getMinValue(),
- metadata.getMaxValue(), false);
+ // In column metadata, nothing other than hasDictionary and bitsPerElement should change.
+ validateMetadataProperties(new SegmentMetadataImpl(INDEX_DIR).getColumnMetadataFor(column),
+ existingSegmentMetadata.getColumnMetadataFor(column), false);
}
}
@@ -1707,22 +1542,9 @@ public class ForwardIndexHandlerTest {
validateIndexMap(column, true, true);
validateIndexesForForwardIndexDisabledColumns(column);
- // In column metadata, nothing other than hasDictionary and dictionaryElementSize should change.
- ColumnMetadata metadata = existingSegmentMetadata.getColumnMetadataFor(column);
- DataType dataType = metadata.getDataType();
- int dictionaryElementSize = 0;
- if (dataType == DataType.STRING || dataType == DataType.BYTES) {
- // This value is based on the rows in createTestData().
- dictionaryElementSize = 7;
- } else if (dataType == DataType.BIG_DECIMAL) {
- dictionaryElementSize = 4;
- }
- int expectedCardinality = column.equals(DIM_MV_PASS_THROUGH_INTEGER) || column.equals(DIM_MV_PASS_THROUGH_LONG)
- ? _cardinalityOfMvEntries : _cardinalityOfSvEntries;
- validateMetadataProperties(column, true, dictionaryElementSize, expectedCardinality,
- metadata.getTotalDocs(), dataType, metadata.getFieldType(), metadata.isSorted(), metadata.isSingleValue(),
- metadata.getMaxNumberOfMultiValues(), metadata.getTotalNumberOfEntries(), metadata.isAutoGenerated(),
- metadata.getMinValue(), metadata.getMaxValue(), false);
+ // In column metadata, nothing other than hasDictionary and bitsPerElement should change.
+ validateMetadataProperties(new SegmentMetadataImpl(INDEX_DIR).getColumnMetadataFor(column),
+ existingSegmentMetadata.getColumnMetadataFor(column), true);
}
}
@@ -1747,13 +1569,8 @@ public class ForwardIndexHandlerTest {
ColumnMetadata metadata = existingSegmentMetadata.getColumnMetadataFor(column);
validateIndexMap(column, true, false);
validateForwardIndex(column, null, metadata.isSorted());
-
// In column metadata, nothing should change.
- validateMetadataProperties(column, metadata.hasDictionary(), metadata.getColumnMaxLength(),
- metadata.getCardinality(), metadata.getTotalDocs(), metadata.getDataType(), metadata.getFieldType(),
- metadata.isSorted(), metadata.isSingleValue(), metadata.getMaxNumberOfMultiValues(),
- metadata.getTotalNumberOfEntries(), metadata.isAutoGenerated(), metadata.getMinValue(),
- metadata.getMaxValue(), false);
+ validateMetadataProperties(new SegmentMetadataImpl(INDEX_DIR).getColumnMetadataFor(column), metadata);
}
}
@@ -1775,27 +1592,14 @@ public class ForwardIndexHandlerTest {
// Tear down before validation. Because columns.psf and index map cleanup happens at segmentDirectory.close()
}
- // Col1 validation.
- ColumnMetadata metadata = existingSegmentMetadata.getColumnMetadataFor(column1);
- validateIndexMap(column1, true, false);
- validateForwardIndex(column1, null, metadata.isSorted());
- // In column metadata, nothing should change.
- validateMetadataProperties(column1, metadata.hasDictionary(), metadata.getColumnMaxLength(),
- metadata.getCardinality(), metadata.getTotalDocs(), metadata.getDataType(), metadata.getFieldType(),
- metadata.isSorted(), metadata.isSingleValue(), metadata.getMaxNumberOfMultiValues(),
- metadata.getTotalNumberOfEntries(), metadata.isAutoGenerated(), metadata.getMinValue(), metadata.getMaxValue(),
- false);
-
- // Col2 validation.
- metadata = existingSegmentMetadata.getColumnMetadataFor(column2);
- validateIndexMap(column2, true, false);
- validateForwardIndex(column2, null, metadata.isSorted());
- // In column metadata, nothing should change.
- validateMetadataProperties(column2, metadata.hasDictionary(), metadata.getColumnMaxLength(),
- metadata.getCardinality(), metadata.getTotalDocs(), metadata.getDataType(), metadata.getFieldType(),
- metadata.isSorted(), metadata.isSingleValue(), metadata.getMaxNumberOfMultiValues(),
- metadata.getTotalNumberOfEntries(), metadata.isAutoGenerated(), metadata.getMinValue(), metadata.getMaxValue(),
- false);
+ SegmentMetadataImpl newSegmentMetadata = new SegmentMetadataImpl(INDEX_DIR);
+ for (String column : List.of(column1, column2)) {
+ ColumnMetadata metadata = existingSegmentMetadata.getColumnMetadataFor(column);
+ validateIndexMap(column, true, false);
+ validateForwardIndex(column, null, metadata.isSorted());
+ // In column metadata, nothing should change.
+ validateMetadataProperties(newSegmentMetadata.getColumnMetadataFor(column), metadata);
+ }
}
@Test
@@ -1821,11 +1625,7 @@ public class ForwardIndexHandlerTest {
validateForwardIndex(column, null, metadata.isSorted());
// In column metadata, some values can change since MV columns with duplicates lose the duplicates on forward index
// regeneration.
- validateMetadataProperties(column, metadata.hasDictionary(), metadata.getColumnMaxLength(),
- metadata.getCardinality(), metadata.getTotalDocs(), metadata.getDataType(), metadata.getFieldType(),
- metadata.isSorted(), metadata.isSingleValue(), metadata.getMaxNumberOfMultiValues(),
- metadata.getTotalNumberOfEntries(), metadata.isAutoGenerated(), metadata.getMinValue(), metadata.getMaxValue(),
- true);
+ validateMetadataProperties(new SegmentMetadataImpl(INDEX_DIR).getColumnMetadataFor(column), metadata, null, true);
}
@Test
@@ -1850,25 +1650,14 @@ public class ForwardIndexHandlerTest {
// Tear down before validation. Because columns.psf and index map cleanup happens at segmentDirectory.close()
}
- // Col1 validation.
- ColumnMetadata metadata = existingSegmentMetadata.getColumnMetadataFor(column1);
- validateIndexMap(column1, false, false);
- validateForwardIndex(column1, CompressionCodec.LZ4, metadata.isSorted());
- // In column metadata, nothing should change.
- validateMetadataProperties(column1, false, 0, metadata.getCardinality(), metadata.getTotalDocs(),
- metadata.getDataType(), metadata.getFieldType(), metadata.isSorted(), metadata.isSingleValue(),
- metadata.getMaxNumberOfMultiValues(), metadata.getTotalNumberOfEntries(), metadata.isAutoGenerated(),
- metadata.getMinValue(), metadata.getMaxValue(), false);
-
- // Col2 validation.
- metadata = existingSegmentMetadata.getColumnMetadataFor(column2);
- validateIndexMap(column2, false, false);
- validateForwardIndex(column2, CompressionCodec.LZ4, metadata.isSorted());
- // In column metadata, nothing should change.
- validateMetadataProperties(column2, false, 0, metadata.getCardinality(), metadata.getTotalDocs(),
- metadata.getDataType(), metadata.getFieldType(), metadata.isSorted(), metadata.isSingleValue(),
- metadata.getMaxNumberOfMultiValues(), metadata.getTotalNumberOfEntries(), metadata.isAutoGenerated(),
- metadata.getMinValue(), metadata.getMaxValue(), false);
+ SegmentMetadataImpl newSegmentMetadata = new SegmentMetadataImpl(INDEX_DIR);
+ for (String column : List.of(column1, column2)) {
+ ColumnMetadata metadata = existingSegmentMetadata.getColumnMetadataFor(column);
+ validateIndexMap(column, false, false);
+ validateForwardIndex(column, CompressionCodec.LZ4, metadata.isSorted());
+ // In column metadata, nothing should change.
+ validateMetadataProperties(newSegmentMetadata.getColumnMetadataFor(column), metadata, false);
+ }
}
@Test
@@ -1896,10 +1685,7 @@ public class ForwardIndexHandlerTest {
validateForwardIndex(column, CompressionCodec.LZ4, metadata.isSorted());
// In column metadata, some values can change since MV columns with duplicates lose the duplicates on forward index
// regeneration.
- validateMetadataProperties(column, false, 0, metadata.getCardinality(), metadata.getTotalDocs(),
- metadata.getDataType(), metadata.getFieldType(), metadata.isSorted(), metadata.isSingleValue(),
- metadata.getMaxNumberOfMultiValues(), metadata.getTotalNumberOfEntries(), metadata.isAutoGenerated(),
- metadata.getMinValue(), metadata.getMaxValue(), true);
+ validateMetadataProperties(new SegmentMetadataImpl(INDEX_DIR).getColumnMetadataFor(column), metadata, false, true);
}
@Test
@@ -1925,18 +1711,15 @@ public class ForwardIndexHandlerTest {
ColumnMetadata metadata = existingSegmentMetadata.getColumnMetadataFor(column);
validateIndexMap(column, false, false);
validateForwardIndex(column, CompressionCodec.LZ4, metadata.isSorted());
-
// In column metadata, nothing should change.
- validateMetadataProperties(column, false, 0, metadata.getCardinality(), metadata.getTotalDocs(),
- metadata.getDataType(), metadata.getFieldType(), metadata.isSorted(), metadata.isSingleValue(),
- metadata.getMaxNumberOfMultiValues(), metadata.getTotalNumberOfEntries(), metadata.isAutoGenerated(),
- metadata.getMinValue(), metadata.getMaxValue(), false);
+ validateMetadataProperties(new SegmentMetadataImpl(INDEX_DIR).getColumnMetadataFor(column), metadata, false);
}
}
@Test
public void testEnableForwardIndexForInvertedIndexDisabledColumn()
throws Exception {
+ String column = DIM_SV_FORWARD_INDEX_DISABLED_INTEGER_WITHOUT_INV_IDX;
SegmentMetadataImpl existingSegmentMetadata;
try (SegmentDirectory segmentDirectory = new SegmentLocalFSDirectory(INDEX_DIR, ReadMode.mmap);
SegmentDirectory.Writer writer = segmentDirectory.createWriter()) {
@@ -1944,28 +1727,24 @@ public class ForwardIndexHandlerTest {
_writer = writer;
existingSegmentMetadata = segmentDirectory.getSegmentMetadata();
- _fieldConfigMap.remove(DIM_SV_FORWARD_INDEX_DISABLED_INTEGER_WITHOUT_INV_IDX);
+ _fieldConfigMap.remove(column);
updateIndices();
// Tear down before validation. Because columns.psf and index map cleanup happens at segmentDirectory.close()
}
// Validate nothing has changed
- validateIndexMap(DIM_SV_FORWARD_INDEX_DISABLED_INTEGER_WITHOUT_INV_IDX, true, true);
- validateIndexesForForwardIndexDisabledColumns(DIM_SV_FORWARD_INDEX_DISABLED_INTEGER_WITHOUT_INV_IDX);
-
+ validateIndexMap(column, true, true);
+ validateIndexesForForwardIndexDisabledColumns(column);
// In column metadata, nothing should change.
- ColumnMetadata metadata =
- existingSegmentMetadata.getColumnMetadataFor(DIM_SV_FORWARD_INDEX_DISABLED_INTEGER_WITHOUT_INV_IDX);
- validateMetadataProperties(DIM_SV_FORWARD_INDEX_DISABLED_INTEGER_WITHOUT_INV_IDX, metadata.hasDictionary(),
- metadata.getColumnMaxLength(), metadata.getCardinality(), metadata.getTotalDocs(), metadata.getDataType(),
- metadata.getFieldType(), metadata.isSorted(), metadata.isSingleValue(), metadata.getMaxNumberOfMultiValues(),
- metadata.getTotalNumberOfEntries(), metadata.isAutoGenerated(), metadata.getMinValue(), metadata.getMaxValue(),
- false);
+ validateMetadataProperties(new SegmentMetadataImpl(INDEX_DIR).getColumnMetadataFor(column),
+ existingSegmentMetadata.getColumnMetadataFor(column));
}
@Test
public void testEnableForwardIndexForDictionaryDisabledColumns()
throws Exception {
+ String column1 = DIM_RAW_SV_FORWARD_INDEX_DISABLED_INTEGER;
+ String column2 = DIM_RAW_MV_FORWARD_INDEX_DISABLED_INTEGER;
SegmentMetadataImpl existingSegmentMetadata;
try (SegmentDirectory segmentDirectory = new SegmentLocalFSDirectory(INDEX_DIR, ReadMode.mmap);
SegmentDirectory.Writer writer = segmentDirectory.createWriter()) {
@@ -1973,31 +1752,21 @@ public class ForwardIndexHandlerTest {
_writer = writer;
existingSegmentMetadata = segmentDirectory.getSegmentMetadata();
- _fieldConfigMap.remove(DIM_SV_FORWARD_INDEX_DISABLED_INTEGER_WITHOUT_INV_IDX);
- _fieldConfigMap.remove(DIM_SV_FORWARD_INDEX_DISABLED_INTEGER_WITH_RANGE_INDEX);
+ _fieldConfigMap.remove(column1);
+ _fieldConfigMap.remove(column2);
updateIndices();
// Tear down before validation. Because columns.psf and index map cleanup happens at segmentDirectory.close()
}
- // Validate nothing has changed
- validateIndexMap(DIM_RAW_SV_FORWARD_INDEX_DISABLED_INTEGER, false, true);
- validateIndexesForForwardIndexDisabledColumns(DIM_RAW_SV_FORWARD_INDEX_DISABLED_INTEGER);
- validateIndexMap(DIM_RAW_MV_FORWARD_INDEX_DISABLED_INTEGER, false, true);
- validateIndexesForForwardIndexDisabledColumns(DIM_RAW_MV_FORWARD_INDEX_DISABLED_INTEGER);
-
- // In column metadata, nothing should change.
- ColumnMetadata metadata = existingSegmentMetadata.getColumnMetadataFor(DIM_RAW_SV_FORWARD_INDEX_DISABLED_INTEGER);
- validateMetadataProperties(DIM_RAW_SV_FORWARD_INDEX_DISABLED_INTEGER, metadata.hasDictionary(),
- metadata.getColumnMaxLength(), metadata.getCardinality(), metadata.getTotalDocs(), metadata.getDataType(),
- metadata.getFieldType(), metadata.isSorted(), metadata.isSingleValue(), metadata.getMaxNumberOfMultiValues(),
- metadata.getTotalNumberOfEntries(), metadata.isAutoGenerated(), metadata.getMinValue(), metadata.getMaxValue(),
- false);
- metadata = existingSegmentMetadata.getColumnMetadataFor(DIM_RAW_MV_FORWARD_INDEX_DISABLED_INTEGER);
- validateMetadataProperties(DIM_RAW_MV_FORWARD_INDEX_DISABLED_INTEGER, metadata.hasDictionary(),
- metadata.getColumnMaxLength(), metadata.getCardinality(), metadata.getTotalDocs(), metadata.getDataType(),
- metadata.getFieldType(), metadata.isSorted(), metadata.isSingleValue(), metadata.getMaxNumberOfMultiValues(),
- metadata.getTotalNumberOfEntries(), metadata.isAutoGenerated(), metadata.getMinValue(), metadata.getMaxValue(),
- false);
+ SegmentMetadataImpl newMetadata = new SegmentMetadataImpl(INDEX_DIR);
+ for (String column : List.of(column1, column2)) {
+ // Validate nothing has changed
+ validateIndexMap(column, false, true);
+ validateIndexesForForwardIndexDisabledColumns(column);
+ // In column metadata, nothing should change.
+ validateMetadataProperties(newMetadata.getColumnMetadataFor(column),
+ existingSegmentMetadata.getColumnMetadataFor(column));
+ }
}
@Test
@@ -2034,17 +1803,8 @@ public class ForwardIndexHandlerTest {
// In column metadata, some values can change since MV columns with duplicates lose the duplicates on forward index
// regeneration.
- ColumnMetadata metadata = existingSegmentMetadata.getColumnMetadataFor(column);
- validateMetadataProperties(column, true, 7, metadata.getCardinality(), metadata.getTotalDocs(),
- metadata.getDataType(), metadata.getFieldType(), metadata.isSorted(), metadata.isSingleValue(),
- metadata.getMaxNumberOfMultiValues(), metadata.getTotalNumberOfEntries(), metadata.isAutoGenerated(),
- metadata.getMinValue(), metadata.getMaxValue(), true);
-
- // Validate that all the duplicates are removed
- SegmentMetadataImpl segmentMetadata = new SegmentMetadataImpl(INDEX_DIR);
- ColumnMetadata columnMetadata = segmentMetadata.getColumnMetadataFor(column);
- assertEquals(columnMetadata.getMaxNumberOfMultiValues(), 1);
- assertEquals(columnMetadata.getTotalNumberOfEntries(), metadata.getTotalDocs());
+ validateMetadataProperties(new SegmentMetadataImpl(INDEX_DIR).getColumnMetadataFor(column),
+ existingSegmentMetadata.getColumnMetadataFor(column), null, true);
}
@Test
@@ -2315,43 +2075,61 @@ public class ForwardIndexHandlerTest {
}
}
- private void validateMetadataProperties(String column, boolean hasDictionary, int dictionaryElementSize,
- int cardinality, int totalDocs, DataType dataType, FieldSpec.FieldType fieldType, boolean isSorted,
- boolean isSingleValue, int maxNumberOfMVEntries, int totalNumberOfEntries, boolean isAutoGenerated,
- Comparable<?> minValue, Comparable<?> maxValue, boolean isRegeneratedMVColumnWithDuplicates)
- throws IOException, ConfigurationException {
- SegmentMetadataImpl segmentMetadata = new SegmentMetadataImpl(INDEX_DIR);
- ColumnMetadata columnMetadata = segmentMetadata.getColumnMetadataFor(column);
-
- assertEquals(columnMetadata.hasDictionary(), hasDictionary, column);
- assertEquals(columnMetadata.getColumnMaxLength(), dictionaryElementSize, column);
- assertEquals(columnMetadata.getCardinality(), cardinality, column);
- assertEquals(columnMetadata.getTotalDocs(), totalDocs, column);
- assertEquals(columnMetadata.getDataType(), dataType, column);
- assertEquals(columnMetadata.getFieldType(), fieldType);
- assertEquals(columnMetadata.isSorted(), isSorted);
- assertEquals(columnMetadata.isSingleValue(), isSingleValue);
+ private void validateMetadataProperties(ColumnMetadata actual, ColumnMetadata expected) {
+ validateMetadataProperties(actual, expected, null);
+ }
+
+ private void validateMetadataProperties(ColumnMetadata actual, ColumnMetadata expected,
+ @Nullable Boolean enableDictionary) {
+ validateMetadataProperties(actual, expected, enableDictionary, false);
+ }
+
+ private void validateMetadataProperties(ColumnMetadata actual, ColumnMetadata expected,
+ @Nullable Boolean enableDictionary, boolean isRegeneratedMVColumnWithDuplicates) {
+ assertEquals(actual.getFieldSpec(), expected.getFieldSpec());
+ assertEquals(actual.getTotalDocs(), expected.getTotalDocs());
+ assertEquals(actual.getCardinality(), expected.getCardinality());
+ assertEquals(actual.isSorted(), expected.isSorted());
+ assertEquals(actual.getMinValue(), expected.getMinValue());
+ assertEquals(actual.getMaxValue(), expected.getMaxValue());
+ assertEquals(actual.isMinMaxValueInvalid(), expected.isMinMaxValueInvalid());
+ assertEquals(actual.getLengthOfShortestElement(), expected.getLengthOfShortestElement());
+ assertEquals(actual.getLengthOfLongestElement(), expected.getLengthOfLongestElement());
+ assertEquals(actual.isAscii(), expected.isAscii());
+ assertEquals(actual.getPartitionFunction(), expected.getPartitionFunction());
+ assertEquals(actual.getPartitions(), expected.getPartitions());
+ assertEquals(actual.isAutoGenerated(), expected.isAutoGenerated());
+ if (enableDictionary != null) {
+ if (enableDictionary) {
+ assertTrue(actual.hasDictionary());
+ assertEquals(actual.getBitsPerElement(), PinotDataBitSet.getNumBitsPerValue(actual.getCardinality() - 1));
+ } else {
+ assertFalse(actual.hasDictionary());
+ assertEquals(actual.getBitsPerElement(), ColumnMetadata.UNAVAILABLE);
+ }
+ } else {
+ assertEquals(actual.hasDictionary(), expected.hasDictionary());
+ assertEquals(actual.getBitsPerElement(), expected.getBitsPerElement());
+ }
if (isRegeneratedMVColumnWithDuplicates) {
// For MV columns with duplicates within a row, the duplicates are removed when regenerating the forward index.
// Thus the metadata might not match depending on how many duplicates were found. Relax these metadata checks
- assertTrue(MV_FORWARD_INDEX_DISABLED_DUPLICATES_COLUMNS.contains(column));
+ assertTrue(MV_FORWARD_INDEX_DISABLED_DUPLICATES_COLUMNS.contains(actual.getColumnName()));
+ DataType dataType = expected.getDataType();
if (dataType == DataType.STRING || dataType == DataType.BYTES) {
// Every entry is duplicated within the row so total number of entries matches number of docs and max number of
// MVs per row is 1
- assertEquals(columnMetadata.getMaxNumberOfMultiValues(), 1);
- assertEquals(columnMetadata.getTotalNumberOfEntries(), totalDocs);
+ assertEquals(actual.getTotalNumberOfEntries(), expected.getTotalDocs());
+ assertEquals(actual.getMaxNumberOfMultiValues(), 1);
} else {
// Cannot check for exact numbers as it will vary depending on number of entries generated per row
- assertTrue(columnMetadata.getMaxNumberOfMultiValues() <= maxNumberOfMVEntries);
- assertTrue(columnMetadata.getTotalNumberOfEntries() <= totalNumberOfEntries);
+ assertTrue(actual.getTotalNumberOfEntries() <= expected.getTotalNumberOfEntries());
+ assertTrue(actual.getMaxNumberOfMultiValues() <= expected.getMaxNumberOfMultiValues());
}
} else {
- assertEquals(columnMetadata.getMaxNumberOfMultiValues(), maxNumberOfMVEntries);
- assertEquals(columnMetadata.getTotalNumberOfEntries(), totalNumberOfEntries);
+ assertEquals(actual.getTotalNumberOfEntries(), expected.getTotalNumberOfEntries());
+ assertEquals(actual.getMaxNumberOfMultiValues(), expected.getMaxNumberOfMultiValues());
}
- assertEquals(columnMetadata.isAutoGenerated(), isAutoGenerated);
- assertEquals(columnMetadata.getMinValue(), minValue);
- assertEquals(columnMetadata.getMaxValue(), maxValue);
}
private FieldIndexConfigs createFieldIndexConfigsFromMetadata(ColumnMetadata columnMetadata) {
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 a695d684736..5477ef96f16 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
@@ -32,11 +32,13 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import javax.annotation.Nullable;
import org.apache.commons.configuration2.PropertiesConfiguration;
import org.apache.commons.configuration2.ex.ConfigurationException;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.pinot.segment.local.PinotBuffersAfterClassCheckRule;
+import org.apache.pinot.segment.local.io.util.PinotDataBitSet;
import org.apache.pinot.segment.local.segment.creator.SegmentTestUtils;
import org.apache.pinot.segment.local.segment.creator.impl.SegmentIndexCreationDriverImpl;
import org.apache.pinot.segment.local.segment.index.converter.SegmentV1V2ToV3FormatConverter;
@@ -73,7 +75,6 @@ import org.apache.pinot.spi.config.table.TableConfig;
import org.apache.pinot.spi.config.table.TableType;
import org.apache.pinot.spi.config.table.ingestion.IngestionConfig;
import org.apache.pinot.spi.config.table.ingestion.TransformConfig;
-import org.apache.pinot.spi.data.DimensionFieldSpec;
import org.apache.pinot.spi.data.FieldSpec;
import org.apache.pinot.spi.data.FieldSpec.DataType;
import org.apache.pinot.spi.data.Schema;
@@ -349,9 +350,8 @@ public class SegmentPreProcessorTest implements PinotBuffersAfterClassCheckRule
_fieldConfigMap.put(NEWLY_ADDED_STRING_MV_COL_RAW,
new FieldConfig(NEWLY_ADDED_STRING_MV_COL_RAW, FieldConfig.EncodingType.RAW,
List.of(FieldConfig.IndexType.TEXT), null, null));
- checkTextIndexCreation(NEWLY_ADDED_STRING_COL_RAW, 1, 1, _newColumnsSchemaWithText, true, true, true, 4);
- checkTextIndexCreation(NEWLY_ADDED_STRING_MV_COL_RAW, 1, 1, _newColumnsSchemaWithText, true, true, false, 4, false,
- 1);
+ checkTextIndexCreation(_newColumnsSchemaWithText, NEWLY_ADDED_STRING_COL_RAW, 1, true, true, 4, true);
+ checkTextIndexCreation(_newColumnsSchemaWithText, NEWLY_ADDED_STRING_MV_COL_RAW, false, 1, true, false, 4, 1, true);
}
@Test(dataProvider = "bothV1AndV3", expectedExceptions = UnsupportedOperationException.class,
@@ -372,7 +372,7 @@ public class SegmentPreProcessorTest implements PinotBuffersAfterClassCheckRule
_fieldConfigMap.put(NEWLY_ADDED_FST_COL_DICT,
new FieldConfig(NEWLY_ADDED_FST_COL_DICT, FieldConfig.EncodingType.DICTIONARY,
List.of(FieldConfig.IndexType.FST), null, null));
- checkFSTIndexCreation(NEWLY_ADDED_FST_COL_DICT, 1, 1, _newColumnsSchemaWithFST, true, true, 4);
+ checkFSTIndexCreation(_newColumnsSchemaWithFST, NEWLY_ADDED_FST_COL_DICT, 1, true, 4, true);
}
@Test(dataProvider = "bothV1AndV3")
@@ -382,7 +382,7 @@ public class SegmentPreProcessorTest implements PinotBuffersAfterClassCheckRule
_fieldConfigMap.put(EXISTING_STRING_COL_DICT,
new FieldConfig(EXISTING_STRING_COL_DICT, FieldConfig.EncodingType.DICTIONARY,
List.of(FieldConfig.IndexType.FST), null, null));
- checkFSTIndexCreation(EXISTING_STRING_COL_DICT, 9, 4, _newColumnsSchemaWithFST, false, false, 26);
+ checkFSTIndexCreation(_newColumnsSchemaWithFST, EXISTING_STRING_COL_DICT, 9, false, 26, false);
}
@Test
@@ -392,25 +392,24 @@ public class SegmentPreProcessorTest implements PinotBuffersAfterClassCheckRule
int approxCardinalityStr = 5; // derived via NoDictColumnStatisticsCollector
// TEST 1. Check running forwardIndexHandler on a V1 segment. No-op for all existing raw columns.
buildV1Segment();
- checkForwardIndexCreation(EXISTING_STRING_COL_RAW, approxCardinalityStr, 3, _schema, false,
- false, false, 0, ChunkCompressionType.LZ4,
- true, 0, DataType.STRING, 100000);
+ checkForwardIndexCreation(_schema, EXISTING_STRING_COL_RAW, DataType.STRING, true, approxCardinalityStr, false,
+ false, 4, 100000, 0, false, ChunkCompressionType.LZ4);
// since dictionary is disabled, the cardinality will be approximate cardinality.
- validateIndex(StandardIndexes.forward(), EXISTING_INT_COL_RAW, approxCardinality, 16, false, false, false, 0,
- true, 0, ChunkCompressionType.LZ4, false, DataType.INT, 100000);
+ validateIndex(StandardIndexes.forward(), EXISTING_INT_COL_RAW, DataType.INT, true, approxCardinality, false, false,
+ 4, 100000, 0, false, ChunkCompressionType.LZ4, false);
// Convert the segment to V3.
convertV1SegmentToV3();
// TEST 2: Enable dictionary on EXISTING_STRING_COL_RAW
_noDictionaryColumns.remove(EXISTING_STRING_COL_RAW);
- checkForwardIndexCreation(EXISTING_STRING_COL_RAW, 5, 3, _schema, false, true, false, 4, null, true, 0,
- DataType.STRING, 100000);
+ checkForwardIndexCreation(_schema, EXISTING_STRING_COL_RAW, DataType.STRING, true, 5, true, false, 4, 100000, 0,
+ false, null);
// TEST 3: Enable dictionary on EXISTING_INT_COL_RAW
_noDictionaryColumns.remove(EXISTING_INT_COL_RAW);
- checkForwardIndexCreation(EXISTING_INT_COL_RAW, 42242, 16, _schema, false, true, false, 0, null, true, 0,
- DataType.INT, 100000);
+ checkForwardIndexCreation(_schema, EXISTING_INT_COL_RAW, DataType.INT, true, 42242, true, false, 4, 100000, 0,
+ false, null);
}
@Test
@@ -420,16 +419,16 @@ public class SegmentPreProcessorTest implements PinotBuffersAfterClassCheckRule
// TEST 1. Check running forwardIndexHandler on a V1 segment. No-op for all existing raw columns.
buildV1Segment();
// since dictionary is disabled, the cardinality will be approximate cardinality.
- checkForwardIndexCreation(EXISTING_INT_COL_RAW_MV, approxCardinality, 15, _schema, false, false, false, 0,
- ChunkCompressionType.LZ4, false, 13, DataType.INT, 106688);
+ checkForwardIndexCreation(_schema, EXISTING_INT_COL_RAW_MV, DataType.INT, false, approxCardinality, false, false, 4,
+ 106688, 13, false, ChunkCompressionType.LZ4);
// Convert the segment to V3.
convertV1SegmentToV3();
// TEST 2: Enable dictionary on EXISTING_STRING_COL_RAW
_noDictionaryColumns.remove(EXISTING_INT_COL_RAW_MV);
- checkForwardIndexCreation(EXISTING_INT_COL_RAW_MV, 18499, 15, _schema, false, true, false, 0, null, false, 13,
- DataType.INT, 106688);
+ checkForwardIndexCreation(_schema, EXISTING_INT_COL_RAW_MV, DataType.INT, false, 18499, true, false, 4, 106688, 13,
+ false, null);
}
@Test
@@ -445,12 +444,12 @@ public class SegmentPreProcessorTest implements PinotBuffersAfterClassCheckRule
_fieldConfigMap.put(EXISTING_STRING_COL_RAW,
new FieldConfig(EXISTING_STRING_COL_RAW, FieldConfig.EncodingType.DICTIONARY,
List.of(FieldConfig.IndexType.INVERTED, FieldConfig.IndexType.TEXT), null, null));
- checkForwardIndexCreation(EXISTING_STRING_COL_RAW, 5, 3, _schema, false, true, false, 4, null, true, 0,
- DataType.STRING, 100000);
- validateIndex(StandardIndexes.inverted(), EXISTING_STRING_COL_RAW, 5, 3, false, true, false, 4, true, 0, null,
- false, DataType.STRING, 100000);
- validateIndex(StandardIndexes.text(), EXISTING_STRING_COL_RAW, 5, 3, false, true, false, 4, true, 0, null, false,
- DataType.STRING, 100000);
+ checkForwardIndexCreation(_schema, EXISTING_STRING_COL_RAW, DataType.STRING, true, 5, true, false, 4, 100000, 0,
+ false, null);
+ validateIndex(StandardIndexes.inverted(), EXISTING_STRING_COL_RAW, DataType.STRING, true, 5, true, false, 4, 100000,
+ 0, false, null, false);
+ validateIndex(StandardIndexes.text(), EXISTING_STRING_COL_RAW, DataType.STRING, true, 5, true, false, 4, 100000, 0,
+ false, null, false);
// TEST 2: EXISTING_STRING_COL_RAW. Enable dictionary on a raw column that already has text index.
resetIndexConfigs();
@@ -459,36 +458,35 @@ public class SegmentPreProcessorTest implements PinotBuffersAfterClassCheckRule
new FieldConfig(EXISTING_STRING_COL_RAW, FieldConfig.EncodingType.RAW, List.of(FieldConfig.IndexType.TEXT),
null, null));
buildV3Segment();
- validateIndex(StandardIndexes.text(), EXISTING_STRING_COL_RAW, approxCardinalityStr, 3, false, false,
- false, 0, true, 0, null, false,
- DataType.STRING, 100000);
+ validateIndex(StandardIndexes.text(), EXISTING_STRING_COL_RAW, DataType.STRING, true, approxCardinalityStr, false,
+ false, 4, 100000, 0, false, null, false);
// At this point, the segment has text index. Now, the reload path should create a dictionary.
_noDictionaryColumns.remove(EXISTING_STRING_COL_RAW);
_fieldConfigMap.put(EXISTING_STRING_COL_RAW,
new FieldConfig(EXISTING_STRING_COL_RAW, FieldConfig.EncodingType.DICTIONARY,
List.of(FieldConfig.IndexType.TEXT), null, null));
- checkForwardIndexCreation(EXISTING_STRING_COL_RAW, 5, 3, _schema, false, true, false, 4, null, true, 0,
- DataType.STRING, 100000);
- validateIndex(StandardIndexes.text(), EXISTING_STRING_COL_RAW, 5, 3, false, true, false, 4, true, 0, null, false,
- DataType.STRING, 100000);
+ checkForwardIndexCreation(_schema, EXISTING_STRING_COL_RAW, DataType.STRING, true, 5, true, false, 4, 100000, 0,
+ false, null);
+ validateIndex(StandardIndexes.text(), EXISTING_STRING_COL_RAW, DataType.STRING, true, 5, true, false, 4, 100000, 0,
+ false, null, false);
// TEST 3: EXISTING_INT_COL_RAW. Enable dictionary on a column that already has range index.
resetIndexConfigs();
_rangeIndexColumns.add(EXISTING_INT_COL_RAW);
buildV3Segment();
// Since dictionary is disabled, the cardinality will be approximate cardinality.
- validateIndex(StandardIndexes.range(), EXISTING_INT_COL_RAW, approxCardinality, 16, false, false, false, 0, true, 0,
- ChunkCompressionType.LZ4, false, DataType.INT, 100000);
+ validateIndex(StandardIndexes.range(), EXISTING_INT_COL_RAW, DataType.INT, true, approxCardinality, false, false, 4,
+ 100000, 0, false, ChunkCompressionType.LZ4, false);
long oldRangeIndexSize = new SegmentMetadataImpl(INDEX_DIR).getColumnMetadataFor(EXISTING_INT_COL_RAW)
.getIndexSizeFor(StandardIndexes.range());
// At this point, the segment has range index. Now the reload path should create a dictionary and rewrite the
// range index.
_noDictionaryColumns.remove(EXISTING_INT_COL_RAW);
- checkForwardIndexCreation(EXISTING_INT_COL_RAW, 42242, 16, _schema, false, true, false, 0, null, true, 0,
- DataType.INT, 100000);
- validateIndex(StandardIndexes.range(), EXISTING_INT_COL_RAW, 42242, 16, false, true, false, 0, true, 0, null, false,
- DataType.INT, 100000);
+ checkForwardIndexCreation(_schema, EXISTING_INT_COL_RAW, DataType.INT, true, 42242, true, false, 4, 100000, 0,
+ false, null);
+ validateIndex(StandardIndexes.range(), EXISTING_INT_COL_RAW, DataType.INT, true, 42242, true, false, 4, 100000, 0,
+ false, null, false);
long newRangeIndexSize = new SegmentMetadataImpl(INDEX_DIR).getColumnMetadataFor(EXISTING_INT_COL_RAW)
.getIndexSizeFor(StandardIndexes.range());
assertNotEquals(oldRangeIndexSize, newRangeIndexSize);
@@ -504,29 +502,29 @@ public class SegmentPreProcessorTest implements PinotBuffersAfterClassCheckRule
_noDictionaryColumns.remove(EXISTING_INT_COL_RAW_MV);
_invertedIndexColumns.add(EXISTING_INT_COL_RAW_MV);
_rangeIndexColumns.add(EXISTING_INT_COL_RAW_MV);
- checkForwardIndexCreation(EXISTING_INT_COL_RAW_MV, 18499, 15, _schema, false, true, false, 0, null, false, 13,
- DataType.INT, 106688);
- validateIndex(StandardIndexes.inverted(), EXISTING_INT_COL_RAW_MV, 18499, 15, false, true, false, 0, false, 13,
- null, false, DataType.INT, 106688);
- validateIndex(StandardIndexes.range(), EXISTING_INT_COL_RAW_MV, 18499, 15, false, true, false, 0, false, 13, null,
- false, DataType.INT, 106688);
+ checkForwardIndexCreation(_schema, EXISTING_INT_COL_RAW_MV, DataType.INT, false, 18499, true, false, 4, 106688, 13,
+ false, null);
+ validateIndex(StandardIndexes.inverted(), EXISTING_INT_COL_RAW_MV, DataType.INT, false, 18499, true, false, 4,
+ 106688, 13, false, null, false);
+ validateIndex(StandardIndexes.range(), EXISTING_INT_COL_RAW_MV, DataType.INT, false, 18499, true, false, 4, 106688,
+ 13, false, null, false);
// TEST 2: EXISTING_INT_COL_RAW_MV. Enable dictionary for an MV column that already has range index.
resetIndexConfigs();
_rangeIndexColumns.add(EXISTING_INT_COL_RAW_MV);
buildV3Segment();
// Since dictionary is disabled, the cardinality will be approximate cardinality.
- validateIndex(StandardIndexes.forward(), EXISTING_INT_COL_RAW_MV, approxCardinality, 15, false, false, false, 0,
- false, 13, ChunkCompressionType.LZ4, false, DataType.INT, 106688);
- validateIndex(StandardIndexes.range(), EXISTING_INT_COL_RAW_MV, approxCardinality, 15, false, false, false, 0,
- false, 13, ChunkCompressionType.LZ4, false, DataType.INT, 106688);
+ validateIndex(StandardIndexes.forward(), EXISTING_INT_COL_RAW_MV, DataType.INT, false, approxCardinality, false,
+ false, 4, 106688, 13, false, ChunkCompressionType.LZ4, false);
+ validateIndex(StandardIndexes.range(), EXISTING_INT_COL_RAW_MV, DataType.INT, false, approxCardinality, false,
+ false, 4, 106688, 13, false, ChunkCompressionType.LZ4, false);
// Enable dictionary.
_noDictionaryColumns.remove(EXISTING_INT_COL_RAW_MV);
- checkForwardIndexCreation(EXISTING_INT_COL_RAW_MV, 18499, 15, _schema, false, true, false, 0, null, false, 13,
- DataType.INT, 106688);
- validateIndex(StandardIndexes.range(), EXISTING_INT_COL_RAW_MV, 18499, 15, false, true, false, 0, false, 13, null,
- false, DataType.INT, 106688);
+ checkForwardIndexCreation(_schema, EXISTING_INT_COL_RAW_MV, DataType.INT, false, 18499, true, false, 4, 106688, 13,
+ false, null);
+ validateIndex(StandardIndexes.range(), EXISTING_INT_COL_RAW_MV, DataType.INT, false, 18499, true, false, 4, 106688,
+ 13, false, null, false);
}
@Test
@@ -534,23 +532,23 @@ public class SegmentPreProcessorTest implements PinotBuffersAfterClassCheckRule
throws Exception {
// TEST 1. Check running forwardIndexHandler on a V1 segment. No-op for all existing dict columns.
buildV1Segment();
- checkForwardIndexCreation(EXISTING_STRING_COL_DICT, 9, 4, _schema, false, true, false, 26, null, true, 0,
- DataType.STRING, 100000);
- validateIndex(StandardIndexes.forward(), COLUMN10_NAME, 3960, 12, false, true, false, 0, true, 0, null, false,
- DataType.INT, 100000);
+ checkForwardIndexCreation(_schema, EXISTING_STRING_COL_DICT, DataType.STRING, true, 9, true, false, 26, 100000, 0,
+ false, null);
+ validateIndex(StandardIndexes.forward(), COLUMN10_NAME, DataType.INT, true, 3960, true, false, 4, 100000, 0, false,
+ null, false);
// Convert the segment to V3.
convertV1SegmentToV3();
// TEST 2: Disable dictionary for EXISTING_STRING_COL_DICT.
_noDictionaryColumns.add(EXISTING_STRING_COL_DICT);
- checkForwardIndexCreation(EXISTING_STRING_COL_DICT, 9, 4, _schema, false, false, false, 0, ChunkCompressionType.LZ4,
- true, 0, DataType.STRING, 100000);
+ checkForwardIndexCreation(_schema, EXISTING_STRING_COL_DICT, DataType.STRING, true, 9, false, false, 26, 100000, 0,
+ false, ChunkCompressionType.LZ4);
// TEST 3: Disable dictionary for COLUMN10_NAME
_noDictionaryColumns.add(COLUMN10_NAME);
- checkForwardIndexCreation(COLUMN10_NAME, 3960, 12, _schema, false, false, false, 0, ChunkCompressionType.LZ4, true,
- 0, DataType.INT, 100000);
+ checkForwardIndexCreation(_schema, COLUMN10_NAME, DataType.INT, true, 3960, false, false, 4, 100000, 0, false,
+ ChunkCompressionType.LZ4);
}
@Test
@@ -561,43 +559,40 @@ public class SegmentPreProcessorTest implements PinotBuffersAfterClassCheckRule
_invertedIndexColumns.add(COLUMN1_NAME);
buildV3Segment();
_noDictionaryColumns.add(COLUMN1_NAME);
- checkForwardIndexCreation(COLUMN1_NAME, 51594, 16, _schema, false, true, false, 0, null, true, 0, DataType.INT,
- 100000);
+ checkForwardIndexCreation(_schema, COLUMN1_NAME, DataType.INT, true, 51594, true, false, 4, 100000, 0, false, null);
// TEST 2: Disable dictionary. Also remove inverted index on column1.
_invertedIndexColumns.remove(COLUMN1_NAME);
- checkForwardIndexCreation(COLUMN1_NAME, 51594, 16, _schema, false, false, false, 0, null, true, 0, DataType.INT,
- 100000);
+ checkForwardIndexCreation(_schema, COLUMN1_NAME, DataType.INT, true, 51594, false, false, 4, 100000, 0, false,
+ null);
// TEST 3: Disable dictionary for a column (Column10) that has range index.
_rangeIndexColumns.add(COLUMN10_NAME);
buildV3Segment();
- validateIndex(StandardIndexes.forward(), COLUMN10_NAME, 3960, 12, false, true, false, 0, true, 0, null, false,
- DataType.INT, 100000);
- validateIndex(StandardIndexes.range(), COLUMN10_NAME, 3960, 12, false, true, false, 0, true, 0, null, false,
- DataType.INT, 100000);
+ validateIndex(StandardIndexes.forward(), COLUMN10_NAME, DataType.INT, true, 3960, true, false, 4, 100000, 0, false,
+ null, false);
+ validateIndex(StandardIndexes.range(), COLUMN10_NAME, DataType.INT, true, 3960, true, false, 4, 100000, 0, false,
+ null, false);
long oldRangeIndexSize =
new SegmentMetadataImpl(INDEX_DIR).getColumnMetadataFor(COLUMN10_NAME).getIndexSizeFor(StandardIndexes.range());
_noDictionaryColumns.add(COLUMN10_NAME);
- checkForwardIndexCreation(COLUMN10_NAME, 3960, 12, _schema, false, false, false, 0, ChunkCompressionType.LZ4, true,
- 0, DataType.INT, 100000);
- validateIndex(StandardIndexes.range(), COLUMN10_NAME, 3960, 12, false, false, false, 0, true, 0,
- ChunkCompressionType.LZ4, false, DataType.INT, 100000);
+ checkForwardIndexCreation(_schema, COLUMN10_NAME, DataType.INT, true, 3960, false, false, 4, 100000, 0, false,
+ ChunkCompressionType.LZ4);
+ validateIndex(StandardIndexes.range(), COLUMN10_NAME, DataType.INT, true, 3960, false, false, 4, 100000, 0, false,
+ ChunkCompressionType.LZ4, false);
long newRangeIndexSize =
new SegmentMetadataImpl(INDEX_DIR).getColumnMetadataFor(COLUMN10_NAME).getIndexSizeFor(StandardIndexes.range());
assertNotEquals(oldRangeIndexSize, newRangeIndexSize);
// TEST4: Disable dictionary but add text index.
- validateIndex(StandardIndexes.forward(), EXISTING_STRING_COL_DICT, 9, 4, false, true, false, 26, true, 0, null,
- false, DataType.STRING, 100000);
+ validateIndex(StandardIndexes.forward(), EXISTING_STRING_COL_DICT, DataType.STRING, true, 9, true, false, 26,
+ 100000, 0, false, null, false);
_noDictionaryColumns.add(EXISTING_STRING_COL_DICT);
_fieldConfigMap.put(EXISTING_STRING_COL_DICT,
new FieldConfig(EXISTING_STRING_COL_DICT, FieldConfig.EncodingType.RAW, List.of(FieldConfig.IndexType.TEXT),
null, null));
- checkForwardIndexCreation(EXISTING_STRING_COL_DICT, 9, 4, _schema, false, false, false, 0, ChunkCompressionType.LZ4,
- true, 0, DataType.STRING, 100000);
- validateIndex(StandardIndexes.forward(), EXISTING_STRING_COL_DICT, 9, 4, false, false, false, 0, true, 0, null,
- false, DataType.STRING, 100000);
+ checkForwardIndexCreation(_schema, EXISTING_STRING_COL_DICT, DataType.STRING, true, 9, false, false, 26, 100000, 0,
+ false, ChunkCompressionType.LZ4);
}
@Test
@@ -607,33 +602,32 @@ public class SegmentPreProcessorTest implements PinotBuffersAfterClassCheckRule
buildV3Segment();
_noDictionaryColumns.remove(EXISTING_INT_COL_RAW_MV);
_rangeIndexColumns.add(EXISTING_INT_COL_RAW_MV);
- checkForwardIndexCreation(EXISTING_INT_COL_RAW_MV, 18499, 15, _schema, false, true, false, 0, null, false, 13,
- DataType.INT, 106688);
- validateIndex(StandardIndexes.range(), EXISTING_INT_COL_RAW_MV, 18499, 15, false, true, false, 0, false, 13, null,
- false, DataType.INT, 106688);
+ checkForwardIndexCreation(_schema, EXISTING_INT_COL_RAW_MV, DataType.INT, false, 18499, true, false, 4, 106688, 13,
+ false, null);
+ validateIndex(StandardIndexes.range(), EXISTING_INT_COL_RAW_MV, DataType.INT, false, 18499, true, false, 4, 106688,
+ 13, false, null, false);
// TEST 1: Disable dictionary on a column where range index is already enabled.
_noDictionaryColumns.add(EXISTING_INT_COL_RAW_MV);
- checkForwardIndexCreation(EXISTING_INT_COL_RAW_MV, 18499, 15, _schema, false, false, false, 0, null, false, 13,
- DataType.INT, 106688);
- validateIndex(StandardIndexes.range(), EXISTING_INT_COL_RAW_MV, 18499, 15, false, false, false, 0, false, 13, null,
- false, DataType.INT, 106688);
+ checkForwardIndexCreation(_schema, EXISTING_INT_COL_RAW_MV, DataType.INT, false, 18499, false, false, 4, 106688, 13,
+ false, null);
+ validateIndex(StandardIndexes.range(), EXISTING_INT_COL_RAW_MV, DataType.INT, false, 18499, false, false, 4, 106688,
+ 13, false, null, false);
// TEST 2. Disable dictionary on a column where inverted index is enabled. Should be a no-op.
- validateIndex(StandardIndexes.forward(), COLUMN7_NAME, 359, 9, false, true, false, 0, false, 24, null, false,
- DataType.INT, 134090);
- validateIndex(StandardIndexes.inverted(), COLUMN7_NAME, 359, 9, false, true, false, 0, false, 24, null, false,
- DataType.INT, 134090);
+ validateIndex(StandardIndexes.forward(), COLUMN7_NAME, DataType.INT, false, 359, true, false, 4, 134090, 24, false,
+ null, false);
+ validateIndex(StandardIndexes.inverted(), COLUMN7_NAME, DataType.INT, false, 359, true, false, 4, 134090, 24, false,
+ null, false);
_noDictionaryColumns.add(COLUMN7_NAME);
- checkForwardIndexCreation(COLUMN7_NAME, 359, 9, _schema, false, true, false, 0, null, false, 24, DataType.INT,
- 134090);
- validateIndex(StandardIndexes.inverted(), COLUMN7_NAME, 359, 9, false, true, false, 0, false, 24, null, false,
- DataType.INT, 134090);
+ checkForwardIndexCreation(_schema, COLUMN7_NAME, DataType.INT, false, 359, true, false, 4, 134090, 24, false, null);
+ validateIndex(StandardIndexes.inverted(), COLUMN7_NAME, DataType.INT, false, 359, true, false, 4, 134090, 24, false,
+ null, false);
// TEST 3: Disable dictionary and disable inverted index on column7.
_invertedIndexColumns.remove(COLUMN7_NAME);
- checkForwardIndexCreation(COLUMN7_NAME, 359, 9, _schema, false, false, false, 0, null, false, 24, DataType.INT,
- 134090);
+ checkForwardIndexCreation(_schema, COLUMN7_NAME, DataType.INT, false, 359, false, false, 4, 134090, 24, false,
+ null);
}
@Test
@@ -647,27 +641,23 @@ public class SegmentPreProcessorTest implements PinotBuffersAfterClassCheckRule
_fieldConfigMap.put(EXISTING_STRING_COL_RAW,
new FieldConfig(EXISTING_STRING_COL_RAW, FieldConfig.EncodingType.RAW, List.of(), CompressionCodec.ZSTANDARD,
null));
- checkForwardIndexCreation(EXISTING_STRING_COL_RAW, approxCardinalityStr, 3, _schema, false,
- false, false, 0, ChunkCompressionType.LZ4,
- true, 0, DataType.STRING, 100000);
+ checkForwardIndexCreation(_schema, EXISTING_STRING_COL_RAW, DataType.STRING, true, approxCardinalityStr, false,
+ false, 4, 100000, 0, false, ChunkCompressionType.LZ4);
// Convert the segment to V3.
convertV1SegmentToV3();
// Test2: Now forward index will be rewritten with ZSTANDARD compressionType.
- checkForwardIndexCreation(EXISTING_STRING_COL_RAW, approxCardinalityStr, 3, _schema, false,
- false, false, 0,
- ChunkCompressionType.ZSTANDARD, true, 0, DataType.STRING, 100000);
+ checkForwardIndexCreation(_schema, EXISTING_STRING_COL_RAW, DataType.STRING, true, approxCardinalityStr, false,
+ false, 4, 100000, 0, false, ChunkCompressionType.ZSTANDARD);
// Test3: Change compression on existing raw index column. Also add text index on same column. Check correctness.
_fieldConfigMap.put(EXISTING_STRING_COL_RAW,
new FieldConfig(EXISTING_STRING_COL_RAW, FieldConfig.EncodingType.RAW, List.of(FieldConfig.IndexType.TEXT),
CompressionCodec.SNAPPY, null));
- checkTextIndexCreation(EXISTING_STRING_COL_RAW, approxCardinalityStr, 3, _schema, false,
- false, false, 0);
- validateIndex(StandardIndexes.forward(), EXISTING_STRING_COL_RAW, approxCardinalityStr, 3, false,
- false, false, 0, true, 0,
- ChunkCompressionType.SNAPPY, false, DataType.STRING, 100000);
+ checkTextIndexCreation(_schema, EXISTING_STRING_COL_RAW, approxCardinalityStr, false, false, 4, false);
+ validateIndex(StandardIndexes.forward(), EXISTING_STRING_COL_RAW, DataType.STRING, true, approxCardinalityStr,
+ false, false, 4, 100000, 0, false, ChunkCompressionType.SNAPPY, false);
// Test4: Change compression on RAW index column. Change another index on another column. Check correctness.
resetIndexConfigs();
@@ -679,19 +669,18 @@ public class SegmentPreProcessorTest implements PinotBuffersAfterClassCheckRule
new FieldConfig(EXISTING_STRING_COL_DICT, FieldConfig.EncodingType.DICTIONARY,
List.of(FieldConfig.IndexType.FST), null, null));
// Check FST index
- checkFSTIndexCreation(EXISTING_STRING_COL_DICT, 9, 4, _newColumnsSchemaWithFST, false, false, 26);
+ checkFSTIndexCreation(_newColumnsSchemaWithFST, EXISTING_STRING_COL_DICT, 9, false, 26, false);
// Check forward index.
- validateIndex(StandardIndexes.forward(), EXISTING_STRING_COL_RAW, approxCardinalityStr, 3, false,
- false, false, 0, true, 0,
- ChunkCompressionType.ZSTANDARD, false, DataType.STRING, 100000);
+ validateIndex(StandardIndexes.forward(), EXISTING_STRING_COL_RAW, DataType.STRING, true, approxCardinalityStr,
+ false, false, 4, 100000, 0, false, ChunkCompressionType.ZSTANDARD, false);
// Test5: Change compressionType for an MV column
_fieldConfigMap.put(EXISTING_INT_COL_RAW_MV,
new FieldConfig(EXISTING_INT_COL_RAW_MV, FieldConfig.EncodingType.RAW, List.of(), CompressionCodec.ZSTANDARD,
null));
// Since dictionary is disabled, the cardinality will be approximate cardinality.
- checkForwardIndexCreation(EXISTING_INT_COL_RAW_MV, approximateCardinality, 15, _schema, false, false, false, 0,
- ChunkCompressionType.ZSTANDARD, false, 13, DataType.INT, 106688);
+ checkForwardIndexCreation(_schema, EXISTING_INT_COL_RAW_MV, DataType.INT, false, approximateCardinality, false,
+ false, 4, 106688, 13, false, ChunkCompressionType.ZSTANDARD);
}
/**
@@ -712,9 +701,9 @@ public class SegmentPreProcessorTest implements PinotBuffersAfterClassCheckRule
_fieldConfigMap.put(NEWLY_ADDED_STRING_MV_COL_DICT,
new FieldConfig(NEWLY_ADDED_STRING_MV_COL_DICT, FieldConfig.EncodingType.DICTIONARY,
List.of(FieldConfig.IndexType.TEXT), null, null));
- checkTextIndexCreation(NEWLY_ADDED_STRING_COL_DICT, 1, 1, _newColumnsSchemaWithText, true, true, true, 4);
- validateIndex(StandardIndexes.text(), NEWLY_ADDED_STRING_MV_COL_DICT, 1, 1, true, true, false, 4, false, 1, null,
- false, DataType.STRING, 100000);
+ checkTextIndexCreation(_newColumnsSchemaWithText, NEWLY_ADDED_STRING_COL_DICT, 1, true, true, 4, true);
+ validateIndex(StandardIndexes.text(), NEWLY_ADDED_STRING_MV_COL_DICT, DataType.STRING, false, 1, true, false, 4,
+ 100000, 1, true, null, false);
}
/**
@@ -730,8 +719,7 @@ public class SegmentPreProcessorTest implements PinotBuffersAfterClassCheckRule
_fieldConfigMap.put(EXISTING_STRING_COL_RAW,
new FieldConfig(EXISTING_STRING_COL_RAW, FieldConfig.EncodingType.RAW, List.of(FieldConfig.IndexType.TEXT),
null, null));
- checkTextIndexCreation(EXISTING_STRING_COL_RAW, approxCardinalityStr, 3, _schema, false,
- false, false, 0);
+ checkTextIndexCreation(_schema, EXISTING_STRING_COL_RAW, approxCardinalityStr, false, false, 4, false);
}
/**
@@ -746,69 +734,69 @@ public class SegmentPreProcessorTest implements PinotBuffersAfterClassCheckRule
_fieldConfigMap.put(EXISTING_STRING_COL_DICT,
new FieldConfig(EXISTING_STRING_COL_DICT, FieldConfig.EncodingType.DICTIONARY,
List.of(FieldConfig.IndexType.TEXT), null, null));
- checkTextIndexCreation(EXISTING_STRING_COL_DICT, 9, 4, _schema, false, true, false, 26);
+ checkTextIndexCreation(_schema, EXISTING_STRING_COL_DICT, 9, true, false, 26, false);
}
- private void checkFSTIndexCreation(String column, int cardinality, int bits, Schema schema, boolean isAutoGenerated,
- boolean isSorted, int dictionaryElementSize)
+ private void checkFSTIndexCreation(Schema schema, String column, int cardinality, boolean isSorted,
+ int lengthOfLongestElement, boolean isAutoGenerated)
throws Exception {
- createAndValidateIndex(StandardIndexes.fst(), column, cardinality, bits, schema, isAutoGenerated, true, isSorted,
- dictionaryElementSize, true, 0, null, false, DataType.STRING, 100000);
+ createAndValidateIndex(schema, StandardIndexes.fst(), column, DataType.STRING, true, cardinality, true, isSorted,
+ lengthOfLongestElement, 100000, 0, isAutoGenerated, null, false);
}
- private void checkTextIndexCreation(String column, int cardinality, int bits, Schema schema, boolean isAutoGenerated,
- boolean hasDictionary, boolean isSorted, int dictionaryElementSize)
+ private void checkTextIndexCreation(Schema schema, String column, int cardinality, boolean hasDictionary,
+ boolean isSorted, int lengthOfLongestElement, boolean isAutoGenerated)
throws Exception {
- createAndValidateIndex(StandardIndexes.text(), column, cardinality, bits, schema, isAutoGenerated, hasDictionary,
- isSorted, dictionaryElementSize, true, 0, null, false, DataType.STRING, 100000);
+ checkTextIndexCreation(schema, column, true, cardinality, hasDictionary, isSorted, lengthOfLongestElement, 0,
+ isAutoGenerated);
}
- private void checkTextIndexCreation(String column, int cardinality, int bits, Schema schema, boolean isAutoGenerated,
- boolean hasDictionary, boolean isSorted, int dictionaryElementSize, boolean isSingleValue,
- int maxNumberOfMultiValues)
+ private void checkTextIndexCreation(Schema schema, String column, boolean isSingleValue, int cardinality,
+ boolean hasDictionary, boolean isSorted, int lengthOfLongestElement, int maxNumberOfMultiValues,
+ boolean isAutoGenerated)
throws Exception {
- createAndValidateIndex(StandardIndexes.text(), column, cardinality, bits, schema, isAutoGenerated, hasDictionary,
- isSorted, dictionaryElementSize, isSingleValue, maxNumberOfMultiValues, null, false, DataType.STRING, 100000);
+ createAndValidateIndex(schema, StandardIndexes.text(), column, DataType.STRING, isSingleValue, cardinality,
+ hasDictionary, isSorted, lengthOfLongestElement, 100000, maxNumberOfMultiValues, isAutoGenerated, null, false);
}
- private void checkForwardIndexCreation(String column, int cardinality, int bits, Schema schema,
- boolean isAutoGenerated, boolean hasDictionary, boolean isSorted, int dictionaryElementSize,
- ChunkCompressionType expectedCompressionType, boolean isSingleValue, int maxNumberOfMultiValues,
- DataType dataType, int totalNumberOfEntries)
+ private void checkForwardIndexCreation(Schema schema, String column, DataType dataType, boolean isSingleValue,
+ int cardinality, boolean hasDictionary, boolean isSorted, int lengthOfLongestElement, int totalNumberOfEntries,
+ int maxNumberOfMultiValues, boolean isAutoGenerated, @Nullable ChunkCompressionType expectedCompressionType)
throws Exception {
- createAndValidateIndex(StandardIndexes.forward(), column, cardinality, bits, schema, isAutoGenerated, hasDictionary,
- isSorted, dictionaryElementSize, isSingleValue, maxNumberOfMultiValues, expectedCompressionType, false,
- dataType, totalNumberOfEntries);
+ createAndValidateIndex(schema, StandardIndexes.forward(), column, dataType, isSingleValue, cardinality,
+ hasDictionary, isSorted, lengthOfLongestElement, totalNumberOfEntries, maxNumberOfMultiValues, isAutoGenerated,
+ expectedCompressionType, false);
}
- private void createAndValidateIndex(IndexType<?, ?, ?> indexType, String column, int cardinality, int bits,
- Schema schema, boolean isAutoGenerated, boolean hasDictionary, boolean isSorted, int dictionaryElementSize,
- boolean isSingleValued, int maxNumberOfMultiValues, ChunkCompressionType expectedCompressionType,
- boolean forwardIndexDisabled, DataType dataType, int totalNumberOfEntries)
+ private void createAndValidateIndex(Schema schema, IndexType<?, ?, ?> indexType, String column, DataType dataType,
+ boolean isSingleValue, int cardinality, boolean hasDictionary, boolean isSorted, int lengthOfLongestElement,
+ int totalNumberOfEntries, int maxNumberOfMultiValues, boolean isAutoGenerated,
+ @Nullable ChunkCompressionType expectedCompressionType, boolean forwardIndexDisabled)
throws Exception {
runPreProcessor(schema);
- validateIndex(indexType, column, cardinality, bits, isAutoGenerated, hasDictionary, isSorted, dictionaryElementSize,
- isSingleValued, maxNumberOfMultiValues, expectedCompressionType, forwardIndexDisabled, dataType,
- totalNumberOfEntries);
+ validateIndex(indexType, column, dataType, isSingleValue, cardinality, hasDictionary, isSorted,
+ lengthOfLongestElement, totalNumberOfEntries, maxNumberOfMultiValues, isAutoGenerated, expectedCompressionType,
+ forwardIndexDisabled);
}
- private void validateIndex(IndexType<?, ?, ?> indexType, String column, int cardinality, int bits,
- boolean isAutoGenerated, boolean hasDictionary, boolean isSorted, int dictionaryElementSize,
- boolean isSingleValued, int maxNumberOfMultiValues, ChunkCompressionType expectedCompressionType,
- boolean forwardIndexDisabled, DataType dataType, int totalNumberOfEntries)
+ private void validateIndex(IndexType<?, ?, ?> indexType, String column, DataType dataType, boolean isSingleValue,
+ int cardinality, boolean hasDictionary, boolean isSorted, int lengthOfLongestElement, int totalNumberOfEntries,
+ int maxNumberOfMultiValues, boolean isAutoGenerated, @Nullable ChunkCompressionType expectedCompressionType,
+ boolean forwardIndexDisabled)
throws Exception {
SegmentMetadataImpl segmentMetadata = new SegmentMetadataImpl(INDEX_DIR);
ColumnMetadata columnMetadata = segmentMetadata.getColumnMetadataFor(column);
- assertEquals(columnMetadata.hasDictionary(), hasDictionary);
- assertEquals(columnMetadata.getFieldSpec(),
- new DimensionFieldSpec(column, dataType, isSingleValued, columnMetadata.getFieldSpec().getMaxLength(), null));
- assertEquals(columnMetadata.getCardinality(), cardinality);
+ assertEquals(columnMetadata.getDataType(), dataType);
+ assertEquals(columnMetadata.isSingleValue(), isSingleValue);
assertEquals(columnMetadata.getTotalDocs(), 100000);
- assertEquals(columnMetadata.getBitsPerElement(), bits);
- assertEquals(columnMetadata.getColumnMaxLength(), dictionaryElementSize);
+ assertEquals(columnMetadata.getCardinality(), cardinality);
+ assertEquals(columnMetadata.hasDictionary(), hasDictionary);
assertEquals(columnMetadata.isSorted(), isSorted);
- assertEquals(columnMetadata.getMaxNumberOfMultiValues(), maxNumberOfMultiValues);
+ assertEquals(columnMetadata.getLengthOfLongestElement(), lengthOfLongestElement);
assertEquals(columnMetadata.getTotalNumberOfEntries(), totalNumberOfEntries);
+ assertEquals(columnMetadata.getMaxNumberOfMultiValues(), maxNumberOfMultiValues);
+ assertEquals(columnMetadata.getBitsPerElement(),
+ hasDictionary ? PinotDataBitSet.getNumBitsPerValue(cardinality - 1) : ColumnMetadata.UNAVAILABLE);
assertEquals(columnMetadata.isAutoGenerated(), isAutoGenerated);
try (SegmentDirectory segmentDirectory = new SegmentLocalFSDirectory(INDEX_DIR, ReadMode.mmap);
@@ -835,9 +823,8 @@ public class SegmentPreProcessorTest implements PinotBuffersAfterClassCheckRule
if (expectedCompressionType != null) {
assertFalse(hasDictionary);
IndexReaderFactory<ForwardIndexReader> readerFactory = StandardIndexes.forward().getReaderFactory();
- FieldIndexConfigs fieldIndexConfigs = new FieldIndexConfigs.Builder()
- .add(StandardIndexes.forward(), ForwardIndexConfig.getDefault())
- .build();
+ FieldIndexConfigs fieldIndexConfigs =
+ new FieldIndexConfigs.Builder().add(StandardIndexes.forward(), ForwardIndexConfig.getDefault()).build();
try (ForwardIndexReader fwdIndexReader = readerFactory.createIndexReader(reader, fieldIndexConfigs,
columnMetadata)) {
ChunkCompressionType compressionType = fwdIndexReader.getCompressionType();
@@ -848,7 +835,7 @@ public class SegmentPreProcessorTest implements PinotBuffersAfterClassCheckRule
assertFalse(inProgressFile.exists());
String fwdIndexFileExtension;
- if (isSingleValued) {
+ if (isSingleValue) {
fwdIndexFileExtension = V1Constants.Indexes.RAW_SV_FORWARD_INDEX_FILE_EXTENSION;
} else {
fwdIndexFileExtension = V1Constants.Indexes.RAW_MV_FORWARD_INDEX_FILE_EXTENSION;
@@ -871,7 +858,7 @@ public class SegmentPreProcessorTest implements PinotBuffersAfterClassCheckRule
}
}
- private void validateIndexDoesNotExist(String column, IndexType<?, ?, ?> indexType)
+ private void validateIndexDoesNotExist(IndexType<?, ?, ?> indexType, String column)
throws Exception {
try (SegmentDirectory segmentDirectory = new SegmentLocalFSDirectory(INDEX_DIR, ReadMode.mmap);
SegmentDirectory.Reader reader = segmentDirectory.createReader()) {
@@ -879,7 +866,7 @@ public class SegmentPreProcessorTest implements PinotBuffersAfterClassCheckRule
}
}
- private void validateIndexExists(String column, IndexType<?, ?, ?> indexType)
+ private void validateIndexExists(IndexType<?, ?, ?> indexType, String column)
throws Exception {
try (SegmentDirectory segmentDirectory = new SegmentLocalFSDirectory(INDEX_DIR, ReadMode.mmap);
SegmentDirectory.Reader reader = segmentDirectory.createReader()) {
@@ -1040,18 +1027,16 @@ public class SegmentPreProcessorTest implements PinotBuffersAfterClassCheckRule
assertNull(segmentMetadata.getColumnMetadataFor(NEW_INT_SV_DIMENSION_COLUMN_NAME));
ColumnMetadata hllMetricMetadata = segmentMetadata.getColumnMetadataFor(NEW_HLL_BYTE_METRIC_COLUMN_NAME);
- FieldSpec expectedHllMetricFieldSpec = _newColumnsSchema3.getFieldSpecFor(NEW_HLL_BYTE_METRIC_COLUMN_NAME);
- expectedHllMetricFieldSpec.setMaxLength(hllMetricMetadata.getFieldSpec().getMaxLength());
- assertEquals(hllMetricMetadata.getFieldSpec(), expectedHllMetricFieldSpec);
- ByteArray expectedDefaultValue = new ByteArray((byte[]) expectedHllMetricFieldSpec.getDefaultNullValue());
+ FieldSpec hllMetricFieldSpec = hllMetricMetadata.getFieldSpec();
+ assertEquals(hllMetricFieldSpec, _newColumnsSchema3.getFieldSpecFor(NEW_HLL_BYTE_METRIC_COLUMN_NAME));
+ ByteArray expectedDefaultValue = new ByteArray((byte[]) hllMetricFieldSpec.getDefaultNullValue());
assertEquals(hllMetricMetadata.getMinValue(), expectedDefaultValue);
assertEquals(hllMetricMetadata.getMaxValue(), expectedDefaultValue);
ColumnMetadata tDigestMetricMetadata = segmentMetadata.getColumnMetadataFor(NEW_TDIGEST_BYTE_METRIC_COLUMN_NAME);
- FieldSpec expectedTDigestMetricFieldSpec = _newColumnsSchema3.getFieldSpecFor(NEW_TDIGEST_BYTE_METRIC_COLUMN_NAME);
- expectedTDigestMetricFieldSpec.setMaxLength(tDigestMetricMetadata.getFieldSpec().getMaxLength());
- assertEquals(tDigestMetricMetadata.getFieldSpec(), expectedTDigestMetricFieldSpec);
- expectedDefaultValue = new ByteArray((byte[]) expectedTDigestMetricFieldSpec.getDefaultNullValue());
+ FieldSpec tDigestMetricFieldSpec = tDigestMetricMetadata.getFieldSpec();
+ assertEquals(tDigestMetricFieldSpec, _newColumnsSchema3.getFieldSpecFor(NEW_TDIGEST_BYTE_METRIC_COLUMN_NAME));
+ expectedDefaultValue = new ByteArray((byte[]) tDigestMetricFieldSpec.getDefaultNullValue());
assertEquals(tDigestMetricMetadata.getMinValue(), expectedDefaultValue);
assertEquals(tDigestMetricMetadata.getMaxValue(), expectedDefaultValue);
}
@@ -1066,17 +1051,19 @@ public class SegmentPreProcessorTest implements PinotBuffersAfterClassCheckRule
// Check all field for one column, and do necessary checks for other columns.
ColumnMetadata columnMetadata = segmentMetadata.getColumnMetadataFor(NEW_INT_METRIC_COLUMN_NAME);
assertEquals(columnMetadata.getFieldSpec(), _newColumnsSchema1.getFieldSpecFor(NEW_INT_METRIC_COLUMN_NAME));
- assertEquals(columnMetadata.getCardinality(), 1);
assertEquals(columnMetadata.getTotalDocs(), 100000);
- assertEquals(columnMetadata.getBitsPerElement(), 1);
- assertEquals(columnMetadata.getColumnMaxLength(), 0);
- assertTrue(columnMetadata.isSorted());
+ assertEquals(columnMetadata.getCardinality(), 1);
assertTrue(columnMetadata.hasDictionary());
- assertEquals(columnMetadata.getMaxNumberOfMultiValues(), 0);
- assertEquals(columnMetadata.getTotalNumberOfEntries(), 100000);
- assertTrue(columnMetadata.isAutoGenerated());
+ assertTrue(columnMetadata.isSorted());
assertEquals(columnMetadata.getMinValue(), 1);
assertEquals(columnMetadata.getMaxValue(), 1);
+ assertEquals(columnMetadata.getLengthOfShortestElement(), 4);
+ assertEquals(columnMetadata.getLengthOfLongestElement(), 4);
+ assertFalse(columnMetadata.isAscii());
+ assertEquals(columnMetadata.getTotalNumberOfEntries(), 100000);
+ assertEquals(columnMetadata.getMaxNumberOfMultiValues(), 0);
+ assertEquals(columnMetadata.getBitsPerElement(), 1);
+ assertTrue(columnMetadata.isAutoGenerated());
columnMetadata = segmentMetadata.getColumnMetadataFor(NEW_LONG_METRIC_COLUMN_NAME);
assertEquals(columnMetadata.getFieldSpec(), _newColumnsSchema1.getFieldSpecFor(NEW_LONG_METRIC_COLUMN_NAME));
@@ -1096,56 +1083,60 @@ public class SegmentPreProcessorTest implements PinotBuffersAfterClassCheckRule
columnMetadata = segmentMetadata.getColumnMetadataFor(NEW_BOOLEAN_SV_DIMENSION_COLUMN_NAME);
assertEquals(columnMetadata.getFieldSpec(),
_newColumnsSchema1.getFieldSpecFor(NEW_BOOLEAN_SV_DIMENSION_COLUMN_NAME));
- assertEquals(columnMetadata.getColumnMaxLength(), 0);
assertEquals(columnMetadata.getMinValue(), 0);
assertEquals(columnMetadata.getMaxValue(), 0);
+ assertEquals(columnMetadata.getLengthOfShortestElement(), 4);
+ assertEquals(columnMetadata.getLengthOfLongestElement(), 4);
columnMetadata = segmentMetadata.getColumnMetadataFor(NEW_STRING_MV_DIMENSION_COLUMN_NAME);
- FieldSpec spec = _newColumnsSchema1.getFieldSpecFor(NEW_STRING_MV_DIMENSION_COLUMN_NAME);
- spec.setMaxLength(columnMetadata.getFieldSpec().getMaxLength());
- assertEquals(columnMetadata.getFieldSpec(), spec);
- assertEquals(columnMetadata.getColumnMaxLength(), 4);
+ assertEquals(columnMetadata.getFieldSpec(),
+ _newColumnsSchema1.getFieldSpecFor(NEW_STRING_MV_DIMENSION_COLUMN_NAME));
assertFalse(columnMetadata.isSorted());
- assertEquals(columnMetadata.getMaxNumberOfMultiValues(), 1);
- assertEquals(columnMetadata.getTotalNumberOfEntries(), 100000);
assertEquals(columnMetadata.getMinValue(), "null");
assertEquals(columnMetadata.getMaxValue(), "null");
+ assertEquals(columnMetadata.getLengthOfShortestElement(), 4);
+ assertEquals(columnMetadata.getLengthOfLongestElement(), 4);
+ assertTrue(columnMetadata.isAscii());
+ assertEquals(columnMetadata.getTotalNumberOfEntries(), 100000);
+ assertEquals(columnMetadata.getMaxNumberOfMultiValues(), 1);
// Derived column
columnMetadata = segmentMetadata.getColumnMetadataFor(NEW_INT_SV_DIMENSION_COLUMN_NAME);
assertEquals(columnMetadata.getFieldSpec(), _newColumnsSchema1.getFieldSpecFor(NEW_INT_SV_DIMENSION_COLUMN_NAME));
- assertTrue(columnMetadata.isAutoGenerated());
ColumnMetadata originalColumnMetadata = segmentMetadata.getColumnMetadataFor(COLUMN1_NAME);
assertEquals(columnMetadata.getCardinality(), originalColumnMetadata.getCardinality());
- assertEquals(columnMetadata.getBitsPerElement(), originalColumnMetadata.getBitsPerElement());
assertEquals(columnMetadata.isSorted(), originalColumnMetadata.isSorted());
assertEquals(columnMetadata.getMinValue(), (int) originalColumnMetadata.getMinValue() + 1);
assertEquals(columnMetadata.getMaxValue(), (int) originalColumnMetadata.getMaxValue() + 1);
+ assertEquals(columnMetadata.getBitsPerElement(), originalColumnMetadata.getBitsPerElement());
+ assertTrue(columnMetadata.isAutoGenerated());
columnMetadata = segmentMetadata.getColumnMetadataFor(NEW_RAW_STRING_SV_DIMENSION_COLUMN_NAME);
- spec = _newColumnsSchema1.getFieldSpecFor(NEW_RAW_STRING_SV_DIMENSION_COLUMN_NAME);
- spec.setMaxLength(columnMetadata.getFieldSpec().getMaxLength());
- assertEquals(columnMetadata.getFieldSpec(), spec);
- assertTrue(columnMetadata.isAutoGenerated());
+ assertEquals(columnMetadata.getFieldSpec(),
+ _newColumnsSchema1.getFieldSpecFor(NEW_RAW_STRING_SV_DIMENSION_COLUMN_NAME));
originalColumnMetadata = segmentMetadata.getColumnMetadataFor("column3");
// exact cardinality for small-N via NoDictColumnStatisticsCollector
assertEquals(columnMetadata.getCardinality(), 5);
- assertEquals(columnMetadata.getBitsPerElement(), originalColumnMetadata.getBitsPerElement());
assertEquals(columnMetadata.getTotalNumberOfEntries(), originalColumnMetadata.getTotalNumberOfEntries());
+ assertEquals(columnMetadata.getBitsPerElement(), ColumnMetadata.UNAVAILABLE);
+ assertTrue(columnMetadata.isAutoGenerated());
columnMetadata = segmentMetadata.getColumnMetadataFor(NEW_NULL_RETURN_STRING_SV_DIMENSION_COLUMN_NAME);
// All the values should be the default null value
assertEquals(columnMetadata.getCardinality(), 1);
- assertTrue(columnMetadata.isAutoGenerated());
assertEquals(columnMetadata.getMinValue(), "nil");
assertEquals(columnMetadata.getMaxValue(), "nil");
+ assertEquals(columnMetadata.getLengthOfShortestElement(), 3);
+ assertEquals(columnMetadata.getLengthOfLongestElement(), 3);
+ assertTrue(columnMetadata.isAscii());
+ assertTrue(columnMetadata.isAutoGenerated());
columnMetadata = segmentMetadata.getColumnMetadataFor(NEW_WRONG_ARG_DATE_TRUNC_DERIVED_COLUMN_NAME);
// All the values should be the default null value
assertEquals(columnMetadata.getCardinality(), 1);
- assertTrue(columnMetadata.isAutoGenerated());
assertEquals(columnMetadata.getMinValue(), Long.MIN_VALUE);
assertEquals(columnMetadata.getMaxValue(), Long.MIN_VALUE);
+ assertTrue(columnMetadata.isAutoGenerated());
// Check dictionary and forward index exist.
try (SegmentDirectory segmentDirectory = new SegmentLocalFSDirectory(INDEX_DIR, ReadMode.mmap);
@@ -1193,14 +1184,14 @@ public class SegmentPreProcessorTest implements PinotBuffersAfterClassCheckRule
// Check column metadata.
columnMetadata = segmentMetadata.getColumnMetadataFor(NEW_INT_METRIC_COLUMN_NAME);
+ assertEquals(columnMetadata.getFieldSpec().getDefaultNullValue(), 2);
assertEquals(columnMetadata.getMinValue(), 2);
assertEquals(columnMetadata.getMaxValue(), 2);
- assertEquals(columnMetadata.getFieldSpec().getDefaultNullValue(), 2);
columnMetadata = segmentMetadata.getColumnMetadataFor(NEW_STRING_MV_DIMENSION_COLUMN_NAME);
+ assertEquals(columnMetadata.getFieldSpec().getDefaultNullValue(), "abcd");
assertEquals(columnMetadata.getMinValue(), "abcd");
assertEquals(columnMetadata.getMaxValue(), "abcd");
- assertEquals(columnMetadata.getFieldSpec().getDefaultNullValue(), "abcd");
}
@Test(dataProvider = "bothV1AndV3")
@@ -1345,8 +1336,9 @@ public class SegmentPreProcessorTest implements PinotBuffersAfterClassCheckRule
buildV1Segment();
String strColumn = "column3";
- _fieldConfigMap.put(strColumn, new FieldConfig(strColumn, FieldConfig.EncodingType.DICTIONARY,
- List.of(FieldConfig.IndexType.FST), null, null));
+ _fieldConfigMap.put(strColumn,
+ new FieldConfig(strColumn, FieldConfig.EncodingType.DICTIONARY, List.of(FieldConfig.IndexType.FST), null,
+ null));
File fstFile = new File(INDEX_DIR, strColumn + V1Constants.Indexes.LUCENE_V912_FST_INDEX_FILE_EXTENSION);
@@ -1379,8 +1371,9 @@ public class SegmentPreProcessorTest implements PinotBuffersAfterClassCheckRule
buildV3Segment();
String strColumn = "column3";
- _fieldConfigMap.put(strColumn, new FieldConfig(strColumn, FieldConfig.EncodingType.DICTIONARY,
- List.of(FieldConfig.IndexType.TEXT), null, Map.of("storeInSegmentFile", "false")));
+ _fieldConfigMap.put(strColumn,
+ new FieldConfig(strColumn, FieldConfig.EncodingType.DICTIONARY, List.of(FieldConfig.IndexType.TEXT), null,
+ Map.of("storeInSegmentFile", "false")));
File segmentDirectory = SegmentDirectoryPaths.segmentDirectoryFor(INDEX_DIR, SegmentVersion.v3);
File nativeTextFile =
@@ -2049,8 +2042,9 @@ public class SegmentPreProcessorTest implements PinotBuffersAfterClassCheckRule
Map.of(FieldConfig.FORWARD_INDEX_DISABLED, "true")));
// Forward index is always going to be present for default SV columns with forward index disabled. This is because
// such default columns are going to be sorted and the forwardIndexDisabled flag is a no-op for sorted columns
- createAndValidateIndex(StandardIndexes.forward(), NEWLY_ADDED_FORWARD_INDEX_DISABLED_COL_SV, 1, 1,
- _newColumnsSchemaWithForwardIndexDisabled, true, true, true, 4, true, 0, null, true, DataType.STRING, 100000);
+ createAndValidateIndex(_newColumnsSchemaWithForwardIndexDisabled, StandardIndexes.forward(),
+ NEWLY_ADDED_FORWARD_INDEX_DISABLED_COL_SV, DataType.STRING, true, 1, true, true, 4, 100000, 0, true, null,
+ true);
// Add a new raw column with no forward index
resetIndexConfigs();
@@ -2062,8 +2056,9 @@ public class SegmentPreProcessorTest implements PinotBuffersAfterClassCheckRule
// Forward index is always going to be present for default SV columns with forward index disabled. This is because
// such default columns are going to be sorted and the forwardIndexDisabled flag is a no-op for sorted columns
// Even raw columns are created with dictionary and forward index
- createAndValidateIndex(StandardIndexes.forward(), NEWLY_ADDED_FORWARD_INDEX_DISABLED_COL_SV, 1, 1,
- _newColumnsSchemaWithForwardIndexDisabled, true, true, true, 4, true, 0, null, true, DataType.STRING, 100000);
+ createAndValidateIndex(_newColumnsSchemaWithForwardIndexDisabled, StandardIndexes.forward(),
+ NEWLY_ADDED_FORWARD_INDEX_DISABLED_COL_SV, DataType.STRING, true, 1, true, true, 4, 100000, 0, true, null,
+ true);
// Add a new column with no forward index or inverted index
resetIndexConfigs();
@@ -2072,8 +2067,9 @@ public class SegmentPreProcessorTest implements PinotBuffersAfterClassCheckRule
new FieldConfig(NEWLY_ADDED_FORWARD_INDEX_DISABLED_COL_SV, FieldConfig.EncodingType.DICTIONARY, List.of(), null,
Map.of(FieldConfig.FORWARD_INDEX_DISABLED, "true")));
// Disabling inverted index should be fine for disabling the forward index
- createAndValidateIndex(StandardIndexes.forward(), NEWLY_ADDED_FORWARD_INDEX_DISABLED_COL_SV, 1, 1,
- _newColumnsSchemaWithForwardIndexDisabled, true, true, true, 4, true, 0, null, true, DataType.STRING, 100000);
+ createAndValidateIndex(_newColumnsSchemaWithForwardIndexDisabled, StandardIndexes.forward(),
+ NEWLY_ADDED_FORWARD_INDEX_DISABLED_COL_SV, DataType.STRING, true, 1, true, true, 4, 100000, 0, true, null,
+ true);
}
/**
@@ -2088,10 +2084,11 @@ public class SegmentPreProcessorTest implements PinotBuffersAfterClassCheckRule
_fieldConfigMap.put(NEWLY_ADDED_FORWARD_INDEX_DISABLED_COL_MV,
new FieldConfig(NEWLY_ADDED_FORWARD_INDEX_DISABLED_COL_MV, FieldConfig.EncodingType.DICTIONARY, List.of(), null,
Map.of(FieldConfig.FORWARD_INDEX_DISABLED, "true")));
- createAndValidateIndex(StandardIndexes.forward(), NEWLY_ADDED_FORWARD_INDEX_DISABLED_COL_MV, 1, 1,
- _newColumnsSchemaWithForwardIndexDisabled, true, true, false, 4, false, 1, null, true, DataType.STRING, 100000);
- validateIndex(StandardIndexes.inverted(), NEWLY_ADDED_FORWARD_INDEX_DISABLED_COL_MV, 1, 1, true, true, false, 4,
- false, 1, null, true, DataType.STRING, 100000);
+ createAndValidateIndex(_newColumnsSchemaWithForwardIndexDisabled, StandardIndexes.forward(),
+ NEWLY_ADDED_FORWARD_INDEX_DISABLED_COL_MV, DataType.STRING, false, 1, true, false, 4, 100000, 1, true, null,
+ true);
+ validateIndex(StandardIndexes.inverted(), NEWLY_ADDED_FORWARD_INDEX_DISABLED_COL_MV, DataType.STRING, false, 1,
+ true, false, 4, 100000, 1, true, null, true);
// Add a new raw column with no forward index
resetIndexConfigs();
@@ -2104,17 +2101,17 @@ public class SegmentPreProcessorTest implements PinotBuffersAfterClassCheckRule
// For V1 segments reload doesn't support modifying the forward index yet. Since for MV columns we create a
// dictionary in the default column handler, the forward index should indeed be disabled but we should still have
// the dictionary.
- createAndValidateIndex(StandardIndexes.forward(), NEWLY_ADDED_FORWARD_INDEX_DISABLED_COL_MV, 1, 1,
- _newColumnsSchemaWithForwardIndexDisabled, true, true, false, 4, false, 1, null, true, DataType.STRING,
- 100000);
- validateIndexExists(NEWLY_ADDED_FORWARD_INDEX_DISABLED_COL_MV, StandardIndexes.dictionary());
+ createAndValidateIndex(_newColumnsSchemaWithForwardIndexDisabled, StandardIndexes.forward(),
+ NEWLY_ADDED_FORWARD_INDEX_DISABLED_COL_MV, DataType.STRING, false, 1, true, false, 4, 100000, 1, true, null,
+ true);
+ validateIndexExists(StandardIndexes.dictionary(), NEWLY_ADDED_FORWARD_INDEX_DISABLED_COL_MV);
} else {
- createAndValidateIndex(StandardIndexes.forward(), NEWLY_ADDED_FORWARD_INDEX_DISABLED_COL_MV, 1, 1,
- _newColumnsSchemaWithForwardIndexDisabled, true, false, false, 0, false, 1, null, true, DataType.STRING,
- 100000);
- validateIndexDoesNotExist(NEWLY_ADDED_FORWARD_INDEX_DISABLED_COL_MV, StandardIndexes.dictionary());
+ createAndValidateIndex(_newColumnsSchemaWithForwardIndexDisabled, StandardIndexes.forward(),
+ NEWLY_ADDED_FORWARD_INDEX_DISABLED_COL_MV, DataType.STRING, false, 1, false, false, 4, 100000, 1, true, null,
+ true);
+ validateIndexDoesNotExist(StandardIndexes.dictionary(), NEWLY_ADDED_FORWARD_INDEX_DISABLED_COL_MV);
}
- validateIndexDoesNotExist(NEWLY_ADDED_FORWARD_INDEX_DISABLED_COL_MV, StandardIndexes.inverted());
+ validateIndexDoesNotExist(StandardIndexes.inverted(), NEWLY_ADDED_FORWARD_INDEX_DISABLED_COL_MV);
// Add a new column with no forward index or inverted index
resetIndexConfigs();
@@ -2122,9 +2119,10 @@ public class SegmentPreProcessorTest implements PinotBuffersAfterClassCheckRule
_fieldConfigMap.put(NEWLY_ADDED_FORWARD_INDEX_DISABLED_COL_MV,
new FieldConfig(NEWLY_ADDED_FORWARD_INDEX_DISABLED_COL_MV, FieldConfig.EncodingType.DICTIONARY, List.of(), null,
Map.of(FieldConfig.FORWARD_INDEX_DISABLED, "true")));
- createAndValidateIndex(StandardIndexes.forward(), NEWLY_ADDED_FORWARD_INDEX_DISABLED_COL_MV, 1, 1,
- _newColumnsSchemaWithForwardIndexDisabled, true, true, false, 4, false, 1, null, true, DataType.STRING, 100000);
- validateIndexDoesNotExist(NEWLY_ADDED_FORWARD_INDEX_DISABLED_COL_MV, StandardIndexes.inverted());
- validateIndexExists(NEWLY_ADDED_FORWARD_INDEX_DISABLED_COL_MV, StandardIndexes.dictionary());
+ createAndValidateIndex(_newColumnsSchemaWithForwardIndexDisabled, StandardIndexes.forward(),
+ NEWLY_ADDED_FORWARD_INDEX_DISABLED_COL_MV, DataType.STRING, false, 1, true, false, 4, 100000, 1, true, null,
+ true);
+ validateIndexDoesNotExist(StandardIndexes.inverted(), NEWLY_ADDED_FORWARD_INDEX_DISABLED_COL_MV);
+ validateIndexExists(StandardIndexes.dictionary(), NEWLY_ADDED_FORWARD_INDEX_DISABLED_COL_MV);
}
}
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 fc53ad163cc..713a5801503 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
@@ -18,8 +18,8 @@
*/
package org.apache.pinot.segment.spi;
+import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
-import java.util.Map;
import java.util.Set;
import javax.annotation.Nullable;
import org.apache.pinot.segment.spi.index.IndexType;
@@ -30,15 +30,11 @@ import org.apache.pinot.spi.data.FieldSpec.DataType;
import org.apache.pinot.spi.data.FieldSpec.FieldType;
-/**
- * The <code>ColumnMetadata</code> class holds the column level management information and data statistics.
- */
+/// The `ColumnMetadata` class holds the column level management information and data statistics.
@InterfaceAudience.Private
@SuppressWarnings("rawtypes")
public interface ColumnMetadata {
-
- /** Value returned by getIndexSizeFor() when given index type can't be found. */
- int INDEX_NOT_FOUND = -1;
+ int UNAVAILABLE = -1;
FieldSpec getFieldSpec();
@@ -58,73 +54,79 @@ public interface ColumnMetadata {
return getFieldSpec().isSingleValueField();
}
+ /// Returns the total number of documents (rows).
int getTotalDocs();
- /**
- * NOTE: When a realtime segment has no-dictionary columns, the cardinality for those columns will be set to
- * {@link Constants#UNKNOWN_CARDINALITY}.
- */
+ /// Returns the cardinality of the column.
+ /// NOTE: When a realtime segment has no-dictionary columns, the cardinality for those columns will be set to
+ /// [Constants#UNKNOWN_CARDINALITY].
int getCardinality();
+ /// Returns `true` when the column is dictionary-encoded, `false` otherwise.
+ @JsonProperty("hasDictionary")
+ boolean hasDictionary();
+
+ /// Returns `true` when all values in a SV column are sorted in ascending order, `false` otherwise.
boolean isSorted();
+ /// Returns the minimum value, or `null` if the value is unavailable.
+ @Nullable
Comparable getMinValue();
+ /// Returns the maximum value, or `null` if the value is unavailable.
+ @Nullable
Comparable getMaxValue();
- default boolean isMinMaxValueInvalid() {
- return false;
- }
+ /// Returns `true` when both min and max value are invalid, and there is no need to regenerate them.
+ boolean isMinMaxValueInvalid();
- @JsonProperty
- boolean hasDictionary();
+ /// Returns the minimum serialized byte length across all elements. For fixed-width types, returns the fixed size.
+ int getLengthOfShortestElement();
- int getColumnMaxLength();
+ /// Returns the maximum serialized byte length across all elements. For fixed-width types, returns the fixed size.
+ int getLengthOfLongestElement();
- int getBitsPerElement();
+ /// Returns `true` when all elements of a STRING column contain only ASCII characters.
+ boolean isAscii();
+ /// Returns the total number of entries.
+ /// - For SV columns, equals the number of rows
+ /// - For MV columns, sums the number of elements across all rows
+ int getTotalNumberOfEntries();
+
+ /// Returns the maximum number of elements within a single MV value, or `0` for SV columns.
int getMaxNumberOfMultiValues();
- int getTotalNumberOfEntries();
+ /// For dictionary-encoded columns, returns the bits required for each element, [#UNAVAILABLE] otherwise.
+ int getBitsPerElement();
+ /// Returns the [PartitionFunction] for the column.
@Nullable
PartitionFunction getPartitionFunction();
+ /// Returns the partitions within which the values exist.
@Nullable
Set<Integer> getPartitions();
- /**
- * If exists, returns size of index for given index type; otherwise returns -1.
- * @param type index type
- */
- default long getIndexSizeFor(IndexType type) {
- return INDEX_NOT_FOUND;
- }
+ /// Returns `true` when the column is auto-generated by the default column handler.
+ boolean isAutoGenerated();
- /**
- * Returns type of index at `position`.
- * @param position - position within collection of indexes
- */
- default short getIndexType(int position) {
- return (short) -1;
- }
+ /// Returns the total number of indexes for the column.
+ @JsonIgnore
+ int getNumIndexes();
- /**
- * Returns size of index at `position`.
- * @param position - position within collection of indexes
- */
- default long getIndexSize(int position) {
- return -1;
- }
+ /// Returns the type of the index at the given position.
+ short getIndexType(int position);
- /**
- * Returns this column's number of indexes.
- */
- default int getNumIndexes() {
- return 0;
- }
+ /// Returns the size of the index at the given position.
+ long getIndexSize(int position);
- boolean isAutoGenerated();
+ /// Returns the size of the given index type if exists, [#UNAVAILABLE] otherwise.
+ long getIndexSizeFor(IndexType type);
- Map<IndexType<?, ?, ?>, Long> getIndexSizeMap();
+ @JsonIgnore
+ @Deprecated(since = "1.6.0", forRemoval = true)
+ default int getColumnMaxLength() {
+ return getLengthOfLongestElement();
+ }
}
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 0db9b1f1012..fab40f3005a 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
@@ -111,34 +111,78 @@ public class V1Constants {
}
public static class Column {
- public static final String CARDINALITY = "cardinality";
- public static final String TOTAL_DOCS = "totalDocs";
- public static final String DATA_TYPE = "dataType";
- public static final String BITS_PER_ELEMENT = "bitsPerElement";
- public static final String DICTIONARY_ELEMENT_SIZE = "lengthOfEachEntry";
+ /// Keys to construct FieldSpec
+ // Optional, available when column key doesn't match field name (e.g. child field)
public static final String COLUMN_NAME = "columnName";
+ // Mandatory
public static final String COLUMN_TYPE = "columnType";
- public static final String IS_SORTED = "isSorted";
- public static final String HAS_DICTIONARY = "hasDictionary";
+ // Mandatory
+ public static final String DATA_TYPE = "dataType";
+ // Mandatory, treated as `true` when missing for backward compatibility
public static final String IS_SINGLE_VALUED = "isSingleValues";
- public static final String MAX_MULTI_VALUE_ELEMENTS = "maxNumberOfMultiValues";
- public static final String TOTAL_NUMBER_OF_ENTRIES = "totalNumberOfEntries";
- public static final String IS_AUTO_GENERATED = "isAutoGenerated";
+ // Optional, not available when value is not supported by CommonConfiguration
public static final String DEFAULT_NULL_VALUE = "defaultNullValue";
+ // Optional, exist for data types stored as STRING/BYTES
+ public static final String SCHEMA_MAX_LENGTH = "schemaMaxLength";
+ // Optional, exist for data types stored as STRING/BYTES
+ public static final String SCHEMA_MAX_LENGTH_EXCEED_STRATEGY = "schemaMaxLengthExceedStrategy";
+ // Optional, exist for DATE_TIME fields
+ public static final String DATETIME_FORMAT = "datetimeFormat";
+ // Optional, exist for DATE_TIME fields
+ public static final String DATETIME_GRANULARITY = "datetimeGranularity";
+ // Optional, exist for COMPLEX fields
+ public static final String COMPLEX_CHILD_FIELD_NAMES = "complexChildFieldNames";
+
+ /// Stats
+ // Mandatory
+ public static final String CARDINALITY = "cardinality";
+ // Mandatory, treated as `true` when missing for backward compatibility
+ public static final String HAS_DICTIONARY = "hasDictionary";
+ // Mandatory, treated as `false` when missing for backward compatibility
+ public static final String IS_SORTED = "isSorted";
+ // Optional
public static final String MIN_VALUE = "minValue";
+ // Optional
public static final String MAX_VALUE = "maxValue";
+ // Optional, set to true when both min and max value are null, and there is no need to regenerate them
public static final String MIN_MAX_VALUE_INVALID = "minMaxValueInvalid";
+ // Optional, exist for variable-length types
+ // NOTE: Added in release 1.6.0. Only exist in segment created after 1.6.0 release.
+ public static final String LENGTH_OF_SHORTEST_ELEMENT = "lengthOfShortestElement";
+ // Optional, exist for variable-length types
+ // NOTE: Added in release 1.6.0. Only exist in segment created after 1.6.0 release.
+ public static final String LENGTH_OF_LONGEST_ELEMENT = "lengthOfLongestElement";
+ // Optional, exist for data types stored as STRING
+ // NOTE: Added in release 1.6.0. Only exist in segment created after 1.6.0 release.
+ public static final String IS_ASCII = "isAscii";
+ // Optional, exist for dictionary encoded columns
+ // TODO: Changed to optional on reader side in release 1.6.0. Change writer side after 1.6.0 release.
+ public static final String BITS_PER_ELEMENT = "bitsPerElement";
+ // Optional, exist for MV columns
+ // TODO: Changed to optional on reader side in release 1.6.0. Change writer side after 1.6.0 release.
+ public static final String MAX_MULTI_VALUE_ELEMENTS = "maxNumberOfMultiValues";
+ // Optional, exist for MV columns
+ // TODO: Changed to optional on reader side in release 1.6.0. Change writer side after 1.6.0 release.
+ public static final String TOTAL_NUMBER_OF_ENTRIES = "totalNumberOfEntries";
+ // Optional, default false
+ public static final String IS_AUTO_GENERATED = "isAutoGenerated";
+
+ /// Partition function, all optional
public static final String PARTITION_FUNCTION = "partitionFunction";
- public static final String PARTITION_FUNCTION_CONFIG = "partitionFunctionConfig";
public static final String NUM_PARTITIONS = "numPartitions";
public static final String PARTITION_VALUES = "partitionValues";
- public static final String DATETIME_FORMAT = "datetimeFormat";
- public static final String DATETIME_GRANULARITY = "datetimeGranularity";
- public static final String COMPLEX_CHILD_FIELD_NAMES = "complexChildFieldNames";
+ public static final String PARTITION_FUNCTION_CONFIG = "partitionFunctionConfig";
+
+ /// Old key maintained for backward compatibility
+ // Replaced by LENGTH_OF_LONGEST_ELEMENT
+ // TODO: Changed to optional on reader side in release 1.6.0. Change writer side after 1.6.0 release.
+ public static final String DICTIONARY_ELEMENT_SIZE = "lengthOfEachEntry";
+
+ // TODO: Removed the usage on reader side in release 1.6.0. Remove it after 1.6.0 release.
+ @Deprecated(since = "1.6.0", forRemoval = true)
+ public static final String TOTAL_DOCS = "totalDocs";
public static final String COLUMN_PROPS_KEY_PREFIX = "column.";
- public static final String SCHEMA_MAX_LENGTH = "schemaMaxLength";
- public static final String SCHEMA_MAX_LENGTH_EXCEED_STRATEGY = "schemaMaxLengthExceedStrategy";
public static String getKeyFor(String column, String key) {
return COLUMN_PROPS_KEY_PREFIX + column + "." + key;
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 45c0b551ae3..d5fd242af57 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
@@ -18,12 +18,10 @@
*/
package org.apache.pinot.segment.spi.index.metadata;
-import com.fasterxml.jackson.annotation.JsonIgnore;
-import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.Maps;
import it.unimi.dsi.fastutil.longs.LongArrayList;
import java.math.BigDecimal;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -45,6 +43,7 @@ import org.apache.pinot.spi.data.DateTimeFieldSpec;
import org.apache.pinot.spi.data.DimensionFieldSpec;
import org.apache.pinot.spi.data.FieldSpec;
import org.apache.pinot.spi.data.FieldSpec.DataType;
+import org.apache.pinot.spi.data.FieldSpec.FieldType;
import org.apache.pinot.spi.data.MetricFieldSpec;
import org.apache.pinot.spi.data.TimeFieldSpec;
import org.apache.pinot.spi.data.TimeGranularitySpec;
@@ -52,51 +51,56 @@ import org.apache.pinot.spi.env.CommonsConfigurationUtils;
import org.apache.pinot.spi.utils.BytesUtils;
+@SuppressWarnings({"rawtypes", "unchecked"})
public class ColumnMetadataImpl implements ColumnMetadata {
private static final long SIZE_MASK = 0xffffffffffffL;
+
private final FieldSpec _fieldSpec;
private final int _totalDocs;
private final int _cardinality;
+ private final boolean _hasDictionary;
private final boolean _sorted;
- private final Comparable<?> _minValue;
- private final Comparable<?> _maxValue;
-
+ private final Comparable _minValue;
+ private final Comparable _maxValue;
private final boolean _minMaxValueInvalid;
- private final boolean _hasDictionary;
- private final int _columnMaxLength;
- private final int _bitsPerElement;
- private final int _maxNumberOfMultiValues;
+ private final int _lengthOfShortestElement;
+ private final int _lengthOfLongestElement;
+ private final boolean _isAscii;
private final int _totalNumberOfEntries;
+ private final int _maxNumberOfMultiValues;
+ private final int _bitsPerElement;
private final PartitionFunction _partitionFunction;
private final Set<Integer> _partitions;
-
- /* List of longs, each encodes:
- * 2 byte - numeric id of IndexType
- * 6 byte - index size */
- private final LongArrayList _indexTypeSizeList;
-
private final boolean _autoGenerated;
- private ColumnMetadataImpl(FieldSpec fieldSpec, int totalDocs, int cardinality, boolean sorted,
- Comparable<?> minValue, Comparable<?> maxValue, boolean minMaxValueInvalid, boolean hasDictionary,
- int columnMaxLength, int bitsPerElement, int maxNumberOfMultiValues, int totalNumberOfEntries,
- @Nullable PartitionFunction partitionFunction, @Nullable Set<Integer> partitions,
- LongArrayList indexSizeList, boolean autoGenerated) {
+ /// List of longs, each encodes:
+ /// - 2 byte - numeric id of IndexType
+ /// - 6 byte - index size
+ ///
+ /// 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) {
_fieldSpec = fieldSpec;
_totalDocs = totalDocs;
_cardinality = cardinality;
+ _hasDictionary = hasDictionary;
_sorted = sorted;
_minValue = minValue;
_maxValue = maxValue;
_minMaxValueInvalid = minMaxValueInvalid;
- _hasDictionary = hasDictionary;
- _columnMaxLength = columnMaxLength;
+ _lengthOfShortestElement = lengthOfShortestElement;
+ _lengthOfLongestElement = lengthOfLongestElement;
+ _isAscii = isAscii;
_bitsPerElement = bitsPerElement;
_maxNumberOfMultiValues = maxNumberOfMultiValues;
_totalNumberOfEntries = totalNumberOfEntries;
_partitionFunction = partitionFunction;
_partitions = partitions;
- _indexTypeSizeList = indexSizeList;
_autoGenerated = autoGenerated;
}
@@ -115,33 +119,46 @@ public class ColumnMetadataImpl implements ColumnMetadata {
return _cardinality;
}
+ @Override
+ public boolean hasDictionary() {
+ return _hasDictionary;
+ }
+
@Override
public boolean isSorted() {
return _sorted;
}
+ @Nullable
@Override
public Comparable<?> getMinValue() {
return _minValue;
}
+ @Nullable
@Override
public Comparable<?> getMaxValue() {
return _maxValue;
}
+ @Override
public boolean isMinMaxValueInvalid() {
return _minMaxValueInvalid;
}
@Override
- public boolean hasDictionary() {
- return _hasDictionary;
+ public int getLengthOfShortestElement() {
+ return _lengthOfShortestElement;
+ }
+
+ @Override
+ public int getLengthOfLongestElement() {
+ return _lengthOfLongestElement;
}
@Override
- public int getColumnMaxLength() {
- return _columnMaxLength;
+ public boolean isAscii() {
+ return _isAscii;
}
@Override
@@ -172,7 +189,11 @@ public class ColumnMetadataImpl implements ColumnMetadata {
}
@Override
- @VisibleForTesting
+ public boolean isAutoGenerated() {
+ return _autoGenerated;
+ }
+
+ @Override
public long getIndexSizeFor(IndexType type) {
short indexId = IndexService.getInstance().getNumericId(type);
for (long typeAndSize : _indexTypeSizeList) {
@@ -180,8 +201,7 @@ public class ColumnMetadataImpl implements ColumnMetadata {
return unpackIndexSize(typeAndSize);
}
}
-
- return INDEX_NOT_FOUND;
+ return UNAVAILABLE;
}
// size should be non-negative 48-bit value
@@ -194,6 +214,11 @@ public class ColumnMetadataImpl implements ColumnMetadata {
_indexTypeSizeList.add(typeAndSize);
}
+ @Override
+ public int getNumIndexes() {
+ return _indexTypeSizeList.size();
+ }
+
@Override
public short getIndexType(int position) {
return unpackIndexType(_indexTypeSizeList.getLong(position));
@@ -212,17 +237,6 @@ public class ColumnMetadataImpl implements ColumnMetadata {
return typeAndSize & SIZE_MASK;
}
- @JsonIgnore
- @Override
- public int getNumIndexes() {
- return _indexTypeSizeList.size();
- }
-
- @Override
- public boolean isAutoGenerated() {
- return _autoGenerated;
- }
-
@Override
public boolean equals(Object o) {
if (this == o) {
@@ -232,51 +246,61 @@ public class ColumnMetadataImpl implements ColumnMetadata {
return false;
}
ColumnMetadataImpl that = (ColumnMetadataImpl) o;
- return _totalDocs == that._totalDocs && _cardinality == that._cardinality && _sorted == that._sorted
- && _hasDictionary == that._hasDictionary && _columnMaxLength == that._columnMaxLength
- && _bitsPerElement == that._bitsPerElement && _maxNumberOfMultiValues == that._maxNumberOfMultiValues
- && _totalNumberOfEntries == that._totalNumberOfEntries && _autoGenerated == that._autoGenerated
- && Objects.equals(_fieldSpec, that._fieldSpec) && Objects.equals(_minValue, that._minValue) && Objects.equals(
- _maxValue, that._maxValue) && Objects.equals(_partitionFunction, that._partitionFunction) && Objects.equals(
- _partitions, that._partitions);
+ return _totalDocs == that._totalDocs && _cardinality == that._cardinality && _hasDictionary == that._hasDictionary
+ && _sorted == that._sorted && _minMaxValueInvalid == that._minMaxValueInvalid
+ && _lengthOfShortestElement == that._lengthOfShortestElement
+ && _lengthOfLongestElement == that._lengthOfLongestElement && _isAscii == that._isAscii
+ && _totalNumberOfEntries == that._totalNumberOfEntries
+ && _maxNumberOfMultiValues == that._maxNumberOfMultiValues && _bitsPerElement == that._bitsPerElement
+ && _autoGenerated == that._autoGenerated && Objects.equals(_fieldSpec, that._fieldSpec) && Objects.equals(
+ _minValue, that._minValue) && Objects.equals(_maxValue, that._maxValue) && Objects.equals(_partitionFunction,
+ that._partitionFunction) && Objects.equals(_partitions, that._partitions) && Objects.equals(_indexTypeSizeList,
+ that._indexTypeSizeList);
}
@Override
public int hashCode() {
- return Objects.hash(_fieldSpec, _totalDocs, _cardinality, _sorted, _minValue, _maxValue, _hasDictionary,
- _columnMaxLength, _bitsPerElement, _maxNumberOfMultiValues, _totalNumberOfEntries, _partitionFunction,
- _partitions, _autoGenerated);
+ return Objects.hash(_fieldSpec, _totalDocs, _cardinality, _hasDictionary, _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 + ", _sorted=" + _sorted + ", _minValue=" + _minValue + ", _maxValue=" + _maxValue
- + ", _hasDictionary=" + _hasDictionary + ", _columnMaxLength=" + _columnMaxLength + ", _bitsPerElement="
- + _bitsPerElement + ", _maxNumberOfMultiValues=" + _maxNumberOfMultiValues + ", _totalNumberOfEntries="
- + _totalNumberOfEntries + ", _partitionFunction=" + _partitionFunction + ", _partitions=" + _partitions
- + ", _autoGenerated=" + _autoGenerated + '}';
+ + _cardinality + ", _hasDictionary=" + _hasDictionary + ", _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 + '}';
}
- public static ColumnMetadataImpl fromPropertiesConfiguration(String column, PropertiesConfiguration config) {
- Builder builder = new Builder().setTotalDocs(config.getInt(Column.getKeyFor(column, Column.TOTAL_DOCS)))
+ public static ColumnMetadataImpl fromPropertiesConfiguration(PropertiesConfiguration config, int totalDocs,
+ String column) {
+ FieldSpec fieldSpec = generateFieldSpec(column, config);
+ Builder builder = new Builder()
+ .setFieldSpec(fieldSpec)
+ .setTotalDocs(totalDocs)
.setCardinality(config.getInt(Column.getKeyFor(column, Column.CARDINALITY)))
- .setSorted(config.getBoolean(Column.getKeyFor(column, Column.IS_SORTED), false))
.setHasDictionary(config.getBoolean(Column.getKeyFor(column, Column.HAS_DICTIONARY), true))
- .setBitsPerElement(config.getInt(Column.getKeyFor(column, Column.BITS_PER_ELEMENT)))
- .setColumnMaxLength(config.getInt(Column.getKeyFor(column, Column.DICTIONARY_ELEMENT_SIZE)))
- .setMaxNumberOfMultiValues(config.getInt(Column.getKeyFor(column, Column.MAX_MULTI_VALUE_ELEMENTS)))
- .setTotalNumberOfEntries(config.getInt(Column.getKeyFor(column, Column.TOTAL_NUMBER_OF_ENTRIES)))
+ .setSorted(config.getBoolean(Column.getKeyFor(column, Column.IS_SORTED), false))
+ .setLengthOfShortestElement(
+ config.getInt(Column.getKeyFor(column, Column.LENGTH_OF_SHORTEST_ELEMENT), UNAVAILABLE))
+ .setLengthOfLongestElement(
+ config.getInt(Column.getKeyFor(column, Column.LENGTH_OF_LONGEST_ELEMENT), UNAVAILABLE))
+ .setDictionaryElementSize(config.getInt(Column.getKeyFor(column, Column.DICTIONARY_ELEMENT_SIZE), UNAVAILABLE))
+ .setAscii(config.getBoolean(Column.getKeyFor(column, Column.IS_ASCII), false))
+ .setTotalNumberOfEntries(config.getInt(Column.getKeyFor(column, Column.TOTAL_NUMBER_OF_ENTRIES), UNAVAILABLE))
+ .setMaxNumberOfMultiValues(
+ config.getInt(Column.getKeyFor(column, Column.MAX_MULTI_VALUE_ELEMENTS), UNAVAILABLE))
+ .setBitsPerElement(config.getInt(Column.getKeyFor(column, Column.BITS_PER_ELEMENT), UNAVAILABLE))
.setAutoGenerated(config.getBoolean(Column.getKeyFor(column, Column.IS_AUTO_GENERATED), false));
- FieldSpec fieldSpec = generateFieldSpec(column, config);
- builder.setFieldSpec(fieldSpec);
+ // Set min/max value
DataType storedType = fieldSpec.getDataType().getStoredType();
-
if (fieldSpec instanceof ComplexFieldSpec) {
// Complex field does not have min/max value
- builder.setMinValue(null);
- builder.setMaxValue(null);
builder.setMinMaxValueInvalid(true);
} else {
// Set min/max value if available
@@ -287,35 +311,35 @@ public class ColumnMetadataImpl implements ColumnMetadata {
String maxString = (String) config.getProperty(Column.getKeyFor(column, Column.MAX_VALUE));
// Set min/max value if available
if (minString != null) {
- builder.setMinValue(builder.parseValue(storedType, column, minString));
+ builder.setMinValue(parseValue(storedType, column, minString));
}
-
if (maxString != null) {
- builder.setMaxValue(builder.parseValue(storedType, column, maxString));
+ builder.setMaxValue(parseValue(storedType, column, maxString));
+ }
+ if (minString == null && maxString == null) {
+ builder.setMinMaxValueInvalid(config.getBoolean(Column.getKeyFor(column, Column.MIN_MAX_VALUE_INVALID), false));
}
- builder.setMinMaxValueInvalid(config.getBoolean(Column.getKeyFor(column, Column.MIN_MAX_VALUE_INVALID), false));
}
+ // Set partition function
String partitionFunctionName = config.getString(Column.getKeyFor(column, Column.PARTITION_FUNCTION), null);
if (partitionFunctionName != null) {
int numPartitions = config.getInt(Column.getKeyFor(column, Column.NUM_PARTITIONS));
- Map<String, String> partitionFunctionConfigMap = null;
Configuration partitionFunctionConfig = config.subset(Column.getKeyFor(column, Column.PARTITION_FUNCTION_CONFIG));
+ Map<String, String> partitionFunctionConfigMap;
if (!partitionFunctionConfig.isEmpty()) {
partitionFunctionConfigMap = new HashMap<>();
- Iterator<String> partitionFunctionConfigKeysIter = partitionFunctionConfig.getKeys();
- while (partitionFunctionConfigKeysIter.hasNext()) {
- String functionConfigKey = partitionFunctionConfigKeysIter.next();
- Object functionConfigValueObj = partitionFunctionConfig.getProperty(functionConfigKey);
- /*
- A partition function config value can have comma and this value is read as a List from
- PropertiesConfiguration.getProperty, Hence we need to rebuild original comma separated string value from
- this list of values.
- */
- partitionFunctionConfigMap.put(functionConfigKey,
- functionConfigValueObj instanceof List ? String.join(",", (List) functionConfigValueObj)
- : functionConfigValueObj.toString());
- }
+ partitionFunctionConfig.forEach((k, v) -> {
+ // NOTE:
+ // A partition function config value can have comma and this value is read as a List from
+ // PropertiesConfiguration.getProperty, hence we need to rebuild original comma separated string value from
+ // this list of values.
+ partitionFunctionConfigMap.put(k,
+ v instanceof List ? String.join(",", (List) v)
+ : v.toString());
+ });
+ } else {
+ partitionFunctionConfigMap = null;
}
PartitionFunction partitionFunction =
PartitionFunctionFactory.getPartitionFunction(partitionFunctionName, numPartitions,
@@ -330,41 +354,31 @@ public class ColumnMetadataImpl implements ColumnMetadata {
public static FieldSpec generateFieldSpec(String column, PropertiesConfiguration config) {
String fieldName = config.getString(Column.getKeyFor(column, Column.COLUMN_NAME), column);
- FieldSpec.FieldType fieldType =
- FieldSpec.FieldType.valueOf(config.getString(Column.getKeyFor(column, Column.COLUMN_TYPE)).toUpperCase());
- DataType dataType = DataType.valueOf(config.getString(Column.getKeyFor(column, Column.DATA_TYPE)).toUpperCase());
- DataType storedType = dataType.getStoredType();
+ FieldType fieldType = config.getEnum(Column.getKeyFor(column, Column.COLUMN_TYPE), FieldType.class);
+ DataType dataType = config.getEnum(Column.getKeyFor(column, Column.DATA_TYPE), DataType.class);
+ boolean isSingleValue = config.getBoolean(Column.getKeyFor(column, Column.IS_SINGLE_VALUED), true);
String defaultNullValueString = config.getString(Column.getKeyFor(column, Column.DEFAULT_NULL_VALUE), null);
- if (defaultNullValueString != null && storedType == DataType.STRING) {
+ if (defaultNullValueString != null && dataType.getStoredType() == DataType.STRING) {
defaultNullValueString = CommonsConfigurationUtils.recoverSpecialCharacterInPropertyValue(defaultNullValueString);
}
- Integer maxLength = config.containsKey(Column.getKeyFor(column, Column.SCHEMA_MAX_LENGTH))
- ? config.getInt(Column.getKeyFor(column, Column.SCHEMA_MAX_LENGTH))
- : null;
+ Integer maxLength = config.getInteger(Column.getKeyFor(column, Column.SCHEMA_MAX_LENGTH), null);
String maxLengthExceedStrategyString =
config.getString(Column.getKeyFor(column, Column.SCHEMA_MAX_LENGTH_EXCEED_STRATEGY), null);
FieldSpec.MaxLengthExceedStrategy maxLengthExceedStrategy = maxLengthExceedStrategyString != null
? FieldSpec.MaxLengthExceedStrategy.valueOf(maxLengthExceedStrategyString) : null;
- FieldSpec fieldSpec;
switch (fieldType) {
case DIMENSION:
- boolean isSingleValue = config.getBoolean(Column.getKeyFor(column, Column.IS_SINGLE_VALUED));
- fieldSpec = new DimensionFieldSpec(fieldName, dataType, isSingleValue, maxLength,
- defaultNullValueString, maxLengthExceedStrategy);
- break;
+ return new DimensionFieldSpec(fieldName, dataType, isSingleValue, maxLength, defaultNullValueString,
+ maxLengthExceedStrategy);
case METRIC:
- fieldSpec =
- new MetricFieldSpec(fieldName, dataType, defaultNullValueString, maxLength, maxLengthExceedStrategy);
- break;
+ return new MetricFieldSpec(fieldName, dataType, defaultNullValueString, maxLength, maxLengthExceedStrategy);
case TIME:
TimeUnit timeUnit = TimeUnit.valueOf(config.getString(Segment.TIME_UNIT, "DAYS").toUpperCase());
- fieldSpec = new TimeFieldSpec(new TimeGranularitySpec(dataType, timeUnit, fieldName));
- break;
+ return new TimeFieldSpec(new TimeGranularitySpec(dataType, timeUnit, fieldName));
case DATE_TIME:
String format = config.getString(Column.getKeyFor(column, Column.DATETIME_FORMAT));
String granularity = config.getString(Column.getKeyFor(column, Column.DATETIME_GRANULARITY));
- fieldSpec = new DateTimeFieldSpec(fieldName, dataType, format, granularity, defaultNullValueString, null);
- break;
+ return new DateTimeFieldSpec(fieldName, dataType, format, granularity, defaultNullValueString, null);
case COMPLEX:
List<String> childFieldNames =
config.getList(String.class, Column.getKeyFor(column, Column.COMPLEX_CHILD_FIELD_NAMES));
@@ -373,27 +387,44 @@ public class ColumnMetadataImpl implements ColumnMetadata {
childFieldSpecs.put(childField,
generateFieldSpec(ComplexFieldSpec.getFullChildName(column, childField), config));
}
- fieldSpec = new ComplexFieldSpec(fieldName, dataType, true, childFieldSpecs);
- break;
+ return new ComplexFieldSpec(fieldName, dataType, true, childFieldSpecs);
default:
throw new IllegalStateException("Unsupported field type: " + fieldType);
}
- return fieldSpec;
}
- // This method is only meant to retain compatibility of deserialization for
- // /tables/{tableName}/segments/{segmentName}/metadata endpoint .
+ private static Comparable parseValue(DataType storedType, String column, String valueString) {
+ switch (storedType) {
+ case INT:
+ return Integer.valueOf(valueString);
+ case LONG:
+ return Long.valueOf(valueString);
+ case FLOAT:
+ return Float.valueOf(valueString);
+ case DOUBLE:
+ return Double.valueOf(valueString);
+ case BIG_DECIMAL:
+ return new BigDecimal(valueString);
+ case STRING:
+ return CommonsConfigurationUtils.recoverSpecialCharacterInPropertyValue(valueString);
+ case BYTES:
+ return BytesUtils.toByteArray(valueString);
+ default:
+ throw new IllegalStateException("Unsupported data type: " + storedType + " for column: " + column);
+ }
+ }
+
+ // NOTE: This method is only meant to retain compatibility of serialization for endpoint:
+ // `/tables/{tableName}/segments/{segmentName}/metadata`
@SuppressWarnings("unused")
public Map<IndexType<?, ?, ?>, Long> getIndexSizeMap() {
IndexService service = IndexService.getInstance();
- Map<IndexType<?, ?, ?>, Long> result = new HashMap<>();
-
+ Map<IndexType<?, ?, ?>, Long> result = Maps.newHashMapWithExpectedSize(_indexTypeSizeList.size());
for (long typeAndSize : _indexTypeSizeList) {
short type = unpackIndexType(typeAndSize);
long size = unpackIndexSize(typeAndSize);
result.put(service.get(type), size);
}
-
return result;
}
@@ -405,22 +436,22 @@ public class ColumnMetadataImpl implements ColumnMetadata {
private FieldSpec _fieldSpec;
private int _totalDocs;
private int _cardinality;
+ private boolean _hasDictionary;
private boolean _sorted;
private Comparable<?> _minValue;
private Comparable<?> _maxValue;
private boolean _minMaxValueInvalid;
- private boolean _hasDictionary;
- private int _columnMaxLength;
- private int _bitsPerElement;
- private int _maxNumberOfMultiValues;
+ private int _lengthOfShortestElement;
+ private int _lengthOfLongestElement;
+ private int _dictionaryElementSize;
+ private boolean _isAscii;
private int _totalNumberOfEntries;
+ private int _maxNumberOfMultiValues;
+ private int _bitsPerElement;
private PartitionFunction _partitionFunction;
private Set<Integer> _partitions;
private boolean _autoGenerated;
- // use non-default size to save space for most columns
- private LongArrayList _indexSizeList = new LongArrayList(2);
-
public Builder setFieldSpec(FieldSpec fieldSpec) {
_fieldSpec = fieldSpec;
return this;
@@ -436,6 +467,11 @@ public class ColumnMetadataImpl implements ColumnMetadata {
return this;
}
+ public Builder setHasDictionary(boolean hasDictionary) {
+ _hasDictionary = hasDictionary;
+ return this;
+ }
+
public Builder setSorted(boolean sorted) {
_sorted = sorted;
return this;
@@ -456,23 +492,23 @@ public class ColumnMetadataImpl implements ColumnMetadata {
return this;
}
- public Builder setHasDictionary(boolean hasDictionary) {
- _hasDictionary = hasDictionary;
+ public Builder setLengthOfShortestElement(int lengthOfShortestElement) {
+ _lengthOfShortestElement = lengthOfShortestElement;
return this;
}
- public Builder setColumnMaxLength(int columnMaxLength) {
- _columnMaxLength = columnMaxLength;
+ public Builder setLengthOfLongestElement(int lengthOfLongestElement) {
+ _lengthOfLongestElement = lengthOfLongestElement;
return this;
}
- public Builder setBitsPerElement(int bitsPerElement) {
- _bitsPerElement = bitsPerElement;
+ public Builder setDictionaryElementSize(int dictionaryElementSize) {
+ _dictionaryElementSize = dictionaryElementSize;
return this;
}
- public Builder setMaxNumberOfMultiValues(int maxNumberOfMultiValues) {
- _maxNumberOfMultiValues = maxNumberOfMultiValues;
+ public Builder setAscii(boolean isAscii) {
+ _isAscii = isAscii;
return this;
}
@@ -481,22 +517,24 @@ public class ColumnMetadataImpl implements ColumnMetadata {
return this;
}
- public Builder setPartitionFunction(PartitionFunction partitionFunction) {
- _partitionFunction = partitionFunction;
+ public Builder setMaxNumberOfMultiValues(int maxNumberOfMultiValues) {
+ _maxNumberOfMultiValues = maxNumberOfMultiValues;
return this;
}
- public Builder setPartitions(Set<Integer> partitions) {
- _partitions = partitions;
+ public Builder setBitsPerElement(int bitsPerElement) {
+ _bitsPerElement = bitsPerElement;
return this;
}
- public void setIndexSizeMap(Map<IndexType<?, ?, ?>, Long> indexSizeMap) {
- throw new UnsupportedOperationException("Use setIndexSizeList()");
+ public Builder setPartitionFunction(PartitionFunction partitionFunction) {
+ _partitionFunction = partitionFunction;
+ return this;
}
- public void setIndexSizeList(LongArrayList indexSizeList) {
- _indexSizeList = indexSizeList;
+ public Builder setPartitions(Set<Integer> partitions) {
+ _partitions = partitions;
+ return this;
}
public Builder setAutoGenerated(boolean autoGenerated) {
@@ -505,30 +543,32 @@ public class ColumnMetadataImpl implements ColumnMetadata {
}
public ColumnMetadataImpl build() {
- return new ColumnMetadataImpl(_fieldSpec, _totalDocs, _cardinality, _sorted, _minValue, _maxValue,
- _minMaxValueInvalid, _hasDictionary, _columnMaxLength, _bitsPerElement, _maxNumberOfMultiValues,
- _totalNumberOfEntries, _partitionFunction, _partitions, _indexSizeList, _autoGenerated);
- }
+ // Canonicalize length of shortest/longest element
+ DataType storedType = _fieldSpec.getDataType().getStoredType();
+ if (storedType.isFixedWidth()) {
+ int size = storedType.size();
+ _lengthOfShortestElement = size;
+ _lengthOfLongestElement = size;
+ } else {
+ if (_lengthOfLongestElement < 0 && _dictionaryElementSize > 0) {
+ _lengthOfLongestElement = _dictionaryElementSize;
+ }
+ }
- private Comparable<?> parseValue(DataType storedType, String column, String valueString) {
- switch (storedType) {
- case INT:
- return Integer.valueOf(valueString);
- case LONG:
- return Long.valueOf(valueString);
- case FLOAT:
- return Float.valueOf(valueString);
- case DOUBLE:
- return Double.valueOf(valueString);
- case BIG_DECIMAL:
- return new BigDecimal(valueString);
- case STRING:
- return CommonsConfigurationUtils.recoverSpecialCharacterInPropertyValue(valueString);
- case BYTES:
- return BytesUtils.toByteArray(valueString);
- default:
- throw new IllegalStateException("Unsupported data type: " + storedType + " for column: " + column);
+ // Canonicalize MV related fields
+ if (_fieldSpec.isSingleValueField()) {
+ _totalNumberOfEntries = _totalDocs;
+ _maxNumberOfMultiValues = 0;
}
+
+ // Canonicalize bits per element
+ if (!_hasDictionary) {
+ _bitsPerElement = UNAVAILABLE;
+ }
+
+ return new ColumnMetadataImpl(_fieldSpec, _totalDocs, _cardinality, _hasDictionary, _sorted, _minValue, _maxValue,
+ _minMaxValueInvalid, _lengthOfShortestElement, _lengthOfLongestElement, _isAscii, _totalNumberOfEntries,
+ _maxNumberOfMultiValues, _bitsPerElement, _partitionFunction, _partitions, _autoGenerated);
}
}
}
diff --git a/pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/index/metadata/SegmentMetadataImpl.java b/pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/index/metadata/SegmentMetadataImpl.java
index 8a8394c7f32..6064ab39f1e 100644
--- a/pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/index/metadata/SegmentMetadataImpl.java
+++ b/pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/index/metadata/SegmentMetadataImpl.java
@@ -75,8 +75,11 @@ public class SegmentMetadataImpl implements SegmentMetadata {
private final File _indexDir;
private final TreeMap<String, ColumnMetadataImpl> _columnMetadataMap;
- private String _segmentName;
private final Schema _schema;
+ private String _segmentName;
+ private int _totalDocs;
+ private SegmentVersion _segmentVersion;
+ private String _creatorName;
private long _crc = Long.MIN_VALUE;
private long _dataCrc = Long.MIN_VALUE;
private long _creationTime = Long.MIN_VALUE;
@@ -89,10 +92,7 @@ public class SegmentMetadataImpl implements SegmentMetadata {
private long _segmentEndTime = Long.MIN_VALUE;
private Interval _timeInterval;
- private SegmentVersion _segmentVersion;
private List<StarTreeV2Metadata> _starTreeV2MetadataList;
- private String _creatorName;
- private int _totalDocs;
private final Map<String, String> _customMap = new HashMap<>();
// Fields specific to realtime table
@@ -117,7 +117,6 @@ public class SegmentMetadataImpl implements SegmentMetadata {
CommonsConfigurationUtils.fromInputStream(metadataPropertiesInputStream);
init(segmentMetadataPropertiesConfiguration);
setTimeInfo(segmentMetadataPropertiesConfiguration);
- _totalDocs = segmentMetadataPropertiesConfiguration.getInt(Segment.SEGMENT_TOTAL_DOCS);
loadCreationMeta(creationMetaInputStream);
}
@@ -137,7 +136,6 @@ public class SegmentMetadataImpl implements SegmentMetadata {
SegmentMetadataUtils.getPropertiesConfiguration(indexDir);
init(segmentMetadataPropertiesConfiguration);
setTimeInfo(segmentMetadataPropertiesConfiguration);
- _totalDocs = segmentMetadataPropertiesConfiguration.getInt(Segment.SEGMENT_TOTAL_DOCS);
File creationMetaFile = SegmentDirectoryPaths.findCreationMetaFile(indexDir);
if (creationMetaFile != null) {
@@ -218,13 +216,16 @@ public class SegmentMetadataImpl implements SegmentMetadata {
private void init(PropertiesConfiguration segmentMetadata)
throws ConfigurationException {
- if (segmentMetadata.containsKey(Segment.SEGMENT_CREATOR_VERSION)) {
- _creatorName = segmentMetadata.getString(Segment.SEGMENT_CREATOR_VERSION);
- }
+ _segmentName = segmentMetadata.getString(Segment.SEGMENT_NAME);
+ _totalDocs = segmentMetadata.getInt(Segment.SEGMENT_TOTAL_DOCS);
+ _segmentVersion = segmentMetadata.getEnum(Segment.SEGMENT_VERSION, SegmentVersion.class, SegmentVersion.v1);
+ _creatorName = segmentMetadata.getString(Segment.SEGMENT_CREATOR_VERSION, null);
- String versionString =
- segmentMetadata.getString(Segment.SEGMENT_VERSION, SegmentVersion.v1.toString());
- _segmentVersion = SegmentVersion.valueOf(versionString);
+ // Set the table name (for backward compatibility)
+ String tableName = segmentMetadata.getString(Segment.TABLE_NAME);
+ if (tableName != null) {
+ _rawTableName = TableNameBuilder.extractRawTableName(tableName);
+ }
// NOTE: here we only add physical columns as virtual columns should not be loaded from metadata file
// NOTE: getList() will always return an non-null List with trimmed strings:
@@ -237,18 +238,10 @@ public class SegmentMetadataImpl implements SegmentMetadata {
addPhysicalColumns(segmentMetadata.getList(Segment.DATETIME_COLUMNS), physicalColumns);
addPhysicalColumns(segmentMetadata.getList(Segment.COMPLEX_COLUMNS), physicalColumns);
- // Set the table name (for backward compatibility)
- String tableName = segmentMetadata.getString(Segment.TABLE_NAME);
- if (tableName != null) {
- _rawTableName = TableNameBuilder.extractRawTableName(tableName);
- }
-
- // Set segment name.
- _segmentName = segmentMetadata.getString(Segment.SEGMENT_NAME);
-
// Build column metadata map and schema.
for (String column : physicalColumns) {
- ColumnMetadataImpl columnMetadata = ColumnMetadataImpl.fromPropertiesConfiguration(column, segmentMetadata);
+ ColumnMetadataImpl columnMetadata =
+ ColumnMetadataImpl.fromPropertiesConfiguration(segmentMetadata, _totalDocs, column);
_columnMetadataMap.put(column, columnMetadata);
_schema.addField(columnMetadata.getFieldSpec());
}
diff --git a/pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/index/reader/MapIndexReader.java b/pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/index/reader/MapIndexReader.java
index 8ed9963b40c..f1f6339fa33 100644
--- a/pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/index/reader/MapIndexReader.java
+++ b/pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/index/reader/MapIndexReader.java
@@ -23,8 +23,6 @@ import java.util.Set;
import org.apache.pinot.segment.spi.ColumnMetadata;
import org.apache.pinot.segment.spi.index.IndexReader;
import org.apache.pinot.segment.spi.index.IndexType;
-import org.apache.pinot.spi.data.FieldSpec;
-import org.apache.pinot.spi.data.FieldSpec.DataType;
/**
@@ -32,8 +30,8 @@ import org.apache.pinot.spi.data.FieldSpec.DataType;
*
* @param <T> Type of the ReaderContext
*/
-public interface MapIndexReader<T extends ForwardIndexReaderContext, R extends IndexReader>
- extends ForwardIndexReader<T> {
+@SuppressWarnings("rawtypes")
+public interface MapIndexReader<T extends ForwardIndexReaderContext> extends ForwardIndexReader<T> {
/**
* Returns the keys in the map index.
@@ -43,26 +41,10 @@ public interface MapIndexReader<T extends ForwardIndexReaderContext, R extends I
/**
* Returns all the indexes for the given key.
*/
- Map<IndexType, R> getKeyIndexes(String key);
-
- /**
- * Returns the reader for the given key.
- */
- IndexReader getKeyReader(String key, IndexType<?, ?, ?> indexType);
-
- /**
- * Returns the field spec of the values in the forward index.
- */
- FieldSpec getKeyFieldSpec(String key);
-
- /**
- * Returns the data type of the values in the forward index. Returns {@link DataType#INT} for dictionary-encoded
- * forward index.
- */
- DataType getKeyStoredType(String key);
+ Map<IndexType, IndexReader> getIndexes(String key);
/**
* Returns the column metadata for the given key.
*/
- ColumnMetadata getKeyMetadata(String key);
+ ColumnMetadata getColumnMetadata(String key);
}
diff --git a/pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/partition/metadata/ColumnPartitionMetadata.java b/pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/partition/metadata/ColumnPartitionMetadata.java
index 2ef55754e56..2110a5e93bd 100644
--- a/pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/partition/metadata/ColumnPartitionMetadata.java
+++ b/pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/partition/metadata/ColumnPartitionMetadata.java
@@ -25,8 +25,9 @@ import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
+import it.unimi.dsi.fastutil.ints.IntSet;
import java.io.IOException;
-import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -113,10 +114,10 @@ public class ColumnPartitionMetadata {
* TODO: remove range format once all segments use integer format
* </ul>
*/
- public static Set<Integer> extractPartitions(List partitionList) {
- Set<Integer> partitions = new HashSet<>();
- for (Object o : partitionList) {
- String partitionString = o.toString();
+ public static IntSet extractPartitions(List<Object> partitionList) {
+ IntSet partitions = new IntOpenHashSet(partitionList.size());
+ for (Object partition : partitionList) {
+ String partitionString = partition.toString();
if (partitionString.charAt(0) == '[') {
// Range format
addRangeToPartitions(partitionString, partitions);
@@ -130,7 +131,7 @@ public class ColumnPartitionMetadata {
/**
* Helper method to add a partition range to a set of partitions.
*/
- private static void addRangeToPartitions(String rangeString, Set<Integer> partitions) {
+ private static void addRangeToPartitions(String rangeString, IntSet partitions) {
int delimiterIndex = rangeString.indexOf(' ');
int start = Integer.parseInt(rangeString.substring(1, delimiterIndex));
int end = Integer.parseInt(rangeString.substring(delimiterIndex + 1, rangeString.length() - 1));
@@ -159,15 +160,17 @@ public class ColumnPartitionMetadata {
public ColumnPartitionMetadata deserialize(JsonParser p, DeserializationContext ctxt)
throws IOException {
JsonNode jsonMetadata = p.getCodec().readTree(p);
- Set<Integer> partitions = new HashSet<>();
+ IntSet partitions;
JsonNode jsonPartitions = jsonMetadata.get(PARTITIONS_KEY);
if (jsonPartitions != null) {
// Integer format: "partitions":[0,1,5]
+ partitions = new IntOpenHashSet(jsonPartitions.size());
for (JsonNode jsonPartition : jsonPartitions) {
partitions.add(jsonPartition.asInt());
}
} else {
// Legacy format: "partitionRanges":"[0 1],[5 5]"
+ partitions = new IntOpenHashSet();
String partitionRanges = jsonMetadata.get(LEGACY_PARTITIONS_KEY).asText();
for (String partitionRange : StringUtils.split(partitionRanges, LEGACY_PARTITION_DELIMITER)) {
addRangeToPartitions(partitionRange, partitions);
@@ -175,11 +178,9 @@ public class ColumnPartitionMetadata {
}
Map<String, String> functionConfig = null;
if (jsonMetadata.has(FUNCTION_CONFIG_KEY)) {
- functionConfig =
- JsonUtils.jsonNodeToObject(jsonMetadata.get(FUNCTION_CONFIG_KEY), new TypeReference<Map<String, String>>() {
- });
+ functionConfig = JsonUtils.jsonNodeToObject(jsonMetadata.get(FUNCTION_CONFIG_KEY), new TypeReference<>() {
+ });
}
-
return new ColumnPartitionMetadata(jsonMetadata.get(FUNCTION_NAME_KEY).asText(),
jsonMetadata.get(NUM_PARTITIONS_KEY).asInt(), partitions, functionConfig);
}
diff --git a/pinot-server/src/main/java/org/apache/pinot/server/api/resources/TablesResource.java b/pinot-server/src/main/java/org/apache/pinot/server/api/resources/TablesResource.java
index f394c51097d..dd3409d7703 100644
--- a/pinot-server/src/main/java/org/apache/pinot/server/api/resources/TablesResource.java
+++ b/pinot-server/src/main/java/org/apache/pinot/server/api/resources/TablesResource.java
@@ -32,6 +32,7 @@ import io.swagger.annotations.SecurityDefinition;
import io.swagger.annotations.SwaggerDefinition;
import java.io.File;
import java.io.IOException;
+import java.math.BigDecimal;
import java.net.URI;
import java.nio.file.Files;
import java.util.ArrayList;
@@ -109,11 +110,11 @@ import org.apache.pinot.server.api.AdminApiApplication;
import org.apache.pinot.server.starter.ServerInstance;
import org.apache.pinot.spi.config.table.TableType;
import org.apache.pinot.spi.data.FieldSpec;
-import org.apache.pinot.spi.data.FieldSpec.DataType;
import org.apache.pinot.spi.stream.ConsumerPartitionState;
import org.apache.pinot.spi.stream.PartitionLagState;
import org.apache.pinot.spi.stream.StreamMetadataProvider;
import org.apache.pinot.spi.stream.StreamPartitionMsgOffset;
+import org.apache.pinot.spi.utils.BigDecimalUtils;
import org.apache.pinot.spi.utils.ByteArray;
import org.apache.pinot.spi.utils.CommonConstants;
import org.apache.pinot.spi.utils.CommonConstants.Helix.StateModel.SegmentStateModel;
@@ -246,23 +247,16 @@ public class TablesResource {
}
for (String column : columnSet) {
ColumnMetadata columnMetadata = segmentMetadata.getColumnMetadataMap().get(column);
- int columnLength;
- DataType storedType = columnMetadata.getDataType().getStoredType();
- if (storedType.isFixedWidth()) {
- // For type of fixed width: INT, LONG, FLOAT, DOUBLE, BOOLEAN (stored as INT), TIMESTAMP (stored as LONG),
- // set the columnLength as the fixed width.
- columnLength = storedType.size();
- } else if (columnMetadata.hasDictionary()) {
- // For type of variable width (String, Bytes), if it's stored using dictionary encoding, set the
- // columnLength as the max length in dictionary.
- columnLength = columnMetadata.getColumnMaxLength();
- } else {
- // For raw STRING/BYTES column, set the columnLength as the length of the max value.
+ int columnLength = columnMetadata.getLengthOfLongestElement();
+ if (columnLength < 0) {
+ // For raw STRING/BYTES/BIG_DECIMAL column, set the columnLength as the length of the max value.
Comparable<?> maxValue = columnMetadata.getMaxValue();
if (maxValue instanceof String) {
columnLength = Utf8.encodedLength((String) maxValue);
} else if (maxValue instanceof ByteArray) {
columnLength = ((ByteArray) maxValue).length();
+ } else if (maxValue instanceof BigDecimal) {
+ columnLength = BigDecimalUtils.byteSize((BigDecimal) maxValue);
} else {
// For type of STRUCT, MAP, LIST, set the columnLength as DEFAULT_MAX_LENGTH (512).
columnLength = FieldSpec.DEFAULT_MAX_LENGTH;
diff --git a/pinot-server/src/test/java/org/apache/pinot/server/api/BaseResourceTest.java b/pinot-server/src/test/java/org/apache/pinot/server/api/BaseResourceTest.java
index a15222d2cc0..71dba3a61bf 100644
--- a/pinot-server/src/test/java/org/apache/pinot/server/api/BaseResourceTest.java
+++ b/pinot-server/src/test/java/org/apache/pinot/server/api/BaseResourceTest.java
@@ -76,22 +76,18 @@ import static org.testng.Assert.assertTrue;
public abstract class BaseResourceTest {
- protected String getAvroFileName() {
- return "data/test_data-mv.avro";
- }
-
- private static final File TEMP_DIR = new File(FileUtils.getTempDirectory(), "BaseResourceTest");
- protected static final String TABLE_NAME = "testTable";
+ protected static final File TEMP_DIR = new File(FileUtils.getTempDirectory(), "BaseResourceTest");
+ protected static final String RAW_TABLE_NAME = "testTable";
+ protected static final String REALTIME_TABLE_NAME = TableNameBuilder.REALTIME.tableNameWithType(RAW_TABLE_NAME);
+ protected static final String OFFLINE_TABLE_NAME = TableNameBuilder.OFFLINE.tableNameWithType(RAW_TABLE_NAME);
protected static final String LLC_SEGMENT_NAME_FOR_UPLOAD_SUCCESS =
- new LLCSegmentName(TableNameBuilder.REALTIME.tableNameWithType(TABLE_NAME), 1, 0,
- System.currentTimeMillis()).getSegmentName();
+ new LLCSegmentName(REALTIME_TABLE_NAME, 1, 0, System.currentTimeMillis()).getSegmentName();
protected static final String LLC_SEGMENT_NAME_FOR_UPLOAD_FAILURE =
- new LLCSegmentName(TableNameBuilder.REALTIME.tableNameWithType(TABLE_NAME), 2, 0,
- System.currentTimeMillis()).getSegmentName();
+ new LLCSegmentName(REALTIME_TABLE_NAME, 2, 0, System.currentTimeMillis()).getSegmentName();
protected static final String SEGMENT_DOWNLOAD_URL =
- StringUtil.join("/", "hdfs://root", TABLE_NAME, LLC_SEGMENT_NAME_FOR_UPLOAD_SUCCESS);
+ StringUtil.join("/", "hdfs://root", RAW_TABLE_NAME, LLC_SEGMENT_NAME_FOR_UPLOAD_SUCCESS);
- private final Map<String, TableDataManager> _tableDataManagerMap = new HashMap<>();
+ protected final Map<String, TableDataManager> _tableDataManagerMap = new HashMap<>();
protected final List<ImmutableSegment> _realtimeIndexSegments = new ArrayList<>();
protected final List<ImmutableSegment> _offlineIndexSegments = new ArrayList<>();
protected File _avroFile;
@@ -100,6 +96,10 @@ public abstract class BaseResourceTest {
protected String _instanceId;
protected ServerInstance _serverInstance;
+ protected String getAvroFileName() {
+ return "data/test_data-mv.avro";
+ }
+
@SuppressWarnings("SuspiciousMethodCalls")
@BeforeClass
public void setUp()
@@ -142,13 +142,10 @@ public abstract class BaseResourceTest {
when(instanceDataManager.getSegmentUploader()).thenReturn(segmentUploader);
// Add the default tables and segments.
- String realtimeTableName = TableNameBuilder.REALTIME.tableNameWithType(TABLE_NAME);
- String offlineTableName = TableNameBuilder.OFFLINE.tableNameWithType(TABLE_NAME);
-
- addTable(realtimeTableName);
- addTable(offlineTableName);
- setUpSegment(realtimeTableName, null, "default", _realtimeIndexSegments);
- setUpSegment(offlineTableName, null, "default", _offlineIndexSegments);
+ addTable(REALTIME_TABLE_NAME);
+ addTable(OFFLINE_TABLE_NAME);
+ setUpSegment(REALTIME_TABLE_NAME, null, "default", _realtimeIndexSegments);
+ setUpSegment(OFFLINE_TABLE_NAME, null, "default", _offlineIndexSegments);
PinotConfiguration serverConf = new PinotConfiguration();
String hostname = serverConf.getProperty(CommonConstants.Helix.KEY_OF_SERVER_NETTY_HOST,
@@ -188,8 +185,7 @@ public abstract class BaseResourceTest {
throws Exception {
List<ImmutableSegment> immutableSegments = new ArrayList<>();
for (int i = 0; i < numSegments; i++) {
- immutableSegments.add(
- setUpSegment(tableNameWithType, null, Integer.toString(_realtimeIndexSegments.size()), segments));
+ immutableSegments.add(setUpSegment(tableNameWithType, null, Integer.toString(segments.size()), segments));
}
return immutableSegments;
}
diff --git a/pinot-server/src/test/java/org/apache/pinot/server/api/TableSizeResourceTest.java b/pinot-server/src/test/java/org/apache/pinot/server/api/TableSizeResourceTest.java
index 8c8eed6e821..ed2b7c72734 100644
--- a/pinot-server/src/test/java/org/apache/pinot/server/api/TableSizeResourceTest.java
+++ b/pinot-server/src/test/java/org/apache/pinot/server/api/TableSizeResourceTest.java
@@ -21,7 +21,6 @@ package org.apache.pinot.server.api;
import javax.ws.rs.core.Response;
import org.apache.pinot.common.restlet.resources.TableSizeInfo;
import org.apache.pinot.segment.spi.ImmutableSegment;
-import org.apache.pinot.spi.utils.builder.TableNameBuilder;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -35,8 +34,8 @@ public class TableSizeResourceTest extends BaseResourceTest {
@Test
public void testTableSizeDetailed() {
- verifyTableSizeDetailedImpl(TableNameBuilder.REALTIME.tableNameWithType(TABLE_NAME), _realtimeIndexSegments.get(0));
- verifyTableSizeDetailedImpl(TableNameBuilder.OFFLINE.tableNameWithType(TABLE_NAME), _offlineIndexSegments.get(0));
+ verifyTableSizeDetailedImpl(REALTIME_TABLE_NAME, _realtimeIndexSegments.get(0));
+ verifyTableSizeDetailedImpl(OFFLINE_TABLE_NAME, _offlineIndexSegments.get(0));
}
private void verifyTableSizeDetailedImpl(String expectedTableName, ImmutableSegment segment) {
@@ -53,9 +52,8 @@ public class TableSizeResourceTest extends BaseResourceTest {
@Test
public void testTableSizeNoDetails() {
- verifyTableSizeNoDetailsImpl(TableNameBuilder.REALTIME.tableNameWithType(TABLE_NAME),
- _realtimeIndexSegments.get(0));
- verifyTableSizeNoDetailsImpl(TableNameBuilder.OFFLINE.tableNameWithType(TABLE_NAME), _offlineIndexSegments.get(0));
+ verifyTableSizeNoDetailsImpl(REALTIME_TABLE_NAME, _realtimeIndexSegments.get(0));
+ verifyTableSizeNoDetailsImpl(OFFLINE_TABLE_NAME, _offlineIndexSegments.get(0));
}
private void verifyTableSizeNoDetailsImpl(String expectedTableName, ImmutableSegment segment) {
@@ -70,8 +68,8 @@ public class TableSizeResourceTest extends BaseResourceTest {
@Test
public void testTableSizeOld() {
- verifyTableSizeOldImpl(TableNameBuilder.REALTIME.tableNameWithType(TABLE_NAME), _realtimeIndexSegments.get(0));
- verifyTableSizeOldImpl(TableNameBuilder.OFFLINE.tableNameWithType(TABLE_NAME), _offlineIndexSegments.get(0));
+ verifyTableSizeOldImpl(REALTIME_TABLE_NAME, _realtimeIndexSegments.get(0));
+ verifyTableSizeOldImpl(OFFLINE_TABLE_NAME, _offlineIndexSegments.get(0));
}
private void verifyTableSizeOldImpl(String expectedTableName, ImmutableSegment segment) {
diff --git a/pinot-server/src/test/java/org/apache/pinot/server/api/TableTierResourceTest.java b/pinot-server/src/test/java/org/apache/pinot/server/api/TableTierResourceTest.java
index e6d53587ebf..61c6f94ddab 100644
--- a/pinot-server/src/test/java/org/apache/pinot/server/api/TableTierResourceTest.java
+++ b/pinot-server/src/test/java/org/apache/pinot/server/api/TableTierResourceTest.java
@@ -22,7 +22,6 @@ import java.util.Collections;
import javax.ws.rs.core.Response;
import org.apache.pinot.common.restlet.resources.TableTierInfo;
import org.apache.pinot.segment.spi.ImmutableSegment;
-import org.apache.pinot.spi.utils.builder.TableNameBuilder;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
@@ -37,34 +36,30 @@ public class TableTierResourceTest extends BaseResourceTest {
@Test
public void testSegmentNotFound() {
- String tableName = TableNameBuilder.OFFLINE.tableNameWithType(TABLE_NAME);
- Response response =
- _webTarget.path(String.format("segments/%s/unknownSegment/tiers", tableName)).request().get(Response.class);
+ Response response = _webTarget.path(String.format("segments/%s/unknownSegment/tiers", OFFLINE_TABLE_NAME))
+ .request()
+ .get(Response.class);
assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode());
}
@Test
public void testTableTierInfo() {
- String tableName = TableNameBuilder.REALTIME.tableNameWithType(TABLE_NAME);
- String requestPath = "/tables/" + tableName + "/tiers";
- verifyTableTierInfo(requestPath, tableName, _realtimeIndexSegments.get(0));
+ String requestPath = "/tables/" + REALTIME_TABLE_NAME + "/tiers";
+ verifyTableTierInfo(requestPath, REALTIME_TABLE_NAME, _realtimeIndexSegments.get(0));
- tableName = TableNameBuilder.OFFLINE.tableNameWithType(TABLE_NAME);
- requestPath = "/tables/" + tableName + "/tiers";
- verifyTableTierInfo(requestPath, tableName, _offlineIndexSegments.get(0));
+ requestPath = "/tables/" + OFFLINE_TABLE_NAME + "/tiers";
+ verifyTableTierInfo(requestPath, OFFLINE_TABLE_NAME, _offlineIndexSegments.get(0));
}
@Test
public void testTableSegmentTierInfo() {
- String tableName = TableNameBuilder.REALTIME.tableNameWithType(TABLE_NAME);
ImmutableSegment segment = _realtimeIndexSegments.get(0);
- String requestPath = "/segments/" + tableName + "/" + segment.getSegmentName() + "/tiers";
- verifyTableTierInfo(requestPath, tableName, segment);
+ String requestPath = "/segments/" + REALTIME_TABLE_NAME + "/" + segment.getSegmentName() + "/tiers";
+ verifyTableTierInfo(requestPath, REALTIME_TABLE_NAME, segment);
- tableName = TableNameBuilder.OFFLINE.tableNameWithType(TABLE_NAME);
segment = _offlineIndexSegments.get(0);
- requestPath = "/segments/" + tableName + "/" + segment.getSegmentName() + "/tiers";
- verifyTableTierInfo(requestPath, tableName, segment);
+ requestPath = "/segments/" + OFFLINE_TABLE_NAME + "/" + segment.getSegmentName() + "/tiers";
+ verifyTableTierInfo(requestPath, OFFLINE_TABLE_NAME, segment);
}
private void verifyTableTierInfo(String requestPath, String expectedTableName, ImmutableSegment segment) {
diff --git a/pinot-server/src/test/java/org/apache/pinot/server/api/TablesResourceTest.java b/pinot-server/src/test/java/org/apache/pinot/server/api/TablesResourceTest.java
index 3b62cc2a3d4..f43c2f52875 100644
--- a/pinot-server/src/test/java/org/apache/pinot/server/api/TablesResourceTest.java
+++ b/pinot-server/src/test/java/org/apache/pinot/server/api/TablesResourceTest.java
@@ -60,6 +60,7 @@ import static org.mockito.Mockito.mock;
public class TablesResourceTest extends BaseResourceTest {
+
@Test
public void getTables()
throws Exception {
@@ -73,8 +74,8 @@ public class TablesResourceTest extends BaseResourceTest {
List<String> tables = tablesList.getTables();
Assert.assertNotNull(tables);
Assert.assertEquals(tables.size(), 2);
- Assert.assertEquals(tables.get(0), TableNameBuilder.REALTIME.tableNameWithType(TABLE_NAME));
- Assert.assertEquals(tables.get(1), TableNameBuilder.OFFLINE.tableNameWithType(TABLE_NAME));
+ Assert.assertEquals(tables.get(0), REALTIME_TABLE_NAME);
+ Assert.assertEquals(tables.get(1), OFFLINE_TABLE_NAME);
String secondTable = "secondTable_REALTIME";
addTable(secondTable);
@@ -86,15 +87,15 @@ public class TablesResourceTest extends BaseResourceTest {
tables = tablesList.getTables();
Assert.assertNotNull(tables);
Assert.assertEquals(tables.size(), 3);
- Assert.assertTrue(tables.contains(TableNameBuilder.REALTIME.tableNameWithType(TABLE_NAME)));
+ Assert.assertTrue(tables.contains(REALTIME_TABLE_NAME));
Assert.assertTrue(tables.contains(secondTable));
- Assert.assertTrue(tables.contains(TableNameBuilder.OFFLINE.tableNameWithType(TABLE_NAME)));
+ Assert.assertTrue(tables.contains(OFFLINE_TABLE_NAME));
}
@Test
public void getSegments()
throws Exception {
- String segmentsPath = "/tables/" + TableNameBuilder.REALTIME.tableNameWithType(TABLE_NAME) + "/segments";
+ String segmentsPath = "/tables/" + REALTIME_TABLE_NAME + "/segments";
IndexSegment defaultSegment = _realtimeIndexSegments.get(0);
TableSegments tableSegments = _webTarget.path(segmentsPath).request().get(TableSegments.class);
@@ -104,8 +105,7 @@ public class TablesResourceTest extends BaseResourceTest {
Assert.assertEquals(segmentNames.size(), 1);
Assert.assertEquals(segmentNames.get(0), _realtimeIndexSegments.get(0).getSegmentName());
- IndexSegment secondSegment =
- setUpSegment(TableNameBuilder.REALTIME.tableNameWithType(TABLE_NAME), null, "0", _realtimeIndexSegments);
+ IndexSegment secondSegment = setUpSegment(REALTIME_TABLE_NAME, null, "0", _realtimeIndexSegments);
tableSegments = _webTarget.path(segmentsPath).request().get(TableSegments.class);
Assert.assertNotNull(tableSegments);
segmentNames = tableSegments.getSegments();
@@ -123,8 +123,7 @@ public class TablesResourceTest extends BaseResourceTest {
@Test
public void getTableIndexes()
throws Exception {
- String tableIndexesPath =
- "/tables/" + TableNameBuilder.forType(TableType.OFFLINE).tableNameWithType(TABLE_NAME) + "/indexes";
+ String tableIndexesPath = "/tables/" + OFFLINE_TABLE_NAME + "/indexes";
JsonNode jsonResponse = JsonUtils.stringToJsonNode(_webTarget.path(tableIndexesPath).request().get(String.class));
TableIndexMetadataResponse tableIndexMetadataResponse =
@@ -156,22 +155,23 @@ public class TablesResourceTest extends BaseResourceTest {
public void getTableMetadata()
throws Exception {
for (TableType tableType : TableType.values()) {
- String tableMetadataPath =
- "/tables/" + TableNameBuilder.forType(tableType).tableNameWithType(TABLE_NAME) + "/metadata";
+ String tableNameWithType = TableNameBuilder.forType(tableType).tableNameWithType(RAW_TABLE_NAME);
+ String tableMetadataPath = "/tables/" + tableNameWithType + "/metadata";
JsonNode jsonResponse =
JsonUtils.stringToJsonNode(_webTarget.path(tableMetadataPath).request().get(String.class));
TableMetadataInfo metadataInfo = JsonUtils.jsonNodeToObject(jsonResponse, TableMetadataInfo.class);
Assert.assertNotNull(metadataInfo);
- Assert.assertEquals(metadataInfo.getTableName(),
- TableNameBuilder.forType(tableType).tableNameWithType(TABLE_NAME));
+ Assert.assertEquals(metadataInfo.getTableName(), tableNameWithType);
Assert.assertEquals(metadataInfo.getColumnLengthMap().size(), 0);
Assert.assertEquals(metadataInfo.getColumnCardinalityMap().size(), 0);
Assert.assertEquals(metadataInfo.getColumnIndexSizeMap().size(), 0);
- jsonResponse = JsonUtils.stringToJsonNode(
- _webTarget.path(tableMetadataPath).queryParam("columns", "column1").queryParam("columns", "column2").request()
- .get(String.class));
+ jsonResponse = JsonUtils.stringToJsonNode(_webTarget.path(tableMetadataPath)
+ .queryParam("columns", "column1")
+ .queryParam("columns", "column2")
+ .request()
+ .get(String.class));
metadataInfo = JsonUtils.jsonNodeToObject(jsonResponse, TableMetadataInfo.class);
Assert.assertEquals(metadataInfo.getColumnLengthMap().size(), 2);
Assert.assertEquals(metadataInfo.getColumnCardinalityMap().size(), 2);
@@ -192,8 +192,8 @@ public class TablesResourceTest extends BaseResourceTest {
public void testSegmentMetadata()
throws Exception {
IndexSegment defaultSegment = _realtimeIndexSegments.get(0);
- String segmentMetadataPath = "/tables/" + TableNameBuilder.REALTIME.tableNameWithType(TABLE_NAME) + "/segments/"
- + defaultSegment.getSegmentName() + "/metadata";
+ String segmentMetadataPath =
+ "/tables/" + REALTIME_TABLE_NAME + "/segments/" + defaultSegment.getSegmentName() + "/metadata";
JsonNode jsonResponse =
JsonUtils.stringToJsonNode(_webTarget.path(segmentMetadataPath).request().get(String.class));
@@ -207,9 +207,11 @@ public class TablesResourceTest extends BaseResourceTest {
Assert.assertEquals(jsonResponse.get("columns").size(), 0);
Assert.assertEquals(jsonResponse.get("indexes").size(), 0);
- jsonResponse = JsonUtils.stringToJsonNode(
- _webTarget.path(segmentMetadataPath).queryParam("columns", "column1").queryParam("columns", "column2").request()
- .get(String.class));
+ jsonResponse = JsonUtils.stringToJsonNode(_webTarget.path(segmentMetadataPath)
+ .queryParam("columns", "column1")
+ .queryParam("columns", "column2")
+ .request()
+ .get(String.class));
Assert.assertEquals(jsonResponse.get("columns").size(), 2);
Assert.assertEquals(jsonResponse.get("indexes").size(), 2);
Assert.assertNotNull(jsonResponse.get("columns").get(0).get("indexSizeMap"));
@@ -231,13 +233,13 @@ public class TablesResourceTest extends BaseResourceTest {
Assert.assertEquals(jsonResponse.get("columns").size(), physicalColumnCount);
Assert.assertEquals(jsonResponse.get("indexes").size(), physicalColumnCount);
- Response response = _webTarget.path("/tables/UNKNOWN_TABLE/segments/" + defaultSegment.getSegmentName()).request()
+ Response response = _webTarget.path("/tables/UNKNOWN_TABLE/segments/" + defaultSegment.getSegmentName())
+ .request()
.get(Response.class);
Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode());
- response = _webTarget.path(
- "/tables/" + TableNameBuilder.REALTIME.tableNameWithType(TABLE_NAME) + "/segments/UNKNOWN_SEGMENT")
- .request().get(Response.class);
+ response =
+ _webTarget.path("/tables/" + REALTIME_TABLE_NAME + "/segments/UNKNOWN_SEGMENT").request().get(Response.class);
Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode());
}
@@ -245,12 +247,12 @@ public class TablesResourceTest extends BaseResourceTest {
public void testSegmentsMetadata()
throws Exception {
IndexSegment defaultSegment = _realtimeIndexSegments.get(0);
- String segmentMetadataPath = "/tables/" + TableNameBuilder.REALTIME.tableNameWithType(TABLE_NAME)
- + "/segments/metadata";
+ String segmentMetadataPath = "/tables/" + REALTIME_TABLE_NAME + "/segments/metadata";
String segmentName = defaultSegment.getSegmentName();
- JsonNode jsonResponse = JsonUtils.stringToJsonNode((_webTarget.path(segmentMetadataPath)
- .queryParam("segmentsToInclude", segmentName)).request().get(String.class));
+ JsonNode jsonResponse = JsonUtils.stringToJsonNode(
+ (_webTarget.path(segmentMetadataPath).queryParam("segmentsToInclude", segmentName)).request()
+ .get(String.class));
JsonNode jsonNode = jsonResponse.get(segmentName);
SegmentMetadata segmentMetadata = defaultSegment.getSegmentMetadata();
Assert.assertEquals(jsonNode.get("segmentName").asText(), segmentMetadata.getName());
@@ -262,9 +264,12 @@ public class TablesResourceTest extends BaseResourceTest {
Assert.assertEquals(jsonNode.get("columns").size(), 0);
Assert.assertEquals(jsonNode.get("indexes").size(), 0);
- jsonResponse = JsonUtils.stringToJsonNode(
- _webTarget.path(segmentMetadataPath).queryParam("columns", "column1").queryParam("columns", "column2")
- .queryParam("segmentsToInclude", segmentName).request().get(String.class));
+ jsonResponse = JsonUtils.stringToJsonNode(_webTarget.path(segmentMetadataPath)
+ .queryParam("columns", "column1")
+ .queryParam("columns", "column2")
+ .queryParam("segmentsToInclude", segmentName)
+ .request()
+ .get(String.class));
jsonNode = jsonResponse.get(segmentName);
Assert.assertEquals(jsonNode.get("columns").size(), 2);
Assert.assertEquals(jsonNode.get("indexes").size(), 2);
@@ -278,7 +283,10 @@ public class TablesResourceTest extends BaseResourceTest {
Assert.assertEquals(jsonNode.get("indexes").get("column2").get("text-index").asText(), "NO");
jsonResponse = JsonUtils.stringToJsonNode((_webTarget.path(segmentMetadataPath)
- .queryParam("columns", "*").queryParam("segmentsToInclude", segmentName).request().get(String.class)));
+ .queryParam("columns", "*")
+ .queryParam("segmentsToInclude", segmentName)
+ .request()
+ .get(String.class)));
int physicalColumnCount = defaultSegment.getPhysicalColumnNames().size();
jsonNode = jsonResponse.get(segmentName);
Assert.assertEquals(jsonNode.get("columns").size(), physicalColumnCount);
@@ -288,11 +296,10 @@ public class TablesResourceTest extends BaseResourceTest {
@Test
public void testSegmentCrcMetadata()
throws Exception {
- String segmentsCrcPath = "/tables/" + TableNameBuilder.REALTIME.tableNameWithType(TABLE_NAME) + "/segments/crc";
+ String segmentsCrcPath = "/tables/" + REALTIME_TABLE_NAME + "/segments/crc";
// Upload segments
- List<ImmutableSegment> immutableSegments =
- setUpSegments(TableNameBuilder.REALTIME.tableNameWithType(TABLE_NAME), 2, _realtimeIndexSegments);
+ List<ImmutableSegment> immutableSegments = setUpSegments(REALTIME_TABLE_NAME, 2, _realtimeIndexSegments);
// Trigger crc api to fetch crc information
String response = _webTarget.path(segmentsCrcPath).request().get(String.class);
@@ -310,19 +317,16 @@ public class TablesResourceTest extends BaseResourceTest {
public void testDownloadSegments()
throws Exception {
// Verify the content of the downloaded segment from a realtime table.
- downLoadAndVerifySegmentContent(TableNameBuilder.REALTIME.tableNameWithType(TABLE_NAME),
- _realtimeIndexSegments.get(0));
+ downloadAndVerifySegmentContent(REALTIME_TABLE_NAME, _realtimeIndexSegments.get(0));
// Verify the content of the downloaded segment from an offline table.
- downLoadAndVerifySegmentContent(TableNameBuilder.OFFLINE.tableNameWithType(TABLE_NAME),
- _offlineIndexSegments.get(0));
+ downloadAndVerifySegmentContent(OFFLINE_TABLE_NAME, _offlineIndexSegments.get(0));
// Verify non-existent table and segment download return NOT_FOUND status.
Response response = _webTarget.path("/tables/UNKNOWN_REALTIME/segments/segmentname").request().get(Response.class);
Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode());
- response = _webTarget.path(
- "/tables/" + TableNameBuilder.REALTIME.tableNameWithType(TABLE_NAME) + "/segments/UNKNOWN_SEGMENT")
- .request().get(Response.class);
+ response =
+ _webTarget.path("/tables/" + REALTIME_TABLE_NAME + "/segments/UNKNOWN_SEGMENT").request().get(Response.class);
Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode());
}
@@ -330,9 +334,8 @@ public class TablesResourceTest extends BaseResourceTest {
public void testDownloadValidDocIdsSnapshot()
throws Exception {
// Verify the content of the downloaded snapshot from a realtime table.
- downLoadAndVerifyValidDocIdsSnapshot(TableNameBuilder.REALTIME.tableNameWithType(TABLE_NAME),
- (ImmutableSegmentImpl) _realtimeIndexSegments.get(0));
- downLoadAndVerifyValidDocIdsSnapshotBitmap(TableNameBuilder.REALTIME.tableNameWithType(TABLE_NAME),
+ downLoadAndVerifyValidDocIdsSnapshot(REALTIME_TABLE_NAME, (ImmutableSegmentImpl) _realtimeIndexSegments.get(0));
+ downLoadAndVerifyValidDocIdsSnapshotBitmap(REALTIME_TABLE_NAME,
(ImmutableSegmentImpl) _realtimeIndexSegments.get(0));
// Verify non-existent table and segment download return NOT_FOUND status.
@@ -340,9 +343,10 @@ public class TablesResourceTest extends BaseResourceTest {
_webTarget.path("/tables/UNKNOWN_REALTIME/segments/segmentname/validDocIds").request().get(Response.class);
Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode());
- response = _webTarget.path(
- String.format("/tables/%s/segments/%s/validDocIds", TableNameBuilder.REALTIME.tableNameWithType(TABLE_NAME),
- "UNKNOWN_SEGMENT")).request().get(Response.class);
+ response =
+ _webTarget.path(String.format("/tables/%s/segments/%s/validDocIds", REALTIME_TABLE_NAME, "UNKNOWN_SEGMENT"))
+ .request()
+ .get(Response.class);
Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode());
}
@@ -352,22 +356,20 @@ public class TablesResourceTest extends BaseResourceTest {
throws IOException {
IndexSegment segment = _realtimeIndexSegments.get(0);
// Verify the content of the downloaded snapshot from a realtime table.
- downLoadAndVerifyValidDocIdsSnapshot(TableNameBuilder.REALTIME.tableNameWithType(TABLE_NAME),
- (ImmutableSegmentImpl) segment);
- downLoadAndVerifyValidDocIdsSnapshotBitmap(TableNameBuilder.REALTIME.tableNameWithType(TABLE_NAME),
- (ImmutableSegmentImpl) segment);
-
- String validDocIdMetadataPath =
- "/tables/" + TableNameBuilder.REALTIME.tableNameWithType(TABLE_NAME) + "/validDocIdMetadata";
- String metadataResponse =
- _webTarget.path(validDocIdMetadataPath).queryParam("segmentNames", segment.getSegmentName()).request()
- .get(String.class);
+ downLoadAndVerifyValidDocIdsSnapshot(REALTIME_TABLE_NAME, (ImmutableSegmentImpl) segment);
+ downLoadAndVerifyValidDocIdsSnapshotBitmap(REALTIME_TABLE_NAME, (ImmutableSegmentImpl) segment);
+
+ String validDocIdMetadataPath = "/tables/" + REALTIME_TABLE_NAME + "/validDocIdMetadata";
+ String metadataResponse = _webTarget.path(validDocIdMetadataPath)
+ .queryParam("segmentNames", segment.getSegmentName())
+ .request()
+ .get(String.class);
JsonNode validDocIdMetadata = JsonUtils.stringToJsonNode(metadataResponse).get(0);
Assert.assertEquals(validDocIdMetadata.get("totalDocs").asInt(), 200000);
Assert.assertEquals(validDocIdMetadata.get("totalValidDocs").asInt(), 8);
Assert.assertEquals(validDocIdMetadata.get("totalInvalidDocs").asInt(), 199992);
- Assert.assertEquals(validDocIdMetadata.get("segmentCrc").asText(), "187068486");
+ Assert.assertEquals(validDocIdMetadata.get("segmentCrc").asText(), segment.getSegmentMetadata().getCrc());
Assert.assertEquals(validDocIdMetadata.get("validDocIdsType").asText(), "SNAPSHOT");
}
@@ -376,26 +378,25 @@ public class TablesResourceTest extends BaseResourceTest {
throws IOException {
IndexSegment segment = _realtimeIndexSegments.get(0);
// Verify the content of the downloaded snapshot from a realtime table.
- downLoadAndVerifyValidDocIdsSnapshot(TableNameBuilder.REALTIME.tableNameWithType(TABLE_NAME),
- (ImmutableSegmentImpl) segment);
- downLoadAndVerifyValidDocIdsSnapshotBitmap(TableNameBuilder.REALTIME.tableNameWithType(TABLE_NAME),
- (ImmutableSegmentImpl) segment);
+ downLoadAndVerifyValidDocIdsSnapshot(REALTIME_TABLE_NAME, (ImmutableSegmentImpl) segment);
+ downLoadAndVerifyValidDocIdsSnapshotBitmap(REALTIME_TABLE_NAME, (ImmutableSegmentImpl) segment);
List<String> segments = List.of(segment.getSegmentName());
TableSegments tableSegments = new TableSegments(segments);
- String validDocIdsMetadataPath =
- "/tables/" + TableNameBuilder.REALTIME.tableNameWithType(TABLE_NAME) + "/validDocIdsMetadata";
- String response =
- _webTarget.path(validDocIdsMetadataPath).queryParam("segmentNames", segment.getSegmentName()).request()
- .post(Entity.json(tableSegments), String.class);
+ String validDocIdsMetadataPath = "/tables/" + REALTIME_TABLE_NAME + "/validDocIdsMetadata";
+ String response = _webTarget.path(validDocIdsMetadataPath)
+ .queryParam("segmentNames", segment.getSegmentName())
+ .request()
+ .post(Entity.json(tableSegments), String.class);
JsonNode validDocIdsMetadata = JsonUtils.stringToJsonNode(response).get(0);
Assert.assertEquals(validDocIdsMetadata.get("totalDocs").asInt(), 200000);
Assert.assertEquals(validDocIdsMetadata.get("totalValidDocs").asInt(), 8);
Assert.assertEquals(validDocIdsMetadata.get("totalInvalidDocs").asInt(), 199992);
- Assert.assertEquals(validDocIdsMetadata.get("segmentCrc").asText(), "187068486");
+ Assert.assertEquals(validDocIdsMetadata.get("segmentCrc").asText(), segment.getSegmentMetadata().getCrc());
Assert.assertEquals(validDocIdsMetadata.get("validDocIdsType").asText(), "SNAPSHOT");
- Assert.assertEquals(validDocIdsMetadata.get("segmentSizeInBytes").asLong(), 4514731);
+ Assert.assertEquals(validDocIdsMetadata.get("segmentSizeInBytes").asLong(),
+ ((ImmutableSegmentImpl) segment).getSegmentSizeBytes());
Assert.assertTrue(validDocIdsMetadata.has("segmentCreationTimeMillis"));
Assert.assertTrue(validDocIdsMetadata.get("segmentCreationTimeMillis").asLong() > 0);
@@ -411,15 +412,12 @@ public class TablesResourceTest extends BaseResourceTest {
throws IOException {
IndexSegment segment = _realtimeIndexSegments.get(0);
// Verify the content of the downloaded snapshot from a realtime table.
- downLoadAndVerifyValidDocIdsSnapshot(TableNameBuilder.REALTIME.tableNameWithType(TABLE_NAME),
- (ImmutableSegmentImpl) segment);
- downLoadAndVerifyValidDocIdsSnapshotBitmap(TableNameBuilder.REALTIME.tableNameWithType(TABLE_NAME),
- (ImmutableSegmentImpl) segment);
+ downLoadAndVerifyValidDocIdsSnapshot(REALTIME_TABLE_NAME, (ImmutableSegmentImpl) segment);
+ downLoadAndVerifyValidDocIdsSnapshotBitmap(REALTIME_TABLE_NAME, (ImmutableSegmentImpl) segment);
List<String> segments = List.of(segment.getSegmentName());
TableSegments tableSegments = new TableSegments(segments);
- String validDocIdsMetadataPath =
- "/tables/" + TableNameBuilder.REALTIME.tableNameWithType(TABLE_NAME) + "/validDocIdsMetadata";
+ String validDocIdsMetadataPath = "/tables/" + REALTIME_TABLE_NAME + "/validDocIdsMetadata";
// Test the new SNAPSHOT_WITH_DELETE validDocIdsType
String response = _webTarget.path(validDocIdsMetadataPath)
@@ -432,9 +430,10 @@ public class TablesResourceTest extends BaseResourceTest {
Assert.assertEquals(validDocIdsMetadata.get("totalDocs").asInt(), 200000);
Assert.assertEquals(validDocIdsMetadata.get("totalValidDocs").asInt(), 8);
Assert.assertEquals(validDocIdsMetadata.get("totalInvalidDocs").asInt(), 199992);
- Assert.assertEquals(validDocIdsMetadata.get("segmentCrc").asText(), "187068486");
+ Assert.assertEquals(validDocIdsMetadata.get("segmentCrc").asText(), segment.getSegmentMetadata().getCrc());
Assert.assertEquals(validDocIdsMetadata.get("validDocIdsType").asText(), "SNAPSHOT_WITH_DELETE");
- Assert.assertEquals(validDocIdsMetadata.get("segmentSizeInBytes").asLong(), 4514731);
+ Assert.assertEquals(validDocIdsMetadata.get("segmentSizeInBytes").asLong(),
+ ((ImmutableSegmentImpl) segment).getSegmentSizeBytes());
Assert.assertTrue(validDocIdsMetadata.has("segmentCreationTimeMillis"));
Assert.assertTrue(validDocIdsMetadata.get("segmentCreationTimeMillis").asLong() > 0);
@@ -446,7 +445,7 @@ public class TablesResourceTest extends BaseResourceTest {
}
// Verify metadata file from segments.
- private void downLoadAndVerifySegmentContent(String tableNameWithType, IndexSegment segment)
+ private void downloadAndVerifySegmentContent(String tableNameWithType, IndexSegment segment)
throws IOException, ConfigurationException {
String segmentPath = "/segments/" + tableNameWithType + "/" + segment.getSegmentName();
@@ -512,9 +511,10 @@ public class TablesResourceTest extends BaseResourceTest {
validDocIdsSnapshot.getMutableRoaringBitmap());
// Check snapshot type
- response =
- _webTarget.path(snapshotPath).queryParam("validDocIdsType", ValidDocIdsType.SNAPSHOT.toString()).request()
- .get(Response.class);
+ response = _webTarget.path(snapshotPath)
+ .queryParam("validDocIdsType", ValidDocIdsType.SNAPSHOT.toString())
+ .request()
+ .get(Response.class);
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
validDocIdsSnapshotBitmap = response.readEntity(byte[].class);
Assert.assertNotNull(validDocIdsSnapshotBitmap);
@@ -522,7 +522,9 @@ public class TablesResourceTest extends BaseResourceTest {
validDocIdsSnapshot.getMutableRoaringBitmap());
// Check onHeap type
- response = _webTarget.path(snapshotPath).queryParam("validDocIdsType", ValidDocIdsType.IN_MEMORY).request()
+ response = _webTarget.path(snapshotPath)
+ .queryParam("validDocIdsType", ValidDocIdsType.IN_MEMORY)
+ .request()
.get(Response.class);
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
validDocIdsSnapshotBitmap = response.readEntity(byte[].class);
@@ -531,9 +533,10 @@ public class TablesResourceTest extends BaseResourceTest {
validDocIds.getMutableRoaringBitmap());
// Check onHeapWithDelete type
- response =
- _webTarget.path(snapshotPath).queryParam("validDocIdsType", ValidDocIdsType.IN_MEMORY_WITH_DELETE.toString())
- .request().get(Response.class);
+ response = _webTarget.path(snapshotPath)
+ .queryParam("validDocIdsType", ValidDocIdsType.IN_MEMORY_WITH_DELETE.toString())
+ .request()
+ .get(Response.class);
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
validDocIdsSnapshotBitmap = response.readEntity(byte[].class);
Assert.assertNotNull(validDocIdsSnapshotBitmap);
@@ -570,12 +573,10 @@ public class TablesResourceTest extends BaseResourceTest {
FileUtils.writeByteArrayToFile(queryableDocIdsSnapshotFile,
RoaringBitmapUtils.serialize(queryableDocIds.getMutableRoaringBitmap()));
- String expectedSegmentCrc = "187068486";
-
// Check no type (default should be validDocIdsSnapshot)
ValidDocIdsBitmapResponse response = _webTarget.path(snapshotPath).request().get(ValidDocIdsBitmapResponse.class);
Assert.assertNotNull(response);
- Assert.assertEquals(response.getSegmentCrc(), expectedSegmentCrc);
+ Assert.assertEquals(response.getSegmentCrc(), segment.getSegmentMetadata().getCrc());
Assert.assertEquals(response.getSegmentName(), segment.getSegmentName());
byte[] validDocIdsSnapshotBitmap = response.getBitmap();
Assert.assertNotNull(validDocIdsSnapshotBitmap);
@@ -583,11 +584,12 @@ public class TablesResourceTest extends BaseResourceTest {
validDocIdsSnapshot.getMutableRoaringBitmap());
// Check snapshot type
- response =
- _webTarget.path(snapshotPath).queryParam("validDocIdsType", ValidDocIdsType.SNAPSHOT.toString()).request()
- .get(ValidDocIdsBitmapResponse.class);
+ response = _webTarget.path(snapshotPath)
+ .queryParam("validDocIdsType", ValidDocIdsType.SNAPSHOT.toString())
+ .request()
+ .get(ValidDocIdsBitmapResponse.class);
Assert.assertNotNull(response);
- Assert.assertEquals(response.getSegmentCrc(), expectedSegmentCrc);
+ Assert.assertEquals(response.getSegmentCrc(), segment.getSegmentMetadata().getCrc());
Assert.assertEquals(response.getSegmentName(), segment.getSegmentName());
validDocIdsSnapshotBitmap = response.getBitmap();
Assert.assertNotNull(validDocIdsSnapshotBitmap);
@@ -595,11 +597,12 @@ public class TablesResourceTest extends BaseResourceTest {
validDocIdsSnapshot.getMutableRoaringBitmap());
// Check onHeap type
- response =
- _webTarget.path(snapshotPath).queryParam("validDocIdsType", ValidDocIdsType.IN_MEMORY.toString()).request()
- .get(ValidDocIdsBitmapResponse.class);
+ response = _webTarget.path(snapshotPath)
+ .queryParam("validDocIdsType", ValidDocIdsType.IN_MEMORY.toString())
+ .request()
+ .get(ValidDocIdsBitmapResponse.class);
Assert.assertNotNull(response);
- Assert.assertEquals(response.getSegmentCrc(), expectedSegmentCrc);
+ Assert.assertEquals(response.getSegmentCrc(), segment.getSegmentMetadata().getCrc());
Assert.assertEquals(response.getSegmentName(), segment.getSegmentName());
validDocIdsSnapshotBitmap = response.getBitmap();
Assert.assertNotNull(validDocIdsSnapshotBitmap);
@@ -607,11 +610,12 @@ public class TablesResourceTest extends BaseResourceTest {
validDocIds.getMutableRoaringBitmap());
// Check onHeapWithDelete type
- response =
- _webTarget.path(snapshotPath).queryParam("validDocIdsType", ValidDocIdsType.IN_MEMORY_WITH_DELETE.toString())
- .request().get(ValidDocIdsBitmapResponse.class);
+ response = _webTarget.path(snapshotPath)
+ .queryParam("validDocIdsType", ValidDocIdsType.IN_MEMORY_WITH_DELETE.toString())
+ .request()
+ .get(ValidDocIdsBitmapResponse.class);
Assert.assertNotNull(response);
- Assert.assertEquals(response.getSegmentCrc(), expectedSegmentCrc);
+ Assert.assertEquals(response.getSegmentCrc(), segment.getSegmentMetadata().getCrc());
Assert.assertEquals(response.getSegmentName(), segment.getSegmentName());
validDocIdsSnapshotBitmap = response.getBitmap();
Assert.assertNotNull(validDocIdsSnapshotBitmap);
@@ -624,13 +628,10 @@ public class TablesResourceTest extends BaseResourceTest {
throws IOException {
IndexSegment segment = _realtimeIndexSegments.get(0);
// Verify the content of the downloaded snapshot from a realtime table.
- downLoadAndVerifyValidDocIdsSnapshot(TableNameBuilder.REALTIME.tableNameWithType(TABLE_NAME),
- (ImmutableSegmentImpl) segment);
- downLoadAndVerifyValidDocIdsSnapshotBitmap(TableNameBuilder.REALTIME.tableNameWithType(TABLE_NAME),
- (ImmutableSegmentImpl) segment);
+ downLoadAndVerifyValidDocIdsSnapshot(REALTIME_TABLE_NAME, (ImmutableSegmentImpl) segment);
+ downLoadAndVerifyValidDocIdsSnapshotBitmap(REALTIME_TABLE_NAME, (ImmutableSegmentImpl) segment);
- String validDocIdsMetadataPath =
- "/tables/" + TableNameBuilder.REALTIME.tableNameWithType(TABLE_NAME) + "/validDocIdMetadata";
+ String validDocIdsMetadataPath = "/tables/" + REALTIME_TABLE_NAME + "/validDocIdMetadata";
// Test GET endpoint with SNAPSHOT_WITH_DELETE validDocIdsType
String response = _webTarget.path(validDocIdsMetadataPath)
@@ -643,7 +644,7 @@ public class TablesResourceTest extends BaseResourceTest {
Assert.assertEquals(validDocIdsMetadata.get("totalDocs").asInt(), 200000);
Assert.assertEquals(validDocIdsMetadata.get("totalValidDocs").asInt(), 8);
Assert.assertEquals(validDocIdsMetadata.get("totalInvalidDocs").asInt(), 199992);
- Assert.assertEquals(validDocIdsMetadata.get("segmentCrc").asText(), "187068486");
+ Assert.assertEquals(validDocIdsMetadata.get("segmentCrc").asText(), segment.getSegmentMetadata().getCrc());
Assert.assertEquals(validDocIdsMetadata.get("validDocIdsType").asText(), "SNAPSHOT_WITH_DELETE");
}
@@ -652,13 +653,11 @@ public class TablesResourceTest extends BaseResourceTest {
throws IOException {
IndexSegment segment = _realtimeIndexSegments.get(0);
// Verify the content of the downloaded snapshot from a realtime table.
- downLoadAndVerifyValidDocIdsSnapshot(TableNameBuilder.REALTIME.tableNameWithType(TABLE_NAME),
- (ImmutableSegmentImpl) segment);
- downLoadAndVerifyValidDocIdsSnapshotBitmap(TableNameBuilder.REALTIME.tableNameWithType(TABLE_NAME),
- (ImmutableSegmentImpl) segment);
+ downLoadAndVerifyValidDocIdsSnapshot(REALTIME_TABLE_NAME, (ImmutableSegmentImpl) segment);
+ downLoadAndVerifyValidDocIdsSnapshotBitmap(REALTIME_TABLE_NAME, (ImmutableSegmentImpl) segment);
- String validDocIdsBitmapPath = "/segments/" + TableNameBuilder.REALTIME.tableNameWithType(TABLE_NAME)
- + "/" + segment.getSegmentName() + "/validDocIdsBitmap";
+ String validDocIdsBitmapPath =
+ "/segments/" + REALTIME_TABLE_NAME + "/" + segment.getSegmentName() + "/validDocIdsBitmap";
// Test validDocIdsBitmap endpoint with SNAPSHOT_WITH_DELETE validDocIdsType
ValidDocIdsBitmapResponse response = _webTarget.path(validDocIdsBitmapPath)
@@ -667,7 +666,7 @@ public class TablesResourceTest extends BaseResourceTest {
.get(ValidDocIdsBitmapResponse.class);
Assert.assertNotNull(response);
- Assert.assertEquals(response.getSegmentCrc(), "187068486");
+ Assert.assertEquals(response.getSegmentCrc(), _realtimeIndexSegments.get(0).getSegmentMetadata().getCrc());
Assert.assertEquals(response.getSegmentName(), segment.getSegmentName());
Assert.assertEquals(response.getValidDocIdsType(), ValidDocIdsType.SNAPSHOT_WITH_DELETE);
Assert.assertNotNull(response.getBitmap());
@@ -676,39 +675,44 @@ public class TablesResourceTest extends BaseResourceTest {
@Test
public void testUploadSegments()
throws Exception {
- setUpSegment(TableNameBuilder.REALTIME.tableNameWithType(TABLE_NAME), LLC_SEGMENT_NAME_FOR_UPLOAD_SUCCESS, null,
- _realtimeIndexSegments);
- setUpSegment(TableNameBuilder.REALTIME.tableNameWithType(TABLE_NAME), LLC_SEGMENT_NAME_FOR_UPLOAD_FAILURE, null,
- _realtimeIndexSegments);
+ setUpSegment(REALTIME_TABLE_NAME, LLC_SEGMENT_NAME_FOR_UPLOAD_SUCCESS, null, _realtimeIndexSegments);
+ setUpSegment(REALTIME_TABLE_NAME, LLC_SEGMENT_NAME_FOR_UPLOAD_FAILURE, null, _realtimeIndexSegments);
// Verify segment uploading succeed.
Response response = _webTarget.path(
- String.format("/segments/%s/%s/upload", TableNameBuilder.REALTIME.tableNameWithType(TABLE_NAME),
- LLC_SEGMENT_NAME_FOR_UPLOAD_SUCCESS)).request().post(null);
+ String.format("/segments/%s/%s/upload", REALTIME_TABLE_NAME, LLC_SEGMENT_NAME_FOR_UPLOAD_SUCCESS))
+ .request()
+ .post(null);
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
Assert.assertEquals(response.readEntity(String.class), SEGMENT_DOWNLOAD_URL);
// Verify bad request: table type is offline
response = _webTarget.path(
- String.format("/segments/%s/%s/upload", TableNameBuilder.OFFLINE.tableNameWithType(TABLE_NAME),
- _offlineIndexSegments.get(0).getSegmentName())).request().post(null);
+ String.format("/segments/%s/%s/upload", OFFLINE_TABLE_NAME, _offlineIndexSegments.get(0).getSegmentName()))
+ .request()
+ .post(null);
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode());
// Verify bad request: segment is not low level consumer segment
response = _webTarget.path(
- String.format("/segments/%s/%s/upload", TableNameBuilder.REALTIME.tableNameWithType(TABLE_NAME),
- _realtimeIndexSegments.get(0).getSegmentName())).request().post(null);
+ String.format("/segments/%s/%s/upload", REALTIME_TABLE_NAME,
+ _realtimeIndexSegments.get(0).getSegmentName()))
+ .request()
+ .post(null);
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode());
// Verify non-existent segment uploading fail with NOT_FOUND status.
- response =
- _webTarget.path(String.format("/segments/%s/%s_dummy/upload", TABLE_NAME, LLC_SEGMENT_NAME_FOR_UPLOAD_SUCCESS))
- .request().post(null);
+ response = _webTarget.path(
+ String.format("/segments/%s/%s_dummy/upload", RAW_TABLE_NAME, LLC_SEGMENT_NAME_FOR_UPLOAD_SUCCESS))
+ .request()
+ .post(null);
Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode());
// Verify fail to upload segment to segment store with internal server error.
- response = _webTarget.path(String.format("/segments/%s/%s/upload", TABLE_NAME, LLC_SEGMENT_NAME_FOR_UPLOAD_FAILURE))
- .request().post(null);
+ response =
+ _webTarget.path(String.format("/segments/%s/%s/upload", RAW_TABLE_NAME, LLC_SEGMENT_NAME_FOR_UPLOAD_FAILURE))
+ .request()
+ .post(null);
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
}
@@ -716,8 +720,8 @@ public class TablesResourceTest extends BaseResourceTest {
public void testOfflineTableSegmentMetadata()
throws Exception {
IndexSegment defaultSegment = _offlineIndexSegments.get(0);
- String segmentMetadataPath = "/tables/" + TableNameBuilder.OFFLINE.tableNameWithType(TABLE_NAME) + "/segments/"
- + defaultSegment.getSegmentName() + "/metadata";
+ String segmentMetadataPath =
+ "/tables/" + OFFLINE_TABLE_NAME + "/segments/" + defaultSegment.getSegmentName() + "/metadata";
JsonNode jsonResponse =
JsonUtils.stringToJsonNode(_webTarget.path(segmentMetadataPath).request().get(String.class));
@@ -732,9 +736,11 @@ public class TablesResourceTest extends BaseResourceTest {
Assert.assertEquals(jsonResponse.get("columns").size(), 0);
Assert.assertEquals(jsonResponse.get("indexes").size(), 0);
- jsonResponse = JsonUtils.stringToJsonNode(
- _webTarget.path(segmentMetadataPath).queryParam("columns", "column1").queryParam("columns", "column2").request()
- .get(String.class));
+ jsonResponse = JsonUtils.stringToJsonNode(_webTarget.path(segmentMetadataPath)
+ .queryParam("columns", "column1")
+ .queryParam("columns", "column2")
+ .request()
+ .get(String.class));
Assert.assertEquals(jsonResponse.get("columns").size(), 2);
Assert.assertEquals(jsonResponse.get("indexes").size(), 2);
Assert.assertEquals(jsonResponse.get("star-tree-index").size(), 0);
@@ -745,13 +751,13 @@ public class TablesResourceTest extends BaseResourceTest {
Assert.assertEquals(jsonResponse.get("columns").size(), physicalColumnCount);
Assert.assertEquals(jsonResponse.get("indexes").size(), physicalColumnCount);
- Response response = _webTarget.path("/tables/UNKNOWN_TABLE/segments/" + defaultSegment.getSegmentName()).request()
+ Response response = _webTarget.path("/tables/UNKNOWN_TABLE/segments/" + defaultSegment.getSegmentName())
+ .request()
.get(Response.class);
Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode());
- response = _webTarget.path(
- "/tables/" + TableNameBuilder.REALTIME.tableNameWithType(TABLE_NAME) + "/segments/UNKNOWN_SEGMENT")
- .request().get(Response.class);
+ response =
+ _webTarget.path("/tables/" + REALTIME_TABLE_NAME + "/segments/UNKNOWN_SEGMENT").request().get(Response.class);
Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode());
}
diff --git a/pinot-spi/src/main/java/org/apache/pinot/spi/data/FieldSpec.java b/pinot-spi/src/main/java/org/apache/pinot/spi/data/FieldSpec.java
index 75b0a17f61d..3a57b742f9a 100644
--- a/pinot-spi/src/main/java/org/apache/pinot/spi/data/FieldSpec.java
+++ b/pinot-spi/src/main/java/org/apache/pinot/spi/data/FieldSpec.java
@@ -304,6 +304,15 @@ public abstract class FieldSpec implements Comparable<FieldSpec>, Serializable {
return DEFAULT_MAX_LENGTH;
}
+ /// Returns the max length of the column if it is not using the default length, `null` otherwise.
+ /// This method should be used to write the `ColumnMetadata`.
+ @JsonIgnore
+ @Nullable
+ public Integer getNonDefaultMaxLength() {
+ int effectiveMaxLength = getEffectiveMaxLength();
+ return effectiveMaxLength != DEFAULT_MAX_LENGTH ? effectiveMaxLength : null;
+ }
+
// Required by JSON de-serializer. DO NOT REMOVE.
// Use getEffectiveMaxLength() for default-aware access.
@Nullable
@@ -338,6 +347,21 @@ public abstract class FieldSpec implements Comparable<FieldSpec>, Serializable {
}
}
+ /// Returns the max length exceed strategy of the column if it is not using the default strategy, `null` otherwise.
+ /// This method should be used to write the `ColumnMetadata`.
+ @JsonIgnore
+ @Nullable
+ public MaxLengthExceedStrategy getNonDefaultMaxLengthExceedStrategy() {
+ MaxLengthExceedStrategy effectiveMaxLengthExceedStrategy = getEffectiveMaxLengthExceedStrategy();
+ if (_dataType == DataType.STRING) {
+ return effectiveMaxLengthExceedStrategy != MaxLengthExceedStrategy.TRIM_LENGTH ? effectiveMaxLengthExceedStrategy
+ : null;
+ } else {
+ return effectiveMaxLengthExceedStrategy != MaxLengthExceedStrategy.NO_ACTION ? effectiveMaxLengthExceedStrategy
+ : null;
+ }
+ }
+
// Required by JSON de-serializer. DO NOT REMOVE.
// Use getEffectiveMaxLengthExceedStrategy() for default-aware access.
@Nullable
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org