You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2021/11/10 04:52:11 UTC

[GitHub] [pinot] Jackie-Jiang commented on a change in pull request #7729: Support Native FST As An Index Subtype for FST Indices

Jackie-Jiang commented on a change in pull request #7729:
URL: https://github.com/apache/pinot/pull/7729#discussion_r746245934



##########
File path: pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/loader/invertedindex/FSTIndexHandler.java
##########
@@ -130,13 +138,20 @@ private void createFSTIndexForColumn(ColumnMetadata columnMetadata)
 
     LOGGER.info("Creating new FST index for column: {} in segment: {}, cardinality: {}", column, segmentName,
         columnMetadata.getCardinality());
-    LuceneFSTIndexCreator luceneFSTIndexCreator = new LuceneFSTIndexCreator(_indexDir, column, null);
+    TextIndexCreator textIndexCreator;

Review comment:
       rename to `fstIndexCreator` to differentiate it from the text index

##########
File path: pinot-spi/src/main/java/org/apache/pinot/spi/config/table/IndexingConfig.java
##########
@@ -86,6 +87,14 @@ public int getRangeIndexVersion() {
     return _rangeIndexVersion;
   }
 
+  public void setFstIndexType(FSTType fstType) {

Review comment:
       Rename to `setFSTIndexType` for consistency. Same for the getter

##########
File path: pinot-core/src/test/java/org/apache/pinot/queries/FSTBasedRegexpLikeQueriesTest.java
##########
@@ -94,19 +95,29 @@ public void setUp()
       throws Exception {
     FileUtils.deleteQuietly(INDEX_DIR);
 
-    buildSegment();
-    IndexLoadingConfig indexLoadingConfig = new IndexLoadingConfig();
-    Set<String> fstIndexCols = new HashSet<>();
-    fstIndexCols.add(DOMAIN_NAMES_COL);
-    indexLoadingConfig.setFSTIndexColumns(fstIndexCols);
-
-    Set<String> invertedIndexCols = new HashSet<>();
-    invertedIndexCols.add(DOMAIN_NAMES_COL);
-    indexLoadingConfig.setInvertedIndexColumns(invertedIndexCols);
-    ImmutableSegment immutableSegment =
-        ImmutableSegmentLoader.load(new File(INDEX_DIR, SEGMENT_NAME), indexLoadingConfig);
-    _indexSegment = immutableSegment;
-    _indexSegments = Arrays.asList(immutableSegment, immutableSegment);
+    List<IndexSegment> segments = new ArrayList<>();
+
+    for (int i = 0; i < 2; i++) {
+      FSTType fstType = i == 1 ? FSTType.NATIVE : FSTType.LUCENE;

Review comment:
       (minor)
   ```suggestion
       for (FSTType fstType : Arrays.asList(FSTType.LUCENE, FSTType.NATIVE)) {
   ```

##########
File path: pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/creator/impl/SegmentColumnarIndexCreator.java
##########
@@ -266,8 +268,19 @@ public void init(SegmentGeneratorConfig segmentCreationSpec, SegmentIndexCreatio
             "FST index is currently only supported on STRING type columns");
         Preconditions.checkState(dictEnabledColumn,
             "FST index is currently only supported on dictionary-encoded columns");
-        _fstIndexCreatorMap.put(columnName, new LuceneFSTIndexCreator(_indexDir, columnName,
-            (String[]) indexCreationInfo.getSortedUniqueElementsArray()));
+        TextIndexCreator textIndexCreator;
+

Review comment:
       (minor) Remove the empty lines as they don't seem to help with readability

##########
File path: pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/loader/invertedindex/FSTIndexHandler.java
##########
@@ -119,7 +125,9 @@ private void createFSTIndexForColumn(ColumnMetadata columnMetadata)
     String segmentName = _segmentMetadata.getName();
     String column = columnMetadata.getColumnName();
     File inProgress = new File(_indexDir, column + ".fst.inprogress");
-    File fstIndexFile = new File(_indexDir, column + FST_INDEX_FILE_EXTENSION);
+    String fileExtension = _fstType == FSTType.LUCENE ? FST_INDEX_FILE_EXTENSION

Review comment:
       We should use the same file extension as we are treating them as the same index but different versions

##########
File path: pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/loader/IndexLoadingConfig.java
##########
@@ -56,6 +57,7 @@
   private Set<String> _invertedIndexColumns = new HashSet<>();
   private Set<String> _rangeIndexColumns = new HashSet<>();
   private int _rangeIndexVersion = IndexingConfig.DEFAULT_RANGE_INDEX_VERSION;
+  private FSTType _fstTypeForFSTIndex = FSTType.LUCENE;

Review comment:
       (minor) Suggest renaming to `_fstIndexType`?

##########
File path: pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/creator/impl/SegmentColumnarIndexCreator.java
##########
@@ -266,8 +268,19 @@ public void init(SegmentGeneratorConfig segmentCreationSpec, SegmentIndexCreatio
             "FST index is currently only supported on STRING type columns");
         Preconditions.checkState(dictEnabledColumn,
             "FST index is currently only supported on dictionary-encoded columns");
-        _fstIndexCreatorMap.put(columnName, new LuceneFSTIndexCreator(_indexDir, columnName,
-            (String[]) indexCreationInfo.getSortedUniqueElementsArray()));
+        TextIndexCreator textIndexCreator;
+
+        if (_config.getFstIndexType() != null
+            && _config.getFstIndexType() == FSTType.NATIVE) {

Review comment:
       ```suggestion
           if (_config.getFstIndexType() == FSTType.NATIVE) {
   ```

##########
File path: pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/index/creator/NativeFSTIndexCreatorTest.java
##########
@@ -0,0 +1,73 @@
+/**
+ * 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.creator;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.ByteOrder;
+import org.apache.commons.io.FileUtils;
+import org.apache.pinot.segment.local.utils.nativefst.NativeFSTIndexCreator;
+import org.apache.pinot.segment.local.utils.nativefst.NativeFSTIndexReader;
+import org.apache.pinot.segment.spi.memory.PinotDataBuffer;
+import org.testng.Assert;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import static org.apache.pinot.segment.spi.V1Constants.Indexes.NATIVE_FST_INDEX_FILE_EXTENSION;
+
+
+public class NativeFSTIndexCreatorTest {
+  private static final File INDEX_DIR = new File(FileUtils.getTempDirectory(), "NativeFSTIndex");
+
+  @BeforeClass
+  public void setUp()
+      throws IOException {
+    FileUtils.forceMkdir(INDEX_DIR);
+  }
+
+  @AfterClass
+  public void tearDown()
+      throws IOException {
+    FileUtils.deleteDirectory(INDEX_DIR);
+  }
+
+  @Test
+  public void testIndexWriterReader()
+      throws IOException {
+    String[] uniqueValues = new String[3];
+    uniqueValues[0] = "hello-world";
+    uniqueValues[1] = "hello-world123";
+    uniqueValues[2] = "still";
+
+    NativeFSTIndexCreator creator = new NativeFSTIndexCreator(INDEX_DIR, "testFSTColumn", uniqueValues);
+    creator.seal();
+    File fstFile = new File(INDEX_DIR, "testFSTColumn" + NATIVE_FST_INDEX_FILE_EXTENSION);
+    PinotDataBuffer pinotDataBuffer =
+        PinotDataBuffer.mapFile(fstFile, true, 0, fstFile.length(), ByteOrder.BIG_ENDIAN, "fstIndexFile");
+    NativeFSTIndexReader reader = new NativeFSTIndexReader(pinotDataBuffer);
+    int[] matchedDictIds = reader.getDictIds("hello.*").toArray();
+    Assert.assertEquals(2, matchedDictIds.length);
+    Assert.assertEquals(0, matchedDictIds[0]);
+    Assert.assertEquals(1, matchedDictIds[1]);
+
+    matchedDictIds = reader.getDictIds(".*llo").toArray();
+    Assert.assertEquals(0, matchedDictIds.length);
+  }
+}

Review comment:
       (minor) new line

##########
File path: pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/creator/SegmentGeneratorConfig.java
##########
@@ -503,6 +507,14 @@ public int getSequenceId() {
     return _sequenceId;
   }
 
+  public void setFstIndexType(FSTType fstType) {

Review comment:
       Rename to `setFSTIndexType` for consistency. Same for the getter

##########
File path: pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/loader/IndexLoadingConfig.java
##########
@@ -289,6 +293,10 @@ public int getRangeIndexVersion() {
     return _rangeIndexVersion;
   }
 
+  public FSTType getFstIndexType() {

Review comment:
       Suggest renaming to `getFSTIndexType` to be consistent with `getFSTIndexColumns`. Same for the setter

##########
File path: pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/column/PhysicalColumnIndexContainer.java
##########
@@ -174,7 +176,12 @@ public PhysicalColumnIndexContainer(SegmentDirectory.Reader segmentReader, Colum
       }
 
       if (loadFSTIndex) {
-        _fstIndex = new LuceneFSTIndexReader(segmentReader.getIndexFor(columnName, ColumnIndexType.FST_INDEX));
+        PinotDataBuffer buffer = segmentReader.getIndexFor(columnName, ColumnIndexType.FST_INDEX);
+        if (indexLoadingConfig.getFstIndexType() == FSTType.NATIVE) {

Review comment:
       (major) This is incorrect. We need to create the proper FST index reader based on the header info from the buffer instead of relying on the table config because the table config might have changed since the segment is generated. See how range index is loaded as an example.




-- 
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-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org