Jackie-Jiang commented on code in PR #14493: URL: https://github.com/apache/pinot/pull/14493#discussion_r1868225424
########## pinot-core/src/test/java/org/apache/pinot/core/data/manager/TableIndexingTest.java: ########## @@ -0,0 +1,717 @@ +/** + * 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.core.data.manager; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.JsonNodeFactory; +import com.fasterxml.jackson.databind.node.ObjectNode; +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.nio.ByteBuffer; +import java.nio.file.Files; +import java.util.ArrayList; +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.core.data.manager.offline.ImmutableSegmentDataManager; +import org.apache.pinot.segment.local.indexsegment.immutable.ImmutableSegmentLoader; +import org.apache.pinot.segment.local.segment.creator.impl.SegmentIndexCreationDriverImpl; +import org.apache.pinot.segment.local.segment.index.loader.IndexLoadingConfig; +import org.apache.pinot.segment.local.segment.readers.GenericRowRecordReader; +import org.apache.pinot.segment.local.utils.TableConfigUtils; +import org.apache.pinot.segment.spi.ImmutableSegment; +import org.apache.pinot.segment.spi.creator.SegmentGeneratorConfig; +import org.apache.pinot.segment.spi.creator.SegmentVersion; +import org.apache.pinot.segment.spi.datasource.DataSource; +import org.apache.pinot.segment.spi.index.IndexService; +import org.apache.pinot.segment.spi.index.startree.StarTreeV2; +import org.apache.pinot.spi.config.table.FieldConfig; +import org.apache.pinot.spi.config.table.IndexingConfig; +import org.apache.pinot.spi.config.table.StarTreeIndexConfig; +import org.apache.pinot.spi.config.table.TableConfig; +import org.apache.pinot.spi.config.table.TableType; +import org.apache.pinot.spi.config.table.TimestampConfig; +import org.apache.pinot.spi.config.table.TimestampIndexGranularity; +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.MetricFieldSpec; +import org.apache.pinot.spi.data.Schema; +import org.apache.pinot.spi.data.readers.GenericRow; +import org.apache.pinot.spi.utils.JsonUtils; +import org.apache.pinot.spi.utils.builder.TableConfigBuilder; +import org.apache.pinot.spi.utils.builder.TableNameBuilder; +import org.apache.pinot.util.TestUtils; +import org.jetbrains.annotations.NotNull; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + + +// Tests various combinations of field type, encoding, single/multi-value and index type +// and compares test case results with TableIndexingTest.csv +public class TableIndexingTest { + private static final File TEMP_DIR = new File(FileUtils.getTempDirectory(), "TableIndexingTest"); + private static final String TABLE_NAME = "mytable"; + private static final String OFFLINE_TABLE_NAME = TableNameBuilder.OFFLINE.tableNameWithType(TABLE_NAME); + public static final String COLUMN_NAME = "col"; + public static final String COLUMN_DAY_NAME = "$col$DAY"; + public static final String COLUMN_MONTH_NAME = "$col$MONTH"; + public static final String COLUMN_WEEK_NAME = "$col$WEEK"; + + private final ArrayList<Schema> _schemas = new ArrayList<>(); + private TestCase[] _testCases; + private Map<TestCase, TestCase> _testCaseMap; + private final List<TestCase> _allResults = new ArrayList<>(); + + @BeforeClass + public void setUp() + throws Exception { + TestUtils.ensureDirectoriesExistAndEmpty(TEMP_DIR); + createSchemas(); + createTestCases(); + readExpectedResults(); + } + + private void createTestCases() { + String[] indexTypes = + { + "timestamp_index", "bloom_filter", "fst_index", "h3_index", "inverted_index", "json_index", + "native_text_index", "text_index", "range_index", "startree_index", "vector_index" + }; Review Comment: (nit) We usually put `{` in the previous line ```suggestion String[] indexTypes = { "timestamp_index", "bloom_filter", "fst_index", "h3_index", "inverted_index", "json_index", "native_text_index", "text_index", "range_index", "startree_index", "vector_index" }; ``` ########## pinot-core/src/test/java/org/apache/pinot/core/data/manager/TableIndexingTest.java: ########## @@ -0,0 +1,717 @@ +/** + * 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.core.data.manager; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.JsonNodeFactory; +import com.fasterxml.jackson.databind.node.ObjectNode; +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.nio.ByteBuffer; +import java.nio.file.Files; +import java.util.ArrayList; +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.core.data.manager.offline.ImmutableSegmentDataManager; +import org.apache.pinot.segment.local.indexsegment.immutable.ImmutableSegmentLoader; +import org.apache.pinot.segment.local.segment.creator.impl.SegmentIndexCreationDriverImpl; +import org.apache.pinot.segment.local.segment.index.loader.IndexLoadingConfig; +import org.apache.pinot.segment.local.segment.readers.GenericRowRecordReader; +import org.apache.pinot.segment.local.utils.TableConfigUtils; +import org.apache.pinot.segment.spi.ImmutableSegment; +import org.apache.pinot.segment.spi.creator.SegmentGeneratorConfig; +import org.apache.pinot.segment.spi.creator.SegmentVersion; +import org.apache.pinot.segment.spi.datasource.DataSource; +import org.apache.pinot.segment.spi.index.IndexService; +import org.apache.pinot.segment.spi.index.startree.StarTreeV2; +import org.apache.pinot.spi.config.table.FieldConfig; +import org.apache.pinot.spi.config.table.IndexingConfig; +import org.apache.pinot.spi.config.table.StarTreeIndexConfig; +import org.apache.pinot.spi.config.table.TableConfig; +import org.apache.pinot.spi.config.table.TableType; +import org.apache.pinot.spi.config.table.TimestampConfig; +import org.apache.pinot.spi.config.table.TimestampIndexGranularity; +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.MetricFieldSpec; +import org.apache.pinot.spi.data.Schema; +import org.apache.pinot.spi.data.readers.GenericRow; +import org.apache.pinot.spi.utils.JsonUtils; +import org.apache.pinot.spi.utils.builder.TableConfigBuilder; +import org.apache.pinot.spi.utils.builder.TableNameBuilder; +import org.apache.pinot.util.TestUtils; +import org.jetbrains.annotations.NotNull; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + + +// Tests various combinations of field type, encoding, single/multi-value and index type +// and compares test case results with TableIndexingTest.csv +public class TableIndexingTest { + private static final File TEMP_DIR = new File(FileUtils.getTempDirectory(), "TableIndexingTest"); + private static final String TABLE_NAME = "mytable"; + private static final String OFFLINE_TABLE_NAME = TableNameBuilder.OFFLINE.tableNameWithType(TABLE_NAME); + public static final String COLUMN_NAME = "col"; + public static final String COLUMN_DAY_NAME = "$col$DAY"; + public static final String COLUMN_MONTH_NAME = "$col$MONTH"; + public static final String COLUMN_WEEK_NAME = "$col$WEEK"; + + private final ArrayList<Schema> _schemas = new ArrayList<>(); + private TestCase[] _testCases; + private Map<TestCase, TestCase> _testCaseMap; + private final List<TestCase> _allResults = new ArrayList<>(); + + @BeforeClass + public void setUp() + throws Exception { + TestUtils.ensureDirectoriesExistAndEmpty(TEMP_DIR); + createSchemas(); + createTestCases(); + readExpectedResults(); + } + + private void createTestCases() { + String[] indexTypes = + { + "timestamp_index", "bloom_filter", "fst_index", "h3_index", "inverted_index", "json_index", + "native_text_index", "text_index", "range_index", "startree_index", "vector_index" + }; + + _testCases = new TestCase[_schemas.size() * indexTypes.length]; + _testCaseMap = new HashMap<>(); + + for (int i = 0; i < _schemas.size(); i++) { + for (int j = 0; j < indexTypes.length; j++) { + TestCase testCase = new TestCase(_schemas.get(i).getSchemaName(), i, indexTypes[j]); + _testCases[i * indexTypes.length + j] = testCase; + _testCaseMap.put(testCase, testCase); + } + } + } + + private void readExpectedResults() + throws IOException { + List<String> expected = readExpectedFromFile(); + // parse csv lines, e.g. INT;sv;raw;timestamp_index;true; + for (int i = 1; i < expected.size(); i++) { + String line = expected.get(i); + if (line.length() == 0) { Review Comment: (nit) My IDE usually gives warning on this ```suggestion if (line.isEmpty()) { ``` -- 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: commits-unsubscr...@pinot.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org