You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by "raghavyadav01 (via GitHub)" <gi...@apache.org> on 2025/04/11 21:25:04 UTC

[PR] Map encoded forward index support [pinot]

raghavyadav01 opened a new pull request, #15526:
URL: https://github.com/apache/pinot/pull/15526

   Changes to Enable Pluggable forward Index and Map Index Filter Operator
   
   ## Overview
   This PR introduces support for pluggable forward index readers  and add MapIndexFilteroperator for MAP columns.
    
   ## Key Changes
   ### 1. Pluggable Forward Index Reader using forward index config.
   ### 2. MapIndexFilterOperator 
   ### 3. Couple of MAP Bug Fixes
   
   ## Testing
   - Integration tests for MAP field types.
   
   ## Breaking Changes
   None. This PR maintains backward compatibility while adding new functionality.
   
   ## Dependencies
   No new dependencies added.
   


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


Re: [PR] Changes to Enable Pluggable forward Index and Map Index Filter Operator for MAP column [pinot]

Posted by "Jackie-Jiang (via GitHub)" <gi...@apache.org>.
Jackie-Jiang commented on code in PR #15526:
URL: https://github.com/apache/pinot/pull/15526#discussion_r2074190878


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/loader/ForwardIndexHandler.java:
##########
@@ -411,7 +412,8 @@ private boolean shouldChangeDictIdCompressionType(String column, SegmentDirector
     // The compression type for an existing segment can only be determined by reading the forward index header.
     ColumnMetadata existingColMetadata = _segmentDirectory.getSegmentMetadata().getColumnMetadataFor(column);
     DictIdCompressionType existingCompressionType;
-    try (ForwardIndexReader<?> fwdIndexReader = ForwardIndexType.read(segmentReader, existingColMetadata)) {
+    try (ForwardIndexReader<?> fwdIndexReader = ForwardIndexType.read(segmentReader, _fieldIndexConfigs.get(column),

Review Comment:
   I don't follow. Can you provide more context?



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


Re: [PR] Changes to Enable Pluggable forward Index and Map Index Filter Operator for MAP column [pinot]

Posted by "raghavyadav01 (via GitHub)" <gi...@apache.org>.
raghavyadav01 commented on code in PR #15526:
URL: https://github.com/apache/pinot/pull/15526#discussion_r2085590131


##########
pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/index/creator/JsonIndexCreator.java:
##########
@@ -34,7 +36,11 @@ public interface JsonIndexCreator extends IndexCreator {
   @Override
   default void add(@Nonnull Object value, int dictId)
       throws IOException {
-    add((String) value);
+    if (value instanceof Map) {

Review Comment:
   If it is ok, I can do the improvement in separate PR. 



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


Re: [PR] Changes to Enable Pluggable forward Index and Map Index Filter Operator for MAP column [pinot]

Posted by "raghavyadav01 (via GitHub)" <gi...@apache.org>.
raghavyadav01 commented on code in PR #15526:
URL: https://github.com/apache/pinot/pull/15526#discussion_r2074141235


##########
pinot-core/src/main/java/org/apache/pinot/core/operator/filter/MapIndexFilterOperator.java:
##########
@@ -0,0 +1,269 @@
+/**
+ * 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.operator.filter;
+
+import com.google.common.base.CaseFormat;
+import java.util.Collections;
+import java.util.List;
+import org.apache.pinot.common.request.context.ExpressionContext;
+import org.apache.pinot.common.request.context.predicate.EqPredicate;
+import org.apache.pinot.common.request.context.predicate.InPredicate;
+import org.apache.pinot.common.request.context.predicate.JsonMatchPredicate;
+import org.apache.pinot.common.request.context.predicate.NotEqPredicate;
+import org.apache.pinot.common.request.context.predicate.NotInPredicate;
+import org.apache.pinot.common.request.context.predicate.Predicate;
+import org.apache.pinot.core.common.BlockDocIdSet;
+import org.apache.pinot.core.common.Operator;
+import org.apache.pinot.core.operator.ExplainAttributeBuilder;
+import org.apache.pinot.core.query.request.context.QueryContext;
+import org.apache.pinot.segment.spi.IndexSegment;
+import org.apache.pinot.segment.spi.datasource.DataSource;
+import org.apache.pinot.segment.spi.index.reader.JsonIndexReader;
+
+
+/**
+ * Filter operator for Map matching that internally uses JsonMatchFilterOperator or ExpressionFilterOperator.
+ * This operator converts map predicates to JSON predicates and delegates filtering operations
+ * to JsonMatchFilterOperator.
+ */
+public class MapIndexFilterOperator extends BaseFilterOperator {
+  private static final String EXPLAIN_NAME = "FILTER_MAP_INDEX";
+
+  private final JsonMatchFilterOperator _jsonMatchOperator;
+  private final ExpressionFilterOperator _expressionFilterOperator;
+  private final String _columnName;
+  private final String _keyName;
+  private final Predicate _predicate;
+  private final JsonMatchPredicate _jsonMatchPredicate;
+
+  public MapIndexFilterOperator(IndexSegment indexSegment, Predicate predicate, QueryContext queryContext,
+      int numDocs) {
+    super(numDocs, false);
+    _predicate = predicate;
+
+    // Get column name and key name from function arguments
+    List<ExpressionContext> arguments = predicate.getLhs().getFunction().getArguments();
+    if (arguments.size() != 2) {
+      throw new IllegalStateException("Expected two arguments (column name and key name), found: " + arguments.size());
+    }
+
+    _columnName = arguments.get(0).getIdentifier();
+    _keyName = cleanKey(String.valueOf(arguments.get(1).getLiteral()));

Review Comment:
   removed MapIndexConfig and fixed KeyName.



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


Re: [PR] Changes to Enable Pluggable forward Index and Map Index Filter Operator for MAP column [pinot]

Posted by "Jackie-Jiang (via GitHub)" <gi...@apache.org>.
Jackie-Jiang commented on code in PR #15526:
URL: https://github.com/apache/pinot/pull/15526#discussion_r2100960553


##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/custom/MapFieldTypeTest.java:
##########
@@ -38,14 +40,15 @@
 import org.testng.annotations.Test;
 
 import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotEquals;
 
 
 @Test(suiteName = "CustomClusterIntegrationTest")
 public class MapFieldTypeTest extends CustomDataQueryClusterIntegrationTest {
 
   // Default settings
   protected static final String DEFAULT_TABLE_NAME = "MapFieldTypeTest";
-  private static final int NUM_DOCS = 1000;
+  private static final int NUM_DOCS = 100;

Review Comment:
   Any specific reason why we want to reduce the scale of this test?



##########
pinot-core/src/main/java/org/apache/pinot/core/operator/filter/JsonMatchFilterOperator.java:
##########
@@ -41,18 +42,36 @@ public class JsonMatchFilterOperator extends BaseFilterOperator {
 
   private final JsonIndexReader _jsonIndex;
   private final JsonMatchPredicate _predicate;
+  private final FilterContext _filterContext;
 
-  public JsonMatchFilterOperator(JsonIndexReader jsonIndex, JsonMatchPredicate predicate,
-      int numDocs) {
+  /**
+   * Constructor that takes a Json Predicate
+   */
+  public JsonMatchFilterOperator(JsonIndexReader jsonIndex, JsonMatchPredicate predicate, int numDocs) {
     super(numDocs, false);
     _jsonIndex = jsonIndex;
     _predicate = predicate;
+    _filterContext = null;
+  }
+
+  /**
+   * Constructor that takes a FilterContext
+   */
+  public JsonMatchFilterOperator(JsonIndexReader jsonIndex, FilterContext filterContext, int numDocs) {
+    super(numDocs, false);
+    _jsonIndex = jsonIndex;
+    _filterContext = filterContext;
+    _predicate = null;
   }
 
   @Override
   protected BlockDocIdSet getTrues() {
-    ImmutableRoaringBitmap bitmap =
-        _jsonIndex.getMatchingDocIds(_predicate.getValue(), _predicate.getCountPredicate());
+    ImmutableRoaringBitmap bitmap;
+    if (_predicate != null) {
+      bitmap = _jsonIndex.getMatchingDocIds(_predicate.getValue(), _predicate.getCountPredicate());
+    } else {
+      bitmap = _jsonIndex.getMatchingDocIds(_filterContext);
+    }

Review Comment:
   (minor) Create a helper method for this



##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/custom/MapFieldTypeTest.java:
##########
@@ -242,9 +282,172 @@ public void testQueries(boolean useMultiStageQueryEngine)
     }
   }
 
+  @Test(dataProvider = "useBothQueryEngines")
+  public void testNotEqPredicate(boolean useMultiStageQueryEngine)
+      throws Exception {
+    setUseMultiStageQueryEngine(useMultiStageQueryEngine);
+
+    // Test NOT_EQ predicate with string map
+    String query = "SELECT stringMap['k2'] FROM " + getTableName() + " WHERE stringMap['k1'] != 'v_25'";
+    JsonNode pinotResponse = postQuery(query);
+    assertEquals(pinotResponse.get("exceptions").size(), 0);
+    JsonNode rows = pinotResponse.get("resultTable").get("rows");
+    // All records except the one with k1 = 'v_25' should be returned
+    // Verify that none of the returned rows have k1 = 'v_25'
+    for (int i = 0; i < rows.size(); i++) {
+      assertNotEquals(rows.get(i).get(0).textValue(), "v_25");
+    }
+
+    // Test NOT_EQ predicate with int map
+    query = "SELECT intMap['k2'] FROM " + getTableName() + " WHERE intMap['k1'] != 25";
+    pinotResponse = postQuery(query);
+    assertEquals(pinotResponse.get("exceptions").size(), 0);
+    rows = pinotResponse.get("resultTable").get("rows");
+    // All records except the one with k1 = 25 should be returned
+    // Verify that none of the returned rows have k1 = 25
+    for (int i = 0; i < rows.size(); i++) {
+      assertNotEquals(rows.get(i).get(0).textValue(), "v_25");
+    }
+
+    // Test NOT_EQ predicate with non-existing key
+    query = "SELECT stringMap['k2'] FROM " + getTableName() + " WHERE stringMap['kk'] != 'v_25'";
+    pinotResponse = postQuery(query);
+    assertEquals(pinotResponse.get("exceptions").size(), 0);
+    rows = pinotResponse.get("resultTable").get("rows");
+    // All records should be returned since the key doesn't exist
+    // assertEquals(rows.size(), 0);
+  }
+
+  @Test(dataProvider = "useBothQueryEngines")
+  public void testInPredicate(boolean useMultiStageQueryEngine)
+      throws Exception {
+    setUseMultiStageQueryEngine(useMultiStageQueryEngine);
+
+    // Test IN predicate with string map
+    String query = "SELECT stringMap['k2'] FROM " + getTableName() + " WHERE stringMap['k1'] IN ('v_25', 'v_26')";
+    JsonNode pinotResponse = postQuery(query);
+    assertEquals(pinotResponse.get("exceptions").size(), 0);
+    JsonNode rows = pinotResponse.get("resultTable").get("rows");
+    // Only records with k1 = 'v_25' or 'v_26' should be returned
+    assertEquals(rows.size(), 2);
+
+    // Verify the returned values
+    for (int i = 0; i < rows.size(); i++) {
+      String value = rows.get(i).get(0).textValue();
+      assert (value.equals("v_25") || value.equals("v_26"));
+    }
+
+    // Test IN predicate with int map
+    query = "SELECT intMap['k2'] FROM " + getTableName() + " WHERE intMap['k1'] IN (25, 26)";
+    pinotResponse = postQuery(query);
+    assertEquals(pinotResponse.get("exceptions").size(), 0);
+    rows = pinotResponse.get("resultTable").get("rows");
+    // Only records with k1 = 25 or 26 should be returned
+    assertEquals(rows.size(), 2);
+
+    // Verify the returned values
+    for (int i = 0; i < rows.size(); i++) {
+      int value = rows.get(i).get(0).intValue();
+      assert (value == 25 || value == 26);
+    }
+
+    // Test IN predicate with non-existing key
+    query = "SELECT stringMap['k2'] FROM " + getTableName() + " WHERE stringMap['kk'] IN ('v_25', 'v_26')";
+    pinotResponse = postQuery(query);
+    assertEquals(pinotResponse.get("exceptions").size(), 0);
+    rows = pinotResponse.get("resultTable").get("rows");
+    // No records should be returned since the key doesn't exist
+    assertEquals(rows.size(), 0);
+  }
+
+  @Test(dataProvider = "useBothQueryEngines")
+  public void testNotInPredicate(boolean useMultiStageQueryEngine)
+      throws Exception {
+    setUseMultiStageQueryEngine(useMultiStageQueryEngine);
+
+    // Test NOT IN predicate with string map
+    String query = "SELECT stringMap['k2'] FROM " + getTableName() + " WHERE stringMap['k1'] NOT IN ('v_25', 'v_26')";
+    JsonNode pinotResponse = postQuery(query);
+    assertEquals(pinotResponse.get("exceptions").size(), 0);
+    JsonNode rows = pinotResponse.get("resultTable").get("rows");
+
+    // Verify the returned values
+    for (int i = 0; i < rows.size(); i++) {
+      String value = rows.get(i).get(0).textValue();
+      assert (!value.equals("v_25") && !value.equals("v_26"));
+    }
+
+    // Test NOT IN predicate with int map
+    query = "SELECT intMap['k2'] FROM " + getTableName() + " WHERE intMap['k1'] NOT IN (25, 26)";
+    pinotResponse = postQuery(query);
+    assertEquals(pinotResponse.get("exceptions").size(), 0);
+    rows = pinotResponse.get("resultTable").get("rows");
+
+    // Verify the returned values
+    for (int i = 0; i < rows.size(); i++) {
+      int value = rows.get(i).get(0).intValue();
+      assert (value != 25 && value != 26);
+    }
+  }
+
+  @Test(dataProvider = "useBothQueryEngines")
+  public void testIsNullPredicate(boolean useMultiStageQueryEngine)
+      throws Exception {
+    setUseMultiStageQueryEngine(useMultiStageQueryEngine);
+
+    // Test IS_NULL predicate with string map
+    String query = "SELECT stringMap['k2'] FROM " + getTableName() + " WHERE stringMap['k1'] IS NULL";
+    JsonNode pinotResponse = postQuery(query);
+    assertEquals(pinotResponse.get("exceptions").size(), 0);
+    JsonNode rows = pinotResponse.get("resultTable").get("rows");
+    assertEquals(rows.size(), 0);
+
+    // Test IS_NULL predicate with non-existing key
+    query = "SELECT stringMap['k2'] FROM " + getTableName() + " WHERE stringMap['kk'] IS NULL";
+    pinotResponse = postQuery(query);
+    assertEquals(pinotResponse.get("exceptions").size(), 0);
+    rows = pinotResponse.get("resultTable").get("rows");
+    assertEquals(rows.size(), 0);
+
+    // Test IS_NOT_NULL predicate with string map
+    query = "SELECT stringMap['k2'] FROM " + getTableName() + " WHERE stringMap['k1'] IS NOT NULL";
+    pinotResponse = postQuery(query);
+    assertEquals(pinotResponse.get("exceptions").size(), 0);
+    rows = pinotResponse.get("resultTable").get("rows");
+    // All records should be returned since all records have k1 defined
+    if (useMultiStageQueryEngine) {
+      assertEquals(rows.size(), getSelectionDefaultDocCount());
+    } else {
+      //First Two rows are null for k1
+      assertEquals(rows.size(), getSelectionDefaultDocCount());
+    }
+  }
+
+  @Test(dataProvider = "useBothQueryEngines")
+  public void testStringWithQuotes(boolean useMultiStageQueryEngine)
+      throws Exception {
+    setUseMultiStageQueryEngine(useMultiStageQueryEngine);
+
+    // Test string with single quote in map value
+    String query = "SELECT stringMap['k2'] FROM " + getTableName() + " WHERE stringMap['k1'] = 'v_25''s value'";
+    JsonNode pinotResponse = postQuery(query);
+    assertEquals(pinotResponse.get("exceptions").size(), 0);
+
+    // Test string with multiple single quotes
+    query = "SELECT stringMap['k2'] FROM " + getTableName() + " WHERE stringMap['k1'] = 'v_25''s ''quoted'' value'";
+    pinotResponse = postQuery(query);
+    assertEquals(pinotResponse.get("exceptions").size(), 0);
+
+    // Test IN predicate with quoted strings
+    query = "SELECT stringMap['k2'] FROM " + getTableName()
+        + " WHERE stringMap['k1'] IN ('v_25''s value', 'v_26''s value')";
+    pinotResponse = postQuery(query);
+    assertEquals(pinotResponse.get("exceptions").size(), 0);
+  }
+
   @Override
   protected void setUseMultiStageQueryEngine(boolean useMultiStageQueryEngine) {
     super.setUseMultiStageQueryEngine(useMultiStageQueryEngine);
-    _setSelectionDefaultDocCount = useMultiStageQueryEngine ? 1000 : 10;
+    _setSelectionDefaultDocCount = useMultiStageQueryEngine ? 100 : 10;

Review Comment:
   Use constant (`NUM_DOCS`) instead of magic number



##########
pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/index/ForwardIndexConfig.java:
##########
@@ -234,6 +305,12 @@ public DictIdCompressionType getDictIdCompressionType() {
     return _dictIdCompressionType;
   }
 
+  @JsonIgnore

Review Comment:
   Why ignoring it?



##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/datasource/BaseDataSource.java:
##########
@@ -127,6 +127,7 @@ public VectorIndexReader getVectorIndex() {
     return getIndex(StandardIndexes.vector());
   }
 
+  @Deprecated

Review Comment:
   Given `MapIndexType` is deleted, consider removing all related classes and methods



##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/custom/MapFieldTypeTest.java:
##########
@@ -84,9 +87,50 @@ public Schema createSchema() {
 
   @Override
   public TableConfig createOfflineTableConfig() {
-    IngestionConfig ingestionConfig = new IngestionConfig();
-    return new TableConfigBuilder(TableType.OFFLINE).setTableName(getTableName()).setIngestionConfig(ingestionConfig)
-        .build();
+    // Create table config with field configs
+    TableConfig config =
+        new TableConfigBuilder(TableType.OFFLINE).setTableName(getTableName()).setIngestionConfig(new IngestionConfig())
+            .build();
+    // Get indexing config
+    List<FieldConfig> fieldConfigList = createFieldConfigs();
+
+    config.setFieldConfigList(fieldConfigList);
+    LOGGER.info("Table config: {}", config);

Review Comment:
   (minor) We don't usually log in test



##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/map/ImmutableMapDataSource.java:
##########
@@ -41,15 +41,12 @@ public class ImmutableMapDataSource extends BaseMapDataSource {
 
   public ImmutableMapDataSource(ColumnMetadata columnMetadata, ColumnIndexContainer columnIndexContainer) {
     super(new ImmutableMapDataSourceMetadata(columnMetadata), columnIndexContainer);
-    MapIndexReader mapIndexReader = getMapIndex();
-    if (mapIndexReader == null) {
-      // Fallback to use forward index
-      ForwardIndexReader<?> forwardIndex = getForwardIndex();
-      if (forwardIndex instanceof MapIndexReader) {
-        mapIndexReader = (MapIndexReader) forwardIndex;
-      } else {
-        mapIndexReader = new MapIndexReaderWrapper(forwardIndex, getFieldSpec());
-      }
+    MapIndexReader mapIndexReader;
+    ForwardIndexReader<?> forwardIndex = getForwardIndex();
+    if (forwardIndex instanceof MapIndexReader) {

Review Comment:
   Is `MapIndexReader` still in use?



##########
pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/index/ForwardIndexConfig.java:
##########
@@ -97,7 +98,10 @@ public static ForwardIndexConfig getDisabled() {
   private final ChunkCompressionType _chunkCompressionType;
   @Nullable
   private final DictIdCompressionType _dictIdCompressionType;
+  @Nullable
+  private final Map<String, Object> _configs;
 
+  @Deprecated
   public ForwardIndexConfig(@Nullable Boolean disabled, @Nullable CompressionCodec compressionCodec,

Review Comment:
   Just make it call the new constructor. No need to duplicate the code



##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/json/JsonIndexType.java:
##########
@@ -95,7 +95,8 @@ public JsonIndexCreator createIndexCreator(IndexCreationContext context, JsonInd
       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,
+    Preconditions.checkState(context.getFieldSpec().getDataType().getStoredType() == FieldSpec.DataType.STRING

Review Comment:
   (minor) Store `context.getFieldSpec().getDataType().getStoredType()` in a local variable, same for other repeated access



##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/custom/MapFieldTypeTest.java:
##########
@@ -84,9 +87,50 @@ public Schema createSchema() {
 
   @Override
   public TableConfig createOfflineTableConfig() {
-    IngestionConfig ingestionConfig = new IngestionConfig();
-    return new TableConfigBuilder(TableType.OFFLINE).setTableName(getTableName()).setIngestionConfig(ingestionConfig)
-        .build();
+    // Create table config with field configs
+    TableConfig config =
+        new TableConfigBuilder(TableType.OFFLINE).setTableName(getTableName()).setIngestionConfig(new IngestionConfig())
+            .build();
+    // Get indexing config
+    List<FieldConfig> fieldConfigList = createFieldConfigs();
+
+    config.setFieldConfigList(fieldConfigList);

Review Comment:
   ```suggestion
       TableConfig config = new TableConfigBuilder(TableType.OFFLINE).setTableName(getTableName())
           .setFieldConfigList(createFieldConfigs())
           .build();
   ```



##########
pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/index/ForwardIndexConfig.java:
##########
@@ -110,7 +114,60 @@ public ForwardIndexConfig(@Nullable Boolean disabled, @Nullable CompressionCodec
     _targetMaxChunkSizeBytes =
         targetMaxChunkSize == null ? _defaultTargetMaxChunkSizeBytes : (int) DataSizeUtils.toBytes(targetMaxChunkSize);
     _targetDocsPerChunk = targetDocsPerChunk == null ? _defaultTargetDocsPerChunk : targetDocsPerChunk;
+    if (compressionCodec != null) {
+      switch (compressionCodec) {
+        case PASS_THROUGH:
+        case CLP:
+        case CLPV2:
+        case CLPV2_ZSTD:
+        case CLPV2_LZ4:
+          _chunkCompressionType = ChunkCompressionType.PASS_THROUGH;
+          _dictIdCompressionType = null;
+          break;
+        case SNAPPY:
+          _chunkCompressionType = ChunkCompressionType.SNAPPY;
+          _dictIdCompressionType = null;
+          break;
+        case ZSTANDARD:
+          _chunkCompressionType = ChunkCompressionType.ZSTANDARD;
+          _dictIdCompressionType = null;
+          break;
+        case LZ4:
+          _chunkCompressionType = ChunkCompressionType.LZ4;
+          _dictIdCompressionType = null;
+          break;
+        case GZIP:
+          _chunkCompressionType = ChunkCompressionType.GZIP;
+          _dictIdCompressionType = null;
+          break;
+        case MV_ENTRY_DICT:
+          _dictIdCompressionType = DictIdCompressionType.MV_ENTRY_DICT;
+          _chunkCompressionType = null;
+          break;
+        default:
+          throw new IllegalStateException("Unsupported compression codec: " + compressionCodec);
+      }
+    } else {
+      _dictIdCompressionType = null;
+      _chunkCompressionType = null;
+    }
+    _configs = null;
+  }
 
+  public ForwardIndexConfig(@Nullable Boolean disabled, @Nullable CompressionCodec compressionCodec,
+      @Nullable Boolean deriveNumDocsPerChunk, @Nullable Integer rawIndexWriterVersion,
+      @Nullable String targetMaxChunkSize, @Nullable Integer targetDocsPerChunk,
+      @JsonProperty("configs") @Nullable Map<String, Object> configs) {

Review Comment:
   No need to annotate `@JsonProperty`



##########
pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/index/ForwardIndexConfig.java:
##########
@@ -150,7 +207,7 @@ public ForwardIndexConfig(@Nullable Boolean disabled, @Nullable CompressionCodec
     }
   }
 
-  @JsonCreator
+  @Deprecated

Review Comment:
   I think you can directly remove this constructor. If you want to keep it, given it is no longer than `@JsonCreator`, remove all `@JsonProperty`



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


Re: [PR] Changes to Enable Pluggable forward Index and Map Index Filter Operator for MAP column [pinot]

Posted by "Jackie-Jiang (via GitHub)" <gi...@apache.org>.
Jackie-Jiang commented on code in PR #15526:
URL: https://github.com/apache/pinot/pull/15526#discussion_r2074186208


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/forward/ForwardIndexReaderFactory.java:
##########
@@ -68,10 +68,33 @@ public static ForwardIndexReaderFactory getInstance() {
   protected ForwardIndexReader createIndexReader(PinotDataBuffer dataBuffer, ColumnMetadata metadata,
       ForwardIndexConfig indexConfig)
       throws IndexReaderConstraintException {
+    if (indexConfig != null && indexConfig.getConfigs().containsKey(ForwardIndexType.FORWARD_INDEX_READER_CLASS_NAME)) {
+      String className = indexConfig.getConfigs().get(ForwardIndexType.FORWARD_INDEX_READER_CLASS_NAME).toString();
+      try {
+        return (ForwardIndexReader) Class.forName(className).getConstructor(PinotDataBuffer.class, ColumnMetadata.class)
+            .newInstance(dataBuffer, metadata);
+      } catch (Exception e) {
+        throw new RuntimeException("Failed to create ForwardIndexReader", e);
+      }
+    }
+    return createIndexReader(dataBuffer, metadata);
+  }
+
+  public static ForwardIndexReader createIndexReader(PinotDataBuffer dataBuffer, ForwardIndexConfig indexConfig,

Review Comment:
   I think we can just remove the `static` one and always use `ForwardIndexReaderFactory.getInstance().createIndexReader()`



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


Re: [PR] Changes to Enable Pluggable forward Index and Map Index Filter Operator for MAP column [pinot]

Posted by "raghavyadav01 (via GitHub)" <gi...@apache.org>.
raghavyadav01 commented on code in PR #15526:
URL: https://github.com/apache/pinot/pull/15526#discussion_r2100742743


##########
pinot-core/src/main/java/org/apache/pinot/core/operator/filter/MapFilterOperator.java:
##########
@@ -0,0 +1,256 @@
+/**
+ * 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.operator.filter;
+
+import com.google.common.base.CaseFormat;
+import java.util.Collections;
+import java.util.List;
+import org.apache.pinot.common.request.context.ExpressionContext;
+import org.apache.pinot.common.request.context.predicate.EqPredicate;
+import org.apache.pinot.common.request.context.predicate.InPredicate;
+import org.apache.pinot.common.request.context.predicate.JsonMatchPredicate;
+import org.apache.pinot.common.request.context.predicate.NotEqPredicate;
+import org.apache.pinot.common.request.context.predicate.NotInPredicate;
+import org.apache.pinot.common.request.context.predicate.Predicate;
+import org.apache.pinot.core.common.BlockDocIdSet;
+import org.apache.pinot.core.common.Operator;
+import org.apache.pinot.core.operator.ExplainAttributeBuilder;
+import org.apache.pinot.core.query.request.context.QueryContext;
+import org.apache.pinot.segment.spi.IndexSegment;
+import org.apache.pinot.segment.spi.datasource.DataSource;
+import org.apache.pinot.segment.spi.index.reader.JsonIndexReader;
+
+
+/**
+ * Filter operator for Map matching that internally uses JsonMatchFilterOperator or ExpressionFilterOperator.
+ * This operator converts map predicates to JSON predicates and delegates filtering operations
+ * to JsonMatchFilterOperator.
+ */
+public class MapFilterOperator extends BaseFilterOperator {
+  private static final String EXPLAIN_NAME = "FILTER_MAP";
+
+  private final JsonMatchFilterOperator _jsonMatchOperator;
+  private final ExpressionFilterOperator _expressionFilterOperator;
+  private final String _columnName;
+  private final String _keyName;
+  private final Predicate _predicate;
+
+  public MapFilterOperator(IndexSegment indexSegment, Predicate predicate, QueryContext queryContext,
+      int numDocs) {
+    super(numDocs, false);
+    _predicate = predicate;
+
+    // Get column name and key name from function arguments
+    List<ExpressionContext> arguments = predicate.getLhs().getFunction().getArguments();
+    if (arguments.size() != 2) {
+      throw new IllegalStateException("Expected two arguments (column name and key name), found: " + arguments.size());
+    }
+
+    _columnName = arguments.get(0).getIdentifier();
+    _keyName = arguments.get(1).getLiteral().getStringValue();
+
+    // Get JSON index and create operator
+    JsonMatchPredicate jsonMatchPredicate;
+    DataSource dataSource = indexSegment.getDataSource(_columnName);
+    JsonIndexReader jsonIndex = dataSource.getJsonIndex();
+    if (jsonIndex != null && useJsonIndex(_predicate.getType())) {
+      jsonMatchPredicate = createJsonMatchPredicate();
+      _jsonMatchOperator = initializeJsonMatchFilterOperator(jsonIndex, jsonMatchPredicate, numDocs);
+      _expressionFilterOperator = null;
+    } else {
+      jsonMatchPredicate = null;
+      _jsonMatchOperator = null;
+      _expressionFilterOperator = new ExpressionFilterOperator(indexSegment, queryContext, predicate, numDocs);
+    }
+  }
+
+  /**
+   * Creates a JsonMatchPredicate based on the original predicate type
+   */
+  private JsonMatchPredicate createJsonMatchPredicate() {
+    // Convert predicate to JSON format based on type
+    String jsonFilterString;
+    switch (_predicate.getType()) {
+      case EQ:
+        jsonFilterString = createJsonEqPredicateValue(_keyName, ((EqPredicate) _predicate).getValue());
+        break;
+      case NOT_EQ:
+        jsonFilterString = createJsonNotEqPredicateValue(_keyName, ((NotEqPredicate) _predicate).getValue());
+        break;
+      case IN:
+        jsonFilterString = createJsonInPredicateValue(_keyName, ((InPredicate) _predicate).getValues());
+        break;
+      case NOT_IN:
+        jsonFilterString = createJsonNotInPredicateValue(_keyName, ((NotInPredicate) _predicate).getValues());
+        break;
+      default:
+        throw new IllegalStateException(
+            "Unsupported predicate type for creating json match predicate: " + _predicate.getType());
+    }
+
+    // Create identifier expression for the JSON column
+    ExpressionContext jsonLhs = ExpressionContext.forIdentifier(_columnName);
+    return new JsonMatchPredicate(jsonLhs, jsonFilterString, null);
+  }
+
+  @Override
+  protected BlockDocIdSet getTrues() {
+    if (_jsonMatchOperator != null) {
+      return _jsonMatchOperator.getTrues();
+    } else {
+      return _expressionFilterOperator.getTrues();
+    }
+  }
+
+  @Override
+  public boolean canOptimizeCount() {
+    if (_jsonMatchOperator != null) {
+      return _jsonMatchOperator.canOptimizeCount();
+    } else {
+      return _expressionFilterOperator.canOptimizeCount();
+    }
+  }
+
+  @Override
+  public int getNumMatchingDocs() {
+    if (_jsonMatchOperator != null) {
+      return _jsonMatchOperator.getNumMatchingDocs();
+    } else {
+      return _expressionFilterOperator.getNumMatchingDocs();
+    }
+  }
+
+  @Override
+  public boolean canProduceBitmaps() {
+    if (_jsonMatchOperator != null) {
+      return _jsonMatchOperator.canProduceBitmaps();
+    } else {
+      return _expressionFilterOperator.canProduceBitmaps();
+    }
+  }
+
+  @Override
+  public BitmapCollection getBitmaps() {
+    if (_jsonMatchOperator != null) {
+      return _jsonMatchOperator.getBitmaps();
+    } else {
+      return _expressionFilterOperator.getBitmaps();
+    }
+  }
+
+  @Override
+  public List<Operator> getChildOperators() {
+    return Collections.emptyList();
+  }
+
+  @Override
+  public String toExplainString() {
+    StringBuilder stringBuilder =
+        new StringBuilder(EXPLAIN_NAME).append("(column:").append(_columnName).append(",key:").append(_keyName)
+            .append(",indexLookUp:map_index").append(",operator:").append(_predicate.getType()).append(",predicate:")
+            .append(_predicate);
+
+    if (_jsonMatchOperator != null) {
+      stringBuilder.append(",delegateTo:json_match");
+    } else {
+      stringBuilder.append(",delegateTo:expression_filter");
+    }
+
+    return stringBuilder.append(')').toString();
+  }
+
+  @Override
+  protected String getExplainName() {
+    return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, EXPLAIN_NAME);
+  }
+
+  @Override
+  protected void explainAttributes(ExplainAttributeBuilder attributeBuilder) {
+    super.explainAttributes(attributeBuilder);
+    attributeBuilder.putString("column", _columnName);
+    attributeBuilder.putString("key", _keyName);
+    attributeBuilder.putString("indexLookUp", "map_index");
+    attributeBuilder.putString("operator", _predicate.getType().name());
+    attributeBuilder.putString("predicate", _predicate.toString());
+
+    if (_jsonMatchOperator != null) {
+      attributeBuilder.putString("delegateTo", "json_match");
+    } else {
+      attributeBuilder.putString("delegateTo", "expression_filter");
+    }
+  }
+
+  /**
+   * Initializes the JsonMatchFilterOperator with the given JsonIndexReader
+   */
+  private JsonMatchFilterOperator initializeJsonMatchFilterOperator(JsonIndexReader jsonIndex,
+      JsonMatchPredicate jsonMatchPredicate, int numDocs) {
+    return new JsonMatchFilterOperator(jsonIndex, jsonMatchPredicate, numDocs);
+  }
+
+  private String createJsonEqPredicateValue(String key, String value) {
+    return String.format("%s = '%s'", key, value);

Review Comment:
   @Jackie-Jiang I have made change to directly construct a Predicate using the key and value, then wrap it as a FilterContext then pass it into the JsonIndexReader. modified the JsonIndexreader interface to take FilterContext. 
   I have also added a test to verify the quote within value string.



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


Re: [PR] Changes to Enable Pluggable forward Index and Map Index Filter Operator for MAP column [pinot]

Posted by "raghavyadav01 (via GitHub)" <gi...@apache.org>.
raghavyadav01 commented on code in PR #15526:
URL: https://github.com/apache/pinot/pull/15526#discussion_r2085587371


##########
pinot-core/src/main/java/org/apache/pinot/core/operator/filter/MapIndexFilterOperator.java:
##########
@@ -0,0 +1,269 @@
+/**
+ * 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.operator.filter;
+
+import com.google.common.base.CaseFormat;
+import java.util.Collections;
+import java.util.List;
+import org.apache.pinot.common.request.context.ExpressionContext;
+import org.apache.pinot.common.request.context.predicate.EqPredicate;
+import org.apache.pinot.common.request.context.predicate.InPredicate;
+import org.apache.pinot.common.request.context.predicate.JsonMatchPredicate;
+import org.apache.pinot.common.request.context.predicate.NotEqPredicate;
+import org.apache.pinot.common.request.context.predicate.NotInPredicate;
+import org.apache.pinot.common.request.context.predicate.Predicate;
+import org.apache.pinot.core.common.BlockDocIdSet;
+import org.apache.pinot.core.common.Operator;
+import org.apache.pinot.core.operator.ExplainAttributeBuilder;
+import org.apache.pinot.core.query.request.context.QueryContext;
+import org.apache.pinot.segment.spi.IndexSegment;
+import org.apache.pinot.segment.spi.datasource.DataSource;
+import org.apache.pinot.segment.spi.index.reader.JsonIndexReader;
+
+
+/**
+ * Filter operator for Map matching that internally uses JsonMatchFilterOperator or ExpressionFilterOperator.
+ * This operator converts map predicates to JSON predicates and delegates filtering operations
+ * to JsonMatchFilterOperator.
+ */
+public class MapIndexFilterOperator extends BaseFilterOperator {
+  private static final String EXPLAIN_NAME = "FILTER_MAP_INDEX";
+
+  private final JsonMatchFilterOperator _jsonMatchOperator;
+  private final ExpressionFilterOperator _expressionFilterOperator;
+  private final String _columnName;
+  private final String _keyName;
+  private final Predicate _predicate;
+  private final JsonMatchPredicate _jsonMatchPredicate;
+
+  public MapIndexFilterOperator(IndexSegment indexSegment, Predicate predicate, QueryContext queryContext,
+      int numDocs) {
+    super(numDocs, false);
+    _predicate = predicate;
+
+    // Get column name and key name from function arguments
+    List<ExpressionContext> arguments = predicate.getLhs().getFunction().getArguments();
+    if (arguments.size() != 2) {
+      throw new IllegalStateException("Expected two arguments (column name and key name), found: " + arguments.size());
+    }
+
+    _columnName = arguments.get(0).getIdentifier();
+    _keyName = cleanKey(String.valueOf(arguments.get(1).getLiteral()));
+
+    // Get JSON index and create operator
+    DataSource dataSource = indexSegment.getDataSource(_columnName);
+    JsonIndexReader jsonIndex = dataSource.getJsonIndex();
+    if (jsonIndex != null && useJsonIndex(_predicate.getType())) {
+      _jsonMatchPredicate = createJsonMatchPredicate();
+      _jsonMatchOperator = initializeJsonMatchFilterOperator(jsonIndex, numDocs);
+      _expressionFilterOperator = null;
+    } else {
+      _jsonMatchPredicate = null;
+      _jsonMatchOperator = null;
+      _expressionFilterOperator = new ExpressionFilterOperator(indexSegment, queryContext, predicate, numDocs);
+    }
+  }
+
+  /**
+   * Creates a JsonMatchPredicate based on the original predicate type
+   */
+  private JsonMatchPredicate createJsonMatchPredicate() {
+    // Convert predicate to JSON format based on type
+    String jsonValue;
+    switch (_predicate.getType()) {
+      case EQ:
+        jsonValue = createJsonEqPredicateValue(_keyName, ((EqPredicate) _predicate).getValue());
+        break;
+      case NOT_EQ:
+        jsonValue = createJsonNotEqPredicateValue(_keyName, ((NotEqPredicate) _predicate).getValue());
+        break;
+      case IN:
+        jsonValue = createJsonInPredicateValue(_keyName, ((InPredicate) _predicate).getValues());
+        break;
+      case NOT_IN:
+        jsonValue = createJsonNotInPredicateValue(_keyName, ((NotInPredicate) _predicate).getValues());
+        break;
+      default:
+        throw new IllegalStateException(
+            "Unsupported predicate type for creating json match predicate: " + _predicate.getType());
+    }
+
+    // Create identifier expression for the JSON column
+    ExpressionContext jsonLhs = ExpressionContext.forIdentifier("json");
+    return new JsonMatchPredicate(jsonLhs, jsonValue, null);
+  }
+
+  @Override
+  protected BlockDocIdSet getTrues() {
+    if (_jsonMatchOperator != null) {
+      return _jsonMatchOperator.getTrues();
+    } else {
+      return _expressionFilterOperator.getTrues();
+    }
+  }
+
+  @Override
+  public boolean canOptimizeCount() {
+    if (_jsonMatchOperator != null) {
+      return _jsonMatchOperator.canOptimizeCount();
+    } else {
+      return _expressionFilterOperator.canOptimizeCount();
+    }
+  }
+
+  @Override
+  public int getNumMatchingDocs() {
+    if (_jsonMatchOperator != null) {
+      return _jsonMatchOperator.getNumMatchingDocs();
+    } else {
+      return _expressionFilterOperator.getNumMatchingDocs();
+    }
+  }
+
+  @Override
+  public boolean canProduceBitmaps() {
+    if (_jsonMatchOperator != null) {
+      return _jsonMatchOperator.canProduceBitmaps();
+    } else {
+      return _expressionFilterOperator.canProduceBitmaps();
+    }
+  }
+
+  @Override
+  public BitmapCollection getBitmaps() {
+    if (_jsonMatchOperator != null) {
+      return _jsonMatchOperator.getBitmaps();
+    } else {
+      return _expressionFilterOperator.getBitmaps();
+    }
+  }
+
+  @Override
+  public List<Operator> getChildOperators() {
+    return Collections.emptyList();
+  }
+
+  @Override
+  public String toExplainString() {
+    StringBuilder stringBuilder =
+        new StringBuilder(EXPLAIN_NAME).append("(column:").append(_columnName).append(",key:").append(_keyName)
+            .append(",indexLookUp:map_index").append(",operator:").append(_predicate.getType()).append(",predicate:")
+            .append(_predicate);
+
+    if (_jsonMatchOperator != null) {
+      stringBuilder.append(",delegateTo:json_match");
+    } else {
+      stringBuilder.append(",delegateTo:expression_filter");
+    }
+
+    return stringBuilder.append(')').toString();
+  }
+
+  @Override
+  protected String getExplainName() {
+    return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, EXPLAIN_NAME);
+  }
+
+  @Override
+  protected void explainAttributes(ExplainAttributeBuilder attributeBuilder) {
+    super.explainAttributes(attributeBuilder);
+    attributeBuilder.putString("column", _columnName);
+    attributeBuilder.putString("key", _keyName);
+    attributeBuilder.putString("indexLookUp", "map_index");
+    attributeBuilder.putString("operator", _predicate.getType().name());
+    attributeBuilder.putString("predicate", _predicate.toString());
+
+    if (_jsonMatchOperator != null) {
+      attributeBuilder.putString("delegateTo", "json_match");
+    } else {
+      attributeBuilder.putString("delegateTo", "expression_filter");
+    }
+  }
+
+  /**
+   * Initializes the JsonMatchFilterOperator with the given JsonIndexReader
+   */
+  private JsonMatchFilterOperator initializeJsonMatchFilterOperator(JsonIndexReader jsonIndex, int numDocs) {
+    return new JsonMatchFilterOperator(jsonIndex, _jsonMatchPredicate, numDocs);
+  }
+
+  private String createJsonEqPredicateValue(String key, String value) {

Review Comment:
   Yes, there was an issue in my manual test which did not catch this issue. As you said, without quote in String value it would not work. I have fixed the code to add quotes in predicate values to create json predicate. 



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


Re: [PR] Changes to Enable Pluggable forward Index and Map Index Filter Operator for MAP column [pinot]

Posted by "raghavyadav01 (via GitHub)" <gi...@apache.org>.
raghavyadav01 commented on code in PR #15526:
URL: https://github.com/apache/pinot/pull/15526#discussion_r2101098868


##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/custom/MapFieldTypeTest.java:
##########
@@ -38,14 +40,15 @@
 import org.testng.annotations.Test;
 
 import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotEquals;
 
 
 @Test(suiteName = "CustomClusterIntegrationTest")
 public class MapFieldTypeTest extends CustomDataQueryClusterIntegrationTest {
 
   // Default settings
   protected static final String DEFAULT_TABLE_NAME = "MapFieldTypeTest";
-  private static final int NUM_DOCS = 1000;
+  private static final int NUM_DOCS = 100;

Review Comment:
   No, I added multiple tests and this is reduce the overall time of tests. 



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


Re: [PR] Changes to Enable Pluggable forward Index and Map Index Filter Operator for MAP column [pinot]

Posted by "Jackie-Jiang (via GitHub)" <gi...@apache.org>.
Jackie-Jiang commented on code in PR #15526:
URL: https://github.com/apache/pinot/pull/15526#discussion_r2074190174


##########
pinot-core/src/main/java/org/apache/pinot/core/operator/filter/MapIndexFilterOperator.java:
##########
@@ -0,0 +1,269 @@
+/**
+ * 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.operator.filter;
+
+import com.google.common.base.CaseFormat;
+import java.util.Collections;
+import java.util.List;
+import org.apache.pinot.common.request.context.ExpressionContext;
+import org.apache.pinot.common.request.context.predicate.EqPredicate;
+import org.apache.pinot.common.request.context.predicate.InPredicate;
+import org.apache.pinot.common.request.context.predicate.JsonMatchPredicate;
+import org.apache.pinot.common.request.context.predicate.NotEqPredicate;
+import org.apache.pinot.common.request.context.predicate.NotInPredicate;
+import org.apache.pinot.common.request.context.predicate.Predicate;
+import org.apache.pinot.core.common.BlockDocIdSet;
+import org.apache.pinot.core.common.Operator;
+import org.apache.pinot.core.operator.ExplainAttributeBuilder;
+import org.apache.pinot.core.query.request.context.QueryContext;
+import org.apache.pinot.segment.spi.IndexSegment;
+import org.apache.pinot.segment.spi.datasource.DataSource;
+import org.apache.pinot.segment.spi.index.reader.JsonIndexReader;
+
+
+/**
+ * Filter operator for Map matching that internally uses JsonMatchFilterOperator or ExpressionFilterOperator.
+ * This operator converts map predicates to JSON predicates and delegates filtering operations
+ * to JsonMatchFilterOperator.
+ */
+public class MapIndexFilterOperator extends BaseFilterOperator {
+  private static final String EXPLAIN_NAME = "FILTER_MAP_INDEX";
+
+  private final JsonMatchFilterOperator _jsonMatchOperator;
+  private final ExpressionFilterOperator _expressionFilterOperator;
+  private final String _columnName;
+  private final String _keyName;
+  private final Predicate _predicate;
+  private final JsonMatchPredicate _jsonMatchPredicate;
+
+  public MapIndexFilterOperator(IndexSegment indexSegment, Predicate predicate, QueryContext queryContext,
+      int numDocs) {
+    super(numDocs, false);
+    _predicate = predicate;
+
+    // Get column name and key name from function arguments
+    List<ExpressionContext> arguments = predicate.getLhs().getFunction().getArguments();
+    if (arguments.size() != 2) {
+      throw new IllegalStateException("Expected two arguments (column name and key name), found: " + arguments.size());
+    }
+
+    _columnName = arguments.get(0).getIdentifier();
+    _keyName = cleanKey(String.valueOf(arguments.get(1).getLiteral()));
+
+    // Get JSON index and create operator
+    DataSource dataSource = indexSegment.getDataSource(_columnName);
+    JsonIndexReader jsonIndex = dataSource.getJsonIndex();
+    if (jsonIndex != null && useJsonIndex(_predicate.getType())) {
+      _jsonMatchPredicate = createJsonMatchPredicate();
+      _jsonMatchOperator = initializeJsonMatchFilterOperator(jsonIndex, numDocs);
+      _expressionFilterOperator = null;
+    } else {
+      _jsonMatchPredicate = null;
+      _jsonMatchOperator = null;
+      _expressionFilterOperator = new ExpressionFilterOperator(indexSegment, queryContext, predicate, numDocs);
+    }
+  }
+
+  /**
+   * Creates a JsonMatchPredicate based on the original predicate type
+   */
+  private JsonMatchPredicate createJsonMatchPredicate() {
+    // Convert predicate to JSON format based on type
+    String jsonValue;
+    switch (_predicate.getType()) {
+      case EQ:
+        jsonValue = createJsonEqPredicateValue(_keyName, ((EqPredicate) _predicate).getValue());
+        break;
+      case NOT_EQ:
+        jsonValue = createJsonNotEqPredicateValue(_keyName, ((NotEqPredicate) _predicate).getValue());
+        break;
+      case IN:
+        jsonValue = createJsonInPredicateValue(_keyName, ((InPredicate) _predicate).getValues());
+        break;
+      case NOT_IN:
+        jsonValue = createJsonNotInPredicateValue(_keyName, ((NotInPredicate) _predicate).getValues());
+        break;
+      default:
+        throw new IllegalStateException(
+            "Unsupported predicate type for creating json match predicate: " + _predicate.getType());
+    }
+
+    // Create identifier expression for the JSON column
+    ExpressionContext jsonLhs = ExpressionContext.forIdentifier("json");
+    return new JsonMatchPredicate(jsonLhs, jsonValue, null);
+  }
+
+  @Override
+  protected BlockDocIdSet getTrues() {
+    if (_jsonMatchOperator != null) {
+      return _jsonMatchOperator.getTrues();
+    } else {
+      return _expressionFilterOperator.getTrues();
+    }
+  }
+
+  @Override
+  public boolean canOptimizeCount() {
+    if (_jsonMatchOperator != null) {
+      return _jsonMatchOperator.canOptimizeCount();
+    } else {
+      return _expressionFilterOperator.canOptimizeCount();
+    }
+  }
+
+  @Override
+  public int getNumMatchingDocs() {
+    if (_jsonMatchOperator != null) {
+      return _jsonMatchOperator.getNumMatchingDocs();
+    } else {
+      return _expressionFilterOperator.getNumMatchingDocs();
+    }
+  }
+
+  @Override
+  public boolean canProduceBitmaps() {
+    if (_jsonMatchOperator != null) {
+      return _jsonMatchOperator.canProduceBitmaps();
+    } else {
+      return _expressionFilterOperator.canProduceBitmaps();
+    }
+  }
+
+  @Override
+  public BitmapCollection getBitmaps() {
+    if (_jsonMatchOperator != null) {
+      return _jsonMatchOperator.getBitmaps();
+    } else {
+      return _expressionFilterOperator.getBitmaps();
+    }
+  }
+
+  @Override
+  public List<Operator> getChildOperators() {
+    return Collections.emptyList();
+  }
+
+  @Override
+  public String toExplainString() {
+    StringBuilder stringBuilder =
+        new StringBuilder(EXPLAIN_NAME).append("(column:").append(_columnName).append(",key:").append(_keyName)
+            .append(",indexLookUp:map_index").append(",operator:").append(_predicate.getType()).append(",predicate:")
+            .append(_predicate);
+
+    if (_jsonMatchOperator != null) {
+      stringBuilder.append(",delegateTo:json_match");
+    } else {
+      stringBuilder.append(",delegateTo:expression_filter");
+    }
+
+    return stringBuilder.append(')').toString();
+  }
+
+  @Override
+  protected String getExplainName() {
+    return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, EXPLAIN_NAME);
+  }
+
+  @Override
+  protected void explainAttributes(ExplainAttributeBuilder attributeBuilder) {
+    super.explainAttributes(attributeBuilder);
+    attributeBuilder.putString("column", _columnName);
+    attributeBuilder.putString("key", _keyName);
+    attributeBuilder.putString("indexLookUp", "map_index");
+    attributeBuilder.putString("operator", _predicate.getType().name());
+    attributeBuilder.putString("predicate", _predicate.toString());
+
+    if (_jsonMatchOperator != null) {
+      attributeBuilder.putString("delegateTo", "json_match");
+    } else {
+      attributeBuilder.putString("delegateTo", "expression_filter");
+    }
+  }
+
+  /**
+   * Initializes the JsonMatchFilterOperator with the given JsonIndexReader
+   */
+  private JsonMatchFilterOperator initializeJsonMatchFilterOperator(JsonIndexReader jsonIndex, int numDocs) {
+    return new JsonMatchFilterOperator(jsonIndex, _jsonMatchPredicate, numDocs);
+  }
+
+  private String createJsonEqPredicateValue(String key, String value) {

Review Comment:
   How about actual string values? Unquoted string is identifier (column name), so I'm surprised that it could work



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


Re: [PR] Changes to Enable Pluggable forward Index and Map Index Filter Operator for MAP column [pinot]

Posted by "raghavyadav01 (via GitHub)" <gi...@apache.org>.
raghavyadav01 commented on code in PR #15526:
URL: https://github.com/apache/pinot/pull/15526#discussion_r2074077955


##########
pinot-core/src/main/java/org/apache/pinot/core/operator/filter/MapIndexFilterOperator.java:
##########
@@ -0,0 +1,269 @@
+/**
+ * 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.operator.filter;
+
+import com.google.common.base.CaseFormat;
+import java.util.Collections;
+import java.util.List;
+import org.apache.pinot.common.request.context.ExpressionContext;
+import org.apache.pinot.common.request.context.predicate.EqPredicate;
+import org.apache.pinot.common.request.context.predicate.InPredicate;
+import org.apache.pinot.common.request.context.predicate.JsonMatchPredicate;
+import org.apache.pinot.common.request.context.predicate.NotEqPredicate;
+import org.apache.pinot.common.request.context.predicate.NotInPredicate;
+import org.apache.pinot.common.request.context.predicate.Predicate;
+import org.apache.pinot.core.common.BlockDocIdSet;
+import org.apache.pinot.core.common.Operator;
+import org.apache.pinot.core.operator.ExplainAttributeBuilder;
+import org.apache.pinot.core.query.request.context.QueryContext;
+import org.apache.pinot.segment.spi.IndexSegment;
+import org.apache.pinot.segment.spi.datasource.DataSource;
+import org.apache.pinot.segment.spi.index.reader.JsonIndexReader;
+
+
+/**
+ * Filter operator for Map matching that internally uses JsonMatchFilterOperator or ExpressionFilterOperator.
+ * This operator converts map predicates to JSON predicates and delegates filtering operations
+ * to JsonMatchFilterOperator.
+ */
+public class MapIndexFilterOperator extends BaseFilterOperator {
+  private static final String EXPLAIN_NAME = "FILTER_MAP_INDEX";
+
+  private final JsonMatchFilterOperator _jsonMatchOperator;
+  private final ExpressionFilterOperator _expressionFilterOperator;
+  private final String _columnName;
+  private final String _keyName;
+  private final Predicate _predicate;
+  private final JsonMatchPredicate _jsonMatchPredicate;

Review Comment:
   No, we can have it as a local variable. Fixed 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: 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


Re: [PR] Changes to Enable Pluggable forward Index and Map Index Filter Operator for MAP column [pinot]

Posted by "Jackie-Jiang (via GitHub)" <gi...@apache.org>.
Jackie-Jiang commented on code in PR #15526:
URL: https://github.com/apache/pinot/pull/15526#discussion_r2082356973


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/forward/ForwardIndexPlugin.java:
##########
@@ -26,10 +26,8 @@
 @AutoService(IndexPlugin.class)
 public class ForwardIndexPlugin implements IndexPlugin<ForwardIndexType> {
 
-  private static final ForwardIndexType INSTANCE = new ForwardIndexType();

Review Comment:
   @gortiz Can you help take a look at this part? What is the correct way to plug-in a custom `ForwardIndexType`? Should it be handled with `@AutoService`?



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


Re: [PR] Map encoded forward index support [pinot]

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #15526:
URL: https://github.com/apache/pinot/pull/15526#issuecomment-2798090557

   ## [Codecov](https://app.codecov.io/gh/apache/pinot/pull/15526?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   Attention: Patch coverage is `7.89474%` with `140 lines` in your changes missing coverage. Please review.
   > Project coverage is 55.83%. Comparing base [(`196de1d`)](https://app.codecov.io/gh/apache/pinot/commit/196de1d54f2af4550949f821b9adf99cccc3d3fc?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) to head [(`c86c758`)](https://app.codecov.io/gh/apache/pinot/commit/c86c7580e57baa57ebc7b07e8298109e37d1f348?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/pinot/pull/15526?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [...t/core/operator/filter/MapIndexFilterOperator.java](https://app.codecov.io/gh/apache/pinot/pull/15526?src=pr&el=tree&filepath=pinot-core%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpinot%2Fcore%2Foperator%2Ffilter%2FMapIndexFilterOperator.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cGlub3QtY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3QvY29yZS9vcGVyYXRvci9maWx0ZXIvTWFwSW5kZXhGaWx0ZXJPcGVyYXRvci5qYXZh) | 0.00% | [95 Missing :warning: ](https://app.codecov.io/gh/apache/pinot/pull/15526?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [...converter/stats/RealtimeSegmentStatsContainer.java](https://app.codecov.io/gh/apache/pinot/pull/15526?src=pr&el=tree&filepath=pinot-segment-local%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpinot%2Fsegment%2Flocal%2Frealtime%2Fconverter%2Fstats%2FRealtimeSegmentStatsContainer.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cGlub3Qtc2VnbWVudC1sb2NhbC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3Qvc2VnbWVudC9sb2NhbC9yZWFsdGltZS9jb252ZXJ0ZXIvc3RhdHMvUmVhbHRpbWVTZWdtZW50U3RhdHNDb250YWluZXIuamF2YQ==) | 0.00% | [12 Missing :warning: ](https://app.codecov.io/gh/apache/pinot/pull/15526?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [...gment/index/forward/ForwardIndexReaderFactory.java](https://app.codecov.io/gh/apache/pinot/pull/15526?src=pr&el=tree&filepath=pinot-segment-local%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpinot%2Fsegment%2Flocal%2Fsegment%2Findex%2Fforward%2FForwardIndexReaderFactory.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cGlub3Qtc2VnbWVudC1sb2NhbC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3Qvc2VnbWVudC9sb2NhbC9zZWdtZW50L2luZGV4L2ZvcndhcmQvRm9yd2FyZEluZGV4UmVhZGVyRmFjdG9yeS5qYXZh) | 25.00% | [5 Missing and 1 partial :warning: ](https://app.codecov.io/gh/apache/pinot/pull/15526?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [...he/pinot/segment/spi/index/ForwardIndexConfig.java](https://app.codecov.io/gh/apache/pinot/pull/15526?src=pr&el=tree&filepath=pinot-segment-spi%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpinot%2Fsegment%2Fspi%2Findex%2FForwardIndexConfig.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cGlub3Qtc2VnbWVudC1zcGkvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3Bpbm90L3NlZ21lbnQvc3BpL2luZGV4L0ZvcndhcmRJbmRleENvbmZpZy5qYXZh) | 0.00% | [5 Missing and 1 partial :warning: ](https://app.codecov.io/gh/apache/pinot/pull/15526?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [...ment/index/forward/ForwardIndexCreatorFactory.java](https://app.codecov.io/gh/apache/pinot/pull/15526?src=pr&el=tree&filepath=pinot-segment-local%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpinot%2Fsegment%2Flocal%2Fsegment%2Findex%2Fforward%2FForwardIndexCreatorFactory.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cGlub3Qtc2VnbWVudC1sb2NhbC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3Qvc2VnbWVudC9sb2NhbC9zZWdtZW50L2luZGV4L2ZvcndhcmQvRm9yd2FyZEluZGV4Q3JlYXRvckZhY3RvcnkuamF2YQ==) | 0.00% | [3 Missing and 1 partial :warning: ](https://app.codecov.io/gh/apache/pinot/pull/15526?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [.../local/segment/index/map/MutableMapDataSource.java](https://app.codecov.io/gh/apache/pinot/pull/15526?src=pr&el=tree&filepath=pinot-segment-local%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpinot%2Fsegment%2Flocal%2Fsegment%2Findex%2Fmap%2FMutableMapDataSource.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cGlub3Qtc2VnbWVudC1sb2NhbC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3Qvc2VnbWVudC9sb2NhbC9zZWdtZW50L2luZGV4L21hcC9NdXRhYmxlTWFwRGF0YVNvdXJjZS5qYXZh) | 0.00% | [4 Missing :warning: ](https://app.codecov.io/gh/apache/pinot/pull/15526?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [...a/org/apache/pinot/common/utils/PinotDataType.java](https://app.codecov.io/gh/apache/pinot/pull/15526?src=pr&el=tree&filepath=pinot-common%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpinot%2Fcommon%2Futils%2FPinotDataType.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cGlub3QtY29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9jb21tb24vdXRpbHMvUGlub3REYXRhVHlwZS5qYXZh) | 0.00% | [3 Missing :warning: ](https://app.codecov.io/gh/apache/pinot/pull/15526?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [...or/impl/stats/MapColumnPreIndexStatsCollector.java](https://app.codecov.io/gh/apache/pinot/pull/15526?src=pr&el=tree&filepath=pinot-segment-local%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpinot%2Fsegment%2Flocal%2Fsegment%2Fcreator%2Fimpl%2Fstats%2FMapColumnPreIndexStatsCollector.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cGlub3Qtc2VnbWVudC1sb2NhbC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3Qvc2VnbWVudC9sb2NhbC9zZWdtZW50L2NyZWF0b3IvaW1wbC9zdGF0cy9NYXBDb2x1bW5QcmVJbmRleFN0YXRzQ29sbGVjdG9yLmphdmE=) | 66.66% | [2 Missing and 1 partial :warning: ](https://app.codecov.io/gh/apache/pinot/pull/15526?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [...ava/org/apache/pinot/core/plan/FilterPlanNode.java](https://app.codecov.io/gh/apache/pinot/pull/15526?src=pr&el=tree&filepath=pinot-core%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpinot%2Fcore%2Fplan%2FFilterPlanNode.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cGlub3QtY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3QvY29yZS9wbGFuL0ZpbHRlclBsYW5Ob2RlLmphdmE=) | 50.00% | [1 Missing and 1 partial :warning: ](https://app.codecov.io/gh/apache/pinot/pull/15526?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [...ocal/segment/index/map/ImmutableMapDataSource.java](https://app.codecov.io/gh/apache/pinot/pull/15526?src=pr&el=tree&filepath=pinot-segment-local%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpinot%2Fsegment%2Flocal%2Fsegment%2Findex%2Fmap%2FImmutableMapDataSource.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cGlub3Qtc2VnbWVudC1sb2NhbC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3Qvc2VnbWVudC9sb2NhbC9zZWdtZW50L2luZGV4L21hcC9JbW11dGFibGVNYXBEYXRhU291cmNlLmphdmE=) | 50.00% | [1 Missing and 1 partial :warning: ](https://app.codecov.io/gh/apache/pinot/pull/15526?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | ... and [3 more](https://app.codecov.io/gh/apache/pinot/pull/15526?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | |
   
   > :exclamation:  There is a different number of reports uploaded between BASE (196de1d) and HEAD (c86c758). Click for more details.
   > 
   > <details><summary>HEAD has 62 uploads less than BASE</summary>
   >
   >| Flag | BASE (196de1d) | HEAD (c86c758) |
   >|------|------|------|
   >|unittests|6|2|
   >|unittests1|3|2|
   >|java-21|10|2|
   >|skip-bytebuffers-false|8|1|
   >|temurin|15|2|
   >|skip-bytebuffers-true|4|1|
   >|unittests2|3|0|
   >|java-11|5|0|
   >|integration|9|0|
   >|integration2|3|0|
   >|integration1|3|0|
   >|custom-integration1|3|0|
   ></details>
   
   <details><summary>Additional details and impacted files</summary>
   
   
   ```diff
   @@             Coverage Diff              @@
   ##             master   #15526      +/-   ##
   ============================================
   - Coverage     62.98%   55.83%   -7.15%     
   + Complexity     1382      681     -701     
   ============================================
     Files          2848     2224     -624     
     Lines        161601   120215   -41386     
     Branches      24754    19201    -5553     
   ============================================
   - Hits         101785    67124   -34661     
   + Misses        52132    47567    -4565     
   + Partials       7684     5524    -2160     
   ```
   
   | [Flag](https://app.codecov.io/gh/apache/pinot/pull/15526/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [custom-integration1](https://app.codecov.io/gh/apache/pinot/pull/15526/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [integration](https://app.codecov.io/gh/apache/pinot/pull/15526/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [integration1](https://app.codecov.io/gh/apache/pinot/pull/15526/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [integration2](https://app.codecov.io/gh/apache/pinot/pull/15526/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [java-11](https://app.codecov.io/gh/apache/pinot/pull/15526/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [java-21](https://app.codecov.io/gh/apache/pinot/pull/15526/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `55.83% <7.89%> (-7.12%)` | :arrow_down: |
   | [skip-bytebuffers-false](https://app.codecov.io/gh/apache/pinot/pull/15526/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `55.81% <7.89%> (-7.17%)` | :arrow_down: |
   | [skip-bytebuffers-true](https://app.codecov.io/gh/apache/pinot/pull/15526/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `55.79% <7.89%> (-7.09%)` | :arrow_down: |
   | [temurin](https://app.codecov.io/gh/apache/pinot/pull/15526/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `55.83% <7.89%> (-7.15%)` | :arrow_down: |
   | [unittests](https://app.codecov.io/gh/apache/pinot/pull/15526/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `55.83% <7.89%> (-7.15%)` | :arrow_down: |
   | [unittests1](https://app.codecov.io/gh/apache/pinot/pull/15526/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `55.83% <7.89%> (-0.07%)` | :arrow_down: |
   | [unittests2](https://app.codecov.io/gh/apache/pinot/pull/15526/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
   
   </details>
   
   [:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/pinot/pull/15526?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   - :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
   </details>


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


Re: [PR] Changes to Enable Pluggable forward Index and Map Index Filter Operator for MAP column [pinot]

Posted by "raghavyadav01 (via GitHub)" <gi...@apache.org>.
raghavyadav01 commented on code in PR #15526:
URL: https://github.com/apache/pinot/pull/15526#discussion_r2103035827


##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/custom/MapFieldTypeTest.java:
##########
@@ -38,14 +40,15 @@
 import org.testng.annotations.Test;
 
 import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotEquals;
 
 
 @Test(suiteName = "CustomClusterIntegrationTest")
 public class MapFieldTypeTest extends CustomDataQueryClusterIntegrationTest {
 
   // Default settings
   protected static final String DEFAULT_TABLE_NAME = "MapFieldTypeTest";
-  private static final int NUM_DOCS = 1000;
+  private static final int NUM_DOCS = 100;

Review Comment:
   reverted back to 1000.



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


Re: [PR] Changes to Enable Pluggable forward Index and Map Index Filter Operator for MAP column [pinot]

Posted by "raghavyadav01 (via GitHub)" <gi...@apache.org>.
raghavyadav01 commented on code in PR #15526:
URL: https://github.com/apache/pinot/pull/15526#discussion_r2101512993


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/map/MutableMapDataSource.java:
##########
@@ -55,15 +55,13 @@ public MutableMapDataSource(FieldSpec fieldSpec, int numDocs, int numValues, int
             partitionFunction, partitions, minValue, maxValue, maxRowLengthInBytes),
         new ColumnIndexContainer.FromMap.Builder().withAll(mutableIndexes).build());
     _mutableIndexes = mutableIndexes;
-    MapIndexReader mapIndexReader = getMapIndex();
-    if (mapIndexReader == null) {
-      // Fallback to use forward index
-      ForwardIndexReader<?> forwardIndex = getForwardIndex();
-      if (forwardIndex instanceof MapIndexReader) {
-        mapIndexReader = (MapIndexReader) forwardIndex;
-      } else {
-        mapIndexReader = new MapIndexReaderWrapper(forwardIndex, getFieldSpec());
-      }
+    MapIndexReader mapIndexReader;
+    // Fallback to use forward index
+    ForwardIndexReader<?> forwardIndex = getForwardIndex();
+    if (forwardIndex instanceof MapIndexReader) {
+      mapIndexReader = (MapIndexReader) forwardIndex;
+    } else {
+      mapIndexReader = new MapIndexReaderWrapper(forwardIndex, getFieldSpec());

Review Comment:
   Yes, the wrapper is required for keyMetadata API while constructing the Key datasource. 



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


Re: [PR] Changes to Enable Pluggable forward Index and Map Index Filter Operator for MAP column [pinot]

Posted by "raghavyadav01 (via GitHub)" <gi...@apache.org>.
raghavyadav01 commented on code in PR #15526:
URL: https://github.com/apache/pinot/pull/15526#discussion_r2074088607


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/map/MutableMapDataSource.java:
##########
@@ -55,15 +55,13 @@ public MutableMapDataSource(FieldSpec fieldSpec, int numDocs, int numValues, int
             partitionFunction, partitions, minValue, maxValue, maxRowLengthInBytes),
         new ColumnIndexContainer.FromMap.Builder().withAll(mutableIndexes).build());
     _mutableIndexes = mutableIndexes;
-    MapIndexReader mapIndexReader = getMapIndex();
-    if (mapIndexReader == null) {
-      // Fallback to use forward index
-      ForwardIndexReader<?> forwardIndex = getForwardIndex();
-      if (forwardIndex instanceof MapIndexReader) {
-        mapIndexReader = (MapIndexReader) forwardIndex;
-      } else {
-        mapIndexReader = new MapIndexReaderWrapper(forwardIndex, getFieldSpec());
-      }
+    MapIndexReader mapIndexReader;
+    // Fallback to use forward index
+    ForwardIndexReader<?> forwardIndex = getForwardIndex();
+    if (forwardIndex instanceof MapIndexReader) {
+      mapIndexReader = (MapIndexReader) forwardIndex;
+    } else {
+      mapIndexReader = new MapIndexReaderWrapper(forwardIndex, getFieldSpec());

Review Comment:
   MapIndexReader provides map key level API's  and MapIndexReaderWrapper wraps forwardIndex to provide the Map key level API's when default forwardIndex is used for Map. 



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


Re: [PR] Changes to Enable Pluggable forward Index and Map Index Filter Operator for MAP column [pinot]

Posted by "raghavyadav01 (via GitHub)" <gi...@apache.org>.
raghavyadav01 commented on code in PR #15526:
URL: https://github.com/apache/pinot/pull/15526#discussion_r2101103411


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/map/ImmutableMapDataSource.java:
##########
@@ -41,15 +41,12 @@ public class ImmutableMapDataSource extends BaseMapDataSource {
 
   public ImmutableMapDataSource(ColumnMetadata columnMetadata, ColumnIndexContainer columnIndexContainer) {
     super(new ImmutableMapDataSourceMetadata(columnMetadata), columnIndexContainer);
-    MapIndexReader mapIndexReader = getMapIndex();
-    if (mapIndexReader == null) {
-      // Fallback to use forward index
-      ForwardIndexReader<?> forwardIndex = getForwardIndex();
-      if (forwardIndex instanceof MapIndexReader) {
-        mapIndexReader = (MapIndexReader) forwardIndex;
-      } else {
-        mapIndexReader = new MapIndexReaderWrapper(forwardIndex, getFieldSpec());
-      }
+    MapIndexReader mapIndexReader;
+    ForwardIndexReader<?> forwardIndex = getForwardIndex();
+    if (forwardIndex instanceof MapIndexReader) {

Review Comment:
   yes, It is used to because of couple of new API's in MapIndexReader for keys. 



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


Re: [PR] Changes to Enable Pluggable forward Index and Map Index Filter Operator for MAP column [pinot]

Posted by "Jackie-Jiang (via GitHub)" <gi...@apache.org>.
Jackie-Jiang commented on code in PR #15526:
URL: https://github.com/apache/pinot/pull/15526#discussion_r2096611126


##########
pinot-core/src/main/java/org/apache/pinot/core/operator/filter/MapFilterOperator.java:
##########
@@ -0,0 +1,256 @@
+/**
+ * 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.operator.filter;
+
+import com.google.common.base.CaseFormat;
+import java.util.Collections;
+import java.util.List;
+import org.apache.pinot.common.request.context.ExpressionContext;
+import org.apache.pinot.common.request.context.predicate.EqPredicate;
+import org.apache.pinot.common.request.context.predicate.InPredicate;
+import org.apache.pinot.common.request.context.predicate.JsonMatchPredicate;
+import org.apache.pinot.common.request.context.predicate.NotEqPredicate;
+import org.apache.pinot.common.request.context.predicate.NotInPredicate;
+import org.apache.pinot.common.request.context.predicate.Predicate;
+import org.apache.pinot.core.common.BlockDocIdSet;
+import org.apache.pinot.core.common.Operator;
+import org.apache.pinot.core.operator.ExplainAttributeBuilder;
+import org.apache.pinot.core.query.request.context.QueryContext;
+import org.apache.pinot.segment.spi.IndexSegment;
+import org.apache.pinot.segment.spi.datasource.DataSource;
+import org.apache.pinot.segment.spi.index.reader.JsonIndexReader;
+
+
+/**
+ * Filter operator for Map matching that internally uses JsonMatchFilterOperator or ExpressionFilterOperator.
+ * This operator converts map predicates to JSON predicates and delegates filtering operations
+ * to JsonMatchFilterOperator.
+ */
+public class MapFilterOperator extends BaseFilterOperator {
+  private static final String EXPLAIN_NAME = "FILTER_MAP";
+
+  private final JsonMatchFilterOperator _jsonMatchOperator;
+  private final ExpressionFilterOperator _expressionFilterOperator;
+  private final String _columnName;
+  private final String _keyName;
+  private final Predicate _predicate;
+
+  public MapFilterOperator(IndexSegment indexSegment, Predicate predicate, QueryContext queryContext,
+      int numDocs) {
+    super(numDocs, false);
+    _predicate = predicate;
+
+    // Get column name and key name from function arguments
+    List<ExpressionContext> arguments = predicate.getLhs().getFunction().getArguments();
+    if (arguments.size() != 2) {
+      throw new IllegalStateException("Expected two arguments (column name and key name), found: " + arguments.size());
+    }
+
+    _columnName = arguments.get(0).getIdentifier();
+    _keyName = arguments.get(1).getLiteral().getStringValue();
+
+    // Get JSON index and create operator
+    JsonMatchPredicate jsonMatchPredicate;
+    DataSource dataSource = indexSegment.getDataSource(_columnName);
+    JsonIndexReader jsonIndex = dataSource.getJsonIndex();
+    if (jsonIndex != null && useJsonIndex(_predicate.getType())) {
+      jsonMatchPredicate = createJsonMatchPredicate();
+      _jsonMatchOperator = initializeJsonMatchFilterOperator(jsonIndex, jsonMatchPredicate, numDocs);
+      _expressionFilterOperator = null;
+    } else {
+      jsonMatchPredicate = null;
+      _jsonMatchOperator = null;
+      _expressionFilterOperator = new ExpressionFilterOperator(indexSegment, queryContext, predicate, numDocs);
+    }
+  }
+
+  /**
+   * Creates a JsonMatchPredicate based on the original predicate type
+   */
+  private JsonMatchPredicate createJsonMatchPredicate() {
+    // Convert predicate to JSON format based on type
+    String jsonFilterString;
+    switch (_predicate.getType()) {
+      case EQ:
+        jsonFilterString = createJsonEqPredicateValue(_keyName, ((EqPredicate) _predicate).getValue());
+        break;
+      case NOT_EQ:
+        jsonFilterString = createJsonNotEqPredicateValue(_keyName, ((NotEqPredicate) _predicate).getValue());
+        break;
+      case IN:
+        jsonFilterString = createJsonInPredicateValue(_keyName, ((InPredicate) _predicate).getValues());
+        break;
+      case NOT_IN:
+        jsonFilterString = createJsonNotInPredicateValue(_keyName, ((NotInPredicate) _predicate).getValues());
+        break;
+      default:
+        throw new IllegalStateException(
+            "Unsupported predicate type for creating json match predicate: " + _predicate.getType());
+    }
+
+    // Create identifier expression for the JSON column
+    ExpressionContext jsonLhs = ExpressionContext.forIdentifier(_columnName);
+    return new JsonMatchPredicate(jsonLhs, jsonFilterString, null);
+  }
+
+  @Override
+  protected BlockDocIdSet getTrues() {
+    if (_jsonMatchOperator != null) {
+      return _jsonMatchOperator.getTrues();
+    } else {
+      return _expressionFilterOperator.getTrues();
+    }
+  }
+
+  @Override
+  public boolean canOptimizeCount() {
+    if (_jsonMatchOperator != null) {
+      return _jsonMatchOperator.canOptimizeCount();
+    } else {
+      return _expressionFilterOperator.canOptimizeCount();
+    }
+  }
+
+  @Override
+  public int getNumMatchingDocs() {
+    if (_jsonMatchOperator != null) {
+      return _jsonMatchOperator.getNumMatchingDocs();
+    } else {
+      return _expressionFilterOperator.getNumMatchingDocs();
+    }
+  }
+
+  @Override
+  public boolean canProduceBitmaps() {
+    if (_jsonMatchOperator != null) {
+      return _jsonMatchOperator.canProduceBitmaps();
+    } else {
+      return _expressionFilterOperator.canProduceBitmaps();
+    }
+  }
+
+  @Override
+  public BitmapCollection getBitmaps() {
+    if (_jsonMatchOperator != null) {
+      return _jsonMatchOperator.getBitmaps();
+    } else {
+      return _expressionFilterOperator.getBitmaps();
+    }
+  }
+
+  @Override
+  public List<Operator> getChildOperators() {
+    return Collections.emptyList();
+  }
+
+  @Override
+  public String toExplainString() {
+    StringBuilder stringBuilder =
+        new StringBuilder(EXPLAIN_NAME).append("(column:").append(_columnName).append(",key:").append(_keyName)
+            .append(",indexLookUp:map_index").append(",operator:").append(_predicate.getType()).append(",predicate:")
+            .append(_predicate);
+
+    if (_jsonMatchOperator != null) {
+      stringBuilder.append(",delegateTo:json_match");
+    } else {
+      stringBuilder.append(",delegateTo:expression_filter");
+    }
+
+    return stringBuilder.append(')').toString();
+  }
+
+  @Override
+  protected String getExplainName() {
+    return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, EXPLAIN_NAME);
+  }
+
+  @Override
+  protected void explainAttributes(ExplainAttributeBuilder attributeBuilder) {
+    super.explainAttributes(attributeBuilder);
+    attributeBuilder.putString("column", _columnName);
+    attributeBuilder.putString("key", _keyName);
+    attributeBuilder.putString("indexLookUp", "map_index");
+    attributeBuilder.putString("operator", _predicate.getType().name());
+    attributeBuilder.putString("predicate", _predicate.toString());
+
+    if (_jsonMatchOperator != null) {
+      attributeBuilder.putString("delegateTo", "json_match");
+    } else {
+      attributeBuilder.putString("delegateTo", "expression_filter");
+    }
+  }
+
+  /**
+   * Initializes the JsonMatchFilterOperator with the given JsonIndexReader
+   */
+  private JsonMatchFilterOperator initializeJsonMatchFilterOperator(JsonIndexReader jsonIndex,
+      JsonMatchPredicate jsonMatchPredicate, int numDocs) {
+    return new JsonMatchFilterOperator(jsonIndex, jsonMatchPredicate, numDocs);
+  }
+
+  private String createJsonEqPredicateValue(String key, String value) {
+    return String.format("%s = '%s'", key, value);

Review Comment:
   This cannot handle the case of string literal with `'` inside. You should be able to directly construct a `Predicate` using the key and value, then wrap it as a `FilterContext` then pass it into the `JsonIndexReader`



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


Re: [PR] Changes to Enable Pluggable forward Index and Map Index Filter Operator for MAP column [pinot]

Posted by "raghavyadav01 (via GitHub)" <gi...@apache.org>.
raghavyadav01 commented on code in PR #15526:
URL: https://github.com/apache/pinot/pull/15526#discussion_r2103359873


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/map/ImmutableMapDataSource.java:
##########
@@ -41,15 +41,12 @@ public class ImmutableMapDataSource extends BaseMapDataSource {
 
   public ImmutableMapDataSource(ColumnMetadata columnMetadata, ColumnIndexContainer columnIndexContainer) {
     super(new ImmutableMapDataSourceMetadata(columnMetadata), columnIndexContainer);
-    MapIndexReader mapIndexReader = getMapIndex();
-    if (mapIndexReader == null) {
-      // Fallback to use forward index
-      ForwardIndexReader<?> forwardIndex = getForwardIndex();
-      if (forwardIndex instanceof MapIndexReader) {
-        mapIndexReader = (MapIndexReader) forwardIndex;
-      } else {
-        mapIndexReader = new MapIndexReaderWrapper(forwardIndex, getFieldSpec());
-      }
+    MapIndexReader mapIndexReader;
+    ForwardIndexReader<?> forwardIndex = getForwardIndex();
+    if (forwardIndex instanceof MapIndexReader) {

Review Comment:
   removed ImmutableMapIndexReader and MutableMapIndex. 



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


Re: [PR] Changes to Enable Pluggable forward Index and Map Index Filter Operator for MAP column [pinot]

Posted by "raghavyadav01 (via GitHub)" <gi...@apache.org>.
raghavyadav01 commented on code in PR #15526:
URL: https://github.com/apache/pinot/pull/15526#discussion_r2101484758


##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/custom/MapFieldTypeTest.java:
##########
@@ -38,14 +40,15 @@
 import org.testng.annotations.Test;
 
 import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotEquals;
 
 
 @Test(suiteName = "CustomClusterIntegrationTest")
 public class MapFieldTypeTest extends CustomDataQueryClusterIntegrationTest {
 
   // Default settings
   protected static final String DEFAULT_TABLE_NAME = "MapFieldTypeTest";
-  private static final int NUM_DOCS = 1000;
+  private static final int NUM_DOCS = 100;

Review Comment:
   No it does not take long that long, I can change back to 1000. 



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


Re: [PR] Changes to Enable Pluggable forward Index and Map Index Filter Operator for MAP column [pinot]

Posted by "raghavyadav01 (via GitHub)" <gi...@apache.org>.
raghavyadav01 commented on code in PR #15526:
URL: https://github.com/apache/pinot/pull/15526#discussion_r2101140617


##########
pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/index/ForwardIndexConfig.java:
##########
@@ -234,6 +305,12 @@ public DictIdCompressionType getDictIdCompressionType() {
     return _dictIdCompressionType;
   }
 
+  @JsonIgnore

Review Comment:
   Its by mistake, removed 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: 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


Re: [PR] Changes to Enable Pluggable forward Index and Map Index Filter Operator for MAP column [pinot]

Posted by "raghavyadav01 (via GitHub)" <gi...@apache.org>.
raghavyadav01 commented on code in PR #15526:
URL: https://github.com/apache/pinot/pull/15526#discussion_r2074158076


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/forward/ForwardIndexReaderFactory.java:
##########
@@ -68,10 +68,33 @@ public static ForwardIndexReaderFactory getInstance() {
   protected ForwardIndexReader createIndexReader(PinotDataBuffer dataBuffer, ColumnMetadata metadata,
       ForwardIndexConfig indexConfig)
       throws IndexReaderConstraintException {
+    if (indexConfig != null && indexConfig.getConfigs().containsKey(ForwardIndexType.FORWARD_INDEX_READER_CLASS_NAME)) {
+      String className = indexConfig.getConfigs().get(ForwardIndexType.FORWARD_INDEX_READER_CLASS_NAME).toString();
+      try {
+        return (ForwardIndexReader) Class.forName(className).getConstructor(PinotDataBuffer.class, ColumnMetadata.class)
+            .newInstance(dataBuffer, metadata);
+      } catch (Exception e) {
+        throw new RuntimeException("Failed to create ForwardIndexReader", e);
+      }
+    }
+    return createIndexReader(dataBuffer, metadata);
+  }
+
+  public static ForwardIndexReader createIndexReader(PinotDataBuffer dataBuffer, ForwardIndexConfig indexConfig,

Review Comment:
   @Jackie-Jiang I had to modify this API to pass indexConfig for Forward Index Handler. The api is very similar to non-static API with different signature. 
   Let me know if you think we should implement it in a different way. 



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


Re: [PR] Changes to Enable Pluggable forward Index and Map Index Filter Operator for MAP column [pinot]

Posted by "raghavyadav01 (via GitHub)" <gi...@apache.org>.
raghavyadav01 commented on code in PR #15526:
URL: https://github.com/apache/pinot/pull/15526#discussion_r2074081298


##########
pinot-core/src/main/java/org/apache/pinot/core/operator/filter/MapIndexFilterOperator.java:
##########
@@ -0,0 +1,269 @@
+/**
+ * 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.operator.filter;
+
+import com.google.common.base.CaseFormat;
+import java.util.Collections;
+import java.util.List;
+import org.apache.pinot.common.request.context.ExpressionContext;
+import org.apache.pinot.common.request.context.predicate.EqPredicate;
+import org.apache.pinot.common.request.context.predicate.InPredicate;
+import org.apache.pinot.common.request.context.predicate.JsonMatchPredicate;
+import org.apache.pinot.common.request.context.predicate.NotEqPredicate;
+import org.apache.pinot.common.request.context.predicate.NotInPredicate;
+import org.apache.pinot.common.request.context.predicate.Predicate;
+import org.apache.pinot.core.common.BlockDocIdSet;
+import org.apache.pinot.core.common.Operator;
+import org.apache.pinot.core.operator.ExplainAttributeBuilder;
+import org.apache.pinot.core.query.request.context.QueryContext;
+import org.apache.pinot.segment.spi.IndexSegment;
+import org.apache.pinot.segment.spi.datasource.DataSource;
+import org.apache.pinot.segment.spi.index.reader.JsonIndexReader;
+
+
+/**
+ * Filter operator for Map matching that internally uses JsonMatchFilterOperator or ExpressionFilterOperator.
+ * This operator converts map predicates to JSON predicates and delegates filtering operations
+ * to JsonMatchFilterOperator.
+ */
+public class MapIndexFilterOperator extends BaseFilterOperator {
+  private static final String EXPLAIN_NAME = "FILTER_MAP_INDEX";
+
+  private final JsonMatchFilterOperator _jsonMatchOperator;
+  private final ExpressionFilterOperator _expressionFilterOperator;
+  private final String _columnName;
+  private final String _keyName;
+  private final Predicate _predicate;
+  private final JsonMatchPredicate _jsonMatchPredicate;
+
+  public MapIndexFilterOperator(IndexSegment indexSegment, Predicate predicate, QueryContext queryContext,
+      int numDocs) {
+    super(numDocs, false);
+    _predicate = predicate;
+
+    // Get column name and key name from function arguments
+    List<ExpressionContext> arguments = predicate.getLhs().getFunction().getArguments();
+    if (arguments.size() != 2) {
+      throw new IllegalStateException("Expected two arguments (column name and key name), found: " + arguments.size());
+    }
+
+    _columnName = arguments.get(0).getIdentifier();
+    _keyName = cleanKey(String.valueOf(arguments.get(1).getLiteral()));
+
+    // Get JSON index and create operator
+    DataSource dataSource = indexSegment.getDataSource(_columnName);
+    JsonIndexReader jsonIndex = dataSource.getJsonIndex();
+    if (jsonIndex != null && useJsonIndex(_predicate.getType())) {
+      _jsonMatchPredicate = createJsonMatchPredicate();
+      _jsonMatchOperator = initializeJsonMatchFilterOperator(jsonIndex, numDocs);
+      _expressionFilterOperator = null;
+    } else {
+      _jsonMatchPredicate = null;
+      _jsonMatchOperator = null;
+      _expressionFilterOperator = new ExpressionFilterOperator(indexSegment, queryContext, predicate, numDocs);
+    }
+  }
+
+  /**
+   * Creates a JsonMatchPredicate based on the original predicate type
+   */
+  private JsonMatchPredicate createJsonMatchPredicate() {
+    // Convert predicate to JSON format based on type
+    String jsonValue;
+    switch (_predicate.getType()) {
+      case EQ:
+        jsonValue = createJsonEqPredicateValue(_keyName, ((EqPredicate) _predicate).getValue());
+        break;
+      case NOT_EQ:
+        jsonValue = createJsonNotEqPredicateValue(_keyName, ((NotEqPredicate) _predicate).getValue());
+        break;
+      case IN:
+        jsonValue = createJsonInPredicateValue(_keyName, ((InPredicate) _predicate).getValues());
+        break;
+      case NOT_IN:
+        jsonValue = createJsonNotInPredicateValue(_keyName, ((NotInPredicate) _predicate).getValues());
+        break;
+      default:
+        throw new IllegalStateException(
+            "Unsupported predicate type for creating json match predicate: " + _predicate.getType());
+    }
+
+    // Create identifier expression for the JSON column
+    ExpressionContext jsonLhs = ExpressionContext.forIdentifier("json");
+    return new JsonMatchPredicate(jsonLhs, jsonValue, null);
+  }
+
+  @Override
+  protected BlockDocIdSet getTrues() {
+    if (_jsonMatchOperator != null) {
+      return _jsonMatchOperator.getTrues();
+    } else {
+      return _expressionFilterOperator.getTrues();
+    }
+  }
+
+  @Override
+  public boolean canOptimizeCount() {
+    if (_jsonMatchOperator != null) {
+      return _jsonMatchOperator.canOptimizeCount();
+    } else {
+      return _expressionFilterOperator.canOptimizeCount();
+    }
+  }
+
+  @Override
+  public int getNumMatchingDocs() {
+    if (_jsonMatchOperator != null) {
+      return _jsonMatchOperator.getNumMatchingDocs();
+    } else {
+      return _expressionFilterOperator.getNumMatchingDocs();
+    }
+  }
+
+  @Override
+  public boolean canProduceBitmaps() {
+    if (_jsonMatchOperator != null) {
+      return _jsonMatchOperator.canProduceBitmaps();
+    } else {
+      return _expressionFilterOperator.canProduceBitmaps();
+    }
+  }
+
+  @Override
+  public BitmapCollection getBitmaps() {
+    if (_jsonMatchOperator != null) {
+      return _jsonMatchOperator.getBitmaps();
+    } else {
+      return _expressionFilterOperator.getBitmaps();
+    }
+  }
+
+  @Override
+  public List<Operator> getChildOperators() {
+    return Collections.emptyList();
+  }
+
+  @Override
+  public String toExplainString() {
+    StringBuilder stringBuilder =
+        new StringBuilder(EXPLAIN_NAME).append("(column:").append(_columnName).append(",key:").append(_keyName)
+            .append(",indexLookUp:map_index").append(",operator:").append(_predicate.getType()).append(",predicate:")
+            .append(_predicate);
+
+    if (_jsonMatchOperator != null) {
+      stringBuilder.append(",delegateTo:json_match");
+    } else {
+      stringBuilder.append(",delegateTo:expression_filter");
+    }
+
+    return stringBuilder.append(')').toString();
+  }
+
+  @Override
+  protected String getExplainName() {
+    return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, EXPLAIN_NAME);
+  }
+
+  @Override
+  protected void explainAttributes(ExplainAttributeBuilder attributeBuilder) {
+    super.explainAttributes(attributeBuilder);
+    attributeBuilder.putString("column", _columnName);
+    attributeBuilder.putString("key", _keyName);
+    attributeBuilder.putString("indexLookUp", "map_index");
+    attributeBuilder.putString("operator", _predicate.getType().name());
+    attributeBuilder.putString("predicate", _predicate.toString());
+
+    if (_jsonMatchOperator != null) {
+      attributeBuilder.putString("delegateTo", "json_match");
+    } else {
+      attributeBuilder.putString("delegateTo", "expression_filter");
+    }
+  }
+
+  /**
+   * Initializes the JsonMatchFilterOperator with the given JsonIndexReader
+   */
+  private JsonMatchFilterOperator initializeJsonMatchFilterOperator(JsonIndexReader jsonIndex, int numDocs) {
+    return new JsonMatchFilterOperator(jsonIndex, _jsonMatchPredicate, numDocs);
+  }
+
+  private String createJsonEqPredicateValue(String key, String value) {

Review Comment:
   Yes, i tested it locally and it works for string. When I used quote then it was failing. 



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


Re: [PR] Changes to Enable Pluggable forward Index and Map Index Filter Operator for MAP column [pinot]

Posted by "raghavyadav01 (via GitHub)" <gi...@apache.org>.
raghavyadav01 commented on code in PR #15526:
URL: https://github.com/apache/pinot/pull/15526#discussion_r2074159717


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/loader/ForwardIndexHandler.java:
##########
@@ -411,7 +412,8 @@ private boolean shouldChangeDictIdCompressionType(String column, SegmentDirector
     // The compression type for an existing segment can only be determined by reading the forward index header.
     ColumnMetadata existingColMetadata = _segmentDirectory.getSegmentMetadata().getColumnMetadataFor(column);
     DictIdCompressionType existingCompressionType;
-    try (ForwardIndexReader<?> fwdIndexReader = ForwardIndexType.read(segmentReader, existingColMetadata)) {
+    try (ForwardIndexReader<?> fwdIndexReader = ForwardIndexType.read(segmentReader, _fieldIndexConfigs.get(column),

Review Comment:
   @Jackie-Jiang Should we have a custom IndexHandler provided in config similar to custom forwardIndex? 



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


Re: [PR] Changes to Enable Pluggable forward Index and Map Index Filter Operator for MAP column [pinot]

Posted by "raghavyadav01 (via GitHub)" <gi...@apache.org>.
raghavyadav01 commented on code in PR #15526:
URL: https://github.com/apache/pinot/pull/15526#discussion_r2074074994


##########
pinot-core/src/main/java/org/apache/pinot/core/plan/FilterPlanNode.java:
##########
@@ -238,6 +248,8 @@ private BaseFilterOperator constructPhysicalOperator(FilterContext filter, int n
             return new H3IndexFilterOperator(_indexSegment, _queryContext, predicate, numDocs);
           } else if (canApplyH3IndexForInclusionCheck(predicate, lhs.getFunction())) {
             return new H3InclusionIndexFilterOperator(_indexSegment, _queryContext, predicate, numDocs);
+          } else if (canApplyMapFilter(predicate, lhs.getIdentifier())) {

Review Comment:
   We do not need MapIndexConfig. I have removed it. 
   Second Argument in canApplyMapFilter is not used and removed 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: 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


Re: [PR] Changes to Enable Pluggable forward Index and Map Index Filter Operator for MAP column [pinot]

Posted by "raghavyadav01 (via GitHub)" <gi...@apache.org>.
raghavyadav01 commented on code in PR #15526:
URL: https://github.com/apache/pinot/pull/15526#discussion_r2101513455


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/map/ImmutableMapDataSource.java:
##########
@@ -41,15 +41,12 @@ public class ImmutableMapDataSource extends BaseMapDataSource {
 
   public ImmutableMapDataSource(ColumnMetadata columnMetadata, ColumnIndexContainer columnIndexContainer) {
     super(new ImmutableMapDataSourceMetadata(columnMetadata), columnIndexContainer);
-    MapIndexReader mapIndexReader = getMapIndex();
-    if (mapIndexReader == null) {
-      // Fallback to use forward index
-      ForwardIndexReader<?> forwardIndex = getForwardIndex();
-      if (forwardIndex instanceof MapIndexReader) {
-        mapIndexReader = (MapIndexReader) forwardIndex;
-      } else {
-        mapIndexReader = new MapIndexReaderWrapper(forwardIndex, getFieldSpec());
-      }
+    MapIndexReader mapIndexReader;
+    ForwardIndexReader<?> forwardIndex = getForwardIndex();
+    if (forwardIndex instanceof MapIndexReader) {

Review Comment:
   ImmutableMapIndexReader or MutableMapIndex is not used anymore, and it can be removed. 



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


Re: [PR] Changes to Enable Pluggable forward Index and Map Index Filter Operator for MAP column [pinot]

Posted by "Jackie-Jiang (via GitHub)" <gi...@apache.org>.
Jackie-Jiang merged PR #15526:
URL: https://github.com/apache/pinot/pull/15526


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


Re: [PR] Changes to Enable Pluggable forward Index and Map Index Filter Operator for MAP column [pinot]

Posted by "Jackie-Jiang (via GitHub)" <gi...@apache.org>.
Jackie-Jiang commented on code in PR #15526:
URL: https://github.com/apache/pinot/pull/15526#discussion_r2103407592


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/readers/json/ImmutableJsonIndexReader.java:
##########
@@ -120,15 +120,22 @@ public ImmutableJsonIndexReader(PinotDataBuffer dataBuffer, int numDocs) {
   }
 
   @Override
-  public MutableRoaringBitmap getMatchingDocIds(String filterString) {
+  public MutableRoaringBitmap getMatchingDocIds(String filterObj) {
     FilterContext filter;
     try {
-      filter = RequestContextUtils.getFilter(CalciteSqlParser.compileToExpression(filterString));
+      filter = RequestContextUtils.getFilter(CalciteSqlParser.compileToExpression((String) filterObj));
       Preconditions.checkArgument(!filter.isConstant());
     } catch (Exception e) {
-      throw new BadQueryRequestException("Invalid json match filter: " + filterString);
+      throw new BadQueryRequestException("Invalid json match filter: " + filterObj);
     }
-
+    return getMatchingDocIds(filter);
+  }
+  @Override

Review Comment:
   (minor) Add an empty line



##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/readers/json/ImmutableJsonIndexReader.java:
##########
@@ -120,15 +120,22 @@ public ImmutableJsonIndexReader(PinotDataBuffer dataBuffer, int numDocs) {
   }
 
   @Override
-  public MutableRoaringBitmap getMatchingDocIds(String filterString) {
+  public MutableRoaringBitmap getMatchingDocIds(String filterObj) {

Review Comment:
   Don't change the argument name. The cast is also redundant



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


Re: [PR] Changes to Enable Pluggable forward Index and Map Index Filter Operator for MAP column [pinot]

Posted by "raghavyadav01 (via GitHub)" <gi...@apache.org>.
raghavyadav01 commented on code in PR #15526:
URL: https://github.com/apache/pinot/pull/15526#discussion_r2074205529


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/loader/ForwardIndexHandler.java:
##########
@@ -411,7 +412,8 @@ private boolean shouldChangeDictIdCompressionType(String column, SegmentDirector
     // The compression type for an existing segment can only be determined by reading the forward index header.
     ColumnMetadata existingColMetadata = _segmentDirectory.getSegmentMetadata().getColumnMetadataFor(column);
     DictIdCompressionType existingCompressionType;
-    try (ForwardIndexReader<?> fwdIndexReader = ForwardIndexType.read(segmentReader, existingColMetadata)) {
+    try (ForwardIndexReader<?> fwdIndexReader = ForwardIndexType.read(segmentReader, _fieldIndexConfigs.get(column),

Review Comment:
   What I mean is - current ForwardIndexHandler only manages updates for standard forward indexes and doesn't support custom logic(may be a custom config change) for custom forward index writers. Since this PR is adding support for custom forward index writers, we should also consider allowing users to specify their own custom ForwardIndexHandler class, similar to how they can specify custom forward index writers and readers.



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


Re: [PR] Changes to Enable Pluggable forward Index and Map Index Filter Operator for MAP column [pinot]

Posted by "Jackie-Jiang (via GitHub)" <gi...@apache.org>.
Jackie-Jiang commented on code in PR #15526:
URL: https://github.com/apache/pinot/pull/15526#discussion_r2069618976


##########
pinot-core/src/main/java/org/apache/pinot/core/plan/FilterPlanNode.java:
##########
@@ -238,6 +248,8 @@ private BaseFilterOperator constructPhysicalOperator(FilterContext filter, int n
             return new H3IndexFilterOperator(_indexSegment, _queryContext, predicate, numDocs);
           } else if (canApplyH3IndexForInclusionCheck(predicate, lhs.getFunction())) {
             return new H3InclusionIndexFilterOperator(_indexSegment, _queryContext, predicate, numDocs);
+          } else if (canApplyMapFilter(predicate, lhs.getIdentifier())) {

Review Comment:
   The second argument is incorrect



##########
pinot-core/src/main/java/org/apache/pinot/core/operator/filter/MapIndexFilterOperator.java:
##########
@@ -0,0 +1,269 @@
+/**
+ * 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.operator.filter;
+
+import com.google.common.base.CaseFormat;
+import java.util.Collections;
+import java.util.List;
+import org.apache.pinot.common.request.context.ExpressionContext;
+import org.apache.pinot.common.request.context.predicate.EqPredicate;
+import org.apache.pinot.common.request.context.predicate.InPredicate;
+import org.apache.pinot.common.request.context.predicate.JsonMatchPredicate;
+import org.apache.pinot.common.request.context.predicate.NotEqPredicate;
+import org.apache.pinot.common.request.context.predicate.NotInPredicate;
+import org.apache.pinot.common.request.context.predicate.Predicate;
+import org.apache.pinot.core.common.BlockDocIdSet;
+import org.apache.pinot.core.common.Operator;
+import org.apache.pinot.core.operator.ExplainAttributeBuilder;
+import org.apache.pinot.core.query.request.context.QueryContext;
+import org.apache.pinot.segment.spi.IndexSegment;
+import org.apache.pinot.segment.spi.datasource.DataSource;
+import org.apache.pinot.segment.spi.index.reader.JsonIndexReader;
+
+
+/**
+ * Filter operator for Map matching that internally uses JsonMatchFilterOperator or ExpressionFilterOperator.
+ * This operator converts map predicates to JSON predicates and delegates filtering operations
+ * to JsonMatchFilterOperator.
+ */
+public class MapIndexFilterOperator extends BaseFilterOperator {
+  private static final String EXPLAIN_NAME = "FILTER_MAP_INDEX";
+
+  private final JsonMatchFilterOperator _jsonMatchOperator;
+  private final ExpressionFilterOperator _expressionFilterOperator;
+  private final String _columnName;
+  private final String _keyName;
+  private final Predicate _predicate;
+  private final JsonMatchPredicate _jsonMatchPredicate;
+
+  public MapIndexFilterOperator(IndexSegment indexSegment, Predicate predicate, QueryContext queryContext,
+      int numDocs) {
+    super(numDocs, false);
+    _predicate = predicate;
+
+    // Get column name and key name from function arguments
+    List<ExpressionContext> arguments = predicate.getLhs().getFunction().getArguments();
+    if (arguments.size() != 2) {
+      throw new IllegalStateException("Expected two arguments (column name and key name), found: " + arguments.size());
+    }
+
+    _columnName = arguments.get(0).getIdentifier();
+    _keyName = cleanKey(String.valueOf(arguments.get(1).getLiteral()));

Review Comment:
   ```suggestion
       _keyName = arguments.get(1).getLiteral().getStringValue();
   ```



##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/map/MutableMapDataSource.java:
##########
@@ -55,15 +55,13 @@ public MutableMapDataSource(FieldSpec fieldSpec, int numDocs, int numValues, int
             partitionFunction, partitions, minValue, maxValue, maxRowLengthInBytes),
         new ColumnIndexContainer.FromMap.Builder().withAll(mutableIndexes).build());
     _mutableIndexes = mutableIndexes;
-    MapIndexReader mapIndexReader = getMapIndex();
-    if (mapIndexReader == null) {
-      // Fallback to use forward index
-      ForwardIndexReader<?> forwardIndex = getForwardIndex();
-      if (forwardIndex instanceof MapIndexReader) {
-        mapIndexReader = (MapIndexReader) forwardIndex;
-      } else {
-        mapIndexReader = new MapIndexReaderWrapper(forwardIndex, getFieldSpec());
-      }
+    MapIndexReader mapIndexReader;
+    // Fallback to use forward index
+    ForwardIndexReader<?> forwardIndex = getForwardIndex();
+    if (forwardIndex instanceof MapIndexReader) {
+      mapIndexReader = (MapIndexReader) forwardIndex;
+    } else {
+      mapIndexReader = new MapIndexReaderWrapper(forwardIndex, getFieldSpec());

Review Comment:
   Not introduced in this PR, but what is the difference between them? Why do we need a wrapper?



##########
pinot-core/src/main/java/org/apache/pinot/core/operator/filter/MapIndexFilterOperator.java:
##########
@@ -0,0 +1,269 @@
+/**
+ * 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.operator.filter;
+
+import com.google.common.base.CaseFormat;
+import java.util.Collections;
+import java.util.List;
+import org.apache.pinot.common.request.context.ExpressionContext;
+import org.apache.pinot.common.request.context.predicate.EqPredicate;
+import org.apache.pinot.common.request.context.predicate.InPredicate;
+import org.apache.pinot.common.request.context.predicate.JsonMatchPredicate;
+import org.apache.pinot.common.request.context.predicate.NotEqPredicate;
+import org.apache.pinot.common.request.context.predicate.NotInPredicate;
+import org.apache.pinot.common.request.context.predicate.Predicate;
+import org.apache.pinot.core.common.BlockDocIdSet;
+import org.apache.pinot.core.common.Operator;
+import org.apache.pinot.core.operator.ExplainAttributeBuilder;
+import org.apache.pinot.core.query.request.context.QueryContext;
+import org.apache.pinot.segment.spi.IndexSegment;
+import org.apache.pinot.segment.spi.datasource.DataSource;
+import org.apache.pinot.segment.spi.index.reader.JsonIndexReader;
+
+
+/**
+ * Filter operator for Map matching that internally uses JsonMatchFilterOperator or ExpressionFilterOperator.
+ * This operator converts map predicates to JSON predicates and delegates filtering operations
+ * to JsonMatchFilterOperator.
+ */
+public class MapIndexFilterOperator extends BaseFilterOperator {
+  private static final String EXPLAIN_NAME = "FILTER_MAP_INDEX";
+
+  private final JsonMatchFilterOperator _jsonMatchOperator;
+  private final ExpressionFilterOperator _expressionFilterOperator;
+  private final String _columnName;
+  private final String _keyName;
+  private final Predicate _predicate;
+  private final JsonMatchPredicate _jsonMatchPredicate;

Review Comment:
   (minor) Do we need this as a member variable? This class serves as a delegate to either json index based operator or udf based operator



##########
pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/index/creator/JsonIndexCreator.java:
##########
@@ -34,7 +36,11 @@ public interface JsonIndexCreator extends IndexCreator {
   @Override
   default void add(@Nonnull Object value, int dictId)
       throws IOException {
-    add((String) value);
+    if (value instanceof Map) {

Review Comment:
   Can we improve it to directly add a `JsonNode` to avoid the extra ser/de?



##########
pinot-core/src/main/java/org/apache/pinot/core/operator/filter/MapIndexFilterOperator.java:
##########
@@ -0,0 +1,269 @@
+/**
+ * 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.operator.filter;
+
+import com.google.common.base.CaseFormat;
+import java.util.Collections;
+import java.util.List;
+import org.apache.pinot.common.request.context.ExpressionContext;
+import org.apache.pinot.common.request.context.predicate.EqPredicate;
+import org.apache.pinot.common.request.context.predicate.InPredicate;
+import org.apache.pinot.common.request.context.predicate.JsonMatchPredicate;
+import org.apache.pinot.common.request.context.predicate.NotEqPredicate;
+import org.apache.pinot.common.request.context.predicate.NotInPredicate;
+import org.apache.pinot.common.request.context.predicate.Predicate;
+import org.apache.pinot.core.common.BlockDocIdSet;
+import org.apache.pinot.core.common.Operator;
+import org.apache.pinot.core.operator.ExplainAttributeBuilder;
+import org.apache.pinot.core.query.request.context.QueryContext;
+import org.apache.pinot.segment.spi.IndexSegment;
+import org.apache.pinot.segment.spi.datasource.DataSource;
+import org.apache.pinot.segment.spi.index.reader.JsonIndexReader;
+
+
+/**
+ * Filter operator for Map matching that internally uses JsonMatchFilterOperator or ExpressionFilterOperator.
+ * This operator converts map predicates to JSON predicates and delegates filtering operations
+ * to JsonMatchFilterOperator.
+ */
+public class MapIndexFilterOperator extends BaseFilterOperator {
+  private static final String EXPLAIN_NAME = "FILTER_MAP_INDEX";
+
+  private final JsonMatchFilterOperator _jsonMatchOperator;
+  private final ExpressionFilterOperator _expressionFilterOperator;
+  private final String _columnName;
+  private final String _keyName;
+  private final Predicate _predicate;
+  private final JsonMatchPredicate _jsonMatchPredicate;
+
+  public MapIndexFilterOperator(IndexSegment indexSegment, Predicate predicate, QueryContext queryContext,
+      int numDocs) {
+    super(numDocs, false);
+    _predicate = predicate;
+
+    // Get column name and key name from function arguments
+    List<ExpressionContext> arguments = predicate.getLhs().getFunction().getArguments();
+    if (arguments.size() != 2) {
+      throw new IllegalStateException("Expected two arguments (column name and key name), found: " + arguments.size());
+    }
+
+    _columnName = arguments.get(0).getIdentifier();
+    _keyName = cleanKey(String.valueOf(arguments.get(1).getLiteral()));
+
+    // Get JSON index and create operator
+    DataSource dataSource = indexSegment.getDataSource(_columnName);
+    JsonIndexReader jsonIndex = dataSource.getJsonIndex();
+    if (jsonIndex != null && useJsonIndex(_predicate.getType())) {
+      _jsonMatchPredicate = createJsonMatchPredicate();
+      _jsonMatchOperator = initializeJsonMatchFilterOperator(jsonIndex, numDocs);
+      _expressionFilterOperator = null;
+    } else {
+      _jsonMatchPredicate = null;
+      _jsonMatchOperator = null;
+      _expressionFilterOperator = new ExpressionFilterOperator(indexSegment, queryContext, predicate, numDocs);
+    }
+  }
+
+  /**
+   * Creates a JsonMatchPredicate based on the original predicate type
+   */
+  private JsonMatchPredicate createJsonMatchPredicate() {
+    // Convert predicate to JSON format based on type
+    String jsonValue;
+    switch (_predicate.getType()) {
+      case EQ:
+        jsonValue = createJsonEqPredicateValue(_keyName, ((EqPredicate) _predicate).getValue());
+        break;
+      case NOT_EQ:
+        jsonValue = createJsonNotEqPredicateValue(_keyName, ((NotEqPredicate) _predicate).getValue());
+        break;
+      case IN:
+        jsonValue = createJsonInPredicateValue(_keyName, ((InPredicate) _predicate).getValues());
+        break;
+      case NOT_IN:
+        jsonValue = createJsonNotInPredicateValue(_keyName, ((NotInPredicate) _predicate).getValues());
+        break;
+      default:
+        throw new IllegalStateException(
+            "Unsupported predicate type for creating json match predicate: " + _predicate.getType());
+    }
+
+    // Create identifier expression for the JSON column
+    ExpressionContext jsonLhs = ExpressionContext.forIdentifier("json");
+    return new JsonMatchPredicate(jsonLhs, jsonValue, null);
+  }
+
+  @Override
+  protected BlockDocIdSet getTrues() {
+    if (_jsonMatchOperator != null) {
+      return _jsonMatchOperator.getTrues();
+    } else {
+      return _expressionFilterOperator.getTrues();
+    }
+  }
+
+  @Override
+  public boolean canOptimizeCount() {
+    if (_jsonMatchOperator != null) {
+      return _jsonMatchOperator.canOptimizeCount();
+    } else {
+      return _expressionFilterOperator.canOptimizeCount();
+    }
+  }
+
+  @Override
+  public int getNumMatchingDocs() {
+    if (_jsonMatchOperator != null) {
+      return _jsonMatchOperator.getNumMatchingDocs();
+    } else {
+      return _expressionFilterOperator.getNumMatchingDocs();
+    }
+  }
+
+  @Override
+  public boolean canProduceBitmaps() {
+    if (_jsonMatchOperator != null) {
+      return _jsonMatchOperator.canProduceBitmaps();
+    } else {
+      return _expressionFilterOperator.canProduceBitmaps();
+    }
+  }
+
+  @Override
+  public BitmapCollection getBitmaps() {
+    if (_jsonMatchOperator != null) {
+      return _jsonMatchOperator.getBitmaps();
+    } else {
+      return _expressionFilterOperator.getBitmaps();
+    }
+  }
+
+  @Override
+  public List<Operator> getChildOperators() {
+    return Collections.emptyList();
+  }
+
+  @Override
+  public String toExplainString() {
+    StringBuilder stringBuilder =
+        new StringBuilder(EXPLAIN_NAME).append("(column:").append(_columnName).append(",key:").append(_keyName)
+            .append(",indexLookUp:map_index").append(",operator:").append(_predicate.getType()).append(",predicate:")
+            .append(_predicate);
+
+    if (_jsonMatchOperator != null) {
+      stringBuilder.append(",delegateTo:json_match");
+    } else {
+      stringBuilder.append(",delegateTo:expression_filter");
+    }
+
+    return stringBuilder.append(')').toString();
+  }
+
+  @Override
+  protected String getExplainName() {
+    return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, EXPLAIN_NAME);
+  }
+
+  @Override
+  protected void explainAttributes(ExplainAttributeBuilder attributeBuilder) {
+    super.explainAttributes(attributeBuilder);
+    attributeBuilder.putString("column", _columnName);
+    attributeBuilder.putString("key", _keyName);
+    attributeBuilder.putString("indexLookUp", "map_index");
+    attributeBuilder.putString("operator", _predicate.getType().name());
+    attributeBuilder.putString("predicate", _predicate.toString());
+
+    if (_jsonMatchOperator != null) {
+      attributeBuilder.putString("delegateTo", "json_match");
+    } else {
+      attributeBuilder.putString("delegateTo", "expression_filter");
+    }
+  }
+
+  /**
+   * Initializes the JsonMatchFilterOperator with the given JsonIndexReader
+   */
+  private JsonMatchFilterOperator initializeJsonMatchFilterOperator(JsonIndexReader jsonIndex, int numDocs) {
+    return new JsonMatchFilterOperator(jsonIndex, _jsonMatchPredicate, numDocs);
+  }
+
+  private String createJsonEqPredicateValue(String key, String value) {

Review Comment:
   Does it work? Do you need to quote the value if it is string?



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


Re: [PR] Changes to Enable Pluggable forward Index and Map Index Filter Operator for MAP column [pinot]

Posted by "Jackie-Jiang (via GitHub)" <gi...@apache.org>.
Jackie-Jiang commented on code in PR #15526:
URL: https://github.com/apache/pinot/pull/15526#discussion_r2101379881


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/map/MutableMapDataSource.java:
##########
@@ -55,15 +55,13 @@ public MutableMapDataSource(FieldSpec fieldSpec, int numDocs, int numValues, int
             partitionFunction, partitions, minValue, maxValue, maxRowLengthInBytes),
         new ColumnIndexContainer.FromMap.Builder().withAll(mutableIndexes).build());
     _mutableIndexes = mutableIndexes;
-    MapIndexReader mapIndexReader = getMapIndex();
-    if (mapIndexReader == null) {
-      // Fallback to use forward index
-      ForwardIndexReader<?> forwardIndex = getForwardIndex();
-      if (forwardIndex instanceof MapIndexReader) {
-        mapIndexReader = (MapIndexReader) forwardIndex;
-      } else {
-        mapIndexReader = new MapIndexReaderWrapper(forwardIndex, getFieldSpec());
-      }
+    MapIndexReader mapIndexReader;
+    // Fallback to use forward index
+    ForwardIndexReader<?> forwardIndex = getForwardIndex();
+    if (forwardIndex instanceof MapIndexReader) {
+      mapIndexReader = (MapIndexReader) forwardIndex;
+    } else {
+      mapIndexReader = new MapIndexReaderWrapper(forwardIndex, getFieldSpec());

Review Comment:
   Given map index is forward index, do we still need this wrapper?



##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/custom/MapFieldTypeTest.java:
##########
@@ -38,14 +40,15 @@
 import org.testng.annotations.Test;
 
 import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotEquals;
 
 
 @Test(suiteName = "CustomClusterIntegrationTest")
 public class MapFieldTypeTest extends CustomDataQueryClusterIntegrationTest {
 
   // Default settings
   protected static final String DEFAULT_TABLE_NAME = "MapFieldTypeTest";
-  private static final int NUM_DOCS = 1000;
+  private static final int NUM_DOCS = 100;

Review Comment:
   How long does it take to process 1000 docs? If we observe long testing time for only 1000 docs, the performance is not acceptable



##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/json/JsonIndexType.java:
##########
@@ -95,7 +95,8 @@ public JsonIndexCreator createIndexCreator(IndexCreationContext context, JsonInd
       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,
+    Preconditions.checkState(context.getFieldSpec().getDataType().getStoredType() == FieldSpec.DataType.STRING

Review Comment:
   ^^



##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/datasource/BaseDataSource.java:
##########
@@ -127,6 +127,7 @@ public VectorIndexReader getVectorIndex() {
     return getIndex(StandardIndexes.vector());
   }
 
+  @Deprecated

Review Comment:
   ^^



##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/map/ImmutableMapDataSource.java:
##########
@@ -41,15 +41,12 @@ public class ImmutableMapDataSource extends BaseMapDataSource {
 
   public ImmutableMapDataSource(ColumnMetadata columnMetadata, ColumnIndexContainer columnIndexContainer) {
     super(new ImmutableMapDataSourceMetadata(columnMetadata), columnIndexContainer);
-    MapIndexReader mapIndexReader = getMapIndex();
-    if (mapIndexReader == null) {
-      // Fallback to use forward index
-      ForwardIndexReader<?> forwardIndex = getForwardIndex();
-      if (forwardIndex instanceof MapIndexReader) {
-        mapIndexReader = (MapIndexReader) forwardIndex;
-      } else {
-        mapIndexReader = new MapIndexReaderWrapper(forwardIndex, getFieldSpec());
-      }
+    MapIndexReader mapIndexReader;
+    ForwardIndexReader<?> forwardIndex = getForwardIndex();
+    if (forwardIndex instanceof MapIndexReader) {

Review Comment:
   I don't see any usage of `ImmutableMapIndexReader` or `MutableMapIndex`, thus wondering how are they wired up



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


Re: [PR] Changes to Enable Pluggable forward Index and Map Index Filter Operator for MAP column [pinot]

Posted by "Jackie-Jiang (via GitHub)" <gi...@apache.org>.
Jackie-Jiang commented on code in PR #15526:
URL: https://github.com/apache/pinot/pull/15526#discussion_r2096611350


##########
pinot-core/src/main/java/org/apache/pinot/core/operator/filter/MapFilterOperator.java:
##########
@@ -0,0 +1,256 @@
+/**
+ * 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.operator.filter;
+
+import com.google.common.base.CaseFormat;
+import java.util.Collections;
+import java.util.List;
+import org.apache.pinot.common.request.context.ExpressionContext;
+import org.apache.pinot.common.request.context.predicate.EqPredicate;
+import org.apache.pinot.common.request.context.predicate.InPredicate;
+import org.apache.pinot.common.request.context.predicate.JsonMatchPredicate;
+import org.apache.pinot.common.request.context.predicate.NotEqPredicate;
+import org.apache.pinot.common.request.context.predicate.NotInPredicate;
+import org.apache.pinot.common.request.context.predicate.Predicate;
+import org.apache.pinot.core.common.BlockDocIdSet;
+import org.apache.pinot.core.common.Operator;
+import org.apache.pinot.core.operator.ExplainAttributeBuilder;
+import org.apache.pinot.core.query.request.context.QueryContext;
+import org.apache.pinot.segment.spi.IndexSegment;
+import org.apache.pinot.segment.spi.datasource.DataSource;
+import org.apache.pinot.segment.spi.index.reader.JsonIndexReader;
+
+
+/**
+ * Filter operator for Map matching that internally uses JsonMatchFilterOperator or ExpressionFilterOperator.
+ * This operator converts map predicates to JSON predicates and delegates filtering operations
+ * to JsonMatchFilterOperator.
+ */
+public class MapFilterOperator extends BaseFilterOperator {
+  private static final String EXPLAIN_NAME = "FILTER_MAP";
+
+  private final JsonMatchFilterOperator _jsonMatchOperator;
+  private final ExpressionFilterOperator _expressionFilterOperator;
+  private final String _columnName;
+  private final String _keyName;
+  private final Predicate _predicate;
+
+  public MapFilterOperator(IndexSegment indexSegment, Predicate predicate, QueryContext queryContext,
+      int numDocs) {
+    super(numDocs, false);
+    _predicate = predicate;
+
+    // Get column name and key name from function arguments
+    List<ExpressionContext> arguments = predicate.getLhs().getFunction().getArguments();
+    if (arguments.size() != 2) {
+      throw new IllegalStateException("Expected two arguments (column name and key name), found: " + arguments.size());
+    }
+
+    _columnName = arguments.get(0).getIdentifier();
+    _keyName = arguments.get(1).getLiteral().getStringValue();
+
+    // Get JSON index and create operator
+    JsonMatchPredicate jsonMatchPredicate;
+    DataSource dataSource = indexSegment.getDataSource(_columnName);
+    JsonIndexReader jsonIndex = dataSource.getJsonIndex();
+    if (jsonIndex != null && useJsonIndex(_predicate.getType())) {
+      jsonMatchPredicate = createJsonMatchPredicate();
+      _jsonMatchOperator = initializeJsonMatchFilterOperator(jsonIndex, jsonMatchPredicate, numDocs);
+      _expressionFilterOperator = null;
+    } else {
+      jsonMatchPredicate = null;
+      _jsonMatchOperator = null;
+      _expressionFilterOperator = new ExpressionFilterOperator(indexSegment, queryContext, predicate, numDocs);
+    }
+  }
+
+  /**
+   * Creates a JsonMatchPredicate based on the original predicate type
+   */
+  private JsonMatchPredicate createJsonMatchPredicate() {
+    // Convert predicate to JSON format based on type
+    String jsonFilterString;
+    switch (_predicate.getType()) {
+      case EQ:
+        jsonFilterString = createJsonEqPredicateValue(_keyName, ((EqPredicate) _predicate).getValue());
+        break;
+      case NOT_EQ:
+        jsonFilterString = createJsonNotEqPredicateValue(_keyName, ((NotEqPredicate) _predicate).getValue());
+        break;
+      case IN:
+        jsonFilterString = createJsonInPredicateValue(_keyName, ((InPredicate) _predicate).getValues());
+        break;
+      case NOT_IN:
+        jsonFilterString = createJsonNotInPredicateValue(_keyName, ((NotInPredicate) _predicate).getValues());
+        break;
+      default:
+        throw new IllegalStateException(
+            "Unsupported predicate type for creating json match predicate: " + _predicate.getType());
+    }
+
+    // Create identifier expression for the JSON column
+    ExpressionContext jsonLhs = ExpressionContext.forIdentifier(_columnName);
+    return new JsonMatchPredicate(jsonLhs, jsonFilterString, null);
+  }
+
+  @Override
+  protected BlockDocIdSet getTrues() {
+    if (_jsonMatchOperator != null) {
+      return _jsonMatchOperator.getTrues();
+    } else {
+      return _expressionFilterOperator.getTrues();
+    }
+  }
+
+  @Override
+  public boolean canOptimizeCount() {
+    if (_jsonMatchOperator != null) {
+      return _jsonMatchOperator.canOptimizeCount();
+    } else {
+      return _expressionFilterOperator.canOptimizeCount();
+    }
+  }
+
+  @Override
+  public int getNumMatchingDocs() {
+    if (_jsonMatchOperator != null) {
+      return _jsonMatchOperator.getNumMatchingDocs();
+    } else {
+      return _expressionFilterOperator.getNumMatchingDocs();
+    }
+  }
+
+  @Override
+  public boolean canProduceBitmaps() {
+    if (_jsonMatchOperator != null) {
+      return _jsonMatchOperator.canProduceBitmaps();
+    } else {
+      return _expressionFilterOperator.canProduceBitmaps();
+    }
+  }
+
+  @Override
+  public BitmapCollection getBitmaps() {
+    if (_jsonMatchOperator != null) {
+      return _jsonMatchOperator.getBitmaps();
+    } else {
+      return _expressionFilterOperator.getBitmaps();
+    }
+  }
+
+  @Override
+  public List<Operator> getChildOperators() {
+    return Collections.emptyList();
+  }
+
+  @Override
+  public String toExplainString() {
+    StringBuilder stringBuilder =
+        new StringBuilder(EXPLAIN_NAME).append("(column:").append(_columnName).append(",key:").append(_keyName)
+            .append(",indexLookUp:map_index").append(",operator:").append(_predicate.getType()).append(",predicate:")
+            .append(_predicate);
+
+    if (_jsonMatchOperator != null) {
+      stringBuilder.append(",delegateTo:json_match");
+    } else {
+      stringBuilder.append(",delegateTo:expression_filter");
+    }
+
+    return stringBuilder.append(')').toString();
+  }
+
+  @Override
+  protected String getExplainName() {
+    return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, EXPLAIN_NAME);
+  }
+
+  @Override
+  protected void explainAttributes(ExplainAttributeBuilder attributeBuilder) {
+    super.explainAttributes(attributeBuilder);
+    attributeBuilder.putString("column", _columnName);
+    attributeBuilder.putString("key", _keyName);
+    attributeBuilder.putString("indexLookUp", "map_index");
+    attributeBuilder.putString("operator", _predicate.getType().name());
+    attributeBuilder.putString("predicate", _predicate.toString());
+
+    if (_jsonMatchOperator != null) {
+      attributeBuilder.putString("delegateTo", "json_match");
+    } else {
+      attributeBuilder.putString("delegateTo", "expression_filter");
+    }
+  }
+
+  /**
+   * Initializes the JsonMatchFilterOperator with the given JsonIndexReader
+   */
+  private JsonMatchFilterOperator initializeJsonMatchFilterOperator(JsonIndexReader jsonIndex,
+      JsonMatchPredicate jsonMatchPredicate, int numDocs) {
+    return new JsonMatchFilterOperator(jsonIndex, jsonMatchPredicate, numDocs);
+  }
+
+  private String createJsonEqPredicateValue(String key, String value) {
+    return String.format("%s = '%s'", key, value);

Review Comment:
   Please add a test to verify it works with a string value with `'` inside



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


Re: [PR] Changes to Enable Pluggable forward Index and Map Index Filter Operator for MAP column [pinot]

Posted by "gortiz (via GitHub)" <gi...@apache.org>.
gortiz commented on code in PR #15526:
URL: https://github.com/apache/pinot/pull/15526#discussion_r2084087073


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/forward/ForwardIndexPlugin.java:
##########
@@ -26,10 +26,8 @@
 @AutoService(IndexPlugin.class)
 public class ForwardIndexPlugin implements IndexPlugin<ForwardIndexType> {
 
-  private static final ForwardIndexType INSTANCE = new ForwardIndexType();

Review Comment:
   I don't think that is the correct way to do it. Instead, I would recommend either:
   - Using the current system, a fork can set a different IndexService instead of using the default. This can easily be done by making IndexService.init() public and then calling IndexService.setInstance()
   - Add a priority for each IndexPlugin, so if there is a collision on id, IndexService.fromServiceLoader() only loads the one with higher priority.



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


Re: [PR] Changes to Enable Pluggable forward Index and Map Index Filter Operator for MAP column [pinot]

Posted by "gortiz (via GitHub)" <gi...@apache.org>.
gortiz commented on code in PR #15526:
URL: https://github.com/apache/pinot/pull/15526#discussion_r2084223639


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/forward/ForwardIndexPlugin.java:
##########
@@ -26,10 +26,8 @@
 @AutoService(IndexPlugin.class)
 public class ForwardIndexPlugin implements IndexPlugin<ForwardIndexType> {
 
-  private static final ForwardIndexType INSTANCE = new ForwardIndexType();

Review Comment:
   I've added the concept of priority in https://github.com/apache/pinot/pull/15766. Please take a look



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


Re: [PR] Changes to Enable Pluggable forward Index and Map Index Filter Operator for MAP column [pinot]

Posted by "raghavyadav01 (via GitHub)" <gi...@apache.org>.
raghavyadav01 commented on code in PR #15526:
URL: https://github.com/apache/pinot/pull/15526#discussion_r2078274406


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/forward/ForwardIndexReaderFactory.java:
##########
@@ -68,10 +68,33 @@ public static ForwardIndexReaderFactory getInstance() {
   protected ForwardIndexReader createIndexReader(PinotDataBuffer dataBuffer, ColumnMetadata metadata,
       ForwardIndexConfig indexConfig)
       throws IndexReaderConstraintException {
+    if (indexConfig != null && indexConfig.getConfigs().containsKey(ForwardIndexType.FORWARD_INDEX_READER_CLASS_NAME)) {
+      String className = indexConfig.getConfigs().get(ForwardIndexType.FORWARD_INDEX_READER_CLASS_NAME).toString();
+      try {
+        return (ForwardIndexReader) Class.forName(className).getConstructor(PinotDataBuffer.class, ColumnMetadata.class)
+            .newInstance(dataBuffer, metadata);
+      } catch (Exception e) {
+        throw new RuntimeException("Failed to create ForwardIndexReader", e);
+      }
+    }
+    return createIndexReader(dataBuffer, metadata);
+  }
+
+  public static ForwardIndexReader createIndexReader(PinotDataBuffer dataBuffer, ForwardIndexConfig indexConfig,

Review Comment:
   removed the static API. 



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