richardstartin commented on a change in pull request #8384:
URL: https://github.com/apache/pinot/pull/8384#discussion_r832624382



##########
File path: 
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/utils/nativefst/NativeTextIndexCreator.java
##########
@@ -0,0 +1,173 @@
+/**
+ * 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.utils.nativefst;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.nio.ByteBuffer;
+import java.nio.channels.FileChannel;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+import org.apache.commons.io.FileUtils;
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.TokenStream;
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
+import 
org.apache.pinot.segment.local.segment.creator.impl.inv.BitmapInvertedIndexWriter;
+import 
org.apache.pinot.segment.local.segment.creator.impl.text.LuceneTextIndexCreator;
+import org.apache.pinot.segment.local.utils.nativefst.builder.FSTBuilder;
+import org.apache.pinot.segment.spi.V1Constants;
+import org.apache.pinot.segment.spi.index.creator.TextIndexCreator;
+import org.roaringbitmap.Container;
+import org.roaringbitmap.RoaringBitmap;
+import org.roaringbitmap.RoaringBitmapWriter;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+
+
+public class NativeTextIndexCreator implements TextIndexCreator {
+    static final String TEMP_DIR_SUFFIX = ".nativetext.idx.tmp";
+    static final String FST_FILE_NAME = "native.fst";
+    static final String INVERTED_INDEX_FILE_NAME = "inverted.index.buf";
+    public static final int HEADER_LENGTH = 24;
+
+    private String _columnName;
+    private FSTBuilder _fstBuilder;
+    private final File _indexFile;
+    private final File _tempDir;
+    private final File _fstIndexFile;
+    private final File _invertedIndexFile;
+    final Map<String, RoaringBitmapWriter<RoaringBitmap>> _postingListMap = 
new TreeMap<>();
+    final RoaringBitmapWriter.Wizard<Container, RoaringBitmap> 
_bitmapWriterWizard = RoaringBitmapWriter.writer();
+    private int _nextDocId = 0;
+    private int _fstDataSize;
+    private int _numBitMaps;
+
+    public NativeTextIndexCreator(String column, File indexDir)
+            throws IOException {
+        _columnName = column;
+        _fstBuilder = new FSTBuilder();
+        _indexFile = new File(indexDir, column + 
V1Constants.Indexes.NATIVE_TEXT_INDEX_FILE_EXTENSION);
+        _tempDir = new File(indexDir, column + TEMP_DIR_SUFFIX);
+        if (_tempDir.exists()) {
+            FileUtils.cleanDirectory(_tempDir);
+        } else {
+            FileUtils.forceMkdir(_tempDir);
+        }
+        _fstIndexFile = new File(_tempDir, FST_FILE_NAME);
+        _invertedIndexFile = new File(_tempDir, INVERTED_INDEX_FILE_NAME);
+    }
+
+    @Override
+    public void add(String document) {
+        List<String> tokens;
+        try {
+            tokens = analyze(document, new 
StandardAnalyzer(LuceneTextIndexCreator.ENGLISH_STOP_WORDS_SET));
+        } catch (IOException e) {
+            throw new RuntimeException(e.getMessage());
+        }
+
+        for (String token : tokens) {
+            addToPostingList(token);
+        }
+
+        _nextDocId++;
+    }
+
+    @Override
+    public void add(String[] documents, int length) {
+        for (int i = 0; i < length; i++) {
+            add(documents[i]);
+        }

Review comment:
       This looks wrong, the API is for MV columns, but each of the values 
would have a different docId implemented this way, and the docId will get out 
of sync with the docId used for indexes on other attributes of the same record 
and for the storage. This will lead to nonsensical query results when filtering 
on MV text attributes.
   
   Without a secondary docId (in the JSON index this is called the flattened 
docId) I don't see how MV columns could work without cross-match after 
tokenisation. Do we have some testing for a query like
   
   ```sql
   select someOtherAttribute from table where mvTextIndexedAttribute like 
'%xyz%`
   ```
   
   with records:
   
   | someOtherAttribute | mvTextIndexedAttribute |
   |---------------------|-------------------------|
   | 0                                |. ['abc', 'xyz'].                  |
   | 1                                |. ['def', 'uvw'].                  |
   
   `like 'xyz'` will produce the bitmap {1}, which will then be used to access 
the wrong value from the forward index for `someOtherAttribute`




-- 
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

Reply via email to