gortiz commented on code in PR #10184:
URL: https://github.com/apache/pinot/pull/10184#discussion_r1153025195
##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/h3/H3IndexType.java:
##########
@@ -19,75 +19,115 @@
package org.apache.pinot.segment.local.segment.index.h3;
+import com.google.common.base.Preconditions;
+import java.io.IOException;
import java.util.Map;
+import java.util.Objects;
import javax.annotation.Nullable;
+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.index.loader.ConfigurableFromIndexLoadingConfig;
+import org.apache.pinot.segment.local.segment.index.loader.IndexLoadingConfig;
+import
org.apache.pinot.segment.local.segment.index.loader.invertedindex.H3IndexHandler;
+import
org.apache.pinot.segment.local.segment.index.readers.geospatial.ImmutableH3IndexReader;
import org.apache.pinot.segment.spi.ColumnMetadata;
import org.apache.pinot.segment.spi.V1Constants;
import org.apache.pinot.segment.spi.creator.IndexCreationContext;
+import org.apache.pinot.segment.spi.index.AbstractIndexType;
+import org.apache.pinot.segment.spi.index.ColumnConfigDeserializer;
import org.apache.pinot.segment.spi.index.FieldIndexConfigs;
-import org.apache.pinot.segment.spi.index.IndexCreator;
+import org.apache.pinot.segment.spi.index.IndexConfigDeserializer;
import org.apache.pinot.segment.spi.index.IndexHandler;
-import org.apache.pinot.segment.spi.index.IndexReader;
import org.apache.pinot.segment.spi.index.IndexReaderFactory;
import org.apache.pinot.segment.spi.index.IndexType;
import org.apache.pinot.segment.spi.index.StandardIndexes;
+import org.apache.pinot.segment.spi.index.creator.GeoSpatialIndexCreator;
+import org.apache.pinot.segment.spi.index.creator.H3IndexConfig;
+import org.apache.pinot.segment.spi.index.reader.H3IndexReader;
+import org.apache.pinot.segment.spi.index.reader.H3IndexResolution;
+import org.apache.pinot.segment.spi.memory.PinotDataBuffer;
import org.apache.pinot.segment.spi.store.SegmentDirectory;
-import org.apache.pinot.spi.config.table.IndexConfig;
+import org.apache.pinot.spi.config.table.FieldConfig;
import org.apache.pinot.spi.config.table.TableConfig;
+import org.apache.pinot.spi.data.FieldSpec;
import org.apache.pinot.spi.data.Schema;
-public class H3IndexType implements IndexType<IndexConfig, IndexReader,
IndexCreator> {
+public class H3IndexType extends AbstractIndexType<H3IndexConfig,
H3IndexReader, GeoSpatialIndexCreator>
+ implements ConfigurableFromIndexLoadingConfig<H3IndexConfig> {
- public static final H3IndexType INSTANCE = new H3IndexType();
-
- private H3IndexType() {
+ protected H3IndexType() {
+ super(StandardIndexes.H3_ID);
}
@Override
- public String getId() {
- return StandardIndexes.H3_ID;
+ public Class<H3IndexConfig> getIndexConfigClass() {
+ return H3IndexConfig.class;
}
@Override
- public Class<IndexConfig> getIndexConfigClass() {
- return IndexConfig.class;
+ public Map<String, H3IndexConfig> fromIndexLoadingConfig(IndexLoadingConfig
indexLoadingConfig) {
+ return indexLoadingConfig.getH3IndexConfigs();
}
@Override
- public IndexConfig getDefaultConfig() {
- return IndexConfig.DISABLED;
+ public H3IndexConfig getDefaultConfig() {
+ return H3IndexConfig.DISABLED;
}
@Override
- public IndexConfig getConfig(TableConfig tableConfig, Schema schema) {
- throw new UnsupportedOperationException();
+ public ColumnConfigDeserializer<H3IndexConfig> getDeserializer() {
+ return IndexConfigDeserializer.fromIndexes("h3", getIndexConfigClass())
+ .withExclusiveAlternative(IndexConfigDeserializer.fromIndexTypes(
+ FieldConfig.IndexType.H3,
+ ((tableConfig, fieldConfig) -> new
H3IndexConfig(fieldConfig.getProperties()))));
}
@Override
- public IndexCreator createIndexCreator(IndexCreationContext context,
IndexConfig indexConfig)
- throws Exception {
- throw new UnsupportedOperationException();
+ public GeoSpatialIndexCreator createIndexCreator(IndexCreationContext
context, H3IndexConfig indexConfig)
+ throws IOException {
+ Preconditions.checkState(context.getFieldSpec().isSingleValueField(),
+ "H3 index is currently only supported on single-value columns");
+
Preconditions.checkState(context.getFieldSpec().getDataType().getStoredType()
== FieldSpec.DataType.BYTES,
+ "H3 index is currently only supported on BYTES columns");
+ H3IndexResolution resolution =
Objects.requireNonNull(indexConfig).getResolution();
+ return context.isOnHeap()
+ ? new OnHeapH3IndexCreator(context.getIndexDir(),
context.getFieldSpec().getName(), resolution)
+ : new OffHeapH3IndexCreator(context.getIndexDir(),
context.getFieldSpec().getName(), resolution);
}
@Override
- public IndexReaderFactory<IndexReader> getReaderFactory() {
- throw new UnsupportedOperationException();
+ public IndexReaderFactory<H3IndexReader> getReaderFactory() {
+ return ReaderFactory.INSTANCE;
}
@Override
public IndexHandler createIndexHandler(SegmentDirectory segmentDirectory,
Map<String, FieldIndexConfigs> configsByCol,
@Nullable Schema schema, @Nullable TableConfig tableConfig) {
- throw new UnsupportedOperationException();
+ return new H3IndexHandler(segmentDirectory, configsByCol, tableConfig);
}
@Override
public String getFileExtension(ColumnMetadata columnMetadata) {
return V1Constants.Indexes.H3_INDEX_FILE_EXTENSION;
}
- @Override
- public String toString() {
- return getId();
+ public static class ReaderFactory extends
IndexReaderFactory.Default<H3IndexConfig, H3IndexReader> {
Review Comment:
the read method in some indexes is just an utility that is there because
previous code had a similar utility function, so not all indexes have it.
--
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]