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



##########
File path: 
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/creator/impl/DefaultIndexCreatorProvider.java
##########
@@ -0,0 +1,249 @@
+/**
+ * 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.creator.impl;
+
+import com.google.common.base.Preconditions;
+import java.io.File;
+import java.io.IOException;
+import java.util.Map;
+import java.util.Objects;
+import 
org.apache.pinot.segment.local.io.writer.impl.BaseChunkSVForwardIndexWriter;
+import 
org.apache.pinot.segment.local.segment.creator.impl.fwd.MultiValueFixedByteRawIndexCreator;
+import 
org.apache.pinot.segment.local.segment.creator.impl.fwd.MultiValueUnsortedForwardIndexCreator;
+import 
org.apache.pinot.segment.local.segment.creator.impl.fwd.MultiValueVarByteRawIndexCreator;
+import 
org.apache.pinot.segment.local.segment.creator.impl.fwd.SingleValueFixedByteRawIndexCreator;
+import 
org.apache.pinot.segment.local.segment.creator.impl.fwd.SingleValueSortedForwardIndexCreator;
+import 
org.apache.pinot.segment.local.segment.creator.impl.fwd.SingleValueUnsortedForwardIndexCreator;
+import 
org.apache.pinot.segment.local.segment.creator.impl.fwd.SingleValueVarByteRawIndexCreator;
+import 
org.apache.pinot.segment.local.segment.creator.impl.inv.OffHeapBitmapInvertedIndexCreator;
+import 
org.apache.pinot.segment.local.segment.creator.impl.inv.OnHeapBitmapInvertedIndexCreator;
+import 
org.apache.pinot.segment.local.segment.creator.impl.inv.geospatial.OffHeapH3IndexCreator;
+import 
org.apache.pinot.segment.local.segment.creator.impl.inv.geospatial.OnHeapH3IndexCreator;
+import 
org.apache.pinot.segment.local.segment.creator.impl.inv.json.OffHeapJsonIndexCreator;
+import 
org.apache.pinot.segment.local.segment.creator.impl.inv.json.OnHeapJsonIndexCreator;
+import 
org.apache.pinot.segment.local.segment.creator.impl.inv.text.LuceneFSTIndexCreator;
+import 
org.apache.pinot.segment.local.segment.creator.impl.text.LuceneTextIndexCreator;
+import org.apache.pinot.segment.local.utils.nativefst.NativeFSTIndexCreator;
+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.index.creator.DictionaryBasedInvertedIndexCreator;
+import org.apache.pinot.segment.spi.index.creator.ForwardIndexCreator;
+import org.apache.pinot.segment.spi.index.creator.GeoSpatialIndexCreator;
+import org.apache.pinot.segment.spi.index.creator.JsonIndexCreator;
+import org.apache.pinot.segment.spi.index.creator.TextIndexCreator;
+import org.apache.pinot.segment.spi.index.reader.H3IndexResolution;
+import org.apache.pinot.spi.config.table.FSTType;
+import org.apache.pinot.spi.config.table.FieldConfig;
+import org.apache.pinot.spi.data.FieldSpec;
+
+
+public final class DefaultIndexCreatorProvider implements IndexCreatorProvider 
{
+
+  @Override
+  public ForwardIndexCreator newForwardIndexCreator(IndexCreationContext 
context)
+      throws Exception {
+    if (context.isRawColumn()) {
+      boolean deriveNumDocsPerChunk =
+          shouldDeriveNumDocsPerChunk(context.getFieldSpec().getName(), 
context.getColumnProperties());
+      int writerVersion = 
rawIndexWriterVersion(context.getFieldSpec().getName(), 
context.getColumnProperties());
+      if (context.getFieldSpec().isSingleValueField()) {
+        return getRawIndexCreatorForSVColumn(context.getIndexDir(), 
context.getChunkCompressionType(),
+            context.getFieldSpec().getName(),
+            context.getFieldSpec().getDataType().getStoredType(), 
context.getTotalDocs(),
+            context.getLengthOfLongestEntry(), deriveNumDocsPerChunk, 
writerVersion);
+      } else {
+        return getRawIndexCreatorForMVColumn(context.getIndexDir(), 
context.getChunkCompressionType(),
+            context.getFieldSpec().getName(), 
context.getFieldSpec().getDataType().getStoredType(),
+            context.getTotalDocs(),
+            context.getMaxNumberOfMultiValueElements(), deriveNumDocsPerChunk, 
writerVersion,
+            context.getMaxRowLengthInBytes());
+      }
+    } else {
+      if (context.getFieldSpec().isSingleValueField()) {
+        if (context.isSorted()) {
+          return new 
SingleValueSortedForwardIndexCreator(context.getIndexDir(), 
context.getFieldSpec().getName(),
+              context.getDistinctValueCount());
+        } else {
+          return new 
SingleValueUnsortedForwardIndexCreator(context.getIndexDir(), 
context.getFieldSpec().getName(),
+              context.getDistinctValueCount(),
+              context.getTotalDocs());
+        }
+      } else {
+        return new 
MultiValueUnsortedForwardIndexCreator(context.getIndexDir(), 
context.getFieldSpec().getName(),
+            context.getDistinctValueCount(),
+            context.getTotalDocs(),
+            context.getTotalNumberOfEntries());
+      }
+    }
+  }
+
+  @Override
+  public DictionaryBasedInvertedIndexCreator 
newInvertedIndexCreator(IndexCreationContext context)
+      throws IOException {
+    if (context.isOnHeap()) {
+      return new OnHeapBitmapInvertedIndexCreator(context.getIndexDir(), 
context.getFieldSpec().getName(),
+          context.getDistinctValueCount());
+    } else {
+      return new OffHeapBitmapInvertedIndexCreator(context.getIndexDir(), 
context.getFieldSpec(),
+          context.getDistinctValueCount(), context.getTotalDocs(),
+          context.getTotalNumberOfEntries());
+    }
+  }
+
+  @Override
+  public JsonIndexCreator newJsonIndexCreator(IndexCreationContext context)
+      throws IOException {
+    Preconditions.checkState(context.getFieldSpec().isSingleValueField(),
+        "Json index is currently only supported on single-value columns");
+    
Preconditions.checkState(context.getFieldSpec().getDataType().getStoredType() 
== FieldSpec.DataType.STRING,
+        "Json index is currently only supported on STRING columns");
+    return context.isOnHeap() ? new 
OnHeapJsonIndexCreator(context.getIndexDir(),
+        context.getFieldSpec().getName())
+        : new OffHeapJsonIndexCreator(context.getIndexDir(), 
context.getFieldSpec().getName());
+  }
+
+  @Override
+  public TextIndexCreator newTextIndexCreator(IndexCreationContext context)
+      throws IOException {
+    // Initialize text index creator
+    
Preconditions.checkState(context.getFieldSpec().getDataType().getStoredType() 
== FieldSpec.DataType.STRING,
+        "Text index is currently only supported on STRING type columns");
+    return new LuceneTextIndexCreator(context.getFieldSpec().getName(), 
context.getIndexDir(),
+        true /* commitOnClose */);
+  }
+
+  @Override
+  public TextIndexCreator newFSTIndexCreator(IndexCreationContext context)
+      throws IOException {
+    Preconditions.checkState(context.getFieldSpec().isSingleValueField(),
+        "FST index is currently only supported on single-value columns");
+    
Preconditions.checkState(context.getFieldSpec().getDataType().getStoredType() 
== FieldSpec.DataType.STRING,
+        "FST index is currently only supported on STRING type columns");
+    Preconditions.checkState(!context.isRawColumn(),
+        "FST index is currently only supported on dictionary-encoded columns");
+    String[] sortedValues = (String[]) context.getSortedUniqueElementsArray();
+    if (context.getFstType() == FSTType.NATIVE) {
+      return new NativeFSTIndexCreator(context.getIndexDir(), 
context.getFieldSpec().getName(), sortedValues);
+    } else {
+      return new LuceneFSTIndexCreator(context.getIndexDir(), 
context.getFieldSpec().getName(), sortedValues);
+    }

Review comment:
       @atris  FYI as FST indexing expert this will be called wherever a 
`TextIndexCreator` would have been constructed verbatim.




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

Reply via email to