vvivekiyer commented on code in PR #9454: URL: https://github.com/apache/pinot/pull/9454#discussion_r982967020
########## pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/index/loader/ForwardIndexHandlerTest.java: ########## @@ -0,0 +1,432 @@ +/** + * 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.loader; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Random; +import org.apache.commons.io.FileUtils; +import org.apache.pinot.segment.local.segment.creator.impl.SegmentIndexCreationDriverImpl; +import org.apache.pinot.segment.local.segment.readers.GenericRowRecordReader; +import org.apache.pinot.segment.local.segment.readers.PinotSegmentColumnReader; +import org.apache.pinot.segment.local.segment.store.SegmentLocalFSDirectory; +import org.apache.pinot.segment.spi.ColumnMetadata; +import org.apache.pinot.segment.spi.V1Constants; +import org.apache.pinot.segment.spi.compression.ChunkCompressionType; +import org.apache.pinot.segment.spi.creator.IndexCreatorProvider; +import org.apache.pinot.segment.spi.creator.SegmentGeneratorConfig; +import org.apache.pinot.segment.spi.index.IndexingOverrides; +import org.apache.pinot.segment.spi.index.metadata.SegmentMetadataImpl; +import org.apache.pinot.segment.spi.index.reader.ForwardIndexReader; +import org.apache.pinot.segment.spi.store.SegmentDirectory; +import org.apache.pinot.spi.config.table.FieldConfig; +import org.apache.pinot.spi.config.table.TableConfig; +import org.apache.pinot.spi.config.table.TableType; +import org.apache.pinot.spi.data.FieldSpec; +import org.apache.pinot.spi.data.Schema; +import org.apache.pinot.spi.data.readers.GenericRow; +import org.apache.pinot.spi.data.readers.RecordReader; +import org.apache.pinot.spi.utils.ReadMode; +import org.apache.pinot.spi.utils.builder.TableConfigBuilder; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import static org.testng.Assert.assertEquals; + + +public class ForwardIndexHandlerTest { + private static final File INDEX_DIR = new File(FileUtils.getTempDirectory(), "ForwardIndexHandlerTest"); + private static final String TABLE_NAME = "myTable"; + private static final String SEGMENT_NAME = "testSegment"; + + // TODO: + // 1. Add other datatypes (double, float, bigdecimal, bytes). Also add MV columns. + // 2. Add text index and other index types for raw columns. + private static final String SNAPPY_STRING = "SNAPPY_STRING"; + private static final String PASS_THROUGH_STRING = "PASS_THROUGH_STRING"; + private static final String ZSTANDARD_STRING = "ZSTANDARD_STRING"; + private static final String LZ4_STRING = "LZ4_STRING"; + + private static final String SNAPPY_LONG = "SNAPPY_LONG"; + private static final String PASS_THROUGH_LONG = "PASS_THROUGH_LONG"; + private static final String ZSTANDARD_LONG = "ZSTANDARD_LONG"; + private static final String LZ4_LONG = "LZ4_LONG"; + + private static final String SNAPPY_INTEGER = "SNAPPY_INTEGER"; + private static final String PASS_THROUGH_INTEGER = "PASS_THROUGH_INTEGER"; + private static final String ZSTANDARD_INTEGER = "ZSTANDARD_INTEGER"; + private static final String LZ4_INTEGER = "LZ4_INTEGER"; + + private static final String DICT_INTEGER = "DICT_INTEGER"; + private static final String DICT_STRING = "DICT_STRING"; + private static final String DICT_LONG = "DICT_LONG"; + + private static final List<String> RAW_SNAPPY_INDEX_COLUMNS = + Arrays.asList(SNAPPY_STRING, SNAPPY_LONG, SNAPPY_INTEGER); + + private static final List<String> RAW_ZSTANDARD_INDEX_COLUMNS = + Arrays.asList(ZSTANDARD_STRING, ZSTANDARD_LONG, ZSTANDARD_INTEGER); + + private static final List<String> RAW_PASS_THROUGH_INDEX_COLUMNS = + Arrays.asList(PASS_THROUGH_STRING, PASS_THROUGH_LONG, PASS_THROUGH_INTEGER); + + private static final List<String> RAW_LZ4_INDEX_COLUMNS = Arrays.asList(LZ4_STRING, LZ4_LONG, LZ4_INTEGER); + + private final List<String> _noDictionaryColumns = new ArrayList<>(); + TableConfig _tableConfig; + Schema _schema; + private SegmentMetadataImpl _existingSegmentMetadata; + private SegmentDirectory.Writer _writer; + private List<FieldConfig.CompressionCodec> _allCompressionTypes = + Arrays.asList(FieldConfig.CompressionCodec.values()); + + @BeforeClass + public void setUp() + throws Exception { + // Delete index directly if it already exists. + FileUtils.deleteQuietly(INDEX_DIR); + + buildSegment(); + } + + private void buildSegment() + throws Exception { + List<GenericRow> rows = createTestData(); + + List<FieldConfig> fieldConfigs = new ArrayList<>( + RAW_SNAPPY_INDEX_COLUMNS.size() + RAW_ZSTANDARD_INDEX_COLUMNS.size() + RAW_PASS_THROUGH_INDEX_COLUMNS.size() + + RAW_LZ4_INDEX_COLUMNS.size()); + + for (String indexColumn : RAW_SNAPPY_INDEX_COLUMNS) { + fieldConfigs.add(new FieldConfig(indexColumn, FieldConfig.EncodingType.RAW, Collections.emptyList(), + FieldConfig.CompressionCodec.SNAPPY, null)); + } + + for (String indexColumn : RAW_ZSTANDARD_INDEX_COLUMNS) { + fieldConfigs.add(new FieldConfig(indexColumn, FieldConfig.EncodingType.RAW, Collections.emptyList(), + FieldConfig.CompressionCodec.ZSTANDARD, null)); + } + + for (String indexColumn : RAW_PASS_THROUGH_INDEX_COLUMNS) { + fieldConfigs.add(new FieldConfig(indexColumn, FieldConfig.EncodingType.RAW, Collections.emptyList(), + FieldConfig.CompressionCodec.PASS_THROUGH, null)); + } + + for (String indexColumn : RAW_LZ4_INDEX_COLUMNS) { + fieldConfigs.add(new FieldConfig(indexColumn, FieldConfig.EncodingType.RAW, Collections.emptyList(), + FieldConfig.CompressionCodec.LZ4, null)); + } + + _noDictionaryColumns.addAll(RAW_SNAPPY_INDEX_COLUMNS); + _noDictionaryColumns.addAll(RAW_ZSTANDARD_INDEX_COLUMNS); + _noDictionaryColumns.addAll(RAW_PASS_THROUGH_INDEX_COLUMNS); + _noDictionaryColumns.addAll(RAW_LZ4_INDEX_COLUMNS); + + _tableConfig = + new TableConfigBuilder(TableType.OFFLINE).setTableName(TABLE_NAME).setNoDictionaryColumns(_noDictionaryColumns) + .setFieldConfigList(fieldConfigs).build(); + _schema = new Schema.SchemaBuilder().setSchemaName(TABLE_NAME) + .addSingleValueDimension(SNAPPY_STRING, FieldSpec.DataType.STRING) + .addSingleValueDimension(PASS_THROUGH_STRING, FieldSpec.DataType.STRING) + .addSingleValueDimension(ZSTANDARD_STRING, FieldSpec.DataType.STRING) + .addSingleValueDimension(LZ4_STRING, FieldSpec.DataType.STRING) + .addSingleValueDimension(SNAPPY_INTEGER, FieldSpec.DataType.INT) + .addSingleValueDimension(ZSTANDARD_INTEGER, FieldSpec.DataType.INT) + .addSingleValueDimension(PASS_THROUGH_INTEGER, FieldSpec.DataType.INT) + .addSingleValueDimension(LZ4_INTEGER, FieldSpec.DataType.INT) + .addSingleValueDimension(SNAPPY_LONG, FieldSpec.DataType.LONG) + .addSingleValueDimension(ZSTANDARD_LONG, FieldSpec.DataType.LONG) + .addSingleValueDimension(PASS_THROUGH_LONG, FieldSpec.DataType.LONG) + .addSingleValueDimension(LZ4_LONG, FieldSpec.DataType.LONG) + .addSingleValueDimension(DICT_INTEGER, FieldSpec.DataType.INT) + .addSingleValueDimension(DICT_LONG, FieldSpec.DataType.LONG) + .addSingleValueDimension(DICT_STRING, FieldSpec.DataType.STRING).build(); Review Comment: Done. ########## pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/loader/ForwardIndexHandler.java: ########## @@ -0,0 +1,274 @@ +/** + * 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.loader; + +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Preconditions; +import java.io.File; +import java.math.BigDecimal; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import org.apache.commons.io.FileUtils; +import org.apache.pinot.segment.local.segment.readers.PinotSegmentColumnReader; +import org.apache.pinot.segment.spi.ColumnMetadata; +import org.apache.pinot.segment.spi.SegmentMetadata; +import org.apache.pinot.segment.spi.V1Constants; +import org.apache.pinot.segment.spi.compression.ChunkCompressionType; +import org.apache.pinot.segment.spi.creator.IndexCreationContext; +import org.apache.pinot.segment.spi.creator.IndexCreatorProvider; +import org.apache.pinot.segment.spi.creator.SegmentVersion; +import org.apache.pinot.segment.spi.index.creator.ForwardIndexCreator; +import org.apache.pinot.segment.spi.index.reader.ForwardIndexReader; +import org.apache.pinot.segment.spi.store.ColumnIndexType; +import org.apache.pinot.segment.spi.store.SegmentDirectory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * Helper class used by {@link SegmentPreProcessor} to make changes to forward index and dictionary configs. Note + * that this handler only works for segment versions >= 3.0. Support for segment version < 3.0 is not added because + * majority of the usecases are in versions >= 3.0 and this avoids adding tech debt. The currently supported + * operations are: + * 1. Change compression on raw SV columns. + * + * TODO: Add support for the following: + * 1. Change compression for raw MV columns + * 2. Enable dictionary + * 3. Disable dictionary + */ +public class ForwardIndexHandler implements IndexHandler { + private static final Logger LOGGER = LoggerFactory.getLogger(ForwardIndexHandler.class); + + private final SegmentMetadata _segmentMetadata; + IndexLoadingConfig _indexLoadingConfig; + + protected enum Operation { + CHANGE_RAW_COMPRESSION_TYPE, Review Comment: Done. ########## pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/loader/ForwardIndexHandler.java: ########## @@ -0,0 +1,274 @@ +/** + * 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.loader; + +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Preconditions; +import java.io.File; +import java.math.BigDecimal; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import org.apache.commons.io.FileUtils; +import org.apache.pinot.segment.local.segment.readers.PinotSegmentColumnReader; +import org.apache.pinot.segment.spi.ColumnMetadata; +import org.apache.pinot.segment.spi.SegmentMetadata; +import org.apache.pinot.segment.spi.V1Constants; +import org.apache.pinot.segment.spi.compression.ChunkCompressionType; +import org.apache.pinot.segment.spi.creator.IndexCreationContext; +import org.apache.pinot.segment.spi.creator.IndexCreatorProvider; +import org.apache.pinot.segment.spi.creator.SegmentVersion; +import org.apache.pinot.segment.spi.index.creator.ForwardIndexCreator; +import org.apache.pinot.segment.spi.index.reader.ForwardIndexReader; +import org.apache.pinot.segment.spi.store.ColumnIndexType; +import org.apache.pinot.segment.spi.store.SegmentDirectory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * Helper class used by {@link SegmentPreProcessor} to make changes to forward index and dictionary configs. Note + * that this handler only works for segment versions >= 3.0. Support for segment version < 3.0 is not added because + * majority of the usecases are in versions >= 3.0 and this avoids adding tech debt. The currently supported + * operations are: + * 1. Change compression on raw SV columns. + * + * TODO: Add support for the following: + * 1. Change compression for raw MV columns + * 2. Enable dictionary + * 3. Disable dictionary + */ +public class ForwardIndexHandler implements IndexHandler { + private static final Logger LOGGER = LoggerFactory.getLogger(ForwardIndexHandler.class); + + private final SegmentMetadata _segmentMetadata; + IndexLoadingConfig _indexLoadingConfig; + + protected enum Operation { + CHANGE_RAW_COMPRESSION_TYPE, + + // TODO: Add other operations like ENABLE_DICTIONARY, DISABLE_DICTIONARY. + } Review Comment: Done -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
