You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by "tarun11Mavani (via GitHub)" <gi...@apache.org> on 2026/06/01 05:24:26 UTC

[PR] [WIP] OPEN_STRUCT storage layer — columnar two-tier dense/sparse index (PR 2/4) [pinot]

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

   Instructions:
   1. The PR has to be tagged with at least one of the following labels (*):
      1. `feature`
      2. `bugfix`
      3. `performance`
      4. `ui`
      5. `backward-incompat`
      6. `release-notes` (**)
   2. Remove these instructions before publishing the PR.
    
   (*) Other labels to consider:
   - `testing`
   - `dependencies`
   - `docker`
   - `kubernetes`
   - `observability`
   - `security`
   - `code-style`
   - `extension-point`
   - `refactor`
   - `cleanup`
   
   (**) Use `release-notes` label for scenarios like:
   - New configuration options
   - Deprecation of configurations
   - Signature changes to public methods/interfaces
   - New plugins added or old plugins 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] [WIP] OPEN_STRUCT storage layer — columnar two-tier dense/sparse index (PR 2/4) [pinot]

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


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/indexsegment/immutable/ImmutableSegmentImpl.java:
##########
@@ -98,13 +104,44 @@ public ImmutableSegmentImpl(
     _dataSources =
         new Object2ObjectOpenHashMap<>(segmentMetadata.getColumnMetadataMap().size());
 
+    Map<String, Map<String, DataSource>> openStructDenseChildren = new HashMap<>();

Review Comment:
   Use Map.of() for all



-- 
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] [WIP] OPEN_STRUCT storage layer — columnar two-tier dense/sparse index (PR 2/4) [pinot]

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

   @xiangfu0 @raghavyadav01 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] OPEN_STRUCT storage layer — columnar two-tier dense/sparse index (PR 2b/4) [pinot]

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


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/openstruct/ImmutableOpenStructDataSource.java:
##########
@@ -0,0 +1,265 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.segment.local.segment.index.openstruct;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import javax.annotation.Nullable;
+import org.apache.pinot.segment.local.segment.index.datasource.BaseDataSource;
+import org.apache.pinot.segment.local.segment.index.datasource.ImmutableDataSource;
+import org.apache.pinot.segment.spi.Constants;
+import org.apache.pinot.segment.spi.datasource.DataSource;
+import org.apache.pinot.segment.spi.datasource.DataSourceMetadata;
+import org.apache.pinot.segment.spi.datasource.OpenStructDataSource;
+import org.apache.pinot.segment.spi.index.column.ColumnIndexContainer;
+import org.apache.pinot.segment.spi.index.reader.Dictionary;
+import org.apache.pinot.segment.spi.index.reader.ForwardIndexReader;
+import org.apache.pinot.segment.spi.index.reader.ForwardIndexReaderContext;
+import org.apache.pinot.segment.spi.index.reader.NullValueVectorReader;
+import org.apache.pinot.segment.spi.partition.PartitionFunction;
+import org.apache.pinot.spi.data.ComplexFieldSpec;
+import org.apache.pinot.spi.data.FieldSpec;
+import org.apache.pinot.spi.data.FieldSpec.DataType;
+import org.apache.pinot.spi.utils.JsonUtils;
+
+
+
+/// Per-key {@link DataSource} accessor for sealed (immutable) segments with an OPEN_STRUCT column.
+///
+/// Always columnar — there is no blob branch. Every key that was dense enough during segment
+/// creation gets its own materialized {@link DataSource} (forward index + optional inverted index /
+/// dictionary). Keys that did not meet the density threshold are stored in an optional sparse
+/// column; the sparse {@link DataSource} is returned for any unmaterialized key lookup.
+///
+/// Use [#isMaterialized(String)] and [#isFullyMaterialized()] together to choose
+/// the query execution path:
+/// - Materialized key → fast path via per-key DataSource (inverted/dictionary index available).
+/// - Not materialized + not fully materialized → fall back to the sparse DataSource.
+/// - Not materialized + fully materialized → key is definitively absent; short-circuit.
+///
+/// Thread-safety: immutable after construction; safe for concurrent reads.
+public class ImmutableOpenStructDataSource extends BaseDataSource implements OpenStructDataSource {
+  private final ComplexFieldSpec _fieldSpec;
+  private final Map<String, DataSource> _perKeyDataSources;
+  @Nullable
+  private final DataSource _sparseDataSource;
+
+  public ImmutableOpenStructDataSource(ComplexFieldSpec fieldSpec, Map<String, DataSource> perKeyDataSources,
+      @Nullable DataSource sparseDataSource, DataSourceMetadata dataSourceMetadata,
+      ColumnIndexContainer indexContainer) {
+    super(dataSourceMetadata, indexContainer);
+    _fieldSpec = fieldSpec;
+    _perKeyDataSources = perKeyDataSources;
+    _sparseDataSource = sparseDataSource;
+  }
+
+  /// Convenience constructor for segment-load time. Synthesizes a minimal {@link DataSourceMetadata}
+  /// for the parent OPEN_STRUCT column (which has no on-disk presence of its own) and uses an empty
+  /// {@link ColumnIndexContainer} — all real readers live on the per-key data sources.
+  public ImmutableOpenStructDataSource(ComplexFieldSpec fieldSpec, Map<String, DataSource> perKeyDataSources,
+      @Nullable DataSource sparseDataSource, int numDocs) {
+    this(fieldSpec, perKeyDataSources, sparseDataSource,
+        new ImmutableOpenStructDataSourceMetadata(fieldSpec, numDocs),
+        new ColumnIndexContainer.FromMap.Builder().build());
+  }
+
+  @Override
+  public ComplexFieldSpec getFieldSpec() {
+    return _fieldSpec;
+  }
+
+  @Override
+  @Nullable
+  public DataSource getDataSource(String key) {
+    DataSource ds = _perKeyDataSources.get(key);
+    return ds != null ? ds : _sparseDataSource;
+  }
+
+  @Override
+  public boolean isMaterialized(String key) {
+    return _perKeyDataSources.containsKey(key);
+  }
+
+  @Override
+  public boolean isFullyMaterialized() {
+    return _sparseDataSource == null;
+  }
+
+  @Override
+  public Map<String, DataSource> getDataSources() {
+    return _perKeyDataSources;
+  }
+
+  @Override
+  @Nullable
+  public DataSourceMetadata getDataSourceMetadata(String key) {
+    DataSource ds = _perKeyDataSources.get(key);
+    return ds != null ? ds.getDataSourceMetadata() : null;
+  }
+
+  @Override
+  @Nullable
+  public ColumnIndexContainer getIndexContainer(String key) {
+    DataSource ds = _perKeyDataSources.get(key);
+    return ds instanceof ImmutableDataSource immutableDs ? immutableDs.getIndexContainer() : null;
+  }
+
+  @SuppressWarnings({"rawtypes", "unchecked"})
+  @Override
+  @Nullable
+  public Map<String, Object> getMapValue(int docId) {
+    Map<String, Object> result = null;
+
+    for (Map.Entry<String, DataSource> entry : _perKeyDataSources.entrySet()) {
+      Object value = readValue(entry.getValue(), docId);
+      if (value != null) {
+        if (result == null) {
+          result = new HashMap<>();
+        }
+        result.put(entry.getKey(), value);
+      }
+    }
+
+    if (_sparseDataSource != null) {
+      Object sparseValue = readValue(_sparseDataSource, docId);
+      if (sparseValue instanceof String) {
+        String json = (String) sparseValue;
+        if (!json.isEmpty()) {
+          try {
+            Map<String, Object> sparseMap = JsonUtils.stringToObject(json, Map.class);

Review Comment:
   This is intentional by design. If user need a type stability, they can declare it via the `childFieldSpecs `.
   I think this is acceptable for first version as the sparse tier has low fill rate and it's not performance critical.



-- 
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] [WIP] OPEN_STRUCT storage layer — columnar two-tier dense/sparse index (PR 2/4) [pinot]

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


##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/custom/OpenStructIngestionCommitTestBase.java:
##########
@@ -0,0 +1,287 @@
+/**
+ * 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.integration.tests.custom;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import java.io.File;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import org.apache.avro.file.DataFileWriter;
+import org.apache.avro.generic.GenericData;
+import org.apache.commons.configuration2.PropertiesConfiguration;
+import org.apache.pinot.segment.local.segment.store.SegmentLocalFSDirectory;
+import org.apache.pinot.segment.spi.ColumnMetadata;
+import org.apache.pinot.segment.spi.V1Constants;
+import org.apache.pinot.segment.spi.index.StandardIndexes;
+import org.apache.pinot.segment.spi.index.metadata.SegmentMetadataImpl;
+import org.apache.pinot.segment.spi.store.SegmentDirectory;
+import org.apache.pinot.segment.spi.store.SegmentDirectoryPaths;
+import org.apache.pinot.spi.config.table.FieldConfig;
+import org.apache.pinot.spi.config.table.OpenStructIndexConfig;
+import org.apache.pinot.spi.config.table.TableConfig;
+import org.apache.pinot.spi.config.table.TableType;
+import org.apache.pinot.spi.data.ComplexFieldSpec;
+import org.apache.pinot.spi.data.DimensionFieldSpec;
+import org.apache.pinot.spi.data.FieldSpec;
+import org.apache.pinot.spi.data.OpenStructNaming;
+import org.apache.pinot.spi.data.Schema;
+import org.apache.pinot.spi.env.CommonsConfigurationUtils;
+import org.apache.pinot.spi.utils.JsonUtils;
+import org.apache.pinot.spi.utils.ReadMode;
+import org.apache.pinot.spi.utils.builder.TableConfigBuilder;
+import org.apache.pinot.spi.utils.builder.TableNameBuilder;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
+
+
+/// Shared base for the OPEN_STRUCT end-to-end ingestion + commit tests.
+///
+/// Builds a table with one OPEN_STRUCT column `metrics` carrying a per-key index matrix
+/// (inverted; dictionary-only; raw) plus two sparse keys, ingests ~1000 rows, and validates the
+/// committed segment's materialized child columns, their `index_map`, and the dense/sparse split.
+///
+/// This class is abstract and is not run on its own; the concrete table-type variant (currently
+/// {@link OpenStructIngestionCommitRealtimeTest}) supplies the table name and commit trigger and
+/// reuses the inherited validation. An OFFLINE variant is added in a follow-up change once the
+/// offline OPEN_STRUCT build path is fixed.
+public abstract class OpenStructIngestionCommitTestBase extends CustomDataQueryClusterIntegrationTest {

Review Comment:
   remove this test before merging. Will add final tests after the query side changes are complete. 



##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/openstruct/ImmutableOpenStructDataSource.java:
##########
@@ -0,0 +1,184 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.segment.local.segment.index.openstruct;
+
+import java.util.Map;
+import javax.annotation.Nullable;
+import org.apache.pinot.segment.local.segment.index.datasource.BaseDataSource;
+import org.apache.pinot.segment.local.segment.index.datasource.ImmutableDataSource;
+import org.apache.pinot.segment.spi.Constants;
+import org.apache.pinot.segment.spi.datasource.DataSource;
+import org.apache.pinot.segment.spi.datasource.DataSourceMetadata;
+import org.apache.pinot.segment.spi.datasource.OpenStructDataSource;
+import org.apache.pinot.segment.spi.index.column.ColumnIndexContainer;
+import org.apache.pinot.segment.spi.partition.PartitionFunction;
+import org.apache.pinot.spi.data.ComplexFieldSpec;
+import org.apache.pinot.spi.data.FieldSpec;
+
+
+/**
+ * Per-key {@link DataSource} accessor for sealed (immutable) segments with an OPEN_STRUCT column.
+ *
+ * <p>Always columnar — there is no blob branch. Every key that was dense enough during segment
+ * creation gets its own materialized {@link DataSource} (forward index + optional inverted index /
+ * dictionary). Keys that did not meet the density threshold are stored in an optional sparse
+ * column; the sparse {@link DataSource} is returned for any unmaterialized key lookup.

Review Comment:
   use md style java doc for all files.



-- 
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] OPEN_STRUCT storage layer — columnar two-tier dense/sparse index (PR 2b/4) [pinot]

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


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/openstruct/ImmutableOpenStructDataSource.java:
##########
@@ -0,0 +1,265 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.segment.local.segment.index.openstruct;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import javax.annotation.Nullable;
+import org.apache.pinot.segment.local.segment.index.datasource.BaseDataSource;
+import org.apache.pinot.segment.local.segment.index.datasource.ImmutableDataSource;
+import org.apache.pinot.segment.spi.Constants;
+import org.apache.pinot.segment.spi.datasource.DataSource;
+import org.apache.pinot.segment.spi.datasource.DataSourceMetadata;
+import org.apache.pinot.segment.spi.datasource.OpenStructDataSource;
+import org.apache.pinot.segment.spi.index.column.ColumnIndexContainer;
+import org.apache.pinot.segment.spi.index.reader.Dictionary;
+import org.apache.pinot.segment.spi.index.reader.ForwardIndexReader;
+import org.apache.pinot.segment.spi.index.reader.ForwardIndexReaderContext;
+import org.apache.pinot.segment.spi.index.reader.NullValueVectorReader;
+import org.apache.pinot.segment.spi.partition.PartitionFunction;
+import org.apache.pinot.spi.data.ComplexFieldSpec;
+import org.apache.pinot.spi.data.FieldSpec;
+import org.apache.pinot.spi.data.FieldSpec.DataType;
+import org.apache.pinot.spi.utils.JsonUtils;
+
+
+
+/// Per-key {@link DataSource} accessor for sealed (immutable) segments with an OPEN_STRUCT column.
+///
+/// Always columnar — there is no blob branch. Every key that was dense enough during segment
+/// creation gets its own materialized {@link DataSource} (forward index + optional inverted index /
+/// dictionary). Keys that did not meet the density threshold are stored in an optional sparse
+/// column; the sparse {@link DataSource} is returned for any unmaterialized key lookup.
+///
+/// Use [#isMaterialized(String)] and [#isFullyMaterialized()] together to choose
+/// the query execution path:
+/// - Materialized key → fast path via per-key DataSource (inverted/dictionary index available).
+/// - Not materialized + not fully materialized → fall back to the sparse DataSource.
+/// - Not materialized + fully materialized → key is definitively absent; short-circuit.
+///
+/// Thread-safety: immutable after construction; safe for concurrent reads.
+public class ImmutableOpenStructDataSource extends BaseDataSource implements OpenStructDataSource {
+  private final ComplexFieldSpec _fieldSpec;
+  private final Map<String, DataSource> _perKeyDataSources;
+  @Nullable
+  private final DataSource _sparseDataSource;
+
+  public ImmutableOpenStructDataSource(ComplexFieldSpec fieldSpec, Map<String, DataSource> perKeyDataSources,
+      @Nullable DataSource sparseDataSource, DataSourceMetadata dataSourceMetadata,
+      ColumnIndexContainer indexContainer) {
+    super(dataSourceMetadata, indexContainer);
+    _fieldSpec = fieldSpec;
+    _perKeyDataSources = perKeyDataSources;
+    _sparseDataSource = sparseDataSource;
+  }
+
+  /// Convenience constructor for segment-load time. Synthesizes a minimal {@link DataSourceMetadata}
+  /// for the parent OPEN_STRUCT column (which has no on-disk presence of its own) and uses an empty
+  /// {@link ColumnIndexContainer} — all real readers live on the per-key data sources.
+  public ImmutableOpenStructDataSource(ComplexFieldSpec fieldSpec, Map<String, DataSource> perKeyDataSources,
+      @Nullable DataSource sparseDataSource, int numDocs) {
+    this(fieldSpec, perKeyDataSources, sparseDataSource,
+        new ImmutableOpenStructDataSourceMetadata(fieldSpec, numDocs),
+        new ColumnIndexContainer.FromMap.Builder().build());
+  }
+

Review Comment:
   The empty container is safe because no query operator calls `getForwardIndex()` on the parent OPEN_STRUCT DataSource — they go through `getDataSource(key)` to access per-key child DataSources. But I agree it's not clean. This ties into comment 4 — if we introduce a shared `CompositeDataSource` base for MAP and OPEN_STRUCT, it could drop the `ColumnIndexContainer` requirement entirely for composite parents. I'd prefer to do that as a follow-up rather than diverge OPEN_STRUCT from MAP's pattern in this 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] OPEN_STRUCT storage layer — columnar two-tier dense/sparse index (PR 2b/4) [pinot]

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


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/openstruct/MutableOpenStructIndex.java:
##########
@@ -0,0 +1,263 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.segment.local.segment.index.openstruct;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import javax.annotation.Nullable;
+import org.apache.pinot.common.utils.DataSchema.ColumnDataType;
+import org.apache.pinot.segment.local.segment.index.map.SimpleColumnMetadata;
+import org.apache.pinot.segment.spi.ColumnMetadata;
+import org.apache.pinot.segment.spi.index.IndexReader;
+import org.apache.pinot.segment.spi.index.IndexType;
+import org.apache.pinot.segment.spi.index.StandardIndexes;
+import org.apache.pinot.segment.spi.index.mutable.MutableIndex;
+import org.apache.pinot.segment.spi.index.reader.ForwardIndexReaderContext;
+import org.apache.pinot.segment.spi.index.reader.OpenStructIndexReader;
+import org.apache.pinot.segment.spi.memory.PinotDataBufferMemoryManager;
+import org.apache.pinot.spi.config.table.OpenStructIndexConfig;
+import org.apache.pinot.spi.data.ComplexFieldSpec;
+import org.apache.pinot.spi.data.DimensionFieldSpec;
+import org.apache.pinot.spi.data.FieldSpec;
+import org.apache.pinot.spi.data.FieldSpec.DataType;
+import org.apache.pinot.spi.data.OpenStructTypeInference;
+import org.apache.pinot.spi.utils.PinotDataType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/// Manages per-key mutable columns for an OPEN_STRUCT column during real-time consumption.
+/// Each discovered key gets its own {@link MutableKeyColumn} (dictionary-encoded forward index +
+/// presence bitmap). Dense/sparse classification is deferred to seal time.
+///
+/// Single-writer for [#index]: the consuming thread calls this method. Readers may
+/// concurrently read [#getKeys()] and [#getKeyColumns()] via the volatile map swap.
+@SuppressWarnings("rawtypes")
+public class MutableOpenStructIndex implements OpenStructIndexReader<ForwardIndexReaderContext>, MutableIndex {
+  private static final Logger LOGGER = LoggerFactory.getLogger(MutableOpenStructIndex.class);
+
+  private final String _openStructColumn;
+  private final OpenStructIndexConfig _config;
+  private final Map<String, FieldSpec> _childFieldSpecs;
+  private final PinotDataBufferMemoryManager _memoryManager;
+  private final int _capacity;
+
+  // Volatile for lock-free reader access; writer always holds the consuming-thread lock.
+  private volatile Map<String, MutableKeyColumn> _keyColumns = new HashMap<>();

Review Comment:
   This is Intentional. `ConcurrentHashMap` would let readers see partially-updated state mid-put. The volatile write in `allocateKeyColumn` publishes the entire map atomically — readers always get a consistent snapshot. Single-writer is guaranteed by Pinot's consuming thread model (one thread per partition). Expanded the comment.
   



##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/indexsegment/immutable/ImmutableSegmentImpl.java:
##########
@@ -98,13 +104,44 @@ public ImmutableSegmentImpl(
     _dataSources =
         new Object2ObjectOpenHashMap<>(segmentMetadata.getColumnMetadataMap().size());
 
+    Map<String, Map<String, DataSource>> openStructDenseChildren = new HashMap<>();
+    Map<String, DataSource> openStructSparseChildren = new HashMap<>();
+    Set<String> openStructParents = new HashSet<>();
+
     for (Map.Entry<String, ColumnMetadata> entry : segmentMetadata.getColumnMetadataMap().entrySet()) {
       String colName = entry.getKey();
       ColumnMetadata columnMetadata = entry.getValue();
+
+      if (columnMetadata instanceof ColumnMetadataImpl && ((ColumnMetadataImpl) columnMetadata).isMaterializedChild()) {
+        String parent = ((ColumnMetadataImpl) columnMetadata).getParentColumn();
+        openStructParents.add(parent);
+        DataSource childDs = new ImmutableDataSource(columnMetadata, _indexContainerMap.get(colName));
+        if (OpenStructNaming.isSparseColumn(colName)) {
+          openStructSparseChildren.put(parent, childDs);
+        } else {
+          openStructDenseChildren.computeIfAbsent(parent, k -> new HashMap<>())
+              .put(OpenStructNaming.parseKey(colName), childDs);
+        }
+        continue;
+      }
+
       if (columnMetadata.getFieldSpec().getDataType() == FieldSpec.DataType.MAP) {
-        _dataSources.put(colName, new ImmutableMapDataSource(entry.getValue(), _indexContainerMap.get(colName)));
+        _dataSources.put(colName, new ImmutableMapDataSource(columnMetadata, _indexContainerMap.get(colName)));
       } else {
-        _dataSources.put(colName, new ImmutableDataSource(entry.getValue(), _indexContainerMap.get(colName)));
+        _dataSources.put(colName, new ImmutableDataSource(columnMetadata, _indexContainerMap.get(colName)));
+      }
+    }
+
+    if (!openStructParents.isEmpty()) {
+      Schema schema = segmentMetadata.getSchema();
+      for (String parent : openStructParents) {
+        FieldSpec fieldSpec = schema != null ? schema.getFieldSpecFor(parent) : null;
+        if (!(fieldSpec instanceof ComplexFieldSpec)) {

Review Comment:
   Done. Added `LOGGER.warn` when the `continue` fires.



##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/loader/IndexLoadingConfig.java:
##########
@@ -415,6 +421,43 @@ private <K, V> Map<K, V> unmodifiable(Map<K, V> map) {
     return map == null ? null : Collections.unmodifiableMap(map);
   }
 
+  public void addOpenStructChildConfigs(SegmentMetadataImpl segmentMetadata) {
+    if (_indexConfigsByColName == null || _dirty) {
+      refreshIndexConfigs();
+    }
+    for (Map.Entry<String, ColumnMetadata> entry : segmentMetadata.getColumnMetadataMap().entrySet()) {
+      String childColumn = entry.getKey();
+      if (!childColumn.contains(OpenStructNaming.SEPARATOR) || _indexConfigsByColName.containsKey(childColumn)) {
+        continue;
+      }
+      if (OpenStructNaming.isSparseColumn(childColumn)) {
+        continue;
+      }
+      String parentColumn = OpenStructNaming.parseParentColumn(childColumn);
+      FieldIndexConfigs parentConfigs = _indexConfigsByColName.get(parentColumn);
+      if (parentConfigs == null) {
+        continue;
+      }
+      IndexConfig osConfig = parentConfigs.getConfig(StandardIndexes.openStruct());
+      if (!(osConfig instanceof OpenStructIndexConfig)) {
+        continue;
+      }
+      OpenStructIndexConfig openStructConfig = (OpenStructIndexConfig) osConfig;
+      String key = OpenStructNaming.parseKey(childColumn);
+      FieldConfig keyFieldConfig = openStructConfig.getValueFieldConfig(key);
+      if (keyFieldConfig == null) {
+        keyFieldConfig = openStructConfig.getDefaultValueFieldConfig();
+      }
+      FieldSpec childFieldSpec = entry.getValue().getFieldSpec();
+      boolean enableInverted = openStructConfig.shouldEnableInvertedIndexForKey(key);
+      FieldIndexConfigs childConfigs = new FieldIndexConfigs.Builder(
+          FieldIndexConfigsUtil.fromFieldConfig(keyFieldConfig, childFieldSpec))
+          .add(StandardIndexes.inverted(), enableInverted ? IndexConfig.ENABLED : IndexConfig.DISABLED)
+          .build();
+      _indexConfigsByColName.put(childColumn, childConfigs);

Review Comment:
   Current flow is safe — `addOpenStructChildConfigs` is the last mutation before configs are consumed. Added a warning comment documenting the constraint. 
   We can revisit this in future if needed but this should be fine for now.
   



##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/openstruct/ImmutableOpenStructDataSource.java:
##########
@@ -0,0 +1,179 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.segment.local.segment.index.openstruct;
+
+import java.util.Map;
+import javax.annotation.Nullable;
+import org.apache.pinot.segment.local.segment.index.datasource.BaseDataSource;
+import org.apache.pinot.segment.local.segment.index.datasource.ImmutableDataSource;
+import org.apache.pinot.segment.spi.Constants;
+import org.apache.pinot.segment.spi.datasource.DataSource;
+import org.apache.pinot.segment.spi.datasource.DataSourceMetadata;
+import org.apache.pinot.segment.spi.datasource.OpenStructDataSource;
+import org.apache.pinot.segment.spi.index.column.ColumnIndexContainer;
+import org.apache.pinot.segment.spi.partition.PartitionFunction;
+import org.apache.pinot.spi.data.ComplexFieldSpec;
+import org.apache.pinot.spi.data.FieldSpec;
+
+
+
+/// Per-key {@link DataSource} accessor for sealed (immutable) segments with an OPEN_STRUCT column.
+///
+/// Always columnar — there is no blob branch. Every key that was dense enough during segment
+/// creation gets its own materialized {@link DataSource} (forward index + optional inverted index /
+/// dictionary). Keys that did not meet the density threshold are stored in an optional sparse
+/// column; the sparse {@link DataSource} is returned for any unmaterialized key lookup.
+///
+/// Use [#isMaterialized(String)] and [#isFullyMaterialized()] together to choose
+/// the query execution path:
+/// - Materialized key → fast path via per-key DataSource (inverted/dictionary index available).
+/// - Not materialized + not fully materialized → fall back to the sparse DataSource.
+/// - Not materialized + fully materialized → key is definitively absent; short-circuit.
+///
+/// Thread-safety: immutable after construction; safe for concurrent reads.
+public class ImmutableOpenStructDataSource extends BaseDataSource implements OpenStructDataSource {
+  private final ComplexFieldSpec _fieldSpec;
+  private final Map<String, DataSource> _perKeyDataSources;
+  @Nullable
+  private final DataSource _sparseDataSource;
+
+  public ImmutableOpenStructDataSource(ComplexFieldSpec fieldSpec, Map<String, DataSource> perKeyDataSources,
+      @Nullable DataSource sparseDataSource, DataSourceMetadata dataSourceMetadata,
+      ColumnIndexContainer indexContainer) {
+    super(dataSourceMetadata, indexContainer);
+    _fieldSpec = fieldSpec;
+    _perKeyDataSources = perKeyDataSources;
+    _sparseDataSource = sparseDataSource;
+  }
+
+  /// Convenience constructor for segment-load time. Synthesizes a minimal {@link DataSourceMetadata}
+  /// for the parent OPEN_STRUCT column (which has no on-disk presence of its own) and uses an empty
+  /// {@link ColumnIndexContainer} — all real readers live on the per-key data sources.
+  public ImmutableOpenStructDataSource(ComplexFieldSpec fieldSpec, Map<String, DataSource> perKeyDataSources,
+      @Nullable DataSource sparseDataSource, int numDocs) {
+    this(fieldSpec, perKeyDataSources, sparseDataSource,
+        new ImmutableOpenStructDataSourceMetadata(fieldSpec, numDocs),
+        new ColumnIndexContainer.FromMap.Builder().build());
+  }
+
+  @Override
+  public ComplexFieldSpec getFieldSpec() {
+    return _fieldSpec;
+  }
+
+  @Override
+  @Nullable
+  public DataSource getDataSource(String key) {
+    DataSource ds = _perKeyDataSources.get(key);
+    return ds != null ? ds : _sparseDataSource;
+  }
+
+  @Override
+  public boolean isMaterialized(String key) {
+    return _perKeyDataSources.containsKey(key);
+  }
+
+  @Override
+  public boolean isFullyMaterialized() {
+    return _sparseDataSource == null;
+  }
+
+  @Override
+  public Map<String, DataSource> getDataSources() {
+    return _perKeyDataSources;
+  }
+
+  @Override
+  @Nullable
+  public DataSourceMetadata getDataSourceMetadata(String key) {
+    DataSource ds = _perKeyDataSources.get(key);
+    return ds != null ? ds.getDataSourceMetadata() : null;
+  }
+

Review Comment:
   Thanks for catching.
   Implemented `getMapValue(int docId)` — needed for minion tasks (refresh, compaction, merge-rollup) that go through `PinotSegmentRecordReader`. Added 5 unit tests.
   



##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/openstruct/MutableOpenStructDataSource.java:
##########
@@ -0,0 +1,180 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.segment.local.segment.index.openstruct;
+
+import java.util.HashMap;
+import java.util.Map;
+import javax.annotation.Nullable;
+import org.apache.pinot.segment.local.segment.index.datasource.BaseDataSource;
+import org.apache.pinot.segment.local.segment.index.datasource.ImmutableDataSource;
+import org.apache.pinot.segment.spi.ColumnMetadata;
+import org.apache.pinot.segment.spi.Constants;
+import org.apache.pinot.segment.spi.datasource.DataSource;
+import org.apache.pinot.segment.spi.datasource.DataSourceMetadata;
+import org.apache.pinot.segment.spi.datasource.OpenStructDataSource;
+import org.apache.pinot.segment.spi.index.IndexReader;
+import org.apache.pinot.segment.spi.index.IndexType;
+import org.apache.pinot.segment.spi.index.column.ColumnIndexContainer;
+import org.apache.pinot.segment.spi.partition.PartitionFunction;
+import org.apache.pinot.spi.data.ComplexFieldSpec;
+import org.apache.pinot.spi.data.FieldSpec;
+
+
+/// Per-key {@link DataSource} accessor for mutable (consuming) segments with an OPEN_STRUCT column.
+///
+/// Always columnar — no blob branch. Per-key DataSources are synthesized on demand from the
+/// underlying {@link MutableOpenStructIndex}; mutable mode always holds every observed key, so
+/// {@link #isFullyMaterialized()} is unconditionally {@code true}.
+public class MutableOpenStructDataSource extends BaseDataSource implements OpenStructDataSource {
+  private final ComplexFieldSpec _fieldSpec;
+  private final MutableOpenStructIndex _index;
+  private final int _numDocs;
+
+  public MutableOpenStructDataSource(ComplexFieldSpec fieldSpec, MutableOpenStructIndex index, int numDocs) {
+    super(new MutableOpenStructDataSourceMetadata(fieldSpec, numDocs),
+        new ColumnIndexContainer.FromMap.Builder().build());
+    _fieldSpec = fieldSpec;
+    _index = index;
+    _numDocs = numDocs;
+  }
+
+  @Override
+  public ComplexFieldSpec getFieldSpec() {
+    return _fieldSpec;
+  }
+
+  @Override
+  @Nullable
+  public DataSource getDataSource(String key) {
+    Map<IndexType, IndexReader> indexes = _index.getIndexes(key);
+    if (indexes == null || indexes.isEmpty()) {
+      return null;
+    }
+    ColumnMetadata metadata = _index.getColumnMetadata(key);
+    return new ImmutableDataSource(metadata,
+        new ColumnIndexContainer.FromMap.Builder().withAll(indexes).build());
+  }
+
+  @Override
+  public boolean isMaterialized(String key) {
+    return _index.getKeyColumn(key) != null;
+  }
+
+  /// Mutable mode always holds every observed key in-memory; the sparse tier exists only after seal.
+  @Override
+  public boolean isFullyMaterialized() {
+    return true;
+  }
+
+  @Override
+  public Map<String, DataSource> getDataSources() {
+    Map<String, DataSource> result = new HashMap<>();
+    for (String key : _index.getKeys()) {

Review Comment:
   Done. `getDataSources()` now snapshots `_index.getKeyColumns()` once.
   



##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/creator/impl/openstruct/OpenStructColumnSplitter.java:
##########
@@ -0,0 +1,540 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.segment.local.segment.creator.impl.openstruct;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import javax.annotation.Nullable;
+import org.apache.commons.configuration2.PropertiesConfiguration;
+import org.apache.pinot.common.utils.DataSchema.ColumnDataType;
+import org.apache.pinot.segment.local.segment.creator.impl.BaseSegmentCreator;
+import org.apache.pinot.segment.local.segment.creator.impl.SegmentDictionaryCreator;
+import org.apache.pinot.segment.local.segment.creator.impl.fwd.SingleValueVarByteRawIndexCreator;
+import org.apache.pinot.segment.local.segment.creator.impl.nullvalue.NullValueVectorCreator;
+import org.apache.pinot.segment.local.segment.creator.impl.stats.AbstractColumnStatisticsCollector;
+import org.apache.pinot.segment.local.segment.creator.impl.stats.StatsCollectorUtil;
+import org.apache.pinot.segment.local.segment.index.dictionary.DictionaryIndexType;
+import org.apache.pinot.segment.local.segment.index.openstruct.OpenStructSupportedIndexes;
+import org.apache.pinot.segment.spi.V1Constants;
+import org.apache.pinot.segment.spi.compression.ChunkCompressionType;
+import org.apache.pinot.segment.spi.creator.IndexCreationContext;
+import org.apache.pinot.segment.spi.index.DictionaryIndexConfig;
+import org.apache.pinot.segment.spi.index.FieldIndexConfigs;
+import org.apache.pinot.segment.spi.index.FieldIndexConfigsUtil;
+import org.apache.pinot.segment.spi.index.ForwardIndexConfig;
+import org.apache.pinot.segment.spi.index.IndexCreator;
+import org.apache.pinot.segment.spi.index.IndexService;
+import org.apache.pinot.segment.spi.index.IndexType;
+import org.apache.pinot.segment.spi.index.StandardIndexes;
+import org.apache.pinot.segment.spi.index.creator.ColumnarOpenStructIndexCreator;
+import org.apache.pinot.spi.config.table.FieldConfig;
+import org.apache.pinot.spi.config.table.IndexConfig;
+import org.apache.pinot.spi.config.table.IndexingConfig;
+import org.apache.pinot.spi.config.table.OpenStructIndexConfig;
+import org.apache.pinot.spi.data.ComplexFieldSpec;
+import org.apache.pinot.spi.data.DimensionFieldSpec;
+import org.apache.pinot.spi.data.FieldSpec;
+import org.apache.pinot.spi.data.FieldSpec.DataType;
+import org.apache.pinot.spi.data.OpenStructNaming;
+import org.apache.pinot.spi.data.OpenStructTypeInference;
+import org.apache.pinot.spi.utils.JsonUtils;
+import org.apache.pinot.spi.utils.PinotDataType;
+import org.roaringbitmap.RoaringBitmap;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/// Splits an OPEN_STRUCT column into per-key materialized columns using standard Pinot index
+/// creators. Dense keys become independent virtual columns; remaining keys go into a single
+/// synthetic JSON column for sparse storage.
+///
+/// Lifecycle: instantiated by `BaseSegmentCreator` for OPEN_STRUCT columns. Receives
+/// per-doc `Map<String, Object>` values via [#add(Map, int)], accumulates in memory,
+/// then on [#seal()] writes per-key column files using standard creators.
+public class OpenStructColumnSplitter implements ColumnarOpenStructIndexCreator {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(OpenStructColumnSplitter.class);
+
+  private final File _indexDir;
+  private final String _columnName;
+  private final Map<String, FieldSpec> _childFieldSpecs;
+  private final OpenStructIndexConfig _config;
+  private final int _maxDenseKeys;
+
+  // Per-key accumulation
+  private final Map<String, RoaringBitmap> _presenceBitmaps = new HashMap<>();
+  private final Map<String, List<Object>> _values = new HashMap<>();
+  private final Map<String, DataType> _inferredTypes = new HashMap<>();
+  private int _numDocs;
+
+  // Resolved at seal time
+  @Nullable
+  private Set<String> _resolvedDenseKeys;
+  private final Map<String, PropertiesConfiguration> _materializedColumnMetadata = new LinkedHashMap<>();
+
+  public OpenStructColumnSplitter(File indexDir, String columnName, FieldSpec fieldSpec,
+      OpenStructIndexConfig config) {
+    _indexDir = indexDir;
+    _columnName = columnName;
+    _config = config;
+    _maxDenseKeys = config.getMaxDenseKeys();
+
+    Map<String, FieldSpec> childFieldSpecs = null;
+    if (fieldSpec instanceof ComplexFieldSpec) {
+      ComplexFieldSpec complexSpec = (ComplexFieldSpec) fieldSpec;
+      childFieldSpecs = complexSpec.getChildFieldSpecs();
+    }
+    _childFieldSpecs = childFieldSpecs != null ? new HashMap<>(childFieldSpecs) : new HashMap<>();
+  }
+
+  @Override
+  public void add(Object value, int docId)
+      throws IOException {
+    if (value instanceof Map) {
+      @SuppressWarnings("unchecked")
+      Map<String, Object> map = (Map<String, Object>) value;
+      addMap(map);
+    } else {
+      addMap(null);
+    }
+  }
+
+  @Override
+  public void add(Map<String, Object> openStructValue, int docId)
+      throws IOException {
+    addMap(openStructValue);
+  }
+
+  @Override
+  public void add(Object[] values, @Nullable int[] dictIds)
+      throws IOException {
+    throw new UnsupportedOperationException("OPEN_STRUCT index is single-value only");
+  }
+
+  /// Returns the resolved dense-key set after [#seal()] or [#classify()].
+  /// Returns an empty set before resolution.
+  public Set<String> getResolvedDenseKeys() {
+    return _resolvedDenseKeys != null ? Collections.unmodifiableSet(_resolvedDenseKeys) : Set.of();
+  }
+
+  /// Resolves dense vs sparse keys without writing any files. Exposed for testing and for callers
+  /// that need the classification independent of file output. [#seal()] calls this internally.
+  public Set<String> classify() {
+    if (_resolvedDenseKeys != null) {
+      return _resolvedDenseKeys;
+    }
+    if (_numDocs == 0 || _presenceBitmaps.isEmpty()) {
+      _resolvedDenseKeys = new LinkedHashSet<>();
+      return _resolvedDenseKeys;
+    }
+    List<String> allKeys = new ArrayList<>(_presenceBitmaps.keySet());
+    allKeys.sort((a, b) -> {
+      double fillA = (double) _presenceBitmaps.get(a).getCardinality() / _numDocs;
+      double fillB = (double) _presenceBitmaps.get(b).getCardinality() / _numDocs;
+      int cmp = Double.compare(fillB, fillA);
+      return cmp != 0 ? cmp : a.compareTo(b);
+    });
+
+    double minFillRate = _config.getDenseKeyMinFillRate();
+    _resolvedDenseKeys = new LinkedHashSet<>();
+
+    Set<String> configuredDenseKeys = _config.getDenseKeys();
+    for (String key : configuredDenseKeys) {
+      if (_presenceBitmaps.containsKey(key) && (_maxDenseKeys < 0 || _resolvedDenseKeys.size() < _maxDenseKeys)) {
+        _resolvedDenseKeys.add(key);
+      }
+    }
+
+    for (String key : allKeys) {
+      if (_resolvedDenseKeys.contains(key)) {
+        continue;
+      }
+      double fillRate = (double) _presenceBitmaps.get(key).getCardinality() / _numDocs;
+      if ((_maxDenseKeys < 0 || _resolvedDenseKeys.size() < _maxDenseKeys) && fillRate >= minFillRate) {
+        _resolvedDenseKeys.add(key);
+      }
+    }
+    return _resolvedDenseKeys;
+  }
+
+  private void addMap(@Nullable Map<String, Object> map) {
+    if (map != null && !map.isEmpty()) {
+      for (Map.Entry<String, Object> entry : map.entrySet()) {
+        String key = entry.getKey();
+        Object rawValue = entry.getValue();
+        if (rawValue == null) {
+          continue;
+        }
+        FieldSpec keySpec = _childFieldSpecs.get(key);
+        DataType valueType = keySpec != null
+            ? keySpec.getDataType()
+            : _inferredTypes.computeIfAbsent(key, k -> {
+              DataType inferred = OpenStructTypeInference.inferDataType(rawValue);
+              return inferred != null ? inferred : DataType.STRING;
+            });
+        if (!_presenceBitmaps.containsKey(key)) {
+          _presenceBitmaps.put(key, new RoaringBitmap());
+          _values.put(key, new ArrayList<>());
+        }
+        _presenceBitmaps.get(key).add(_numDocs);
+        Object coerced;
+        try {
+          PinotDataType sourceType = PinotDataType.getSingleValueType(rawValue);
+          PinotDataType destType = ColumnDataType.fromDataTypeSV(valueType.getStoredType()).toPinotDataType();
+          coerced = destType.convert(rawValue, sourceType);
+        } catch (Exception e) {
+          LOGGER.warn("OPEN_STRUCT '{}': coercion failed for key '{}' value '{}' to {}. Skipping.",
+              _columnName, key, rawValue, valueType, e);
+          _presenceBitmaps.get(key).remove(_numDocs);
+          continue;
+        }
+        _values.get(key).add(coerced);
+      }
+    }
+    _numDocs++;
+  }
+
+  @Override
+  public void seal()
+      throws IOException {
+    classify();
+    if (_resolvedDenseKeys == null || (_numDocs == 0 && _presenceBitmaps.isEmpty())) {
+      return;
+    }
+
+    for (String key : _resolvedDenseKeys) {
+      writeDenseKeyColumn(key);
+    }
+
+    List<String> sparseKeys = new ArrayList<>();
+    for (String key : _presenceBitmaps.keySet()) {
+      if (!_resolvedDenseKeys.contains(key)) {
+        sparseKeys.add(key);
+      }
+    }
+    if (!sparseKeys.isEmpty()) {
+      writeSparseJsonColumn(sparseKeys);
+    }
+
+    emitParentColumnMetadata(!sparseKeys.isEmpty());
+  }
+
+  @Override
+  public void close()
+      throws IOException {
+    // Nothing to close — sub-creators are created and closed within seal()
+  }
+
+  @Override
+  public Map<String, PropertiesConfiguration> getMaterializedColumnMetadata() {
+    return _materializedColumnMetadata;
+  }
+
+  private void writeDenseKeyColumn(String key)
+      throws IOException {
+    String materializedCol = OpenStructNaming.materializedColumnName(_columnName, key);
+    FieldSpec keySpec = _childFieldSpecs.get(key);
+    DataType valueType = keySpec != null
+        ? keySpec.getDataType()
+        : _inferredTypes.getOrDefault(key, DataType.STRING);
+    DataType storedType = valueType.getStoredType();
+    RoaringBitmap presence = _presenceBitmaps.get(key);
+    List<Object> values = _values.get(key);
+
+    // Synthetic field spec for the materialized child. Its natural Pinot dimension null value is the value
+    // stored for absent docs, so column metadata stays consistent with on-disk content.
+    DimensionFieldSpec childFieldSpec = new DimensionFieldSpec(materializedCol, storedType, true);
+    Object defaultValue = childFieldSpec.getDefaultNullValue();
+
+    // Collect statistics the standard way: present docs contribute their value, absent docs the default
+    // (absent docs are also marked in the null vector below).
+    AbstractColumnStatisticsCollector statsCollector =
+        StatsCollectorUtil.createStatsCollector(childFieldSpec, null);
+    int statsOrdinal = 0;
+    for (int docId = 0; docId < _numDocs; docId++) {
+      statsCollector.collect(presence.contains(docId) ? values.get(statsOrdinal++) : defaultValue);
+    }
+    statsCollector.seal();
+
+    // Build per-key index configuration from the key's FieldConfig (falling back to the default), then apply
+    // the OPEN_STRUCT inverted-on default. No TableConfig/Schema required.
+    FieldConfig keyFieldConfig = _config.getValueFieldConfig(key);
+    if (keyFieldConfig == null) {
+      keyFieldConfig = _config.getDefaultValueFieldConfig();
+    }
+    boolean enableInverted = _config.shouldEnableInvertedIndexForKey(key);
+    FieldIndexConfigs configsForDecision = new FieldIndexConfigs.Builder(
+        FieldIndexConfigsUtil.fromFieldConfig(keyFieldConfig, childFieldSpec))
+        .add(StandardIndexes.inverted(), enableInverted ? IndexConfig.ENABLED : IndexConfig.DISABLED)
+        .build();
+
+    boolean useDictionary = resolveUseDictionary(childFieldSpec, configsForDecision, statsCollector);
+
+    // Reconcile dictionary + forward encoding with the final decision (mirrors BaseSegmentCreator.adaptConfig);
+    // ForwardIndexCreatorFactory selects dict-vs-raw from the forward config's EncodingType. A compression codec
+    // applies only to the raw forward format (LZ4 preserves the dense child's current on-disk layout); attaching
+    // one to a dictionary-encoded forward is rejected by ForwardIndexType.validate.
+    ForwardIndexConfig.Builder forwardBuilder = new ForwardIndexConfig.Builder(
+        useDictionary ? FieldConfig.EncodingType.DICTIONARY : FieldConfig.EncodingType.RAW);
+    if (!useDictionary) {
+      forwardBuilder.withCompressionCodec(FieldConfig.CompressionCodec.LZ4);
+    }
+    FieldIndexConfigs fieldIndexConfigs = new FieldIndexConfigs.Builder(configsForDecision)
+        .add(StandardIndexes.dictionary(),
+            useDictionary ? DictionaryIndexConfig.DEFAULT : DictionaryIndexConfig.DISABLED)
+        .add(StandardIndexes.forward(), forwardBuilder.build())
+        .build();
+
+    int dictElementSize = writeColumnIndexes(materializedCol, storedType, presence, values,
+        defaultValue, statsCollector, useDictionary, fieldIndexConfigs, childFieldSpec);
+
+    NullValueVectorCreator nullCreator = new NullValueVectorCreator(_indexDir, materializedCol);
+    try {
+      for (int docId = 0; docId < _numDocs; docId++) {
+        if (!presence.contains(docId)) {
+          nullCreator.setNull(docId);
+        }
+      }
+      nullCreator.seal();
+    } finally {
+      nullCreator.close();
+    }
+
+    PropertiesConfiguration props = new PropertiesConfiguration();
+    FieldConfig.EncodingType encoding =
+        useDictionary ? FieldConfig.EncodingType.DICTIONARY : FieldConfig.EncodingType.RAW;
+    BaseSegmentCreator.addColumnMetadataInfo(props, materializedCol, statsCollector, _numDocs, childFieldSpec,
+        useDictionary, dictElementSize, encoding, false);
+    // OPEN_STRUCT-specific keys not written by addColumnMetadataInfo.
+    props.setProperty(
+        V1Constants.MetadataKeys.Column.getKeyFor(materializedCol, V1Constants.MetadataKeys.Column.PARENT_COLUMN),
+        _columnName);
+    props.setProperty(V1Constants.MetadataKeys.Column.getKeyFor(materializedCol, "hasNullValue"), true);
+    if (enableInverted && useDictionary) {
+      props.setProperty(V1Constants.MetadataKeys.Column.getKeyFor(materializedCol, "hasInvertedIndex"), true);
+    }
+    _materializedColumnMetadata.put(materializedCol, props);
+  }
+
+  /// Decides dictionary vs raw encoding for a materialized child column, mirroring the three steps of
+  /// `BaseSegmentCreator.createDictionaryForColumn` with standard default flags (optimizeDictionary
+  /// off => dictionary unless explicitly disabled and not required by an enabled index).
+  private boolean resolveUseDictionary(FieldSpec childFieldSpec, FieldIndexConfigs fieldIndexConfigs,
+      AbstractColumnStatisticsCollector statsCollector) {
+    if (DictionaryIndexConfig.requiresDictionary(childFieldSpec, fieldIndexConfigs)) {
+      return true;
+    }
+    if (fieldIndexConfigs.getConfig(StandardIndexes.dictionary()).isDisabled()) {
+      return false;
+    }
+    return DictionaryIndexType.ignoreDictionaryOverride(false, false,
+        IndexingConfig.DEFAULT_NO_DICTIONARY_SIZE_RATIO_THRESHOLD, null, childFieldSpec, fieldIndexConfigs,
+        statsCollector.getCardinality(), statsCollector.getTotalNumberOfEntries());
+  }
+
+  /// Writes the dictionary (when used) plus all vetted, enabled indexes for a materialized child column through
+  /// the standard index-creator family, driven from a single per-doc loop. Returns the dictionary element size in
+  /// bytes (0 when raw-encoded), for column metadata. The dictionary is built separately because its build
+  /// lifecycle is CUSTOM and it supplies the dictIds the per-row creators consume.
+  private int writeColumnIndexes(String materializedCol, DataType storedType, RoaringBitmap presence,
+      List<Object> values, Object defaultValue, AbstractColumnStatisticsCollector statsCollector,
+      boolean useDictionary, FieldIndexConfigs fieldIndexConfigs, FieldSpec childFieldSpec)
+      throws IOException {
+    int dictElementSize = 0;
+    SegmentDictionaryCreator dictCreator = null;
+    try {
+      if (useDictionary) {
+        dictCreator = new SegmentDictionaryCreator(materializedCol, storedType,
+            new File(_indexDir, materializedCol + V1Constants.Dict.FILE_EXTENSION), true);
+        dictCreator.build(statsCollector.getUniqueValuesSet());
+      }
+
+      // Index-creation context built from the sealed collector (a ColumnShape) — no TableConfig required.
+      IndexCreationContext context =
+          new IndexCreationContext.Builder(_indexDir, null, statsCollector, useDictionary, false)
+              .withOnHeap(false).build();
+
+      List<IndexCreator> creators = new ArrayList<>();
+      try {
+        for (IndexType<?, ?, ?> indexType : IndexService.getInstance().getAllIndexes()) {
+          if (indexType.getIndexBuildLifecycle() != IndexType.BuildLifecycle.DURING_SEGMENT_CREATION) {
+            continue;   // excludes dictionary (lifecycle CUSTOM), built separately above
+          }
+          if (!OpenStructSupportedIndexes.ALLOWED_PRETTY_NAMES.contains(indexType.getPrettyName())) {
+            continue;   // non-vetted indexes already rejected at table-config validation; defensive backstop
+          }
+          IndexCreator creator = createColumnIndexCreator(indexType, context, fieldIndexConfigs, materializedCol,
+              childFieldSpec);
+          if (creator != null) {
+            creators.add(creator);
+          }
+        }
+
+        int ordinal = 0;
+        for (int docId = 0; docId < _numDocs; docId++) {
+          Object value = presence.contains(docId) ? values.get(ordinal++) : defaultValue;
+          int dictId = useDictionary ? dictCreator.indexOfSV(value) : -1;
+          for (IndexCreator creator : creators) {
+            creator.add(value, dictId);
+          }
+        }
+        for (IndexCreator creator : creators) {
+          creator.seal();
+        }
+      } finally {
+        for (IndexCreator creator : creators) {
+          creator.close();
+        }
+        if (dictCreator != null) {
+          dictElementSize = dictCreator.getNumBytesPerEntry();
+          dictCreator.seal();
+        }
+      }
+    } finally {
+      if (dictCreator != null) {
+        dictCreator.close();
+      }
+    }
+    return dictElementSize;
+  }
+
+  @Nullable
+  private static <C extends IndexConfig> IndexCreator createColumnIndexCreator(IndexType<C, ?, ?> indexType,
+      IndexCreationContext context, FieldIndexConfigs fieldIndexConfigs, String materializedCol,
+      FieldSpec childFieldSpec)
+      throws IOException {
+    // Materialized child columns exist in no schema/TableConfig, so the standard table-config-time validation
+    // never sees them. Run the index type's own guards here against the resolved child FieldSpec (e.g. range
+    // rejects a non-numeric column without a dictionary) so misconfigurations fail with the canonical message
+    // instead of crashing opaquely inside the creator. validate() internally no-ops when the index is disabled.
+    indexType.validate(fieldIndexConfigs, childFieldSpec, null);
+    C config = fieldIndexConfigs.getConfig(indexType);
+    if (!config.isEnabled() || !indexType.shouldCreateIndex(context, config)) {
+      return null;
+    }
+    try {
+      return indexType.createIndexCreator(context, config);
+    } catch (IOException e) {
+      throw e;
+    } catch (Exception e) {
+      throw new IOException("Failed to create " + indexType.getPrettyName() + " creator for: " + materializedCol, e);
+    }
+  }
+
+  private void writeSparseJsonColumn(List<String> sparseKeys)
+      throws IOException {
+    String sparseCol = OpenStructNaming.sparseColumnName(_columnName);
+    int maxLen = 1;
+    String[] jsonPerDoc = new String[_numDocs];
+    int nonNullCount = 0;
+    for (int docId = 0; docId < _numDocs; docId++) {
+      Map<String, Object> sparseEntries = new LinkedHashMap<>();
+      for (String key : sparseKeys) {
+        RoaringBitmap presence = _presenceBitmaps.get(key);
+        if (presence != null && presence.contains(docId)) {
+          int ordinal = presence.rank(docId) - 1;
+          sparseEntries.put(key, _values.get(key).get(ordinal));
+        }
+      }
+      if (!sparseEntries.isEmpty()) {
+        try {
+          String json = JsonUtils.objectToString(sparseEntries);
+          jsonPerDoc[docId] = json;
+          maxLen = Math.max(maxLen, json.getBytes(StandardCharsets.UTF_8).length);
+          nonNullCount++;
+        } catch (IOException e) {
+          throw new RuntimeException("Failed to serialize sparse entries for docId " + docId, e);
+        }
+      }
+    }
+
+    SingleValueVarByteRawIndexCreator fwdCreator = new SingleValueVarByteRawIndexCreator(
+        _indexDir, ChunkCompressionType.LZ4, sparseCol, _numDocs, DataType.STRING, maxLen);
+    NullValueVectorCreator nullCreator = new NullValueVectorCreator(_indexDir, sparseCol);
+    try {
+      for (int docId = 0; docId < _numDocs; docId++) {

Review Comment:
   Two-pass is required: `SingleValueVarByteRawIndexCreator` takes `maxLen` as a constructor arg, only known after the first loop. The allocation concern is already fixed by #6 (`Utf8.encodedLength`).
   



##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/creator/impl/openstruct/OpenStructColumnSplitter.java:
##########
@@ -0,0 +1,540 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.segment.local.segment.creator.impl.openstruct;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import javax.annotation.Nullable;
+import org.apache.commons.configuration2.PropertiesConfiguration;
+import org.apache.pinot.common.utils.DataSchema.ColumnDataType;
+import org.apache.pinot.segment.local.segment.creator.impl.BaseSegmentCreator;
+import org.apache.pinot.segment.local.segment.creator.impl.SegmentDictionaryCreator;
+import org.apache.pinot.segment.local.segment.creator.impl.fwd.SingleValueVarByteRawIndexCreator;
+import org.apache.pinot.segment.local.segment.creator.impl.nullvalue.NullValueVectorCreator;
+import org.apache.pinot.segment.local.segment.creator.impl.stats.AbstractColumnStatisticsCollector;
+import org.apache.pinot.segment.local.segment.creator.impl.stats.StatsCollectorUtil;
+import org.apache.pinot.segment.local.segment.index.dictionary.DictionaryIndexType;
+import org.apache.pinot.segment.local.segment.index.openstruct.OpenStructSupportedIndexes;
+import org.apache.pinot.segment.spi.V1Constants;
+import org.apache.pinot.segment.spi.compression.ChunkCompressionType;
+import org.apache.pinot.segment.spi.creator.IndexCreationContext;
+import org.apache.pinot.segment.spi.index.DictionaryIndexConfig;
+import org.apache.pinot.segment.spi.index.FieldIndexConfigs;
+import org.apache.pinot.segment.spi.index.FieldIndexConfigsUtil;
+import org.apache.pinot.segment.spi.index.ForwardIndexConfig;
+import org.apache.pinot.segment.spi.index.IndexCreator;
+import org.apache.pinot.segment.spi.index.IndexService;
+import org.apache.pinot.segment.spi.index.IndexType;
+import org.apache.pinot.segment.spi.index.StandardIndexes;
+import org.apache.pinot.segment.spi.index.creator.ColumnarOpenStructIndexCreator;
+import org.apache.pinot.spi.config.table.FieldConfig;
+import org.apache.pinot.spi.config.table.IndexConfig;
+import org.apache.pinot.spi.config.table.IndexingConfig;
+import org.apache.pinot.spi.config.table.OpenStructIndexConfig;
+import org.apache.pinot.spi.data.ComplexFieldSpec;
+import org.apache.pinot.spi.data.DimensionFieldSpec;
+import org.apache.pinot.spi.data.FieldSpec;
+import org.apache.pinot.spi.data.FieldSpec.DataType;
+import org.apache.pinot.spi.data.OpenStructNaming;
+import org.apache.pinot.spi.data.OpenStructTypeInference;
+import org.apache.pinot.spi.utils.JsonUtils;
+import org.apache.pinot.spi.utils.PinotDataType;
+import org.roaringbitmap.RoaringBitmap;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/// Splits an OPEN_STRUCT column into per-key materialized columns using standard Pinot index
+/// creators. Dense keys become independent virtual columns; remaining keys go into a single
+/// synthetic JSON column for sparse storage.
+///
+/// Lifecycle: instantiated by `BaseSegmentCreator` for OPEN_STRUCT columns. Receives
+/// per-doc `Map<String, Object>` values via [#add(Map, int)], accumulates in memory,
+/// then on [#seal()] writes per-key column files using standard creators.
+public class OpenStructColumnSplitter implements ColumnarOpenStructIndexCreator {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(OpenStructColumnSplitter.class);
+
+  private final File _indexDir;
+  private final String _columnName;
+  private final Map<String, FieldSpec> _childFieldSpecs;
+  private final OpenStructIndexConfig _config;
+  private final int _maxDenseKeys;
+
+  // Per-key accumulation
+  private final Map<String, RoaringBitmap> _presenceBitmaps = new HashMap<>();
+  private final Map<String, List<Object>> _values = new HashMap<>();
+  private final Map<String, DataType> _inferredTypes = new HashMap<>();
+  private int _numDocs;
+
+  // Resolved at seal time
+  @Nullable
+  private Set<String> _resolvedDenseKeys;
+  private final Map<String, PropertiesConfiguration> _materializedColumnMetadata = new LinkedHashMap<>();
+
+  public OpenStructColumnSplitter(File indexDir, String columnName, FieldSpec fieldSpec,
+      OpenStructIndexConfig config) {
+    _indexDir = indexDir;
+    _columnName = columnName;
+    _config = config;
+    _maxDenseKeys = config.getMaxDenseKeys();
+
+    Map<String, FieldSpec> childFieldSpecs = null;
+    if (fieldSpec instanceof ComplexFieldSpec) {
+      ComplexFieldSpec complexSpec = (ComplexFieldSpec) fieldSpec;
+      childFieldSpecs = complexSpec.getChildFieldSpecs();
+    }
+    _childFieldSpecs = childFieldSpecs != null ? new HashMap<>(childFieldSpecs) : new HashMap<>();
+  }
+
+  @Override
+  public void add(Object value, int docId)
+      throws IOException {
+    if (value instanceof Map) {
+      @SuppressWarnings("unchecked")
+      Map<String, Object> map = (Map<String, Object>) value;
+      addMap(map);
+    } else {
+      addMap(null);
+    }
+  }
+
+  @Override
+  public void add(Map<String, Object> openStructValue, int docId)
+      throws IOException {
+    addMap(openStructValue);
+  }
+
+  @Override
+  public void add(Object[] values, @Nullable int[] dictIds)
+      throws IOException {
+    throw new UnsupportedOperationException("OPEN_STRUCT index is single-value only");
+  }
+
+  /// Returns the resolved dense-key set after [#seal()] or [#classify()].
+  /// Returns an empty set before resolution.
+  public Set<String> getResolvedDenseKeys() {
+    return _resolvedDenseKeys != null ? Collections.unmodifiableSet(_resolvedDenseKeys) : Set.of();
+  }
+
+  /// Resolves dense vs sparse keys without writing any files. Exposed for testing and for callers
+  /// that need the classification independent of file output. [#seal()] calls this internally.
+  public Set<String> classify() {
+    if (_resolvedDenseKeys != null) {
+      return _resolvedDenseKeys;
+    }
+    if (_numDocs == 0 || _presenceBitmaps.isEmpty()) {
+      _resolvedDenseKeys = new LinkedHashSet<>();
+      return _resolvedDenseKeys;
+    }
+    List<String> allKeys = new ArrayList<>(_presenceBitmaps.keySet());
+    allKeys.sort((a, b) -> {
+      double fillA = (double) _presenceBitmaps.get(a).getCardinality() / _numDocs;
+      double fillB = (double) _presenceBitmaps.get(b).getCardinality() / _numDocs;
+      int cmp = Double.compare(fillB, fillA);
+      return cmp != 0 ? cmp : a.compareTo(b);
+    });
+
+    double minFillRate = _config.getDenseKeyMinFillRate();
+    _resolvedDenseKeys = new LinkedHashSet<>();
+
+    Set<String> configuredDenseKeys = _config.getDenseKeys();
+    for (String key : configuredDenseKeys) {
+      if (_presenceBitmaps.containsKey(key) && (_maxDenseKeys < 0 || _resolvedDenseKeys.size() < _maxDenseKeys)) {
+        _resolvedDenseKeys.add(key);
+      }
+    }
+
+    for (String key : allKeys) {
+      if (_resolvedDenseKeys.contains(key)) {
+        continue;
+      }
+      double fillRate = (double) _presenceBitmaps.get(key).getCardinality() / _numDocs;

Review Comment:
   Done. Used `computeIfAbsent` + cached local references to reduce from ~6 lookups per key per doc to 2.
   



##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/creator/impl/openstruct/OpenStructColumnSplitter.java:
##########
@@ -0,0 +1,540 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.segment.local.segment.creator.impl.openstruct;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import javax.annotation.Nullable;
+import org.apache.commons.configuration2.PropertiesConfiguration;
+import org.apache.pinot.common.utils.DataSchema.ColumnDataType;
+import org.apache.pinot.segment.local.segment.creator.impl.BaseSegmentCreator;
+import org.apache.pinot.segment.local.segment.creator.impl.SegmentDictionaryCreator;
+import org.apache.pinot.segment.local.segment.creator.impl.fwd.SingleValueVarByteRawIndexCreator;
+import org.apache.pinot.segment.local.segment.creator.impl.nullvalue.NullValueVectorCreator;
+import org.apache.pinot.segment.local.segment.creator.impl.stats.AbstractColumnStatisticsCollector;
+import org.apache.pinot.segment.local.segment.creator.impl.stats.StatsCollectorUtil;
+import org.apache.pinot.segment.local.segment.index.dictionary.DictionaryIndexType;
+import org.apache.pinot.segment.local.segment.index.openstruct.OpenStructSupportedIndexes;
+import org.apache.pinot.segment.spi.V1Constants;
+import org.apache.pinot.segment.spi.compression.ChunkCompressionType;
+import org.apache.pinot.segment.spi.creator.IndexCreationContext;
+import org.apache.pinot.segment.spi.index.DictionaryIndexConfig;
+import org.apache.pinot.segment.spi.index.FieldIndexConfigs;
+import org.apache.pinot.segment.spi.index.FieldIndexConfigsUtil;
+import org.apache.pinot.segment.spi.index.ForwardIndexConfig;
+import org.apache.pinot.segment.spi.index.IndexCreator;
+import org.apache.pinot.segment.spi.index.IndexService;
+import org.apache.pinot.segment.spi.index.IndexType;
+import org.apache.pinot.segment.spi.index.StandardIndexes;
+import org.apache.pinot.segment.spi.index.creator.ColumnarOpenStructIndexCreator;
+import org.apache.pinot.spi.config.table.FieldConfig;
+import org.apache.pinot.spi.config.table.IndexConfig;
+import org.apache.pinot.spi.config.table.IndexingConfig;
+import org.apache.pinot.spi.config.table.OpenStructIndexConfig;
+import org.apache.pinot.spi.data.ComplexFieldSpec;
+import org.apache.pinot.spi.data.DimensionFieldSpec;
+import org.apache.pinot.spi.data.FieldSpec;
+import org.apache.pinot.spi.data.FieldSpec.DataType;
+import org.apache.pinot.spi.data.OpenStructNaming;
+import org.apache.pinot.spi.data.OpenStructTypeInference;
+import org.apache.pinot.spi.utils.JsonUtils;
+import org.apache.pinot.spi.utils.PinotDataType;
+import org.roaringbitmap.RoaringBitmap;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/// Splits an OPEN_STRUCT column into per-key materialized columns using standard Pinot index
+/// creators. Dense keys become independent virtual columns; remaining keys go into a single
+/// synthetic JSON column for sparse storage.
+///
+/// Lifecycle: instantiated by `BaseSegmentCreator` for OPEN_STRUCT columns. Receives
+/// per-doc `Map<String, Object>` values via [#add(Map, int)], accumulates in memory,
+/// then on [#seal()] writes per-key column files using standard creators.
+public class OpenStructColumnSplitter implements ColumnarOpenStructIndexCreator {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(OpenStructColumnSplitter.class);
+
+  private final File _indexDir;
+  private final String _columnName;
+  private final Map<String, FieldSpec> _childFieldSpecs;
+  private final OpenStructIndexConfig _config;
+  private final int _maxDenseKeys;
+
+  // Per-key accumulation
+  private final Map<String, RoaringBitmap> _presenceBitmaps = new HashMap<>();
+  private final Map<String, List<Object>> _values = new HashMap<>();
+  private final Map<String, DataType> _inferredTypes = new HashMap<>();
+  private int _numDocs;
+
+  // Resolved at seal time
+  @Nullable
+  private Set<String> _resolvedDenseKeys;
+  private final Map<String, PropertiesConfiguration> _materializedColumnMetadata = new LinkedHashMap<>();
+
+  public OpenStructColumnSplitter(File indexDir, String columnName, FieldSpec fieldSpec,
+      OpenStructIndexConfig config) {
+    _indexDir = indexDir;
+    _columnName = columnName;
+    _config = config;
+    _maxDenseKeys = config.getMaxDenseKeys();
+
+    Map<String, FieldSpec> childFieldSpecs = null;
+    if (fieldSpec instanceof ComplexFieldSpec) {
+      ComplexFieldSpec complexSpec = (ComplexFieldSpec) fieldSpec;
+      childFieldSpecs = complexSpec.getChildFieldSpecs();
+    }
+    _childFieldSpecs = childFieldSpecs != null ? new HashMap<>(childFieldSpecs) : new HashMap<>();
+  }
+
+  @Override
+  public void add(Object value, int docId)
+      throws IOException {
+    if (value instanceof Map) {
+      @SuppressWarnings("unchecked")
+      Map<String, Object> map = (Map<String, Object>) value;
+      addMap(map);
+    } else {
+      addMap(null);
+    }
+  }
+
+  @Override
+  public void add(Map<String, Object> openStructValue, int docId)
+      throws IOException {
+    addMap(openStructValue);
+  }
+
+  @Override
+  public void add(Object[] values, @Nullable int[] dictIds)
+      throws IOException {
+    throw new UnsupportedOperationException("OPEN_STRUCT index is single-value only");
+  }
+
+  /// Returns the resolved dense-key set after [#seal()] or [#classify()].
+  /// Returns an empty set before resolution.
+  public Set<String> getResolvedDenseKeys() {
+    return _resolvedDenseKeys != null ? Collections.unmodifiableSet(_resolvedDenseKeys) : Set.of();
+  }
+
+  /// Resolves dense vs sparse keys without writing any files. Exposed for testing and for callers
+  /// that need the classification independent of file output. [#seal()] calls this internally.
+  public Set<String> classify() {
+    if (_resolvedDenseKeys != null) {
+      return _resolvedDenseKeys;
+    }
+    if (_numDocs == 0 || _presenceBitmaps.isEmpty()) {
+      _resolvedDenseKeys = new LinkedHashSet<>();
+      return _resolvedDenseKeys;
+    }
+    List<String> allKeys = new ArrayList<>(_presenceBitmaps.keySet());
+    allKeys.sort((a, b) -> {
+      double fillA = (double) _presenceBitmaps.get(a).getCardinality() / _numDocs;
+      double fillB = (double) _presenceBitmaps.get(b).getCardinality() / _numDocs;
+      int cmp = Double.compare(fillB, fillA);
+      return cmp != 0 ? cmp : a.compareTo(b);
+    });
+
+    double minFillRate = _config.getDenseKeyMinFillRate();
+    _resolvedDenseKeys = new LinkedHashSet<>();
+
+    Set<String> configuredDenseKeys = _config.getDenseKeys();
+    for (String key : configuredDenseKeys) {
+      if (_presenceBitmaps.containsKey(key) && (_maxDenseKeys < 0 || _resolvedDenseKeys.size() < _maxDenseKeys)) {
+        _resolvedDenseKeys.add(key);
+      }
+    }
+
+    for (String key : allKeys) {
+      if (_resolvedDenseKeys.contains(key)) {
+        continue;
+      }
+      double fillRate = (double) _presenceBitmaps.get(key).getCardinality() / _numDocs;
+      if ((_maxDenseKeys < 0 || _resolvedDenseKeys.size() < _maxDenseKeys) && fillRate >= minFillRate) {
+        _resolvedDenseKeys.add(key);
+      }
+    }
+    return _resolvedDenseKeys;
+  }
+
+  private void addMap(@Nullable Map<String, Object> map) {
+    if (map != null && !map.isEmpty()) {
+      for (Map.Entry<String, Object> entry : map.entrySet()) {
+        String key = entry.getKey();
+        Object rawValue = entry.getValue();
+        if (rawValue == null) {
+          continue;
+        }
+        FieldSpec keySpec = _childFieldSpecs.get(key);
+        DataType valueType = keySpec != null
+            ? keySpec.getDataType()
+            : _inferredTypes.computeIfAbsent(key, k -> {
+              DataType inferred = OpenStructTypeInference.inferDataType(rawValue);
+              return inferred != null ? inferred : DataType.STRING;
+            });
+        if (!_presenceBitmaps.containsKey(key)) {
+          _presenceBitmaps.put(key, new RoaringBitmap());
+          _values.put(key, new ArrayList<>());
+        }
+        _presenceBitmaps.get(key).add(_numDocs);
+        Object coerced;
+        try {
+          PinotDataType sourceType = PinotDataType.getSingleValueType(rawValue);
+          PinotDataType destType = ColumnDataType.fromDataTypeSV(valueType.getStoredType()).toPinotDataType();
+          coerced = destType.convert(rawValue, sourceType);
+        } catch (Exception e) {
+          LOGGER.warn("OPEN_STRUCT '{}': coercion failed for key '{}' value '{}' to {}. Skipping.",
+              _columnName, key, rawValue, valueType, e);
+          _presenceBitmaps.get(key).remove(_numDocs);
+          continue;
+        }
+        _values.get(key).add(coerced);
+      }
+    }
+    _numDocs++;
+  }
+
+  @Override
+  public void seal()
+      throws IOException {
+    classify();
+    if (_resolvedDenseKeys == null || (_numDocs == 0 && _presenceBitmaps.isEmpty())) {
+      return;
+    }
+
+    for (String key : _resolvedDenseKeys) {
+      writeDenseKeyColumn(key);
+    }
+
+    List<String> sparseKeys = new ArrayList<>();
+    for (String key : _presenceBitmaps.keySet()) {
+      if (!_resolvedDenseKeys.contains(key)) {
+        sparseKeys.add(key);
+      }
+    }
+    if (!sparseKeys.isEmpty()) {
+      writeSparseJsonColumn(sparseKeys);
+    }
+
+    emitParentColumnMetadata(!sparseKeys.isEmpty());
+  }
+
+  @Override
+  public void close()
+      throws IOException {
+    // Nothing to close — sub-creators are created and closed within seal()
+  }
+
+  @Override
+  public Map<String, PropertiesConfiguration> getMaterializedColumnMetadata() {
+    return _materializedColumnMetadata;
+  }
+
+  private void writeDenseKeyColumn(String key)
+      throws IOException {
+    String materializedCol = OpenStructNaming.materializedColumnName(_columnName, key);
+    FieldSpec keySpec = _childFieldSpecs.get(key);
+    DataType valueType = keySpec != null
+        ? keySpec.getDataType()
+        : _inferredTypes.getOrDefault(key, DataType.STRING);
+    DataType storedType = valueType.getStoredType();
+    RoaringBitmap presence = _presenceBitmaps.get(key);
+    List<Object> values = _values.get(key);
+
+    // Synthetic field spec for the materialized child. Its natural Pinot dimension null value is the value
+    // stored for absent docs, so column metadata stays consistent with on-disk content.
+    DimensionFieldSpec childFieldSpec = new DimensionFieldSpec(materializedCol, storedType, true);
+    Object defaultValue = childFieldSpec.getDefaultNullValue();
+
+    // Collect statistics the standard way: present docs contribute their value, absent docs the default
+    // (absent docs are also marked in the null vector below).
+    AbstractColumnStatisticsCollector statsCollector =
+        StatsCollectorUtil.createStatsCollector(childFieldSpec, null);
+    int statsOrdinal = 0;
+    for (int docId = 0; docId < _numDocs; docId++) {
+      statsCollector.collect(presence.contains(docId) ? values.get(statsOrdinal++) : defaultValue);
+    }
+    statsCollector.seal();
+
+    // Build per-key index configuration from the key's FieldConfig (falling back to the default), then apply
+    // the OPEN_STRUCT inverted-on default. No TableConfig/Schema required.
+    FieldConfig keyFieldConfig = _config.getValueFieldConfig(key);
+    if (keyFieldConfig == null) {
+      keyFieldConfig = _config.getDefaultValueFieldConfig();
+    }
+    boolean enableInverted = _config.shouldEnableInvertedIndexForKey(key);
+    FieldIndexConfigs configsForDecision = new FieldIndexConfigs.Builder(
+        FieldIndexConfigsUtil.fromFieldConfig(keyFieldConfig, childFieldSpec))
+        .add(StandardIndexes.inverted(), enableInverted ? IndexConfig.ENABLED : IndexConfig.DISABLED)
+        .build();
+
+    boolean useDictionary = resolveUseDictionary(childFieldSpec, configsForDecision, statsCollector);
+
+    // Reconcile dictionary + forward encoding with the final decision (mirrors BaseSegmentCreator.adaptConfig);
+    // ForwardIndexCreatorFactory selects dict-vs-raw from the forward config's EncodingType. A compression codec
+    // applies only to the raw forward format (LZ4 preserves the dense child's current on-disk layout); attaching
+    // one to a dictionary-encoded forward is rejected by ForwardIndexType.validate.
+    ForwardIndexConfig.Builder forwardBuilder = new ForwardIndexConfig.Builder(
+        useDictionary ? FieldConfig.EncodingType.DICTIONARY : FieldConfig.EncodingType.RAW);
+    if (!useDictionary) {
+      forwardBuilder.withCompressionCodec(FieldConfig.CompressionCodec.LZ4);
+    }
+    FieldIndexConfigs fieldIndexConfigs = new FieldIndexConfigs.Builder(configsForDecision)
+        .add(StandardIndexes.dictionary(),
+            useDictionary ? DictionaryIndexConfig.DEFAULT : DictionaryIndexConfig.DISABLED)
+        .add(StandardIndexes.forward(), forwardBuilder.build())
+        .build();
+
+    int dictElementSize = writeColumnIndexes(materializedCol, storedType, presence, values,
+        defaultValue, statsCollector, useDictionary, fieldIndexConfigs, childFieldSpec);
+
+    NullValueVectorCreator nullCreator = new NullValueVectorCreator(_indexDir, materializedCol);
+    try {
+      for (int docId = 0; docId < _numDocs; docId++) {
+        if (!presence.contains(docId)) {
+          nullCreator.setNull(docId);
+        }
+      }
+      nullCreator.seal();
+    } finally {
+      nullCreator.close();
+    }
+
+    PropertiesConfiguration props = new PropertiesConfiguration();
+    FieldConfig.EncodingType encoding =
+        useDictionary ? FieldConfig.EncodingType.DICTIONARY : FieldConfig.EncodingType.RAW;
+    BaseSegmentCreator.addColumnMetadataInfo(props, materializedCol, statsCollector, _numDocs, childFieldSpec,
+        useDictionary, dictElementSize, encoding, false);
+    // OPEN_STRUCT-specific keys not written by addColumnMetadataInfo.
+    props.setProperty(
+        V1Constants.MetadataKeys.Column.getKeyFor(materializedCol, V1Constants.MetadataKeys.Column.PARENT_COLUMN),
+        _columnName);
+    props.setProperty(V1Constants.MetadataKeys.Column.getKeyFor(materializedCol, "hasNullValue"), true);
+    if (enableInverted && useDictionary) {
+      props.setProperty(V1Constants.MetadataKeys.Column.getKeyFor(materializedCol, "hasInvertedIndex"), true);
+    }
+    _materializedColumnMetadata.put(materializedCol, props);
+  }
+
+  /// Decides dictionary vs raw encoding for a materialized child column, mirroring the three steps of
+  /// `BaseSegmentCreator.createDictionaryForColumn` with standard default flags (optimizeDictionary
+  /// off => dictionary unless explicitly disabled and not required by an enabled index).
+  private boolean resolveUseDictionary(FieldSpec childFieldSpec, FieldIndexConfigs fieldIndexConfigs,
+      AbstractColumnStatisticsCollector statsCollector) {
+    if (DictionaryIndexConfig.requiresDictionary(childFieldSpec, fieldIndexConfigs)) {
+      return true;
+    }
+    if (fieldIndexConfigs.getConfig(StandardIndexes.dictionary()).isDisabled()) {
+      return false;
+    }
+    return DictionaryIndexType.ignoreDictionaryOverride(false, false,
+        IndexingConfig.DEFAULT_NO_DICTIONARY_SIZE_RATIO_THRESHOLD, null, childFieldSpec, fieldIndexConfigs,
+        statsCollector.getCardinality(), statsCollector.getTotalNumberOfEntries());
+  }
+
+  /// Writes the dictionary (when used) plus all vetted, enabled indexes for a materialized child column through
+  /// the standard index-creator family, driven from a single per-doc loop. Returns the dictionary element size in
+  /// bytes (0 when raw-encoded), for column metadata. The dictionary is built separately because its build
+  /// lifecycle is CUSTOM and it supplies the dictIds the per-row creators consume.
+  private int writeColumnIndexes(String materializedCol, DataType storedType, RoaringBitmap presence,
+      List<Object> values, Object defaultValue, AbstractColumnStatisticsCollector statsCollector,
+      boolean useDictionary, FieldIndexConfigs fieldIndexConfigs, FieldSpec childFieldSpec)
+      throws IOException {
+    int dictElementSize = 0;
+    SegmentDictionaryCreator dictCreator = null;
+    try {
+      if (useDictionary) {
+        dictCreator = new SegmentDictionaryCreator(materializedCol, storedType,
+            new File(_indexDir, materializedCol + V1Constants.Dict.FILE_EXTENSION), true);
+        dictCreator.build(statsCollector.getUniqueValuesSet());
+      }
+
+      // Index-creation context built from the sealed collector (a ColumnShape) — no TableConfig required.
+      IndexCreationContext context =
+          new IndexCreationContext.Builder(_indexDir, null, statsCollector, useDictionary, false)
+              .withOnHeap(false).build();
+
+      List<IndexCreator> creators = new ArrayList<>();
+      try {
+        for (IndexType<?, ?, ?> indexType : IndexService.getInstance().getAllIndexes()) {
+          if (indexType.getIndexBuildLifecycle() != IndexType.BuildLifecycle.DURING_SEGMENT_CREATION) {
+            continue;   // excludes dictionary (lifecycle CUSTOM), built separately above
+          }
+          if (!OpenStructSupportedIndexes.ALLOWED_PRETTY_NAMES.contains(indexType.getPrettyName())) {
+            continue;   // non-vetted indexes already rejected at table-config validation; defensive backstop
+          }
+          IndexCreator creator = createColumnIndexCreator(indexType, context, fieldIndexConfigs, materializedCol,
+              childFieldSpec);
+          if (creator != null) {
+            creators.add(creator);
+          }
+        }
+
+        int ordinal = 0;
+        for (int docId = 0; docId < _numDocs; docId++) {
+          Object value = presence.contains(docId) ? values.get(ordinal++) : defaultValue;
+          int dictId = useDictionary ? dictCreator.indexOfSV(value) : -1;
+          for (IndexCreator creator : creators) {
+            creator.add(value, dictId);
+          }
+        }
+        for (IndexCreator creator : creators) {
+          creator.seal();
+        }
+      } finally {
+        for (IndexCreator creator : creators) {
+          creator.close();
+        }
+        if (dictCreator != null) {
+          dictElementSize = dictCreator.getNumBytesPerEntry();
+          dictCreator.seal();
+        }
+      }
+    } finally {
+      if (dictCreator != null) {
+        dictCreator.close();
+      }
+    }
+    return dictElementSize;
+  }
+
+  @Nullable
+  private static <C extends IndexConfig> IndexCreator createColumnIndexCreator(IndexType<C, ?, ?> indexType,
+      IndexCreationContext context, FieldIndexConfigs fieldIndexConfigs, String materializedCol,
+      FieldSpec childFieldSpec)
+      throws IOException {
+    // Materialized child columns exist in no schema/TableConfig, so the standard table-config-time validation
+    // never sees them. Run the index type's own guards here against the resolved child FieldSpec (e.g. range
+    // rejects a non-numeric column without a dictionary) so misconfigurations fail with the canonical message
+    // instead of crashing opaquely inside the creator. validate() internally no-ops when the index is disabled.
+    indexType.validate(fieldIndexConfigs, childFieldSpec, null);
+    C config = fieldIndexConfigs.getConfig(indexType);
+    if (!config.isEnabled() || !indexType.shouldCreateIndex(context, config)) {
+      return null;
+    }
+    try {
+      return indexType.createIndexCreator(context, config);
+    } catch (IOException e) {
+      throw e;
+    } catch (Exception e) {
+      throw new IOException("Failed to create " + indexType.getPrettyName() + " creator for: " + materializedCol, e);
+    }
+  }
+
+  private void writeSparseJsonColumn(List<String> sparseKeys)
+      throws IOException {
+    String sparseCol = OpenStructNaming.sparseColumnName(_columnName);
+    int maxLen = 1;
+    String[] jsonPerDoc = new String[_numDocs];
+    int nonNullCount = 0;
+    for (int docId = 0; docId < _numDocs; docId++) {
+      Map<String, Object> sparseEntries = new LinkedHashMap<>();
+      for (String key : sparseKeys) {
+        RoaringBitmap presence = _presenceBitmaps.get(key);
+        if (presence != null && presence.contains(docId)) {
+          int ordinal = presence.rank(docId) - 1;
+          sparseEntries.put(key, _values.get(key).get(ordinal));
+        }
+      }
+      if (!sparseEntries.isEmpty()) {
+        try {
+          String json = JsonUtils.objectToString(sparseEntries);
+          jsonPerDoc[docId] = json;
+          maxLen = Math.max(maxLen, json.getBytes(StandardCharsets.UTF_8).length);

Review Comment:
   Done. Replaced with `Utf8.encodedLength(json)` — zero alloc, consistent with rest of Pinot code.
   



##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/openstruct/MutableOpenStructIndex.java:
##########
@@ -0,0 +1,263 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.segment.local.segment.index.openstruct;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import javax.annotation.Nullable;
+import org.apache.pinot.common.utils.DataSchema.ColumnDataType;
+import org.apache.pinot.segment.local.segment.index.map.SimpleColumnMetadata;
+import org.apache.pinot.segment.spi.ColumnMetadata;
+import org.apache.pinot.segment.spi.index.IndexReader;
+import org.apache.pinot.segment.spi.index.IndexType;
+import org.apache.pinot.segment.spi.index.StandardIndexes;
+import org.apache.pinot.segment.spi.index.mutable.MutableIndex;
+import org.apache.pinot.segment.spi.index.reader.ForwardIndexReaderContext;
+import org.apache.pinot.segment.spi.index.reader.OpenStructIndexReader;
+import org.apache.pinot.segment.spi.memory.PinotDataBufferMemoryManager;
+import org.apache.pinot.spi.config.table.OpenStructIndexConfig;
+import org.apache.pinot.spi.data.ComplexFieldSpec;
+import org.apache.pinot.spi.data.DimensionFieldSpec;
+import org.apache.pinot.spi.data.FieldSpec;
+import org.apache.pinot.spi.data.FieldSpec.DataType;
+import org.apache.pinot.spi.data.OpenStructTypeInference;
+import org.apache.pinot.spi.utils.PinotDataType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/// Manages per-key mutable columns for an OPEN_STRUCT column during real-time consumption.
+/// Each discovered key gets its own {@link MutableKeyColumn} (dictionary-encoded forward index +
+/// presence bitmap). Dense/sparse classification is deferred to seal time.
+///
+/// Single-writer for [#index]: the consuming thread calls this method. Readers may
+/// concurrently read [#getKeys()] and [#getKeyColumns()] via the volatile map swap.
+@SuppressWarnings("rawtypes")
+public class MutableOpenStructIndex implements OpenStructIndexReader<ForwardIndexReaderContext>, MutableIndex {
+  private static final Logger LOGGER = LoggerFactory.getLogger(MutableOpenStructIndex.class);
+
+  private final String _openStructColumn;
+  private final OpenStructIndexConfig _config;
+  private final Map<String, FieldSpec> _childFieldSpecs;
+  private final PinotDataBufferMemoryManager _memoryManager;
+  private final int _capacity;
+
+  // Volatile for lock-free reader access; writer always holds the consuming-thread lock.
+  private volatile Map<String, MutableKeyColumn> _keyColumns = new HashMap<>();
+
+  public MutableOpenStructIndex(String openStructColumn, ComplexFieldSpec fieldSpec,
+      OpenStructIndexConfig config, PinotDataBufferMemoryManager memoryManager, int capacity) {
+    _openStructColumn = openStructColumn;
+    _config = config;
+    _memoryManager = memoryManager;
+    _capacity = capacity;
+
+    Map<String, FieldSpec> childFieldSpecs = fieldSpec.getChildFieldSpecs();
+    _childFieldSpecs = childFieldSpecs != null ? new HashMap<>(childFieldSpecs) : new HashMap<>();
+  }
+
+  @Override
+  public void add(Object value, int dictId, int docId) {
+    index(docId, value);
+  }
+
+  @Override
+  public void add(Object[] values, @Nullable int[] dictIds, int docId) {
+    throw new UnsupportedOperationException("OPEN_STRUCT does not support multi-value indexing");
+  }
+
+  /// Indexes the OPEN_STRUCT value for the given document. `value` must be a
+  /// `Map<String, Object>` or `null`; null and non-Map values are silently skipped.
+  @SuppressWarnings("unchecked")
+  public void index(int docId, @Nullable Object value) {
+    if (!(value instanceof Map)) {
+      return;
+    }
+    Map<String, Object> map = (Map<String, Object>) value;
+    for (Map.Entry<String, Object> entry : map.entrySet()) {
+      String key = entry.getKey();
+      Object rawValue = entry.getValue();
+      if (rawValue == null) {
+        continue;
+      }
+
+      MutableKeyColumn keyCol = _keyColumns.get(key);
+      if (keyCol == null) {
+        // Mutable mode holds every observed key (see MutableOpenStructDataSource#isFullyMaterialized);
+        // dense/sparse classification (maxDenseKeys / denseKeys) is applied at seal time by the segment
+        // build, so no key is dropped during consumption.
+        // Resolve stored type and coerce BEFORE allocating a column so a first-row coercion failure
+        // does not allocate a column that was never usable.
+        DataType resolvedType = resolveStoredType(key, rawValue);
+        if (resolvedType == null) {
+          continue;
+        }
+        Object coerced = tryCoerce(key, rawValue, resolvedType);
+        if (coerced == null) {
+          continue;
+        }
+        keyCol = allocateKeyColumn(key, resolvedType);
+        keyCol.setValue(docId, coerced);
+        continue;
+      }
+
+      DataType storedType = keyCol.getStoredType();
+      Object coerced = tryCoerce(key, rawValue, storedType);
+      if (coerced == null) {
+        continue;
+      }
+      keyCol.setValue(docId, coerced);
+    }
+  }
+
+  /// Resolves the stored type for a key without allocating any state. Returns null when the type
+  /// cannot be inferred (caller should skip the entry).
+  @Nullable
+  private DataType resolveStoredType(String key, Object rawValue) {
+    FieldSpec spec = _childFieldSpecs.get(key);
+    DataType valueType;
+    if (spec != null) {
+      valueType = spec.getDataType();
+    } else {
+      valueType = OpenStructTypeInference.inferDataType(rawValue);
+      if (valueType == null) {
+        LOGGER.warn("OPEN_STRUCT '{}': could not infer DataType for key '{}' from value of class '{}'."
+                + " Dropping the entry.",
+            _openStructColumn, key, rawValue.getClass().getName());
+        return null;
+      }
+    }
+    return valueType.getStoredType();
+  }
+
+  /// Coerces rawValue to storedType. Returns null on failure (logged at WARN); the caller drops
+  /// the entry. Note: a successful coerce of a "null"-shaped raw value would also return null —
+  /// but callers gate on rawValue != null before reaching here.
+  @Nullable
+  private Object tryCoerce(String key, Object rawValue, DataType storedType) {
+    try {
+      PinotDataType sourceType = PinotDataType.getSingleValueType(rawValue);
+      PinotDataType destType = ColumnDataType.fromDataTypeSV(storedType).toPinotDataType();

Review Comment:
   Done. Cached `PinotDataType` in `MutableKeyColumn._destType` at construction time. `tryCoerce` now uses the cached value instead of recomputing per doc.
   



-- 
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] OPEN_STRUCT storage layer — columnar two-tier dense/sparse index (PR 2b/4) [pinot]

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


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/openstruct/ImmutableOpenStructDataSource.java:
##########
@@ -0,0 +1,268 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.segment.local.segment.index.openstruct;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import javax.annotation.Nullable;
+import org.apache.pinot.segment.local.segment.index.datasource.BaseDataSource;
+import org.apache.pinot.segment.local.segment.index.datasource.ImmutableDataSource;
+import org.apache.pinot.segment.spi.Constants;
+import org.apache.pinot.segment.spi.datasource.DataSource;
+import org.apache.pinot.segment.spi.datasource.DataSourceMetadata;
+import org.apache.pinot.segment.spi.datasource.OpenStructDataSource;
+import org.apache.pinot.segment.spi.index.column.ColumnIndexContainer;
+import org.apache.pinot.segment.spi.index.reader.Dictionary;
+import org.apache.pinot.segment.spi.index.reader.ForwardIndexReader;
+import org.apache.pinot.segment.spi.index.reader.ForwardIndexReaderContext;
+import org.apache.pinot.segment.spi.index.reader.NullValueVectorReader;
+import org.apache.pinot.segment.spi.partition.PartitionFunction;
+import org.apache.pinot.spi.data.ComplexFieldSpec;
+import org.apache.pinot.spi.data.FieldSpec;
+import org.apache.pinot.spi.data.FieldSpec.DataType;
+import org.apache.pinot.spi.utils.JsonUtils;
+
+
+
+/// Per-key {@link DataSource} accessor for sealed (immutable) segments with an OPEN_STRUCT column.
+///
+/// Always columnar — there is no blob branch. Every key that was dense enough during segment
+/// creation gets its own materialized {@link DataSource} (forward index + optional inverted index /
+/// dictionary). Keys that did not meet the density threshold are stored in an optional sparse
+/// column; the sparse {@link DataSource} is returned for any unmaterialized key lookup.
+///
+/// Use [#isMaterialized(String)] and [#isFullyMaterialized()] together to choose
+/// the query execution path:
+/// - Materialized key → fast path via per-key DataSource (inverted/dictionary index available).
+/// - Not materialized + not fully materialized → fall back to the sparse DataSource.
+/// - Not materialized + fully materialized → key is definitively absent; short-circuit.
+///
+/// Thread-safety: immutable after construction; safe for concurrent reads.
+public class ImmutableOpenStructDataSource extends BaseDataSource implements OpenStructDataSource {
+  private final ComplexFieldSpec _fieldSpec;
+  private final Map<String, DataSource> _perKeyDataSources;
+  @Nullable
+  private final DataSource _sparseDataSource;
+
+  public ImmutableOpenStructDataSource(ComplexFieldSpec fieldSpec, Map<String, DataSource> perKeyDataSources,
+      @Nullable DataSource sparseDataSource, DataSourceMetadata dataSourceMetadata,
+      ColumnIndexContainer indexContainer) {
+    super(dataSourceMetadata, indexContainer);
+    _fieldSpec = fieldSpec;
+    _perKeyDataSources = perKeyDataSources;
+    _sparseDataSource = sparseDataSource;
+  }
+
+  /// Convenience constructor for segment-load time. Synthesizes a minimal {@link DataSourceMetadata}
+  /// for the parent OPEN_STRUCT column (which has no on-disk presence of its own) and uses an empty
+  /// {@link ColumnIndexContainer} — all real readers live on the per-key data sources.
+  public ImmutableOpenStructDataSource(ComplexFieldSpec fieldSpec, Map<String, DataSource> perKeyDataSources,
+      @Nullable DataSource sparseDataSource, int numDocs) {
+    this(fieldSpec, perKeyDataSources, sparseDataSource,
+        new ImmutableOpenStructDataSourceMetadata(fieldSpec, numDocs),
+        new ColumnIndexContainer.FromMap.Builder().build());
+  }
+
+  @Override
+  public ComplexFieldSpec getFieldSpec() {
+    return _fieldSpec;
+  }
+
+  @Override
+  @Nullable
+  public DataSource getDataSource(String key) {
+    DataSource ds = _perKeyDataSources.get(key);
+    return ds != null ? ds : _sparseDataSource;
+  }
+
+  @Override
+  public boolean isMaterialized(String key) {
+    return _perKeyDataSources.containsKey(key);
+  }
+
+  @Override
+  public boolean isFullyMaterialized() {
+    return _sparseDataSource == null;
+  }
+
+  /// Returns only the materialized (dense) key DataSources. Sparse keys are not included because
+  /// they share a single JSON column and have no individual DataSource. Use {@link #getMapValue}
+  /// to read the full key set (dense + sparse) for a given document.
+  @Override
+  public Map<String, DataSource> getDataSources() {
+    return _perKeyDataSources;
+  }
+
+  @Override
+  @Nullable
+  public DataSourceMetadata getDataSourceMetadata(String key) {
+    DataSource ds = _perKeyDataSources.get(key);
+    return ds != null ? ds.getDataSourceMetadata() : null;
+  }
+

Review Comment:
   This path is only exercised during:
   1. Realtime segment seal (mutable → immutable conversion) — `MutableOpenStructIndex.getMapValue()` reads from in-memory `MutableKeyColumn.getValue(docId)`, which is a direct array lookup, no `ForwardIndexReader.createContext()` involved.
   2. `PinotSegmentRecordReader` during merge-rollup/refresh/compaction (minion tasks) — batch, not latency-sensitive.
    
   The immutable `ImmutableOpenStructDataSource` doesn't implement `getMapValue` at all — it inherits the default `throw UnsupportedOperationException`. So the O(docs × keys) context allocation concern doesn't apply to the current code.
    
   If/when we add immutable `getMapValue` (e.g. for segment-to-segment reprocessing), pre-creating contexts per-key would be the right approach.
    



-- 
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] OPEN_STRUCT storage layer — columnar two-tier dense/sparse index (PR 2b/4) [pinot]

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


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/indexsegment/mutable/MutableSegmentImpl.java:
##########
@@ -1708,6 +1749,11 @@ private class IndexContainer implements Closeable {
     }
 
     DataSource toDataSource() {
+      if (_fieldSpec.getDataType() == DataType.OPEN_STRUCT) {

Review Comment:
   Good catch. Added a `Preconditions.checkState` guard — OPEN_STRUCT without its index is unusable (no forward index, no child columns), so it now fails fast with a clear message instead of NPE-ing at query time.
   



-- 
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] OPEN_STRUCT storage layer — columnar two-tier dense/sparse index (PR 2b/4) [pinot]

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


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/loader/IndexLoadingConfig.java:
##########
@@ -408,6 +414,47 @@ private <K, V> Map<K, V> unmodifiable(Map<K, V> map) {
     return map == null ? null : Collections.unmodifiableMap(map);
   }
 
+  // NOTE: entries added here are written directly into _indexConfigsByColName. Any later call that
+  // sets _dirty = true (e.g. setSegmentTier, addKnownColumns) will trigger refreshIndexConfigs()
+  // and rebuild the map from scratch, wiping these entries. Callers must ensure no dirty-flag
+  // mutations happen between this call and the point where the configs are consumed.
+  public void addOpenStructChildConfigs(SegmentMetadataImpl segmentMetadata) {
+    if (_indexConfigsByColName == null || _dirty) {
+      refreshIndexConfigs();
+    }
+    for (Map.Entry<String, ColumnMetadata> entry : segmentMetadata.getColumnMetadataMap().entrySet()) {
+      String childColumn = entry.getKey();
+      if (!childColumn.contains(OpenStructNaming.SEPARATOR) || _indexConfigsByColName.containsKey(childColumn)) {
+        continue;
+      }
+      if (OpenStructNaming.isSparseColumn(childColumn)) {
+        continue;
+      }
+      String parentColumn = OpenStructNaming.parseParentColumn(childColumn);
+      FieldIndexConfigs parentConfigs = _indexConfigsByColName.get(parentColumn);
+      if (parentConfigs == null) {
+        continue;

Review Comment:
   `addOpenStructChildConfigs` writes entries into `_indexConfigsByColName` that a later `_dirty = true` (`setSegmentTier`, `addKnownColumns`) would rebuild away — the comment flags this but doesn't prevent it. Could these child configs live in a separate field that `refreshIndexConfigs()` re-merges, so correctness doesn't depend on caller ordering?



##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/indexsegment/mutable/MutableSegmentImpl.java:
##########
@@ -1310,6 +1334,20 @@ public void commit() {
     }
   }
 
+  /**
+   * Returns the per-column mutable OPEN_STRUCT index, or {@code null} if the column is not OPEN_STRUCT
+   * or the index has not been initialized.
+   */
+  @Nullable
+  public MutableOpenStructIndex getOpenStructIndex(String column) {
+    IndexContainer container = _indexContainerMap.get(column);
+    if (container == null) {
+      return null;

Review Comment:
   This new public method returns the concrete `MutableOpenStructIndex` rather than the `OpenStructIndexReader` SPI. Is the concrete type needed by callers, or could it return the interface to keep the impl encapsulated?



##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/creator/impl/SegmentColumnarIndexCreator.java:
##########
@@ -135,6 +147,34 @@ public void indexColumn(String columnName, @Nullable int[] sortedDocIds, IndexSe
     }

Review Comment:
   OPEN_STRUCT special-casing via `instanceof OpenStructDataSource` now lives in 4 separate pipeline classes (here, `PinotSegmentRecordReader`, `RealtimeSegmentStatsContainer`, `ImmutableSegmentImpl`). It mirrors the existing MAP handling so it's consistent, but is there appetite to push this behind a polymorphic hook on the DataSource/IndexType so future composite types don't each add another `instanceof` fork?



##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/openstruct/ImmutableOpenStructDataSource.java:
##########
@@ -0,0 +1,265 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.segment.local.segment.index.openstruct;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import javax.annotation.Nullable;
+import org.apache.pinot.segment.local.segment.index.datasource.BaseDataSource;
+import org.apache.pinot.segment.local.segment.index.datasource.ImmutableDataSource;
+import org.apache.pinot.segment.spi.Constants;
+import org.apache.pinot.segment.spi.datasource.DataSource;
+import org.apache.pinot.segment.spi.datasource.DataSourceMetadata;
+import org.apache.pinot.segment.spi.datasource.OpenStructDataSource;
+import org.apache.pinot.segment.spi.index.column.ColumnIndexContainer;
+import org.apache.pinot.segment.spi.index.reader.Dictionary;
+import org.apache.pinot.segment.spi.index.reader.ForwardIndexReader;
+import org.apache.pinot.segment.spi.index.reader.ForwardIndexReaderContext;
+import org.apache.pinot.segment.spi.index.reader.NullValueVectorReader;
+import org.apache.pinot.segment.spi.partition.PartitionFunction;
+import org.apache.pinot.spi.data.ComplexFieldSpec;
+import org.apache.pinot.spi.data.FieldSpec;
+import org.apache.pinot.spi.data.FieldSpec.DataType;
+import org.apache.pinot.spi.utils.JsonUtils;
+
+
+
+/// Per-key {@link DataSource} accessor for sealed (immutable) segments with an OPEN_STRUCT column.
+///
+/// Always columnar — there is no blob branch. Every key that was dense enough during segment
+/// creation gets its own materialized {@link DataSource} (forward index + optional inverted index /
+/// dictionary). Keys that did not meet the density threshold are stored in an optional sparse
+/// column; the sparse {@link DataSource} is returned for any unmaterialized key lookup.
+///
+/// Use [#isMaterialized(String)] and [#isFullyMaterialized()] together to choose
+/// the query execution path:
+/// - Materialized key → fast path via per-key DataSource (inverted/dictionary index available).
+/// - Not materialized + not fully materialized → fall back to the sparse DataSource.
+/// - Not materialized + fully materialized → key is definitively absent; short-circuit.
+///
+/// Thread-safety: immutable after construction; safe for concurrent reads.
+public class ImmutableOpenStructDataSource extends BaseDataSource implements OpenStructDataSource {
+  private final ComplexFieldSpec _fieldSpec;
+  private final Map<String, DataSource> _perKeyDataSources;
+  @Nullable
+  private final DataSource _sparseDataSource;
+
+  public ImmutableOpenStructDataSource(ComplexFieldSpec fieldSpec, Map<String, DataSource> perKeyDataSources,
+      @Nullable DataSource sparseDataSource, DataSourceMetadata dataSourceMetadata,
+      ColumnIndexContainer indexContainer) {
+    super(dataSourceMetadata, indexContainer);
+    _fieldSpec = fieldSpec;
+    _perKeyDataSources = perKeyDataSources;
+    _sparseDataSource = sparseDataSource;
+  }
+
+  /// Convenience constructor for segment-load time. Synthesizes a minimal {@link DataSourceMetadata}
+  /// for the parent OPEN_STRUCT column (which has no on-disk presence of its own) and uses an empty
+  /// {@link ColumnIndexContainer} — all real readers live on the per-key data sources.
+  public ImmutableOpenStructDataSource(ComplexFieldSpec fieldSpec, Map<String, DataSource> perKeyDataSources,
+      @Nullable DataSource sparseDataSource, int numDocs) {
+    this(fieldSpec, perKeyDataSources, sparseDataSource,
+        new ImmutableOpenStructDataSourceMetadata(fieldSpec, numDocs),
+        new ColumnIndexContainer.FromMap.Builder().build());
+  }
+
+  @Override
+  public ComplexFieldSpec getFieldSpec() {
+    return _fieldSpec;
+  }
+
+  @Override
+  @Nullable
+  public DataSource getDataSource(String key) {
+    DataSource ds = _perKeyDataSources.get(key);
+    return ds != null ? ds : _sparseDataSource;
+  }
+
+  @Override
+  public boolean isMaterialized(String key) {
+    return _perKeyDataSources.containsKey(key);
+  }
+
+  @Override
+  public boolean isFullyMaterialized() {
+    return _sparseDataSource == null;
+  }
+
+  @Override
+  public Map<String, DataSource> getDataSources() {
+    return _perKeyDataSources;
+  }
+
+  @Override
+  @Nullable
+  public DataSourceMetadata getDataSourceMetadata(String key) {
+    DataSource ds = _perKeyDataSources.get(key);
+    return ds != null ? ds.getDataSourceMetadata() : null;
+  }
+
+  @Override
+  @Nullable
+  public ColumnIndexContainer getIndexContainer(String key) {
+    DataSource ds = _perKeyDataSources.get(key);
+    return ds instanceof ImmutableDataSource immutableDs ? immutableDs.getIndexContainer() : null;
+  }
+
+  @SuppressWarnings({"rawtypes", "unchecked"})
+  @Override
+  @Nullable
+  public Map<String, Object> getMapValue(int docId) {
+    Map<String, Object> result = null;
+
+    for (Map.Entry<String, DataSource> entry : _perKeyDataSources.entrySet()) {
+      Object value = readValue(entry.getValue(), docId);
+      if (value != null) {
+        if (result == null) {
+          result = new HashMap<>();
+        }
+        result.put(entry.getKey(), value);
+      }
+    }
+
+    if (_sparseDataSource != null) {
+      Object sparseValue = readValue(_sparseDataSource, docId);
+      if (sparseValue instanceof String) {
+        String json = (String) sparseValue;
+        if (!json.isEmpty()) {
+          try {
+            Map<String, Object> sparseMap = JsonUtils.stringToObject(json, Map.class);

Review Comment:
   Sparse keys are parsed via `JsonUtils.stringToObject(json, Map.class)`, yielding generic JSON types. When `PinotSegmentRecordReader` rebuilds this map and feeds it into a new segment build (minion merge/rollup), sparse values come back as inferred JSON types rather than their original declared types — so a key could re-infer differently (e.g. LONG→INT) across rebuilds. Is round-trip type stability a concern here, or are sparse keys untyped by design?



##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/openstruct/ImmutableOpenStructDataSource.java:
##########
@@ -0,0 +1,265 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.segment.local.segment.index.openstruct;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import javax.annotation.Nullable;
+import org.apache.pinot.segment.local.segment.index.datasource.BaseDataSource;
+import org.apache.pinot.segment.local.segment.index.datasource.ImmutableDataSource;
+import org.apache.pinot.segment.spi.Constants;
+import org.apache.pinot.segment.spi.datasource.DataSource;
+import org.apache.pinot.segment.spi.datasource.DataSourceMetadata;
+import org.apache.pinot.segment.spi.datasource.OpenStructDataSource;
+import org.apache.pinot.segment.spi.index.column.ColumnIndexContainer;
+import org.apache.pinot.segment.spi.index.reader.Dictionary;
+import org.apache.pinot.segment.spi.index.reader.ForwardIndexReader;
+import org.apache.pinot.segment.spi.index.reader.ForwardIndexReaderContext;
+import org.apache.pinot.segment.spi.index.reader.NullValueVectorReader;
+import org.apache.pinot.segment.spi.partition.PartitionFunction;
+import org.apache.pinot.spi.data.ComplexFieldSpec;
+import org.apache.pinot.spi.data.FieldSpec;
+import org.apache.pinot.spi.data.FieldSpec.DataType;
+import org.apache.pinot.spi.utils.JsonUtils;
+
+
+
+/// Per-key {@link DataSource} accessor for sealed (immutable) segments with an OPEN_STRUCT column.
+///
+/// Always columnar — there is no blob branch. Every key that was dense enough during segment
+/// creation gets its own materialized {@link DataSource} (forward index + optional inverted index /
+/// dictionary). Keys that did not meet the density threshold are stored in an optional sparse
+/// column; the sparse {@link DataSource} is returned for any unmaterialized key lookup.
+///
+/// Use [#isMaterialized(String)] and [#isFullyMaterialized()] together to choose
+/// the query execution path:
+/// - Materialized key → fast path via per-key DataSource (inverted/dictionary index available).
+/// - Not materialized + not fully materialized → fall back to the sparse DataSource.
+/// - Not materialized + fully materialized → key is definitively absent; short-circuit.
+///
+/// Thread-safety: immutable after construction; safe for concurrent reads.
+public class ImmutableOpenStructDataSource extends BaseDataSource implements OpenStructDataSource {
+  private final ComplexFieldSpec _fieldSpec;
+  private final Map<String, DataSource> _perKeyDataSources;
+  @Nullable
+  private final DataSource _sparseDataSource;
+
+  public ImmutableOpenStructDataSource(ComplexFieldSpec fieldSpec, Map<String, DataSource> perKeyDataSources,
+      @Nullable DataSource sparseDataSource, DataSourceMetadata dataSourceMetadata,
+      ColumnIndexContainer indexContainer) {
+    super(dataSourceMetadata, indexContainer);
+    _fieldSpec = fieldSpec;
+    _perKeyDataSources = perKeyDataSources;
+    _sparseDataSource = sparseDataSource;
+  }
+
+  /// Convenience constructor for segment-load time. Synthesizes a minimal {@link DataSourceMetadata}
+  /// for the parent OPEN_STRUCT column (which has no on-disk presence of its own) and uses an empty
+  /// {@link ColumnIndexContainer} — all real readers live on the per-key data sources.
+  public ImmutableOpenStructDataSource(ComplexFieldSpec fieldSpec, Map<String, DataSource> perKeyDataSources,
+      @Nullable DataSource sparseDataSource, int numDocs) {
+    this(fieldSpec, perKeyDataSources, sparseDataSource,
+        new ImmutableOpenStructDataSourceMetadata(fieldSpec, numDocs),
+        new ColumnIndexContainer.FromMap.Builder().build());
+  }
+

Review Comment:
   This extends `BaseDataSource` but backs the parent with an empty `ColumnIndexContainer`, so `getForwardIndex()`/`getDictionary()` return null on the parent — which `BaseDataSource` consumers generally assume is non-null. Is `BaseDataSource` the right base here vs. a thinner `DataSource` impl, given the parent has no physical column of its own? Any column-wide sweep calling `getForwardIndex()` could NPE on the parent.



##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/indexsegment/mutable/MutableSegmentImpl.java:
##########
@@ -1708,6 +1749,11 @@ private class IndexContainer implements Closeable {
     }
 
     DataSource toDataSource() {
+      if (_fieldSpec.getDataType() == DataType.OPEN_STRUCT) {

Review Comment:
   `toDataSource()` routes any OPEN_STRUCT column to `MutableOpenStructDataSource` with `(MutableOpenStructIndex) idx`, but the index is only created when the config is present + enabled. If OPEN_STRUCT is declared with the index disabled, `idx` is null → NPE on query/seal. Guard for null, or enforce "OPEN_STRUCT requires the index enabled"?



##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/creator/impl/BaseSegmentCreator.java:
##########
@@ -552,6 +553,31 @@ protected void writeMetadata()
           hasDictionary, dictionaryElementSize, fwdConfig.getEncodingType(), false);
     }
 
+    // OPEN_STRUCT splitters produce per-key materialized child columns (col$key, col$__sparse__) that
+    // are not in _columnStatisticsMap. Merge their pre-built metadata into the segment properties so
+    // each child appears as its own column at load time, and register them as dimensions so the V3
+    // converter and SegmentMetadataImpl discover their index files.
+    List<String> openStructChildColumns = new ArrayList<>();
+    for (ColumnIndexCreators columnIndexCreators : _colIndexes.values()) {
+      for (IndexCreator indexCreator : columnIndexCreators.getIndexCreators()) {
+        if (indexCreator instanceof ColumnarOpenStructIndexCreator) {
+          ColumnarOpenStructIndexCreator splitter = (ColumnarOpenStructIndexCreator) indexCreator;
+          for (Map.Entry<String, PropertiesConfiguration> childEntry
+              : splitter.getMaterializedColumnMetadata().entrySet()) {
+            String childCol = childEntry.getKey();
+            PropertiesConfiguration childProps = childEntry.getValue();
+            childProps.getKeys().forEachRemaining(key -> properties.setProperty(key, childProps.getProperty(key)));
+            openStructChildColumns.add(childCol);
+          }
+        }
+      }
+    }
+    if (!openStructChildColumns.isEmpty()) {
+      List<String> dimensions = new ArrayList<>(_config.getDimensions());
+      dimensions.addAll(openStructChildColumns);
+      properties.setProperty(DIMENSIONS, dimensions);

Review Comment:
   The splitter's synthetic children (`col$key`, `col$__sparse__`) are appended to the segment `DIMENSIONS` property. Any consumer that reads the segment dimension list and reconciles it against the table schema will now see columns that don't exist in the schema — could this confuse metadata/validation paths? Is `DIMENSIONS` the right place vs. a dedicated child-column marker in metadata?



##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/openstruct/ImmutableOpenStructDataSource.java:
##########
@@ -0,0 +1,265 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.segment.local.segment.index.openstruct;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import javax.annotation.Nullable;
+import org.apache.pinot.segment.local.segment.index.datasource.BaseDataSource;
+import org.apache.pinot.segment.local.segment.index.datasource.ImmutableDataSource;
+import org.apache.pinot.segment.spi.Constants;
+import org.apache.pinot.segment.spi.datasource.DataSource;
+import org.apache.pinot.segment.spi.datasource.DataSourceMetadata;
+import org.apache.pinot.segment.spi.datasource.OpenStructDataSource;
+import org.apache.pinot.segment.spi.index.column.ColumnIndexContainer;
+import org.apache.pinot.segment.spi.index.reader.Dictionary;
+import org.apache.pinot.segment.spi.index.reader.ForwardIndexReader;
+import org.apache.pinot.segment.spi.index.reader.ForwardIndexReaderContext;
+import org.apache.pinot.segment.spi.index.reader.NullValueVectorReader;
+import org.apache.pinot.segment.spi.partition.PartitionFunction;
+import org.apache.pinot.spi.data.ComplexFieldSpec;
+import org.apache.pinot.spi.data.FieldSpec;
+import org.apache.pinot.spi.data.FieldSpec.DataType;
+import org.apache.pinot.spi.utils.JsonUtils;
+
+
+
+/// Per-key {@link DataSource} accessor for sealed (immutable) segments with an OPEN_STRUCT column.
+///
+/// Always columnar — there is no blob branch. Every key that was dense enough during segment
+/// creation gets its own materialized {@link DataSource} (forward index + optional inverted index /
+/// dictionary). Keys that did not meet the density threshold are stored in an optional sparse
+/// column; the sparse {@link DataSource} is returned for any unmaterialized key lookup.
+///
+/// Use [#isMaterialized(String)] and [#isFullyMaterialized()] together to choose
+/// the query execution path:
+/// - Materialized key → fast path via per-key DataSource (inverted/dictionary index available).
+/// - Not materialized + not fully materialized → fall back to the sparse DataSource.
+/// - Not materialized + fully materialized → key is definitively absent; short-circuit.
+///
+/// Thread-safety: immutable after construction; safe for concurrent reads.
+public class ImmutableOpenStructDataSource extends BaseDataSource implements OpenStructDataSource {
+  private final ComplexFieldSpec _fieldSpec;
+  private final Map<String, DataSource> _perKeyDataSources;
+  @Nullable
+  private final DataSource _sparseDataSource;
+
+  public ImmutableOpenStructDataSource(ComplexFieldSpec fieldSpec, Map<String, DataSource> perKeyDataSources,
+      @Nullable DataSource sparseDataSource, DataSourceMetadata dataSourceMetadata,
+      ColumnIndexContainer indexContainer) {
+    super(dataSourceMetadata, indexContainer);
+    _fieldSpec = fieldSpec;
+    _perKeyDataSources = perKeyDataSources;
+    _sparseDataSource = sparseDataSource;
+  }
+
+  /// Convenience constructor for segment-load time. Synthesizes a minimal {@link DataSourceMetadata}
+  /// for the parent OPEN_STRUCT column (which has no on-disk presence of its own) and uses an empty
+  /// {@link ColumnIndexContainer} — all real readers live on the per-key data sources.
+  public ImmutableOpenStructDataSource(ComplexFieldSpec fieldSpec, Map<String, DataSource> perKeyDataSources,
+      @Nullable DataSource sparseDataSource, int numDocs) {
+    this(fieldSpec, perKeyDataSources, sparseDataSource,
+        new ImmutableOpenStructDataSourceMetadata(fieldSpec, numDocs),
+        new ColumnIndexContainer.FromMap.Builder().build());
+  }
+
+  @Override
+  public ComplexFieldSpec getFieldSpec() {
+    return _fieldSpec;
+  }
+
+  @Override
+  @Nullable
+  public DataSource getDataSource(String key) {
+    DataSource ds = _perKeyDataSources.get(key);
+    return ds != null ? ds : _sparseDataSource;
+  }
+
+  @Override
+  public boolean isMaterialized(String key) {
+    return _perKeyDataSources.containsKey(key);
+  }
+
+  @Override
+  public boolean isFullyMaterialized() {
+    return _sparseDataSource == null;
+  }
+
+  @Override
+  public Map<String, DataSource> getDataSources() {
+    return _perKeyDataSources;
+  }
+
+  @Override
+  @Nullable
+  public DataSourceMetadata getDataSourceMetadata(String key) {

Review Comment:
   `getDataSources()` returns only `_perKeyDataSources` (dense), so sparse-backed keys are invisible to callers iterating this map, while `getDataSource(key)` *does* fall back to sparse. Is that asymmetry intended? If so, worth documenting the contract as "materialized keys only" so callers don't treat it as the full key set.



-- 
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] OPEN_STRUCT storage layer — columnar two-tier dense/sparse index (PR 2b/4) [pinot]

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


-- 
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] [WIP] OPEN_STRUCT storage layer — columnar two-tier dense/sparse index (PR 2/4) [pinot]

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


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/openstruct/ImmutableOpenStructDataSource.java:
##########
@@ -0,0 +1,184 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.segment.local.segment.index.openstruct;
+
+import java.util.Map;
+import javax.annotation.Nullable;
+import org.apache.pinot.segment.local.segment.index.datasource.BaseDataSource;
+import org.apache.pinot.segment.local.segment.index.datasource.ImmutableDataSource;
+import org.apache.pinot.segment.spi.Constants;
+import org.apache.pinot.segment.spi.datasource.DataSource;
+import org.apache.pinot.segment.spi.datasource.DataSourceMetadata;
+import org.apache.pinot.segment.spi.datasource.OpenStructDataSource;
+import org.apache.pinot.segment.spi.index.column.ColumnIndexContainer;
+import org.apache.pinot.segment.spi.partition.PartitionFunction;
+import org.apache.pinot.spi.data.ComplexFieldSpec;
+import org.apache.pinot.spi.data.FieldSpec;
+
+
+/**
+ * Per-key {@link DataSource} accessor for sealed (immutable) segments with an OPEN_STRUCT column.
+ *
+ * <p>Always columnar — there is no blob branch. Every key that was dense enough during segment
+ * creation gets its own materialized {@link DataSource} (forward index + optional inverted index /
+ * dictionary). Keys that did not meet the density threshold are stored in an optional sparse
+ * column; the sparse {@link DataSource} is returned for any unmaterialized key lookup.

Review Comment:
   use md style java doc for all files.



-- 
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] [WIP] OPEN_STRUCT storage layer — columnar two-tier dense/sparse index (PR 2/4) [pinot]

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


##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/custom/OpenStructIngestionCommitTestBase.java:
##########
@@ -0,0 +1,287 @@
+/**
+ * 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.integration.tests.custom;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import java.io.File;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import org.apache.avro.file.DataFileWriter;
+import org.apache.avro.generic.GenericData;
+import org.apache.commons.configuration2.PropertiesConfiguration;
+import org.apache.pinot.segment.local.segment.store.SegmentLocalFSDirectory;
+import org.apache.pinot.segment.spi.ColumnMetadata;
+import org.apache.pinot.segment.spi.V1Constants;
+import org.apache.pinot.segment.spi.index.StandardIndexes;
+import org.apache.pinot.segment.spi.index.metadata.SegmentMetadataImpl;
+import org.apache.pinot.segment.spi.store.SegmentDirectory;
+import org.apache.pinot.segment.spi.store.SegmentDirectoryPaths;
+import org.apache.pinot.spi.config.table.FieldConfig;
+import org.apache.pinot.spi.config.table.OpenStructIndexConfig;
+import org.apache.pinot.spi.config.table.TableConfig;
+import org.apache.pinot.spi.config.table.TableType;
+import org.apache.pinot.spi.data.ComplexFieldSpec;
+import org.apache.pinot.spi.data.DimensionFieldSpec;
+import org.apache.pinot.spi.data.FieldSpec;
+import org.apache.pinot.spi.data.OpenStructNaming;
+import org.apache.pinot.spi.data.Schema;
+import org.apache.pinot.spi.env.CommonsConfigurationUtils;
+import org.apache.pinot.spi.utils.JsonUtils;
+import org.apache.pinot.spi.utils.ReadMode;
+import org.apache.pinot.spi.utils.builder.TableConfigBuilder;
+import org.apache.pinot.spi.utils.builder.TableNameBuilder;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
+
+
+/// Shared base for the OPEN_STRUCT end-to-end ingestion + commit tests.
+///
+/// Builds a table with one OPEN_STRUCT column `metrics` carrying a per-key index matrix
+/// (inverted; dictionary-only; raw) plus two sparse keys, ingests ~1000 rows, and validates the
+/// committed segment's materialized child columns, their `index_map`, and the dense/sparse split.
+///
+/// This class is abstract and is not run on its own; the concrete table-type variant (currently
+/// {@link OpenStructIngestionCommitRealtimeTest}) supplies the table name and commit trigger and
+/// reuses the inherited validation. An OFFLINE variant is added in a follow-up change once the
+/// offline OPEN_STRUCT build path is fixed.
+public abstract class OpenStructIngestionCommitTestBase extends CustomDataQueryClusterIntegrationTest {

Review Comment:
   remove this test before merging. Will add final tests after the query side changes are complete. 



-- 
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] OPEN_STRUCT storage layer — columnar two-tier dense/sparse index (PR 2b/4) [pinot]

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


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/loader/IndexLoadingConfig.java:
##########
@@ -408,6 +414,47 @@ private <K, V> Map<K, V> unmodifiable(Map<K, V> map) {
     return map == null ? null : Collections.unmodifiableMap(map);
   }
 
+  // NOTE: entries added here are written directly into _indexConfigsByColName. Any later call that
+  // sets _dirty = true (e.g. setSegmentTier, addKnownColumns) will trigger refreshIndexConfigs()
+  // and rebuild the map from scratch, wiping these entries. Callers must ensure no dirty-flag
+  // mutations happen between this call and the point where the configs are consumed.
+  public void addOpenStructChildConfigs(SegmentMetadataImpl segmentMetadata) {
+    if (_indexConfigsByColName == null || _dirty) {
+      refreshIndexConfigs();
+    }
+    for (Map.Entry<String, ColumnMetadata> entry : segmentMetadata.getColumnMetadataMap().entrySet()) {
+      String childColumn = entry.getKey();
+      if (!childColumn.contains(OpenStructNaming.SEPARATOR) || _indexConfigsByColName.containsKey(childColumn)) {
+        continue;
+      }
+      if (OpenStructNaming.isSparseColumn(childColumn)) {
+        continue;
+      }
+      String parentColumn = OpenStructNaming.parseParentColumn(childColumn);
+      FieldIndexConfigs parentConfigs = _indexConfigsByColName.get(parentColumn);
+      if (parentConfigs == null) {
+        continue;

Review Comment:
   Good catch — Anurag flagged the same concern. The implicit ordering dependency is fragile.
    
   Fixed: `addOpenStructChildConfigs` now stores the `SegmentMetadataImpl` reference, and `refreshIndexConfigs()` re-derives the child configs after every dirty rebuild. The entries are always computed from first principles (segment metadata + parent's `OpenStructIndexConfig`), so they survive any `setSegmentTier()` or `addKnownColumns()` call regardless of ordering.
   



-- 
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] OPEN_STRUCT storage layer — columnar two-tier dense/sparse index (PR 2b/4) [pinot]

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


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/indexsegment/mutable/MutableSegmentImpl.java:
##########
@@ -1310,6 +1334,20 @@ public void commit() {
     }
   }
 
+  /**
+   * Returns the per-column mutable OPEN_STRUCT index, or {@code null} if the column is not OPEN_STRUCT
+   * or the index has not been initialized.
+   */
+  @Nullable
+  public MutableOpenStructIndex getOpenStructIndex(String column) {
+    IndexContainer container = _indexContainerMap.get(column);
+    if (container == null) {
+      return null;

Review Comment:
   Actually this is not even being used anywhere and I had kept it from earlier impl. I have removed this for now and can add it back in future if I need this.



-- 
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] OPEN_STRUCT storage layer — columnar two-tier dense/sparse index (PR 2b/4) [pinot]

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

   Opened and merged docs update: pinot-contrib/pinot-docs#931
   
   Docs PR: https://github.com/pinot-contrib/pinot-docs/pull/931


-- 
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] OPEN_STRUCT storage layer — columnar two-tier dense/sparse index (PR 2b/4) [pinot]

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


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/openstruct/ImmutableOpenStructDataSource.java:
##########
@@ -0,0 +1,265 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.segment.local.segment.index.openstruct;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import javax.annotation.Nullable;
+import org.apache.pinot.segment.local.segment.index.datasource.BaseDataSource;
+import org.apache.pinot.segment.local.segment.index.datasource.ImmutableDataSource;
+import org.apache.pinot.segment.spi.Constants;
+import org.apache.pinot.segment.spi.datasource.DataSource;
+import org.apache.pinot.segment.spi.datasource.DataSourceMetadata;
+import org.apache.pinot.segment.spi.datasource.OpenStructDataSource;
+import org.apache.pinot.segment.spi.index.column.ColumnIndexContainer;
+import org.apache.pinot.segment.spi.index.reader.Dictionary;
+import org.apache.pinot.segment.spi.index.reader.ForwardIndexReader;
+import org.apache.pinot.segment.spi.index.reader.ForwardIndexReaderContext;
+import org.apache.pinot.segment.spi.index.reader.NullValueVectorReader;
+import org.apache.pinot.segment.spi.partition.PartitionFunction;
+import org.apache.pinot.spi.data.ComplexFieldSpec;
+import org.apache.pinot.spi.data.FieldSpec;
+import org.apache.pinot.spi.data.FieldSpec.DataType;
+import org.apache.pinot.spi.utils.JsonUtils;
+
+
+
+/// Per-key {@link DataSource} accessor for sealed (immutable) segments with an OPEN_STRUCT column.
+///
+/// Always columnar — there is no blob branch. Every key that was dense enough during segment
+/// creation gets its own materialized {@link DataSource} (forward index + optional inverted index /
+/// dictionary). Keys that did not meet the density threshold are stored in an optional sparse
+/// column; the sparse {@link DataSource} is returned for any unmaterialized key lookup.
+///
+/// Use [#isMaterialized(String)] and [#isFullyMaterialized()] together to choose
+/// the query execution path:
+/// - Materialized key → fast path via per-key DataSource (inverted/dictionary index available).
+/// - Not materialized + not fully materialized → fall back to the sparse DataSource.
+/// - Not materialized + fully materialized → key is definitively absent; short-circuit.
+///
+/// Thread-safety: immutable after construction; safe for concurrent reads.
+public class ImmutableOpenStructDataSource extends BaseDataSource implements OpenStructDataSource {
+  private final ComplexFieldSpec _fieldSpec;
+  private final Map<String, DataSource> _perKeyDataSources;
+  @Nullable
+  private final DataSource _sparseDataSource;
+
+  public ImmutableOpenStructDataSource(ComplexFieldSpec fieldSpec, Map<String, DataSource> perKeyDataSources,
+      @Nullable DataSource sparseDataSource, DataSourceMetadata dataSourceMetadata,
+      ColumnIndexContainer indexContainer) {
+    super(dataSourceMetadata, indexContainer);
+    _fieldSpec = fieldSpec;
+    _perKeyDataSources = perKeyDataSources;
+    _sparseDataSource = sparseDataSource;
+  }
+
+  /// Convenience constructor for segment-load time. Synthesizes a minimal {@link DataSourceMetadata}
+  /// for the parent OPEN_STRUCT column (which has no on-disk presence of its own) and uses an empty
+  /// {@link ColumnIndexContainer} — all real readers live on the per-key data sources.
+  public ImmutableOpenStructDataSource(ComplexFieldSpec fieldSpec, Map<String, DataSource> perKeyDataSources,
+      @Nullable DataSource sparseDataSource, int numDocs) {
+    this(fieldSpec, perKeyDataSources, sparseDataSource,
+        new ImmutableOpenStructDataSourceMetadata(fieldSpec, numDocs),
+        new ColumnIndexContainer.FromMap.Builder().build());
+  }
+
+  @Override
+  public ComplexFieldSpec getFieldSpec() {
+    return _fieldSpec;
+  }
+
+  @Override
+  @Nullable
+  public DataSource getDataSource(String key) {
+    DataSource ds = _perKeyDataSources.get(key);
+    return ds != null ? ds : _sparseDataSource;
+  }
+
+  @Override
+  public boolean isMaterialized(String key) {
+    return _perKeyDataSources.containsKey(key);
+  }
+
+  @Override
+  public boolean isFullyMaterialized() {
+    return _sparseDataSource == null;
+  }
+
+  @Override
+  public Map<String, DataSource> getDataSources() {
+    return _perKeyDataSources;
+  }
+
+  @Override
+  @Nullable
+  public DataSourceMetadata getDataSourceMetadata(String key) {

Review Comment:
   The asymmetry is intentional. `getDataSources()` returns only materialized (dense) keys because those are the keys with real columnar DataSources. Sparse keys don't have individual DataSources — they're packed into a single JSON column. `getDataSource(key)` falls back to the sparse DataSource for unmaterialized keys so that per-key query access still works.
   I have updated the java doc.
   



-- 
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] [WIP] OPEN_STRUCT storage layer — columnar two-tier dense/sparse index (PR 2/4) [pinot]

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


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/openstruct/ImmutableOpenStructDataSource.java:
##########
@@ -0,0 +1,184 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.segment.local.segment.index.openstruct;
+
+import java.util.Map;
+import javax.annotation.Nullable;
+import org.apache.pinot.segment.local.segment.index.datasource.BaseDataSource;
+import org.apache.pinot.segment.local.segment.index.datasource.ImmutableDataSource;
+import org.apache.pinot.segment.spi.Constants;
+import org.apache.pinot.segment.spi.datasource.DataSource;
+import org.apache.pinot.segment.spi.datasource.DataSourceMetadata;
+import org.apache.pinot.segment.spi.datasource.OpenStructDataSource;
+import org.apache.pinot.segment.spi.index.column.ColumnIndexContainer;
+import org.apache.pinot.segment.spi.partition.PartitionFunction;
+import org.apache.pinot.spi.data.ComplexFieldSpec;
+import org.apache.pinot.spi.data.FieldSpec;
+
+
+/**
+ * Per-key {@link DataSource} accessor for sealed (immutable) segments with an OPEN_STRUCT column.
+ *
+ * <p>Always columnar — there is no blob branch. Every key that was dense enough during segment

Review Comment:
   Use md style java docs.



##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/openstruct/ImmutableOpenStructDataSource.java:
##########
@@ -0,0 +1,184 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.segment.local.segment.index.openstruct;
+
+import java.util.Map;
+import javax.annotation.Nullable;
+import org.apache.pinot.segment.local.segment.index.datasource.BaseDataSource;
+import org.apache.pinot.segment.local.segment.index.datasource.ImmutableDataSource;
+import org.apache.pinot.segment.spi.Constants;
+import org.apache.pinot.segment.spi.datasource.DataSource;
+import org.apache.pinot.segment.spi.datasource.DataSourceMetadata;
+import org.apache.pinot.segment.spi.datasource.OpenStructDataSource;
+import org.apache.pinot.segment.spi.index.column.ColumnIndexContainer;
+import org.apache.pinot.segment.spi.partition.PartitionFunction;
+import org.apache.pinot.spi.data.ComplexFieldSpec;
+import org.apache.pinot.spi.data.FieldSpec;
+
+
+/**
+ * Per-key {@link DataSource} accessor for sealed (immutable) segments with an OPEN_STRUCT column.
+ *
+ * <p>Always columnar — there is no blob branch. Every key that was dense enough during segment

Review Comment:
   Use md style java docs.



-- 
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] OPEN_STRUCT storage layer — columnar two-tier dense/sparse index (PR 2b/4) [pinot]

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


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/loader/IndexLoadingConfig.java:
##########
@@ -415,6 +421,43 @@ private <K, V> Map<K, V> unmodifiable(Map<K, V> map) {
     return map == null ? null : Collections.unmodifiableMap(map);
   }
 
+  public void addOpenStructChildConfigs(SegmentMetadataImpl segmentMetadata) {
+    if (_indexConfigsByColName == null || _dirty) {
+      refreshIndexConfigs();
+    }
+    for (Map.Entry<String, ColumnMetadata> entry : segmentMetadata.getColumnMetadataMap().entrySet()) {
+      String childColumn = entry.getKey();
+      if (!childColumn.contains(OpenStructNaming.SEPARATOR) || _indexConfigsByColName.containsKey(childColumn)) {
+        continue;
+      }
+      if (OpenStructNaming.isSparseColumn(childColumn)) {
+        continue;
+      }
+      String parentColumn = OpenStructNaming.parseParentColumn(childColumn);
+      FieldIndexConfigs parentConfigs = _indexConfigsByColName.get(parentColumn);
+      if (parentConfigs == null) {
+        continue;
+      }
+      IndexConfig osConfig = parentConfigs.getConfig(StandardIndexes.openStruct());
+      if (!(osConfig instanceof OpenStructIndexConfig)) {
+        continue;
+      }
+      OpenStructIndexConfig openStructConfig = (OpenStructIndexConfig) osConfig;
+      String key = OpenStructNaming.parseKey(childColumn);
+      FieldConfig keyFieldConfig = openStructConfig.getValueFieldConfig(key);
+      if (keyFieldConfig == null) {
+        keyFieldConfig = openStructConfig.getDefaultValueFieldConfig();
+      }
+      FieldSpec childFieldSpec = entry.getValue().getFieldSpec();
+      boolean enableInverted = openStructConfig.shouldEnableInvertedIndexForKey(key);
+      FieldIndexConfigs childConfigs = new FieldIndexConfigs.Builder(
+          FieldIndexConfigsUtil.fromFieldConfig(keyFieldConfig, childFieldSpec))
+          .add(StandardIndexes.inverted(), enableInverted ? IndexConfig.ENABLED : IndexConfig.DISABLED)
+          .build();
+      _indexConfigsByColName.put(childColumn, childConfigs);

Review Comment:
   Fixed this. More details in https://github.com/apache/pinot/pull/18643#discussion_r3503441561



-- 
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] OPEN_STRUCT storage layer — columnar two-tier dense/sparse index (PR 2b/4) [pinot]

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


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/indexsegment/immutable/ImmutableSegmentImpl.java:
##########
@@ -98,13 +104,44 @@ public ImmutableSegmentImpl(
     _dataSources =
         new Object2ObjectOpenHashMap<>(segmentMetadata.getColumnMetadataMap().size());
 
+    Map<String, Map<String, DataSource>> openStructDenseChildren = new HashMap<>();
+    Map<String, DataSource> openStructSparseChildren = new HashMap<>();
+    Set<String> openStructParents = new HashSet<>();
+
     for (Map.Entry<String, ColumnMetadata> entry : segmentMetadata.getColumnMetadataMap().entrySet()) {
       String colName = entry.getKey();
       ColumnMetadata columnMetadata = entry.getValue();
+
+      if (columnMetadata instanceof ColumnMetadataImpl && ((ColumnMetadataImpl) columnMetadata).isMaterializedChild()) {
+        String parent = ((ColumnMetadataImpl) columnMetadata).getParentColumn();
+        openStructParents.add(parent);
+        DataSource childDs = new ImmutableDataSource(columnMetadata, _indexContainerMap.get(colName));
+        if (OpenStructNaming.isSparseColumn(colName)) {
+          openStructSparseChildren.put(parent, childDs);
+        } else {
+          openStructDenseChildren.computeIfAbsent(parent, k -> new HashMap<>())
+              .put(OpenStructNaming.parseKey(colName), childDs);
+        }
+        continue;
+      }
+
       if (columnMetadata.getFieldSpec().getDataType() == FieldSpec.DataType.MAP) {
-        _dataSources.put(colName, new ImmutableMapDataSource(entry.getValue(), _indexContainerMap.get(colName)));
+        _dataSources.put(colName, new ImmutableMapDataSource(columnMetadata, _indexContainerMap.get(colName)));
       } else {
-        _dataSources.put(colName, new ImmutableDataSource(entry.getValue(), _indexContainerMap.get(colName)));
+        _dataSources.put(colName, new ImmutableDataSource(columnMetadata, _indexContainerMap.get(colName)));
+      }
+    }
+
+    if (!openStructParents.isEmpty()) {
+      Schema schema = segmentMetadata.getSchema();
+      for (String parent : openStructParents) {
+        FieldSpec fieldSpec = schema != null ? schema.getFieldSpecFor(parent) : null;
+        if (!(fieldSpec instanceof ComplexFieldSpec)) {

Review Comment:
   Can you explain this in the comments ?  If the
     schema is null or the fieldSpec is the wrong type, seems like the parent column is silently skipped and no DataSource is created and no error  logged. The child columns were already skipped earlier. This means OPEN_STRUCT data exists on disk but is completely invisible to queries ?



##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/openstruct/MutableOpenStructIndex.java:
##########
@@ -0,0 +1,263 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.segment.local.segment.index.openstruct;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import javax.annotation.Nullable;
+import org.apache.pinot.common.utils.DataSchema.ColumnDataType;
+import org.apache.pinot.segment.local.segment.index.map.SimpleColumnMetadata;
+import org.apache.pinot.segment.spi.ColumnMetadata;
+import org.apache.pinot.segment.spi.index.IndexReader;
+import org.apache.pinot.segment.spi.index.IndexType;
+import org.apache.pinot.segment.spi.index.StandardIndexes;
+import org.apache.pinot.segment.spi.index.mutable.MutableIndex;
+import org.apache.pinot.segment.spi.index.reader.ForwardIndexReaderContext;
+import org.apache.pinot.segment.spi.index.reader.OpenStructIndexReader;
+import org.apache.pinot.segment.spi.memory.PinotDataBufferMemoryManager;
+import org.apache.pinot.spi.config.table.OpenStructIndexConfig;
+import org.apache.pinot.spi.data.ComplexFieldSpec;
+import org.apache.pinot.spi.data.DimensionFieldSpec;
+import org.apache.pinot.spi.data.FieldSpec;
+import org.apache.pinot.spi.data.FieldSpec.DataType;
+import org.apache.pinot.spi.data.OpenStructTypeInference;
+import org.apache.pinot.spi.utils.PinotDataType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/// Manages per-key mutable columns for an OPEN_STRUCT column during real-time consumption.
+/// Each discovered key gets its own {@link MutableKeyColumn} (dictionary-encoded forward index +
+/// presence bitmap). Dense/sparse classification is deferred to seal time.
+///
+/// Single-writer for [#index]: the consuming thread calls this method. Readers may
+/// concurrently read [#getKeys()] and [#getKeyColumns()] via the volatile map swap.
+@SuppressWarnings("rawtypes")
+public class MutableOpenStructIndex implements OpenStructIndexReader<ForwardIndexReaderContext>, MutableIndex {
+  private static final Logger LOGGER = LoggerFactory.getLogger(MutableOpenStructIndex.class);
+
+  private final String _openStructColumn;
+  private final OpenStructIndexConfig _config;
+  private final Map<String, FieldSpec> _childFieldSpecs;
+  private final PinotDataBufferMemoryManager _memoryManager;
+  private final int _capacity;
+
+  // Volatile for lock-free reader access; writer always holds the consuming-thread lock.
+  private volatile Map<String, MutableKeyColumn> _keyColumns = new HashMap<>();

Review Comment:
   Should this be a concurrent hash map instead ? How do we enforce the single thread write - dont see any safety locks in this path. Its documented, but not enforced. 
   



##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/loader/IndexLoadingConfig.java:
##########
@@ -415,6 +421,43 @@ private <K, V> Map<K, V> unmodifiable(Map<K, V> map) {
     return map == null ? null : Collections.unmodifiableMap(map);
   }
 
+  public void addOpenStructChildConfigs(SegmentMetadataImpl segmentMetadata) {
+    if (_indexConfigsByColName == null || _dirty) {
+      refreshIndexConfigs();
+    }
+    for (Map.Entry<String, ColumnMetadata> entry : segmentMetadata.getColumnMetadataMap().entrySet()) {
+      String childColumn = entry.getKey();
+      if (!childColumn.contains(OpenStructNaming.SEPARATOR) || _indexConfigsByColName.containsKey(childColumn)) {
+        continue;
+      }
+      if (OpenStructNaming.isSparseColumn(childColumn)) {
+        continue;
+      }
+      String parentColumn = OpenStructNaming.parseParentColumn(childColumn);
+      FieldIndexConfigs parentConfigs = _indexConfigsByColName.get(parentColumn);
+      if (parentConfigs == null) {
+        continue;
+      }
+      IndexConfig osConfig = parentConfigs.getConfig(StandardIndexes.openStruct());
+      if (!(osConfig instanceof OpenStructIndexConfig)) {
+        continue;
+      }
+      OpenStructIndexConfig openStructConfig = (OpenStructIndexConfig) osConfig;
+      String key = OpenStructNaming.parseKey(childColumn);
+      FieldConfig keyFieldConfig = openStructConfig.getValueFieldConfig(key);
+      if (keyFieldConfig == null) {
+        keyFieldConfig = openStructConfig.getDefaultValueFieldConfig();
+      }
+      FieldSpec childFieldSpec = entry.getValue().getFieldSpec();
+      boolean enableInverted = openStructConfig.shouldEnableInvertedIndexForKey(key);
+      FieldIndexConfigs childConfigs = new FieldIndexConfigs.Builder(
+          FieldIndexConfigsUtil.fromFieldConfig(keyFieldConfig, childFieldSpec))
+          .add(StandardIndexes.inverted(), enableInverted ? IndexConfig.ENABLED : IndexConfig.DISABLED)
+          .build();
+      _indexConfigsByColName.put(childColumn, childConfigs);

Review Comment:
   Should we directly update _indexConfigsByColName after refreshIndexConfigs(). A subsequent refreshIndexConfigs() call would rebuild the map and wipe
     these entries ? We should store overrides in a separate overlay map ?



##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/openstruct/ImmutableOpenStructDataSource.java:
##########
@@ -0,0 +1,179 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.segment.local.segment.index.openstruct;
+
+import java.util.Map;
+import javax.annotation.Nullable;
+import org.apache.pinot.segment.local.segment.index.datasource.BaseDataSource;
+import org.apache.pinot.segment.local.segment.index.datasource.ImmutableDataSource;
+import org.apache.pinot.segment.spi.Constants;
+import org.apache.pinot.segment.spi.datasource.DataSource;
+import org.apache.pinot.segment.spi.datasource.DataSourceMetadata;
+import org.apache.pinot.segment.spi.datasource.OpenStructDataSource;
+import org.apache.pinot.segment.spi.index.column.ColumnIndexContainer;
+import org.apache.pinot.segment.spi.partition.PartitionFunction;
+import org.apache.pinot.spi.data.ComplexFieldSpec;
+import org.apache.pinot.spi.data.FieldSpec;
+
+
+
+/// Per-key {@link DataSource} accessor for sealed (immutable) segments with an OPEN_STRUCT column.
+///
+/// Always columnar — there is no blob branch. Every key that was dense enough during segment
+/// creation gets its own materialized {@link DataSource} (forward index + optional inverted index /
+/// dictionary). Keys that did not meet the density threshold are stored in an optional sparse
+/// column; the sparse {@link DataSource} is returned for any unmaterialized key lookup.
+///
+/// Use [#isMaterialized(String)] and [#isFullyMaterialized()] together to choose
+/// the query execution path:
+/// - Materialized key → fast path via per-key DataSource (inverted/dictionary index available).
+/// - Not materialized + not fully materialized → fall back to the sparse DataSource.
+/// - Not materialized + fully materialized → key is definitively absent; short-circuit.
+///
+/// Thread-safety: immutable after construction; safe for concurrent reads.
+public class ImmutableOpenStructDataSource extends BaseDataSource implements OpenStructDataSource {
+  private final ComplexFieldSpec _fieldSpec;
+  private final Map<String, DataSource> _perKeyDataSources;
+  @Nullable
+  private final DataSource _sparseDataSource;
+
+  public ImmutableOpenStructDataSource(ComplexFieldSpec fieldSpec, Map<String, DataSource> perKeyDataSources,
+      @Nullable DataSource sparseDataSource, DataSourceMetadata dataSourceMetadata,
+      ColumnIndexContainer indexContainer) {
+    super(dataSourceMetadata, indexContainer);
+    _fieldSpec = fieldSpec;
+    _perKeyDataSources = perKeyDataSources;
+    _sparseDataSource = sparseDataSource;
+  }
+
+  /// Convenience constructor for segment-load time. Synthesizes a minimal {@link DataSourceMetadata}
+  /// for the parent OPEN_STRUCT column (which has no on-disk presence of its own) and uses an empty
+  /// {@link ColumnIndexContainer} — all real readers live on the per-key data sources.
+  public ImmutableOpenStructDataSource(ComplexFieldSpec fieldSpec, Map<String, DataSource> perKeyDataSources,
+      @Nullable DataSource sparseDataSource, int numDocs) {
+    this(fieldSpec, perKeyDataSources, sparseDataSource,
+        new ImmutableOpenStructDataSourceMetadata(fieldSpec, numDocs),
+        new ColumnIndexContainer.FromMap.Builder().build());
+  }
+
+  @Override
+  public ComplexFieldSpec getFieldSpec() {
+    return _fieldSpec;
+  }
+
+  @Override
+  @Nullable
+  public DataSource getDataSource(String key) {
+    DataSource ds = _perKeyDataSources.get(key);
+    return ds != null ? ds : _sparseDataSource;
+  }
+
+  @Override
+  public boolean isMaterialized(String key) {
+    return _perKeyDataSources.containsKey(key);
+  }
+
+  @Override
+  public boolean isFullyMaterialized() {
+    return _sparseDataSource == null;
+  }
+
+  @Override
+  public Map<String, DataSource> getDataSources() {
+    return _perKeyDataSources;
+  }
+
+  @Override
+  @Nullable
+  public DataSourceMetadata getDataSourceMetadata(String key) {
+    DataSource ds = _perKeyDataSources.get(key);
+    return ds != null ? ds.getDataSourceMetadata() : null;
+  }
+

Review Comment:
   Dont see `getMapValue(int docId)` implementation here,  but the `MutableOpenStructDataSource` has it. What's the implication ?
   



##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/openstruct/MutableOpenStructDataSource.java:
##########
@@ -0,0 +1,180 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.segment.local.segment.index.openstruct;
+
+import java.util.HashMap;
+import java.util.Map;
+import javax.annotation.Nullable;
+import org.apache.pinot.segment.local.segment.index.datasource.BaseDataSource;
+import org.apache.pinot.segment.local.segment.index.datasource.ImmutableDataSource;
+import org.apache.pinot.segment.spi.ColumnMetadata;
+import org.apache.pinot.segment.spi.Constants;
+import org.apache.pinot.segment.spi.datasource.DataSource;
+import org.apache.pinot.segment.spi.datasource.DataSourceMetadata;
+import org.apache.pinot.segment.spi.datasource.OpenStructDataSource;
+import org.apache.pinot.segment.spi.index.IndexReader;
+import org.apache.pinot.segment.spi.index.IndexType;
+import org.apache.pinot.segment.spi.index.column.ColumnIndexContainer;
+import org.apache.pinot.segment.spi.partition.PartitionFunction;
+import org.apache.pinot.spi.data.ComplexFieldSpec;
+import org.apache.pinot.spi.data.FieldSpec;
+
+
+/// Per-key {@link DataSource} accessor for mutable (consuming) segments with an OPEN_STRUCT column.
+///
+/// Always columnar — no blob branch. Per-key DataSources are synthesized on demand from the
+/// underlying {@link MutableOpenStructIndex}; mutable mode always holds every observed key, so
+/// {@link #isFullyMaterialized()} is unconditionally {@code true}.
+public class MutableOpenStructDataSource extends BaseDataSource implements OpenStructDataSource {
+  private final ComplexFieldSpec _fieldSpec;
+  private final MutableOpenStructIndex _index;
+  private final int _numDocs;
+
+  public MutableOpenStructDataSource(ComplexFieldSpec fieldSpec, MutableOpenStructIndex index, int numDocs) {
+    super(new MutableOpenStructDataSourceMetadata(fieldSpec, numDocs),
+        new ColumnIndexContainer.FromMap.Builder().build());
+    _fieldSpec = fieldSpec;
+    _index = index;
+    _numDocs = numDocs;
+  }
+
+  @Override
+  public ComplexFieldSpec getFieldSpec() {
+    return _fieldSpec;
+  }
+
+  @Override
+  @Nullable
+  public DataSource getDataSource(String key) {
+    Map<IndexType, IndexReader> indexes = _index.getIndexes(key);
+    if (indexes == null || indexes.isEmpty()) {
+      return null;
+    }
+    ColumnMetadata metadata = _index.getColumnMetadata(key);
+    return new ImmutableDataSource(metadata,
+        new ColumnIndexContainer.FromMap.Builder().withAll(indexes).build());
+  }
+
+  @Override
+  public boolean isMaterialized(String key) {
+    return _index.getKeyColumn(key) != null;
+  }
+
+  /// Mutable mode always holds every observed key in-memory; the sparse tier exists only after seal.
+  @Override
+  public boolean isFullyMaterialized() {
+    return true;
+  }
+
+  @Override
+  public Map<String, DataSource> getDataSources() {
+    Map<String, DataSource> result = new HashMap<>();
+    for (String key : _index.getKeys()) {

Review Comment:
   This calls the MutableOpenStructIndex.getKeys() in a loop while the underlying is a volatile concurrent map. Lets take a snapshot of the map and then run the loop ? 
   
   ```
   Map<String, MutableKeyColumn> snapshot = _keyColumns;
     for (String key : snapshot.keySet()) { ... }
   ```



##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/openstruct/MutableOpenStructIndex.java:
##########
@@ -0,0 +1,263 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.segment.local.segment.index.openstruct;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import javax.annotation.Nullable;
+import org.apache.pinot.common.utils.DataSchema.ColumnDataType;
+import org.apache.pinot.segment.local.segment.index.map.SimpleColumnMetadata;
+import org.apache.pinot.segment.spi.ColumnMetadata;
+import org.apache.pinot.segment.spi.index.IndexReader;
+import org.apache.pinot.segment.spi.index.IndexType;
+import org.apache.pinot.segment.spi.index.StandardIndexes;
+import org.apache.pinot.segment.spi.index.mutable.MutableIndex;
+import org.apache.pinot.segment.spi.index.reader.ForwardIndexReaderContext;
+import org.apache.pinot.segment.spi.index.reader.OpenStructIndexReader;
+import org.apache.pinot.segment.spi.memory.PinotDataBufferMemoryManager;
+import org.apache.pinot.spi.config.table.OpenStructIndexConfig;
+import org.apache.pinot.spi.data.ComplexFieldSpec;
+import org.apache.pinot.spi.data.DimensionFieldSpec;
+import org.apache.pinot.spi.data.FieldSpec;
+import org.apache.pinot.spi.data.FieldSpec.DataType;
+import org.apache.pinot.spi.data.OpenStructTypeInference;
+import org.apache.pinot.spi.utils.PinotDataType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/// Manages per-key mutable columns for an OPEN_STRUCT column during real-time consumption.
+/// Each discovered key gets its own {@link MutableKeyColumn} (dictionary-encoded forward index +
+/// presence bitmap). Dense/sparse classification is deferred to seal time.
+///
+/// Single-writer for [#index]: the consuming thread calls this method. Readers may
+/// concurrently read [#getKeys()] and [#getKeyColumns()] via the volatile map swap.
+@SuppressWarnings("rawtypes")
+public class MutableOpenStructIndex implements OpenStructIndexReader<ForwardIndexReaderContext>, MutableIndex {
+  private static final Logger LOGGER = LoggerFactory.getLogger(MutableOpenStructIndex.class);
+
+  private final String _openStructColumn;
+  private final OpenStructIndexConfig _config;
+  private final Map<String, FieldSpec> _childFieldSpecs;
+  private final PinotDataBufferMemoryManager _memoryManager;
+  private final int _capacity;
+
+  // Volatile for lock-free reader access; writer always holds the consuming-thread lock.
+  private volatile Map<String, MutableKeyColumn> _keyColumns = new HashMap<>();
+
+  public MutableOpenStructIndex(String openStructColumn, ComplexFieldSpec fieldSpec,
+      OpenStructIndexConfig config, PinotDataBufferMemoryManager memoryManager, int capacity) {
+    _openStructColumn = openStructColumn;
+    _config = config;
+    _memoryManager = memoryManager;
+    _capacity = capacity;
+
+    Map<String, FieldSpec> childFieldSpecs = fieldSpec.getChildFieldSpecs();
+    _childFieldSpecs = childFieldSpecs != null ? new HashMap<>(childFieldSpecs) : new HashMap<>();
+  }
+
+  @Override
+  public void add(Object value, int dictId, int docId) {
+    index(docId, value);
+  }
+
+  @Override
+  public void add(Object[] values, @Nullable int[] dictIds, int docId) {
+    throw new UnsupportedOperationException("OPEN_STRUCT does not support multi-value indexing");
+  }
+
+  /// Indexes the OPEN_STRUCT value for the given document. `value` must be a
+  /// `Map<String, Object>` or `null`; null and non-Map values are silently skipped.
+  @SuppressWarnings("unchecked")
+  public void index(int docId, @Nullable Object value) {
+    if (!(value instanceof Map)) {
+      return;
+    }
+    Map<String, Object> map = (Map<String, Object>) value;
+    for (Map.Entry<String, Object> entry : map.entrySet()) {
+      String key = entry.getKey();
+      Object rawValue = entry.getValue();
+      if (rawValue == null) {
+        continue;
+      }
+
+      MutableKeyColumn keyCol = _keyColumns.get(key);
+      if (keyCol == null) {
+        // Mutable mode holds every observed key (see MutableOpenStructDataSource#isFullyMaterialized);
+        // dense/sparse classification (maxDenseKeys / denseKeys) is applied at seal time by the segment
+        // build, so no key is dropped during consumption.
+        // Resolve stored type and coerce BEFORE allocating a column so a first-row coercion failure
+        // does not allocate a column that was never usable.
+        DataType resolvedType = resolveStoredType(key, rawValue);
+        if (resolvedType == null) {
+          continue;
+        }
+        Object coerced = tryCoerce(key, rawValue, resolvedType);
+        if (coerced == null) {
+          continue;
+        }
+        keyCol = allocateKeyColumn(key, resolvedType);
+        keyCol.setValue(docId, coerced);
+        continue;
+      }
+
+      DataType storedType = keyCol.getStoredType();
+      Object coerced = tryCoerce(key, rawValue, storedType);
+      if (coerced == null) {
+        continue;
+      }
+      keyCol.setValue(docId, coerced);
+    }
+  }
+
+  /// Resolves the stored type for a key without allocating any state. Returns null when the type
+  /// cannot be inferred (caller should skip the entry).
+  @Nullable
+  private DataType resolveStoredType(String key, Object rawValue) {
+    FieldSpec spec = _childFieldSpecs.get(key);
+    DataType valueType;
+    if (spec != null) {
+      valueType = spec.getDataType();
+    } else {
+      valueType = OpenStructTypeInference.inferDataType(rawValue);
+      if (valueType == null) {
+        LOGGER.warn("OPEN_STRUCT '{}': could not infer DataType for key '{}' from value of class '{}'."
+                + " Dropping the entry.",
+            _openStructColumn, key, rawValue.getClass().getName());
+        return null;
+      }
+    }
+    return valueType.getStoredType();
+  }
+
+  /// Coerces rawValue to storedType. Returns null on failure (logged at WARN); the caller drops
+  /// the entry. Note: a successful coerce of a "null"-shaped raw value would also return null —
+  /// but callers gate on rawValue != null before reaching here.
+  @Nullable
+  private Object tryCoerce(String key, Object rawValue, DataType storedType) {
+    try {
+      PinotDataType sourceType = PinotDataType.getSingleValueType(rawValue);
+      PinotDataType destType = ColumnDataType.fromDataTypeSV(storedType).toPinotDataType();

Review Comment:
   `ColumnDataType.fromDataTypeSV(storedType).toPinotDataType()` - This must be re-resolving per doc per key? The stored type is fixed per key so can we cache the destination PinotDataType at first-encounter time ?



##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/creator/impl/openstruct/OpenStructColumnSplitter.java:
##########
@@ -0,0 +1,540 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.segment.local.segment.creator.impl.openstruct;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import javax.annotation.Nullable;
+import org.apache.commons.configuration2.PropertiesConfiguration;
+import org.apache.pinot.common.utils.DataSchema.ColumnDataType;
+import org.apache.pinot.segment.local.segment.creator.impl.BaseSegmentCreator;
+import org.apache.pinot.segment.local.segment.creator.impl.SegmentDictionaryCreator;
+import org.apache.pinot.segment.local.segment.creator.impl.fwd.SingleValueVarByteRawIndexCreator;
+import org.apache.pinot.segment.local.segment.creator.impl.nullvalue.NullValueVectorCreator;
+import org.apache.pinot.segment.local.segment.creator.impl.stats.AbstractColumnStatisticsCollector;
+import org.apache.pinot.segment.local.segment.creator.impl.stats.StatsCollectorUtil;
+import org.apache.pinot.segment.local.segment.index.dictionary.DictionaryIndexType;
+import org.apache.pinot.segment.local.segment.index.openstruct.OpenStructSupportedIndexes;
+import org.apache.pinot.segment.spi.V1Constants;
+import org.apache.pinot.segment.spi.compression.ChunkCompressionType;
+import org.apache.pinot.segment.spi.creator.IndexCreationContext;
+import org.apache.pinot.segment.spi.index.DictionaryIndexConfig;
+import org.apache.pinot.segment.spi.index.FieldIndexConfigs;
+import org.apache.pinot.segment.spi.index.FieldIndexConfigsUtil;
+import org.apache.pinot.segment.spi.index.ForwardIndexConfig;
+import org.apache.pinot.segment.spi.index.IndexCreator;
+import org.apache.pinot.segment.spi.index.IndexService;
+import org.apache.pinot.segment.spi.index.IndexType;
+import org.apache.pinot.segment.spi.index.StandardIndexes;
+import org.apache.pinot.segment.spi.index.creator.ColumnarOpenStructIndexCreator;
+import org.apache.pinot.spi.config.table.FieldConfig;
+import org.apache.pinot.spi.config.table.IndexConfig;
+import org.apache.pinot.spi.config.table.IndexingConfig;
+import org.apache.pinot.spi.config.table.OpenStructIndexConfig;
+import org.apache.pinot.spi.data.ComplexFieldSpec;
+import org.apache.pinot.spi.data.DimensionFieldSpec;
+import org.apache.pinot.spi.data.FieldSpec;
+import org.apache.pinot.spi.data.FieldSpec.DataType;
+import org.apache.pinot.spi.data.OpenStructNaming;
+import org.apache.pinot.spi.data.OpenStructTypeInference;
+import org.apache.pinot.spi.utils.JsonUtils;
+import org.apache.pinot.spi.utils.PinotDataType;
+import org.roaringbitmap.RoaringBitmap;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/// Splits an OPEN_STRUCT column into per-key materialized columns using standard Pinot index
+/// creators. Dense keys become independent virtual columns; remaining keys go into a single
+/// synthetic JSON column for sparse storage.
+///
+/// Lifecycle: instantiated by `BaseSegmentCreator` for OPEN_STRUCT columns. Receives
+/// per-doc `Map<String, Object>` values via [#add(Map, int)], accumulates in memory,
+/// then on [#seal()] writes per-key column files using standard creators.
+public class OpenStructColumnSplitter implements ColumnarOpenStructIndexCreator {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(OpenStructColumnSplitter.class);
+
+  private final File _indexDir;
+  private final String _columnName;
+  private final Map<String, FieldSpec> _childFieldSpecs;
+  private final OpenStructIndexConfig _config;
+  private final int _maxDenseKeys;
+
+  // Per-key accumulation
+  private final Map<String, RoaringBitmap> _presenceBitmaps = new HashMap<>();
+  private final Map<String, List<Object>> _values = new HashMap<>();
+  private final Map<String, DataType> _inferredTypes = new HashMap<>();
+  private int _numDocs;
+
+  // Resolved at seal time
+  @Nullable
+  private Set<String> _resolvedDenseKeys;
+  private final Map<String, PropertiesConfiguration> _materializedColumnMetadata = new LinkedHashMap<>();
+
+  public OpenStructColumnSplitter(File indexDir, String columnName, FieldSpec fieldSpec,
+      OpenStructIndexConfig config) {
+    _indexDir = indexDir;
+    _columnName = columnName;
+    _config = config;
+    _maxDenseKeys = config.getMaxDenseKeys();
+
+    Map<String, FieldSpec> childFieldSpecs = null;
+    if (fieldSpec instanceof ComplexFieldSpec) {
+      ComplexFieldSpec complexSpec = (ComplexFieldSpec) fieldSpec;
+      childFieldSpecs = complexSpec.getChildFieldSpecs();
+    }
+    _childFieldSpecs = childFieldSpecs != null ? new HashMap<>(childFieldSpecs) : new HashMap<>();
+  }
+
+  @Override
+  public void add(Object value, int docId)
+      throws IOException {
+    if (value instanceof Map) {
+      @SuppressWarnings("unchecked")
+      Map<String, Object> map = (Map<String, Object>) value;
+      addMap(map);
+    } else {
+      addMap(null);
+    }
+  }
+
+  @Override
+  public void add(Map<String, Object> openStructValue, int docId)
+      throws IOException {
+    addMap(openStructValue);
+  }
+
+  @Override
+  public void add(Object[] values, @Nullable int[] dictIds)
+      throws IOException {
+    throw new UnsupportedOperationException("OPEN_STRUCT index is single-value only");
+  }
+
+  /// Returns the resolved dense-key set after [#seal()] or [#classify()].
+  /// Returns an empty set before resolution.
+  public Set<String> getResolvedDenseKeys() {
+    return _resolvedDenseKeys != null ? Collections.unmodifiableSet(_resolvedDenseKeys) : Set.of();
+  }
+
+  /// Resolves dense vs sparse keys without writing any files. Exposed for testing and for callers
+  /// that need the classification independent of file output. [#seal()] calls this internally.
+  public Set<String> classify() {
+    if (_resolvedDenseKeys != null) {
+      return _resolvedDenseKeys;
+    }
+    if (_numDocs == 0 || _presenceBitmaps.isEmpty()) {
+      _resolvedDenseKeys = new LinkedHashSet<>();
+      return _resolvedDenseKeys;
+    }
+    List<String> allKeys = new ArrayList<>(_presenceBitmaps.keySet());
+    allKeys.sort((a, b) -> {
+      double fillA = (double) _presenceBitmaps.get(a).getCardinality() / _numDocs;
+      double fillB = (double) _presenceBitmaps.get(b).getCardinality() / _numDocs;
+      int cmp = Double.compare(fillB, fillA);
+      return cmp != 0 ? cmp : a.compareTo(b);
+    });
+
+    double minFillRate = _config.getDenseKeyMinFillRate();
+    _resolvedDenseKeys = new LinkedHashSet<>();
+
+    Set<String> configuredDenseKeys = _config.getDenseKeys();
+    for (String key : configuredDenseKeys) {
+      if (_presenceBitmaps.containsKey(key) && (_maxDenseKeys < 0 || _resolvedDenseKeys.size() < _maxDenseKeys)) {
+        _resolvedDenseKeys.add(key);
+      }
+    }
+
+    for (String key : allKeys) {
+      if (_resolvedDenseKeys.contains(key)) {
+        continue;
+      }
+      double fillRate = (double) _presenceBitmaps.get(key).getCardinality() / _numDocs;
+      if ((_maxDenseKeys < 0 || _resolvedDenseKeys.size() < _maxDenseKeys) && fillRate >= minFillRate) {
+        _resolvedDenseKeys.add(key);
+      }
+    }
+    return _resolvedDenseKeys;
+  }
+
+  private void addMap(@Nullable Map<String, Object> map) {
+    if (map != null && !map.isEmpty()) {
+      for (Map.Entry<String, Object> entry : map.entrySet()) {
+        String key = entry.getKey();
+        Object rawValue = entry.getValue();
+        if (rawValue == null) {
+          continue;
+        }
+        FieldSpec keySpec = _childFieldSpecs.get(key);
+        DataType valueType = keySpec != null
+            ? keySpec.getDataType()
+            : _inferredTypes.computeIfAbsent(key, k -> {
+              DataType inferred = OpenStructTypeInference.inferDataType(rawValue);
+              return inferred != null ? inferred : DataType.STRING;
+            });
+        if (!_presenceBitmaps.containsKey(key)) {
+          _presenceBitmaps.put(key, new RoaringBitmap());
+          _values.put(key, new ArrayList<>());
+        }
+        _presenceBitmaps.get(key).add(_numDocs);
+        Object coerced;
+        try {
+          PinotDataType sourceType = PinotDataType.getSingleValueType(rawValue);
+          PinotDataType destType = ColumnDataType.fromDataTypeSV(valueType.getStoredType()).toPinotDataType();
+          coerced = destType.convert(rawValue, sourceType);
+        } catch (Exception e) {
+          LOGGER.warn("OPEN_STRUCT '{}': coercion failed for key '{}' value '{}' to {}. Skipping.",
+              _columnName, key, rawValue, valueType, e);
+          _presenceBitmaps.get(key).remove(_numDocs);
+          continue;
+        }
+        _values.get(key).add(coerced);
+      }
+    }
+    _numDocs++;
+  }
+
+  @Override
+  public void seal()
+      throws IOException {
+    classify();
+    if (_resolvedDenseKeys == null || (_numDocs == 0 && _presenceBitmaps.isEmpty())) {
+      return;
+    }
+
+    for (String key : _resolvedDenseKeys) {
+      writeDenseKeyColumn(key);
+    }
+
+    List<String> sparseKeys = new ArrayList<>();
+    for (String key : _presenceBitmaps.keySet()) {
+      if (!_resolvedDenseKeys.contains(key)) {
+        sparseKeys.add(key);
+      }
+    }
+    if (!sparseKeys.isEmpty()) {
+      writeSparseJsonColumn(sparseKeys);
+    }
+
+    emitParentColumnMetadata(!sparseKeys.isEmpty());
+  }
+
+  @Override
+  public void close()
+      throws IOException {
+    // Nothing to close — sub-creators are created and closed within seal()
+  }
+
+  @Override
+  public Map<String, PropertiesConfiguration> getMaterializedColumnMetadata() {
+    return _materializedColumnMetadata;
+  }
+
+  private void writeDenseKeyColumn(String key)
+      throws IOException {
+    String materializedCol = OpenStructNaming.materializedColumnName(_columnName, key);
+    FieldSpec keySpec = _childFieldSpecs.get(key);
+    DataType valueType = keySpec != null
+        ? keySpec.getDataType()
+        : _inferredTypes.getOrDefault(key, DataType.STRING);
+    DataType storedType = valueType.getStoredType();
+    RoaringBitmap presence = _presenceBitmaps.get(key);
+    List<Object> values = _values.get(key);
+
+    // Synthetic field spec for the materialized child. Its natural Pinot dimension null value is the value
+    // stored for absent docs, so column metadata stays consistent with on-disk content.
+    DimensionFieldSpec childFieldSpec = new DimensionFieldSpec(materializedCol, storedType, true);
+    Object defaultValue = childFieldSpec.getDefaultNullValue();
+
+    // Collect statistics the standard way: present docs contribute their value, absent docs the default
+    // (absent docs are also marked in the null vector below).
+    AbstractColumnStatisticsCollector statsCollector =
+        StatsCollectorUtil.createStatsCollector(childFieldSpec, null);
+    int statsOrdinal = 0;
+    for (int docId = 0; docId < _numDocs; docId++) {
+      statsCollector.collect(presence.contains(docId) ? values.get(statsOrdinal++) : defaultValue);
+    }
+    statsCollector.seal();
+
+    // Build per-key index configuration from the key's FieldConfig (falling back to the default), then apply
+    // the OPEN_STRUCT inverted-on default. No TableConfig/Schema required.
+    FieldConfig keyFieldConfig = _config.getValueFieldConfig(key);
+    if (keyFieldConfig == null) {
+      keyFieldConfig = _config.getDefaultValueFieldConfig();
+    }
+    boolean enableInverted = _config.shouldEnableInvertedIndexForKey(key);
+    FieldIndexConfigs configsForDecision = new FieldIndexConfigs.Builder(
+        FieldIndexConfigsUtil.fromFieldConfig(keyFieldConfig, childFieldSpec))
+        .add(StandardIndexes.inverted(), enableInverted ? IndexConfig.ENABLED : IndexConfig.DISABLED)
+        .build();
+
+    boolean useDictionary = resolveUseDictionary(childFieldSpec, configsForDecision, statsCollector);
+
+    // Reconcile dictionary + forward encoding with the final decision (mirrors BaseSegmentCreator.adaptConfig);
+    // ForwardIndexCreatorFactory selects dict-vs-raw from the forward config's EncodingType. A compression codec
+    // applies only to the raw forward format (LZ4 preserves the dense child's current on-disk layout); attaching
+    // one to a dictionary-encoded forward is rejected by ForwardIndexType.validate.
+    ForwardIndexConfig.Builder forwardBuilder = new ForwardIndexConfig.Builder(
+        useDictionary ? FieldConfig.EncodingType.DICTIONARY : FieldConfig.EncodingType.RAW);
+    if (!useDictionary) {
+      forwardBuilder.withCompressionCodec(FieldConfig.CompressionCodec.LZ4);
+    }
+    FieldIndexConfigs fieldIndexConfigs = new FieldIndexConfigs.Builder(configsForDecision)
+        .add(StandardIndexes.dictionary(),
+            useDictionary ? DictionaryIndexConfig.DEFAULT : DictionaryIndexConfig.DISABLED)
+        .add(StandardIndexes.forward(), forwardBuilder.build())
+        .build();
+
+    int dictElementSize = writeColumnIndexes(materializedCol, storedType, presence, values,
+        defaultValue, statsCollector, useDictionary, fieldIndexConfigs, childFieldSpec);
+
+    NullValueVectorCreator nullCreator = new NullValueVectorCreator(_indexDir, materializedCol);
+    try {
+      for (int docId = 0; docId < _numDocs; docId++) {
+        if (!presence.contains(docId)) {
+          nullCreator.setNull(docId);
+        }
+      }
+      nullCreator.seal();
+    } finally {
+      nullCreator.close();
+    }
+
+    PropertiesConfiguration props = new PropertiesConfiguration();
+    FieldConfig.EncodingType encoding =
+        useDictionary ? FieldConfig.EncodingType.DICTIONARY : FieldConfig.EncodingType.RAW;
+    BaseSegmentCreator.addColumnMetadataInfo(props, materializedCol, statsCollector, _numDocs, childFieldSpec,
+        useDictionary, dictElementSize, encoding, false);
+    // OPEN_STRUCT-specific keys not written by addColumnMetadataInfo.
+    props.setProperty(
+        V1Constants.MetadataKeys.Column.getKeyFor(materializedCol, V1Constants.MetadataKeys.Column.PARENT_COLUMN),
+        _columnName);
+    props.setProperty(V1Constants.MetadataKeys.Column.getKeyFor(materializedCol, "hasNullValue"), true);
+    if (enableInverted && useDictionary) {
+      props.setProperty(V1Constants.MetadataKeys.Column.getKeyFor(materializedCol, "hasInvertedIndex"), true);
+    }
+    _materializedColumnMetadata.put(materializedCol, props);
+  }
+
+  /// Decides dictionary vs raw encoding for a materialized child column, mirroring the three steps of
+  /// `BaseSegmentCreator.createDictionaryForColumn` with standard default flags (optimizeDictionary
+  /// off => dictionary unless explicitly disabled and not required by an enabled index).
+  private boolean resolveUseDictionary(FieldSpec childFieldSpec, FieldIndexConfigs fieldIndexConfigs,
+      AbstractColumnStatisticsCollector statsCollector) {
+    if (DictionaryIndexConfig.requiresDictionary(childFieldSpec, fieldIndexConfigs)) {
+      return true;
+    }
+    if (fieldIndexConfigs.getConfig(StandardIndexes.dictionary()).isDisabled()) {
+      return false;
+    }
+    return DictionaryIndexType.ignoreDictionaryOverride(false, false,
+        IndexingConfig.DEFAULT_NO_DICTIONARY_SIZE_RATIO_THRESHOLD, null, childFieldSpec, fieldIndexConfigs,
+        statsCollector.getCardinality(), statsCollector.getTotalNumberOfEntries());
+  }
+
+  /// Writes the dictionary (when used) plus all vetted, enabled indexes for a materialized child column through
+  /// the standard index-creator family, driven from a single per-doc loop. Returns the dictionary element size in
+  /// bytes (0 when raw-encoded), for column metadata. The dictionary is built separately because its build
+  /// lifecycle is CUSTOM and it supplies the dictIds the per-row creators consume.
+  private int writeColumnIndexes(String materializedCol, DataType storedType, RoaringBitmap presence,
+      List<Object> values, Object defaultValue, AbstractColumnStatisticsCollector statsCollector,
+      boolean useDictionary, FieldIndexConfigs fieldIndexConfigs, FieldSpec childFieldSpec)
+      throws IOException {
+    int dictElementSize = 0;
+    SegmentDictionaryCreator dictCreator = null;
+    try {
+      if (useDictionary) {
+        dictCreator = new SegmentDictionaryCreator(materializedCol, storedType,
+            new File(_indexDir, materializedCol + V1Constants.Dict.FILE_EXTENSION), true);
+        dictCreator.build(statsCollector.getUniqueValuesSet());
+      }
+
+      // Index-creation context built from the sealed collector (a ColumnShape) — no TableConfig required.
+      IndexCreationContext context =
+          new IndexCreationContext.Builder(_indexDir, null, statsCollector, useDictionary, false)
+              .withOnHeap(false).build();
+
+      List<IndexCreator> creators = new ArrayList<>();
+      try {
+        for (IndexType<?, ?, ?> indexType : IndexService.getInstance().getAllIndexes()) {
+          if (indexType.getIndexBuildLifecycle() != IndexType.BuildLifecycle.DURING_SEGMENT_CREATION) {
+            continue;   // excludes dictionary (lifecycle CUSTOM), built separately above
+          }
+          if (!OpenStructSupportedIndexes.ALLOWED_PRETTY_NAMES.contains(indexType.getPrettyName())) {
+            continue;   // non-vetted indexes already rejected at table-config validation; defensive backstop
+          }
+          IndexCreator creator = createColumnIndexCreator(indexType, context, fieldIndexConfigs, materializedCol,
+              childFieldSpec);
+          if (creator != null) {
+            creators.add(creator);
+          }
+        }
+
+        int ordinal = 0;
+        for (int docId = 0; docId < _numDocs; docId++) {
+          Object value = presence.contains(docId) ? values.get(ordinal++) : defaultValue;
+          int dictId = useDictionary ? dictCreator.indexOfSV(value) : -1;
+          for (IndexCreator creator : creators) {
+            creator.add(value, dictId);
+          }
+        }
+        for (IndexCreator creator : creators) {
+          creator.seal();
+        }
+      } finally {
+        for (IndexCreator creator : creators) {
+          creator.close();
+        }
+        if (dictCreator != null) {
+          dictElementSize = dictCreator.getNumBytesPerEntry();
+          dictCreator.seal();
+        }
+      }
+    } finally {
+      if (dictCreator != null) {
+        dictCreator.close();
+      }
+    }
+    return dictElementSize;
+  }
+
+  @Nullable
+  private static <C extends IndexConfig> IndexCreator createColumnIndexCreator(IndexType<C, ?, ?> indexType,
+      IndexCreationContext context, FieldIndexConfigs fieldIndexConfigs, String materializedCol,
+      FieldSpec childFieldSpec)
+      throws IOException {
+    // Materialized child columns exist in no schema/TableConfig, so the standard table-config-time validation
+    // never sees them. Run the index type's own guards here against the resolved child FieldSpec (e.g. range
+    // rejects a non-numeric column without a dictionary) so misconfigurations fail with the canonical message
+    // instead of crashing opaquely inside the creator. validate() internally no-ops when the index is disabled.
+    indexType.validate(fieldIndexConfigs, childFieldSpec, null);
+    C config = fieldIndexConfigs.getConfig(indexType);
+    if (!config.isEnabled() || !indexType.shouldCreateIndex(context, config)) {
+      return null;
+    }
+    try {
+      return indexType.createIndexCreator(context, config);
+    } catch (IOException e) {
+      throw e;
+    } catch (Exception e) {
+      throw new IOException("Failed to create " + indexType.getPrettyName() + " creator for: " + materializedCol, e);
+    }
+  }
+
+  private void writeSparseJsonColumn(List<String> sparseKeys)
+      throws IOException {
+    String sparseCol = OpenStructNaming.sparseColumnName(_columnName);
+    int maxLen = 1;
+    String[] jsonPerDoc = new String[_numDocs];
+    int nonNullCount = 0;
+    for (int docId = 0; docId < _numDocs; docId++) {
+      Map<String, Object> sparseEntries = new LinkedHashMap<>();
+      for (String key : sparseKeys) {
+        RoaringBitmap presence = _presenceBitmaps.get(key);
+        if (presence != null && presence.contains(docId)) {
+          int ordinal = presence.rank(docId) - 1;
+          sparseEntries.put(key, _values.get(key).get(ordinal));
+        }
+      }
+      if (!sparseEntries.isEmpty()) {
+        try {
+          String json = JsonUtils.objectToString(sparseEntries);
+          jsonPerDoc[docId] = json;
+          maxLen = Math.max(maxLen, json.getBytes(StandardCharsets.UTF_8).length);

Review Comment:
   This is not needed per doc ? `json.getBytes(UTF_8).length` allocates a fresh byte[] solely to measure UTF-8 byte length, then discards it, waste of memory just to be cleaned up by GC ?



##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/creator/impl/openstruct/OpenStructColumnSplitter.java:
##########
@@ -0,0 +1,540 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.segment.local.segment.creator.impl.openstruct;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import javax.annotation.Nullable;
+import org.apache.commons.configuration2.PropertiesConfiguration;
+import org.apache.pinot.common.utils.DataSchema.ColumnDataType;
+import org.apache.pinot.segment.local.segment.creator.impl.BaseSegmentCreator;
+import org.apache.pinot.segment.local.segment.creator.impl.SegmentDictionaryCreator;
+import org.apache.pinot.segment.local.segment.creator.impl.fwd.SingleValueVarByteRawIndexCreator;
+import org.apache.pinot.segment.local.segment.creator.impl.nullvalue.NullValueVectorCreator;
+import org.apache.pinot.segment.local.segment.creator.impl.stats.AbstractColumnStatisticsCollector;
+import org.apache.pinot.segment.local.segment.creator.impl.stats.StatsCollectorUtil;
+import org.apache.pinot.segment.local.segment.index.dictionary.DictionaryIndexType;
+import org.apache.pinot.segment.local.segment.index.openstruct.OpenStructSupportedIndexes;
+import org.apache.pinot.segment.spi.V1Constants;
+import org.apache.pinot.segment.spi.compression.ChunkCompressionType;
+import org.apache.pinot.segment.spi.creator.IndexCreationContext;
+import org.apache.pinot.segment.spi.index.DictionaryIndexConfig;
+import org.apache.pinot.segment.spi.index.FieldIndexConfigs;
+import org.apache.pinot.segment.spi.index.FieldIndexConfigsUtil;
+import org.apache.pinot.segment.spi.index.ForwardIndexConfig;
+import org.apache.pinot.segment.spi.index.IndexCreator;
+import org.apache.pinot.segment.spi.index.IndexService;
+import org.apache.pinot.segment.spi.index.IndexType;
+import org.apache.pinot.segment.spi.index.StandardIndexes;
+import org.apache.pinot.segment.spi.index.creator.ColumnarOpenStructIndexCreator;
+import org.apache.pinot.spi.config.table.FieldConfig;
+import org.apache.pinot.spi.config.table.IndexConfig;
+import org.apache.pinot.spi.config.table.IndexingConfig;
+import org.apache.pinot.spi.config.table.OpenStructIndexConfig;
+import org.apache.pinot.spi.data.ComplexFieldSpec;
+import org.apache.pinot.spi.data.DimensionFieldSpec;
+import org.apache.pinot.spi.data.FieldSpec;
+import org.apache.pinot.spi.data.FieldSpec.DataType;
+import org.apache.pinot.spi.data.OpenStructNaming;
+import org.apache.pinot.spi.data.OpenStructTypeInference;
+import org.apache.pinot.spi.utils.JsonUtils;
+import org.apache.pinot.spi.utils.PinotDataType;
+import org.roaringbitmap.RoaringBitmap;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/// Splits an OPEN_STRUCT column into per-key materialized columns using standard Pinot index
+/// creators. Dense keys become independent virtual columns; remaining keys go into a single
+/// synthetic JSON column for sparse storage.
+///
+/// Lifecycle: instantiated by `BaseSegmentCreator` for OPEN_STRUCT columns. Receives
+/// per-doc `Map<String, Object>` values via [#add(Map, int)], accumulates in memory,
+/// then on [#seal()] writes per-key column files using standard creators.
+public class OpenStructColumnSplitter implements ColumnarOpenStructIndexCreator {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(OpenStructColumnSplitter.class);
+
+  private final File _indexDir;
+  private final String _columnName;
+  private final Map<String, FieldSpec> _childFieldSpecs;
+  private final OpenStructIndexConfig _config;
+  private final int _maxDenseKeys;
+
+  // Per-key accumulation
+  private final Map<String, RoaringBitmap> _presenceBitmaps = new HashMap<>();
+  private final Map<String, List<Object>> _values = new HashMap<>();
+  private final Map<String, DataType> _inferredTypes = new HashMap<>();
+  private int _numDocs;
+
+  // Resolved at seal time
+  @Nullable
+  private Set<String> _resolvedDenseKeys;
+  private final Map<String, PropertiesConfiguration> _materializedColumnMetadata = new LinkedHashMap<>();
+
+  public OpenStructColumnSplitter(File indexDir, String columnName, FieldSpec fieldSpec,
+      OpenStructIndexConfig config) {
+    _indexDir = indexDir;
+    _columnName = columnName;
+    _config = config;
+    _maxDenseKeys = config.getMaxDenseKeys();
+
+    Map<String, FieldSpec> childFieldSpecs = null;
+    if (fieldSpec instanceof ComplexFieldSpec) {
+      ComplexFieldSpec complexSpec = (ComplexFieldSpec) fieldSpec;
+      childFieldSpecs = complexSpec.getChildFieldSpecs();
+    }
+    _childFieldSpecs = childFieldSpecs != null ? new HashMap<>(childFieldSpecs) : new HashMap<>();
+  }
+
+  @Override
+  public void add(Object value, int docId)
+      throws IOException {
+    if (value instanceof Map) {
+      @SuppressWarnings("unchecked")
+      Map<String, Object> map = (Map<String, Object>) value;
+      addMap(map);
+    } else {
+      addMap(null);
+    }
+  }
+
+  @Override
+  public void add(Map<String, Object> openStructValue, int docId)
+      throws IOException {
+    addMap(openStructValue);
+  }
+
+  @Override
+  public void add(Object[] values, @Nullable int[] dictIds)
+      throws IOException {
+    throw new UnsupportedOperationException("OPEN_STRUCT index is single-value only");
+  }
+
+  /// Returns the resolved dense-key set after [#seal()] or [#classify()].
+  /// Returns an empty set before resolution.
+  public Set<String> getResolvedDenseKeys() {
+    return _resolvedDenseKeys != null ? Collections.unmodifiableSet(_resolvedDenseKeys) : Set.of();
+  }
+
+  /// Resolves dense vs sparse keys without writing any files. Exposed for testing and for callers
+  /// that need the classification independent of file output. [#seal()] calls this internally.
+  public Set<String> classify() {
+    if (_resolvedDenseKeys != null) {
+      return _resolvedDenseKeys;
+    }
+    if (_numDocs == 0 || _presenceBitmaps.isEmpty()) {
+      _resolvedDenseKeys = new LinkedHashSet<>();
+      return _resolvedDenseKeys;
+    }
+    List<String> allKeys = new ArrayList<>(_presenceBitmaps.keySet());
+    allKeys.sort((a, b) -> {
+      double fillA = (double) _presenceBitmaps.get(a).getCardinality() / _numDocs;
+      double fillB = (double) _presenceBitmaps.get(b).getCardinality() / _numDocs;
+      int cmp = Double.compare(fillB, fillA);
+      return cmp != 0 ? cmp : a.compareTo(b);
+    });
+
+    double minFillRate = _config.getDenseKeyMinFillRate();
+    _resolvedDenseKeys = new LinkedHashSet<>();
+
+    Set<String> configuredDenseKeys = _config.getDenseKeys();
+    for (String key : configuredDenseKeys) {
+      if (_presenceBitmaps.containsKey(key) && (_maxDenseKeys < 0 || _resolvedDenseKeys.size() < _maxDenseKeys)) {
+        _resolvedDenseKeys.add(key);
+      }
+    }
+
+    for (String key : allKeys) {
+      if (_resolvedDenseKeys.contains(key)) {
+        continue;
+      }
+      double fillRate = (double) _presenceBitmaps.get(key).getCardinality() / _numDocs;
+      if ((_maxDenseKeys < 0 || _resolvedDenseKeys.size() < _maxDenseKeys) && fillRate >= minFillRate) {
+        _resolvedDenseKeys.add(key);
+      }
+    }
+    return _resolvedDenseKeys;
+  }
+
+  private void addMap(@Nullable Map<String, Object> map) {
+    if (map != null && !map.isEmpty()) {
+      for (Map.Entry<String, Object> entry : map.entrySet()) {
+        String key = entry.getKey();
+        Object rawValue = entry.getValue();
+        if (rawValue == null) {
+          continue;
+        }
+        FieldSpec keySpec = _childFieldSpecs.get(key);
+        DataType valueType = keySpec != null
+            ? keySpec.getDataType()
+            : _inferredTypes.computeIfAbsent(key, k -> {
+              DataType inferred = OpenStructTypeInference.inferDataType(rawValue);
+              return inferred != null ? inferred : DataType.STRING;
+            });
+        if (!_presenceBitmaps.containsKey(key)) {
+          _presenceBitmaps.put(key, new RoaringBitmap());
+          _values.put(key, new ArrayList<>());
+        }
+        _presenceBitmaps.get(key).add(_numDocs);
+        Object coerced;
+        try {
+          PinotDataType sourceType = PinotDataType.getSingleValueType(rawValue);
+          PinotDataType destType = ColumnDataType.fromDataTypeSV(valueType.getStoredType()).toPinotDataType();
+          coerced = destType.convert(rawValue, sourceType);
+        } catch (Exception e) {
+          LOGGER.warn("OPEN_STRUCT '{}': coercion failed for key '{}' value '{}' to {}. Skipping.",
+              _columnName, key, rawValue, valueType, e);
+          _presenceBitmaps.get(key).remove(_numDocs);
+          continue;
+        }
+        _values.get(key).add(coerced);
+      }
+    }
+    _numDocs++;
+  }
+
+  @Override
+  public void seal()
+      throws IOException {
+    classify();
+    if (_resolvedDenseKeys == null || (_numDocs == 0 && _presenceBitmaps.isEmpty())) {
+      return;
+    }
+
+    for (String key : _resolvedDenseKeys) {
+      writeDenseKeyColumn(key);
+    }
+
+    List<String> sparseKeys = new ArrayList<>();
+    for (String key : _presenceBitmaps.keySet()) {
+      if (!_resolvedDenseKeys.contains(key)) {
+        sparseKeys.add(key);
+      }
+    }
+    if (!sparseKeys.isEmpty()) {
+      writeSparseJsonColumn(sparseKeys);
+    }
+
+    emitParentColumnMetadata(!sparseKeys.isEmpty());
+  }
+
+  @Override
+  public void close()
+      throws IOException {
+    // Nothing to close — sub-creators are created and closed within seal()
+  }
+
+  @Override
+  public Map<String, PropertiesConfiguration> getMaterializedColumnMetadata() {
+    return _materializedColumnMetadata;
+  }
+
+  private void writeDenseKeyColumn(String key)
+      throws IOException {
+    String materializedCol = OpenStructNaming.materializedColumnName(_columnName, key);
+    FieldSpec keySpec = _childFieldSpecs.get(key);
+    DataType valueType = keySpec != null
+        ? keySpec.getDataType()
+        : _inferredTypes.getOrDefault(key, DataType.STRING);
+    DataType storedType = valueType.getStoredType();
+    RoaringBitmap presence = _presenceBitmaps.get(key);
+    List<Object> values = _values.get(key);
+
+    // Synthetic field spec for the materialized child. Its natural Pinot dimension null value is the value
+    // stored for absent docs, so column metadata stays consistent with on-disk content.
+    DimensionFieldSpec childFieldSpec = new DimensionFieldSpec(materializedCol, storedType, true);
+    Object defaultValue = childFieldSpec.getDefaultNullValue();
+
+    // Collect statistics the standard way: present docs contribute their value, absent docs the default
+    // (absent docs are also marked in the null vector below).
+    AbstractColumnStatisticsCollector statsCollector =
+        StatsCollectorUtil.createStatsCollector(childFieldSpec, null);
+    int statsOrdinal = 0;
+    for (int docId = 0; docId < _numDocs; docId++) {
+      statsCollector.collect(presence.contains(docId) ? values.get(statsOrdinal++) : defaultValue);
+    }
+    statsCollector.seal();
+
+    // Build per-key index configuration from the key's FieldConfig (falling back to the default), then apply
+    // the OPEN_STRUCT inverted-on default. No TableConfig/Schema required.
+    FieldConfig keyFieldConfig = _config.getValueFieldConfig(key);
+    if (keyFieldConfig == null) {
+      keyFieldConfig = _config.getDefaultValueFieldConfig();
+    }
+    boolean enableInverted = _config.shouldEnableInvertedIndexForKey(key);
+    FieldIndexConfigs configsForDecision = new FieldIndexConfigs.Builder(
+        FieldIndexConfigsUtil.fromFieldConfig(keyFieldConfig, childFieldSpec))
+        .add(StandardIndexes.inverted(), enableInverted ? IndexConfig.ENABLED : IndexConfig.DISABLED)
+        .build();
+
+    boolean useDictionary = resolveUseDictionary(childFieldSpec, configsForDecision, statsCollector);
+
+    // Reconcile dictionary + forward encoding with the final decision (mirrors BaseSegmentCreator.adaptConfig);
+    // ForwardIndexCreatorFactory selects dict-vs-raw from the forward config's EncodingType. A compression codec
+    // applies only to the raw forward format (LZ4 preserves the dense child's current on-disk layout); attaching
+    // one to a dictionary-encoded forward is rejected by ForwardIndexType.validate.
+    ForwardIndexConfig.Builder forwardBuilder = new ForwardIndexConfig.Builder(
+        useDictionary ? FieldConfig.EncodingType.DICTIONARY : FieldConfig.EncodingType.RAW);
+    if (!useDictionary) {
+      forwardBuilder.withCompressionCodec(FieldConfig.CompressionCodec.LZ4);
+    }
+    FieldIndexConfigs fieldIndexConfigs = new FieldIndexConfigs.Builder(configsForDecision)
+        .add(StandardIndexes.dictionary(),
+            useDictionary ? DictionaryIndexConfig.DEFAULT : DictionaryIndexConfig.DISABLED)
+        .add(StandardIndexes.forward(), forwardBuilder.build())
+        .build();
+
+    int dictElementSize = writeColumnIndexes(materializedCol, storedType, presence, values,
+        defaultValue, statsCollector, useDictionary, fieldIndexConfigs, childFieldSpec);
+
+    NullValueVectorCreator nullCreator = new NullValueVectorCreator(_indexDir, materializedCol);
+    try {
+      for (int docId = 0; docId < _numDocs; docId++) {
+        if (!presence.contains(docId)) {
+          nullCreator.setNull(docId);
+        }
+      }
+      nullCreator.seal();
+    } finally {
+      nullCreator.close();
+    }
+
+    PropertiesConfiguration props = new PropertiesConfiguration();
+    FieldConfig.EncodingType encoding =
+        useDictionary ? FieldConfig.EncodingType.DICTIONARY : FieldConfig.EncodingType.RAW;
+    BaseSegmentCreator.addColumnMetadataInfo(props, materializedCol, statsCollector, _numDocs, childFieldSpec,
+        useDictionary, dictElementSize, encoding, false);
+    // OPEN_STRUCT-specific keys not written by addColumnMetadataInfo.
+    props.setProperty(
+        V1Constants.MetadataKeys.Column.getKeyFor(materializedCol, V1Constants.MetadataKeys.Column.PARENT_COLUMN),
+        _columnName);
+    props.setProperty(V1Constants.MetadataKeys.Column.getKeyFor(materializedCol, "hasNullValue"), true);
+    if (enableInverted && useDictionary) {
+      props.setProperty(V1Constants.MetadataKeys.Column.getKeyFor(materializedCol, "hasInvertedIndex"), true);
+    }
+    _materializedColumnMetadata.put(materializedCol, props);
+  }
+
+  /// Decides dictionary vs raw encoding for a materialized child column, mirroring the three steps of
+  /// `BaseSegmentCreator.createDictionaryForColumn` with standard default flags (optimizeDictionary
+  /// off => dictionary unless explicitly disabled and not required by an enabled index).
+  private boolean resolveUseDictionary(FieldSpec childFieldSpec, FieldIndexConfigs fieldIndexConfigs,
+      AbstractColumnStatisticsCollector statsCollector) {
+    if (DictionaryIndexConfig.requiresDictionary(childFieldSpec, fieldIndexConfigs)) {
+      return true;
+    }
+    if (fieldIndexConfigs.getConfig(StandardIndexes.dictionary()).isDisabled()) {
+      return false;
+    }
+    return DictionaryIndexType.ignoreDictionaryOverride(false, false,
+        IndexingConfig.DEFAULT_NO_DICTIONARY_SIZE_RATIO_THRESHOLD, null, childFieldSpec, fieldIndexConfigs,
+        statsCollector.getCardinality(), statsCollector.getTotalNumberOfEntries());
+  }
+
+  /// Writes the dictionary (when used) plus all vetted, enabled indexes for a materialized child column through
+  /// the standard index-creator family, driven from a single per-doc loop. Returns the dictionary element size in
+  /// bytes (0 when raw-encoded), for column metadata. The dictionary is built separately because its build
+  /// lifecycle is CUSTOM and it supplies the dictIds the per-row creators consume.
+  private int writeColumnIndexes(String materializedCol, DataType storedType, RoaringBitmap presence,
+      List<Object> values, Object defaultValue, AbstractColumnStatisticsCollector statsCollector,
+      boolean useDictionary, FieldIndexConfigs fieldIndexConfigs, FieldSpec childFieldSpec)
+      throws IOException {
+    int dictElementSize = 0;
+    SegmentDictionaryCreator dictCreator = null;
+    try {
+      if (useDictionary) {
+        dictCreator = new SegmentDictionaryCreator(materializedCol, storedType,
+            new File(_indexDir, materializedCol + V1Constants.Dict.FILE_EXTENSION), true);
+        dictCreator.build(statsCollector.getUniqueValuesSet());
+      }
+
+      // Index-creation context built from the sealed collector (a ColumnShape) — no TableConfig required.
+      IndexCreationContext context =
+          new IndexCreationContext.Builder(_indexDir, null, statsCollector, useDictionary, false)
+              .withOnHeap(false).build();
+
+      List<IndexCreator> creators = new ArrayList<>();
+      try {
+        for (IndexType<?, ?, ?> indexType : IndexService.getInstance().getAllIndexes()) {
+          if (indexType.getIndexBuildLifecycle() != IndexType.BuildLifecycle.DURING_SEGMENT_CREATION) {
+            continue;   // excludes dictionary (lifecycle CUSTOM), built separately above
+          }
+          if (!OpenStructSupportedIndexes.ALLOWED_PRETTY_NAMES.contains(indexType.getPrettyName())) {
+            continue;   // non-vetted indexes already rejected at table-config validation; defensive backstop
+          }
+          IndexCreator creator = createColumnIndexCreator(indexType, context, fieldIndexConfigs, materializedCol,
+              childFieldSpec);
+          if (creator != null) {
+            creators.add(creator);
+          }
+        }
+
+        int ordinal = 0;
+        for (int docId = 0; docId < _numDocs; docId++) {
+          Object value = presence.contains(docId) ? values.get(ordinal++) : defaultValue;
+          int dictId = useDictionary ? dictCreator.indexOfSV(value) : -1;
+          for (IndexCreator creator : creators) {
+            creator.add(value, dictId);
+          }
+        }
+        for (IndexCreator creator : creators) {
+          creator.seal();
+        }
+      } finally {
+        for (IndexCreator creator : creators) {
+          creator.close();
+        }
+        if (dictCreator != null) {
+          dictElementSize = dictCreator.getNumBytesPerEntry();
+          dictCreator.seal();
+        }
+      }
+    } finally {
+      if (dictCreator != null) {
+        dictCreator.close();
+      }
+    }
+    return dictElementSize;
+  }
+
+  @Nullable
+  private static <C extends IndexConfig> IndexCreator createColumnIndexCreator(IndexType<C, ?, ?> indexType,
+      IndexCreationContext context, FieldIndexConfigs fieldIndexConfigs, String materializedCol,
+      FieldSpec childFieldSpec)
+      throws IOException {
+    // Materialized child columns exist in no schema/TableConfig, so the standard table-config-time validation
+    // never sees them. Run the index type's own guards here against the resolved child FieldSpec (e.g. range
+    // rejects a non-numeric column without a dictionary) so misconfigurations fail with the canonical message
+    // instead of crashing opaquely inside the creator. validate() internally no-ops when the index is disabled.
+    indexType.validate(fieldIndexConfigs, childFieldSpec, null);
+    C config = fieldIndexConfigs.getConfig(indexType);
+    if (!config.isEnabled() || !indexType.shouldCreateIndex(context, config)) {
+      return null;
+    }
+    try {
+      return indexType.createIndexCreator(context, config);
+    } catch (IOException e) {
+      throw e;
+    } catch (Exception e) {
+      throw new IOException("Failed to create " + indexType.getPrettyName() + " creator for: " + materializedCol, e);
+    }
+  }
+
+  private void writeSparseJsonColumn(List<String> sparseKeys)
+      throws IOException {
+    String sparseCol = OpenStructNaming.sparseColumnName(_columnName);
+    int maxLen = 1;
+    String[] jsonPerDoc = new String[_numDocs];
+    int nonNullCount = 0;
+    for (int docId = 0; docId < _numDocs; docId++) {
+      Map<String, Object> sparseEntries = new LinkedHashMap<>();
+      for (String key : sparseKeys) {
+        RoaringBitmap presence = _presenceBitmaps.get(key);
+        if (presence != null && presence.contains(docId)) {
+          int ordinal = presence.rank(docId) - 1;
+          sparseEntries.put(key, _values.get(key).get(ordinal));
+        }
+      }
+      if (!sparseEntries.isEmpty()) {
+        try {
+          String json = JsonUtils.objectToString(sparseEntries);
+          jsonPerDoc[docId] = json;
+          maxLen = Math.max(maxLen, json.getBytes(StandardCharsets.UTF_8).length);
+          nonNullCount++;
+        } catch (IOException e) {
+          throw new RuntimeException("Failed to serialize sparse entries for docId " + docId, e);
+        }
+      }
+    }
+
+    SingleValueVarByteRawIndexCreator fwdCreator = new SingleValueVarByteRawIndexCreator(
+        _indexDir, ChunkCompressionType.LZ4, sparseCol, _numDocs, DataType.STRING, maxLen);
+    NullValueVectorCreator nullCreator = new NullValueVectorCreator(_indexDir, sparseCol);
+    try {
+      for (int docId = 0; docId < _numDocs; docId++) {

Review Comment:
   Can we combine this loop for the above ? Seems like the above loop is just allocating String[_numDocs] , no reason for double loop ?



##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/creator/impl/openstruct/OpenStructColumnSplitter.java:
##########
@@ -0,0 +1,540 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.segment.local.segment.creator.impl.openstruct;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import javax.annotation.Nullable;
+import org.apache.commons.configuration2.PropertiesConfiguration;
+import org.apache.pinot.common.utils.DataSchema.ColumnDataType;
+import org.apache.pinot.segment.local.segment.creator.impl.BaseSegmentCreator;
+import org.apache.pinot.segment.local.segment.creator.impl.SegmentDictionaryCreator;
+import org.apache.pinot.segment.local.segment.creator.impl.fwd.SingleValueVarByteRawIndexCreator;
+import org.apache.pinot.segment.local.segment.creator.impl.nullvalue.NullValueVectorCreator;
+import org.apache.pinot.segment.local.segment.creator.impl.stats.AbstractColumnStatisticsCollector;
+import org.apache.pinot.segment.local.segment.creator.impl.stats.StatsCollectorUtil;
+import org.apache.pinot.segment.local.segment.index.dictionary.DictionaryIndexType;
+import org.apache.pinot.segment.local.segment.index.openstruct.OpenStructSupportedIndexes;
+import org.apache.pinot.segment.spi.V1Constants;
+import org.apache.pinot.segment.spi.compression.ChunkCompressionType;
+import org.apache.pinot.segment.spi.creator.IndexCreationContext;
+import org.apache.pinot.segment.spi.index.DictionaryIndexConfig;
+import org.apache.pinot.segment.spi.index.FieldIndexConfigs;
+import org.apache.pinot.segment.spi.index.FieldIndexConfigsUtil;
+import org.apache.pinot.segment.spi.index.ForwardIndexConfig;
+import org.apache.pinot.segment.spi.index.IndexCreator;
+import org.apache.pinot.segment.spi.index.IndexService;
+import org.apache.pinot.segment.spi.index.IndexType;
+import org.apache.pinot.segment.spi.index.StandardIndexes;
+import org.apache.pinot.segment.spi.index.creator.ColumnarOpenStructIndexCreator;
+import org.apache.pinot.spi.config.table.FieldConfig;
+import org.apache.pinot.spi.config.table.IndexConfig;
+import org.apache.pinot.spi.config.table.IndexingConfig;
+import org.apache.pinot.spi.config.table.OpenStructIndexConfig;
+import org.apache.pinot.spi.data.ComplexFieldSpec;
+import org.apache.pinot.spi.data.DimensionFieldSpec;
+import org.apache.pinot.spi.data.FieldSpec;
+import org.apache.pinot.spi.data.FieldSpec.DataType;
+import org.apache.pinot.spi.data.OpenStructNaming;
+import org.apache.pinot.spi.data.OpenStructTypeInference;
+import org.apache.pinot.spi.utils.JsonUtils;
+import org.apache.pinot.spi.utils.PinotDataType;
+import org.roaringbitmap.RoaringBitmap;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/// Splits an OPEN_STRUCT column into per-key materialized columns using standard Pinot index
+/// creators. Dense keys become independent virtual columns; remaining keys go into a single
+/// synthetic JSON column for sparse storage.
+///
+/// Lifecycle: instantiated by `BaseSegmentCreator` for OPEN_STRUCT columns. Receives
+/// per-doc `Map<String, Object>` values via [#add(Map, int)], accumulates in memory,
+/// then on [#seal()] writes per-key column files using standard creators.
+public class OpenStructColumnSplitter implements ColumnarOpenStructIndexCreator {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(OpenStructColumnSplitter.class);
+
+  private final File _indexDir;
+  private final String _columnName;
+  private final Map<String, FieldSpec> _childFieldSpecs;
+  private final OpenStructIndexConfig _config;
+  private final int _maxDenseKeys;
+
+  // Per-key accumulation
+  private final Map<String, RoaringBitmap> _presenceBitmaps = new HashMap<>();
+  private final Map<String, List<Object>> _values = new HashMap<>();
+  private final Map<String, DataType> _inferredTypes = new HashMap<>();
+  private int _numDocs;
+
+  // Resolved at seal time
+  @Nullable
+  private Set<String> _resolvedDenseKeys;
+  private final Map<String, PropertiesConfiguration> _materializedColumnMetadata = new LinkedHashMap<>();
+
+  public OpenStructColumnSplitter(File indexDir, String columnName, FieldSpec fieldSpec,
+      OpenStructIndexConfig config) {
+    _indexDir = indexDir;
+    _columnName = columnName;
+    _config = config;
+    _maxDenseKeys = config.getMaxDenseKeys();
+
+    Map<String, FieldSpec> childFieldSpecs = null;
+    if (fieldSpec instanceof ComplexFieldSpec) {
+      ComplexFieldSpec complexSpec = (ComplexFieldSpec) fieldSpec;
+      childFieldSpecs = complexSpec.getChildFieldSpecs();
+    }
+    _childFieldSpecs = childFieldSpecs != null ? new HashMap<>(childFieldSpecs) : new HashMap<>();
+  }
+
+  @Override
+  public void add(Object value, int docId)
+      throws IOException {
+    if (value instanceof Map) {
+      @SuppressWarnings("unchecked")
+      Map<String, Object> map = (Map<String, Object>) value;
+      addMap(map);
+    } else {
+      addMap(null);
+    }
+  }
+
+  @Override
+  public void add(Map<String, Object> openStructValue, int docId)
+      throws IOException {
+    addMap(openStructValue);
+  }
+
+  @Override
+  public void add(Object[] values, @Nullable int[] dictIds)
+      throws IOException {
+    throw new UnsupportedOperationException("OPEN_STRUCT index is single-value only");
+  }
+
+  /// Returns the resolved dense-key set after [#seal()] or [#classify()].
+  /// Returns an empty set before resolution.
+  public Set<String> getResolvedDenseKeys() {
+    return _resolvedDenseKeys != null ? Collections.unmodifiableSet(_resolvedDenseKeys) : Set.of();
+  }
+
+  /// Resolves dense vs sparse keys without writing any files. Exposed for testing and for callers
+  /// that need the classification independent of file output. [#seal()] calls this internally.
+  public Set<String> classify() {
+    if (_resolvedDenseKeys != null) {
+      return _resolvedDenseKeys;
+    }
+    if (_numDocs == 0 || _presenceBitmaps.isEmpty()) {
+      _resolvedDenseKeys = new LinkedHashSet<>();
+      return _resolvedDenseKeys;
+    }
+    List<String> allKeys = new ArrayList<>(_presenceBitmaps.keySet());
+    allKeys.sort((a, b) -> {
+      double fillA = (double) _presenceBitmaps.get(a).getCardinality() / _numDocs;
+      double fillB = (double) _presenceBitmaps.get(b).getCardinality() / _numDocs;
+      int cmp = Double.compare(fillB, fillA);
+      return cmp != 0 ? cmp : a.compareTo(b);
+    });
+
+    double minFillRate = _config.getDenseKeyMinFillRate();
+    _resolvedDenseKeys = new LinkedHashSet<>();
+
+    Set<String> configuredDenseKeys = _config.getDenseKeys();
+    for (String key : configuredDenseKeys) {
+      if (_presenceBitmaps.containsKey(key) && (_maxDenseKeys < 0 || _resolvedDenseKeys.size() < _maxDenseKeys)) {
+        _resolvedDenseKeys.add(key);
+      }
+    }
+
+    for (String key : allKeys) {
+      if (_resolvedDenseKeys.contains(key)) {
+        continue;
+      }
+      double fillRate = (double) _presenceBitmaps.get(key).getCardinality() / _numDocs;

Review Comment:
   Recommendation for optimization, For each key in each doc, 3-4 HashMap lookups for the same key in this code (containsKey, get for bitmap, get for values). Can we use computeIfAbsent and cache references  through the code 



-- 
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] OPEN_STRUCT storage layer — columnar two-tier dense/sparse index (PR 2b/4) [pinot]

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


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/openstruct/ImmutableOpenStructDataSource.java:
##########
@@ -0,0 +1,265 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.segment.local.segment.index.openstruct;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import javax.annotation.Nullable;
+import org.apache.pinot.segment.local.segment.index.datasource.BaseDataSource;
+import org.apache.pinot.segment.local.segment.index.datasource.ImmutableDataSource;
+import org.apache.pinot.segment.spi.Constants;
+import org.apache.pinot.segment.spi.datasource.DataSource;
+import org.apache.pinot.segment.spi.datasource.DataSourceMetadata;
+import org.apache.pinot.segment.spi.datasource.OpenStructDataSource;
+import org.apache.pinot.segment.spi.index.column.ColumnIndexContainer;
+import org.apache.pinot.segment.spi.index.reader.Dictionary;
+import org.apache.pinot.segment.spi.index.reader.ForwardIndexReader;
+import org.apache.pinot.segment.spi.index.reader.ForwardIndexReaderContext;
+import org.apache.pinot.segment.spi.index.reader.NullValueVectorReader;
+import org.apache.pinot.segment.spi.partition.PartitionFunction;
+import org.apache.pinot.spi.data.ComplexFieldSpec;
+import org.apache.pinot.spi.data.FieldSpec;
+import org.apache.pinot.spi.data.FieldSpec.DataType;
+import org.apache.pinot.spi.utils.JsonUtils;
+
+
+
+/// Per-key {@link DataSource} accessor for sealed (immutable) segments with an OPEN_STRUCT column.
+///
+/// Always columnar — there is no blob branch. Every key that was dense enough during segment
+/// creation gets its own materialized {@link DataSource} (forward index + optional inverted index /
+/// dictionary). Keys that did not meet the density threshold are stored in an optional sparse
+/// column; the sparse {@link DataSource} is returned for any unmaterialized key lookup.
+///
+/// Use [#isMaterialized(String)] and [#isFullyMaterialized()] together to choose
+/// the query execution path:
+/// - Materialized key → fast path via per-key DataSource (inverted/dictionary index available).
+/// - Not materialized + not fully materialized → fall back to the sparse DataSource.
+/// - Not materialized + fully materialized → key is definitively absent; short-circuit.
+///
+/// Thread-safety: immutable after construction; safe for concurrent reads.
+public class ImmutableOpenStructDataSource extends BaseDataSource implements OpenStructDataSource {
+  private final ComplexFieldSpec _fieldSpec;
+  private final Map<String, DataSource> _perKeyDataSources;
+  @Nullable
+  private final DataSource _sparseDataSource;
+
+  public ImmutableOpenStructDataSource(ComplexFieldSpec fieldSpec, Map<String, DataSource> perKeyDataSources,
+      @Nullable DataSource sparseDataSource, DataSourceMetadata dataSourceMetadata,
+      ColumnIndexContainer indexContainer) {
+    super(dataSourceMetadata, indexContainer);
+    _fieldSpec = fieldSpec;
+    _perKeyDataSources = perKeyDataSources;
+    _sparseDataSource = sparseDataSource;
+  }
+
+  /// Convenience constructor for segment-load time. Synthesizes a minimal {@link DataSourceMetadata}
+  /// for the parent OPEN_STRUCT column (which has no on-disk presence of its own) and uses an empty
+  /// {@link ColumnIndexContainer} — all real readers live on the per-key data sources.
+  public ImmutableOpenStructDataSource(ComplexFieldSpec fieldSpec, Map<String, DataSource> perKeyDataSources,
+      @Nullable DataSource sparseDataSource, int numDocs) {
+    this(fieldSpec, perKeyDataSources, sparseDataSource,
+        new ImmutableOpenStructDataSourceMetadata(fieldSpec, numDocs),
+        new ColumnIndexContainer.FromMap.Builder().build());
+  }
+

Review Comment:
   This follows the same pattern as MAP — `BaseMapDataSource extends BaseDataSource` with `getDictionary()` returning null (line 61). 
   One difference: MAP's parent container holds a `MapIndexReader` as its forward index (the blob reader), while OPEN_STRUCT's parent container is empty because there's no blob — all data lives in materialized child columns.
   



-- 
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] OPEN_STRUCT storage layer — columnar two-tier dense/sparse index (PR 2b/4) [pinot]

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


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/openstruct/ImmutableOpenStructDataSource.java:
##########
@@ -0,0 +1,265 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.segment.local.segment.index.openstruct;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import javax.annotation.Nullable;
+import org.apache.pinot.segment.local.segment.index.datasource.BaseDataSource;
+import org.apache.pinot.segment.local.segment.index.datasource.ImmutableDataSource;
+import org.apache.pinot.segment.spi.Constants;
+import org.apache.pinot.segment.spi.datasource.DataSource;
+import org.apache.pinot.segment.spi.datasource.DataSourceMetadata;
+import org.apache.pinot.segment.spi.datasource.OpenStructDataSource;
+import org.apache.pinot.segment.spi.index.column.ColumnIndexContainer;
+import org.apache.pinot.segment.spi.index.reader.Dictionary;
+import org.apache.pinot.segment.spi.index.reader.ForwardIndexReader;
+import org.apache.pinot.segment.spi.index.reader.ForwardIndexReaderContext;
+import org.apache.pinot.segment.spi.index.reader.NullValueVectorReader;
+import org.apache.pinot.segment.spi.partition.PartitionFunction;
+import org.apache.pinot.spi.data.ComplexFieldSpec;
+import org.apache.pinot.spi.data.FieldSpec;
+import org.apache.pinot.spi.data.FieldSpec.DataType;
+import org.apache.pinot.spi.utils.JsonUtils;
+
+
+
+/// Per-key {@link DataSource} accessor for sealed (immutable) segments with an OPEN_STRUCT column.
+///
+/// Always columnar — there is no blob branch. Every key that was dense enough during segment
+/// creation gets its own materialized {@link DataSource} (forward index + optional inverted index /
+/// dictionary). Keys that did not meet the density threshold are stored in an optional sparse
+/// column; the sparse {@link DataSource} is returned for any unmaterialized key lookup.
+///
+/// Use [#isMaterialized(String)] and [#isFullyMaterialized()] together to choose
+/// the query execution path:
+/// - Materialized key → fast path via per-key DataSource (inverted/dictionary index available).
+/// - Not materialized + not fully materialized → fall back to the sparse DataSource.
+/// - Not materialized + fully materialized → key is definitively absent; short-circuit.
+///
+/// Thread-safety: immutable after construction; safe for concurrent reads.
+public class ImmutableOpenStructDataSource extends BaseDataSource implements OpenStructDataSource {
+  private final ComplexFieldSpec _fieldSpec;
+  private final Map<String, DataSource> _perKeyDataSources;
+  @Nullable
+  private final DataSource _sparseDataSource;
+
+  public ImmutableOpenStructDataSource(ComplexFieldSpec fieldSpec, Map<String, DataSource> perKeyDataSources,
+      @Nullable DataSource sparseDataSource, DataSourceMetadata dataSourceMetadata,
+      ColumnIndexContainer indexContainer) {
+    super(dataSourceMetadata, indexContainer);
+    _fieldSpec = fieldSpec;
+    _perKeyDataSources = perKeyDataSources;
+    _sparseDataSource = sparseDataSource;
+  }
+
+  /// Convenience constructor for segment-load time. Synthesizes a minimal {@link DataSourceMetadata}
+  /// for the parent OPEN_STRUCT column (which has no on-disk presence of its own) and uses an empty
+  /// {@link ColumnIndexContainer} — all real readers live on the per-key data sources.
+  public ImmutableOpenStructDataSource(ComplexFieldSpec fieldSpec, Map<String, DataSource> perKeyDataSources,
+      @Nullable DataSource sparseDataSource, int numDocs) {
+    this(fieldSpec, perKeyDataSources, sparseDataSource,
+        new ImmutableOpenStructDataSourceMetadata(fieldSpec, numDocs),
+        new ColumnIndexContainer.FromMap.Builder().build());
+  }
+

Review Comment:
   The parent `ImmutableOpenStructDataSource` has an empty index container, so `getForwardIndex()`/`getDictionary()` return null on the parent. Per-key access is fine, but does `SELECT my_open_struct FROM table` work? MAP survives this via its `MapIndexReader`; the OPEN_STRUCT parent has nothing, so a projection reading the parent's forward index would NPE. Is whole-struct selection supported here, or deferred to the query-layer 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] OPEN_STRUCT storage layer — columnar two-tier dense/sparse index (PR 2b/4) [pinot]

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


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/openstruct/ImmutableOpenStructDataSource.java:
##########
@@ -0,0 +1,268 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.segment.local.segment.index.openstruct;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import javax.annotation.Nullable;
+import org.apache.pinot.segment.local.segment.index.datasource.BaseDataSource;
+import org.apache.pinot.segment.local.segment.index.datasource.ImmutableDataSource;
+import org.apache.pinot.segment.spi.Constants;
+import org.apache.pinot.segment.spi.datasource.DataSource;
+import org.apache.pinot.segment.spi.datasource.DataSourceMetadata;
+import org.apache.pinot.segment.spi.datasource.OpenStructDataSource;
+import org.apache.pinot.segment.spi.index.column.ColumnIndexContainer;
+import org.apache.pinot.segment.spi.index.reader.Dictionary;
+import org.apache.pinot.segment.spi.index.reader.ForwardIndexReader;
+import org.apache.pinot.segment.spi.index.reader.ForwardIndexReaderContext;
+import org.apache.pinot.segment.spi.index.reader.NullValueVectorReader;
+import org.apache.pinot.segment.spi.partition.PartitionFunction;
+import org.apache.pinot.spi.data.ComplexFieldSpec;
+import org.apache.pinot.spi.data.FieldSpec;
+import org.apache.pinot.spi.data.FieldSpec.DataType;
+import org.apache.pinot.spi.utils.JsonUtils;
+
+
+
+/// Per-key {@link DataSource} accessor for sealed (immutable) segments with an OPEN_STRUCT column.
+///
+/// Always columnar — there is no blob branch. Every key that was dense enough during segment
+/// creation gets its own materialized {@link DataSource} (forward index + optional inverted index /
+/// dictionary). Keys that did not meet the density threshold are stored in an optional sparse
+/// column; the sparse {@link DataSource} is returned for any unmaterialized key lookup.
+///
+/// Use [#isMaterialized(String)] and [#isFullyMaterialized()] together to choose
+/// the query execution path:
+/// - Materialized key → fast path via per-key DataSource (inverted/dictionary index available).
+/// - Not materialized + not fully materialized → fall back to the sparse DataSource.
+/// - Not materialized + fully materialized → key is definitively absent; short-circuit.
+///
+/// Thread-safety: immutable after construction; safe for concurrent reads.
+public class ImmutableOpenStructDataSource extends BaseDataSource implements OpenStructDataSource {
+  private final ComplexFieldSpec _fieldSpec;
+  private final Map<String, DataSource> _perKeyDataSources;
+  @Nullable
+  private final DataSource _sparseDataSource;
+
+  public ImmutableOpenStructDataSource(ComplexFieldSpec fieldSpec, Map<String, DataSource> perKeyDataSources,
+      @Nullable DataSource sparseDataSource, DataSourceMetadata dataSourceMetadata,
+      ColumnIndexContainer indexContainer) {
+    super(dataSourceMetadata, indexContainer);
+    _fieldSpec = fieldSpec;
+    _perKeyDataSources = perKeyDataSources;
+    _sparseDataSource = sparseDataSource;
+  }
+
+  /// Convenience constructor for segment-load time. Synthesizes a minimal {@link DataSourceMetadata}
+  /// for the parent OPEN_STRUCT column (which has no on-disk presence of its own) and uses an empty
+  /// {@link ColumnIndexContainer} — all real readers live on the per-key data sources.
+  public ImmutableOpenStructDataSource(ComplexFieldSpec fieldSpec, Map<String, DataSource> perKeyDataSources,
+      @Nullable DataSource sparseDataSource, int numDocs) {
+    this(fieldSpec, perKeyDataSources, sparseDataSource,
+        new ImmutableOpenStructDataSourceMetadata(fieldSpec, numDocs),
+        new ColumnIndexContainer.FromMap.Builder().build());
+  }
+
+  @Override
+  public ComplexFieldSpec getFieldSpec() {
+    return _fieldSpec;
+  }
+
+  @Override
+  @Nullable
+  public DataSource getDataSource(String key) {
+    DataSource ds = _perKeyDataSources.get(key);
+    return ds != null ? ds : _sparseDataSource;
+  }
+
+  @Override
+  public boolean isMaterialized(String key) {
+    return _perKeyDataSources.containsKey(key);
+  }
+
+  @Override
+  public boolean isFullyMaterialized() {
+    return _sparseDataSource == null;
+  }
+
+  /// Returns only the materialized (dense) key DataSources. Sparse keys are not included because
+  /// they share a single JSON column and have no individual DataSource. Use {@link #getMapValue}
+  /// to read the full key set (dense + sparse) for a given document.
+  @Override
+  public Map<String, DataSource> getDataSources() {
+    return _perKeyDataSources;
+  }
+
+  @Override
+  @Nullable
+  public DataSourceMetadata getDataSourceMetadata(String key) {
+    DataSource ds = _perKeyDataSources.get(key);
+    return ds != null ? ds.getDataSourceMetadata() : null;
+  }
+

Review Comment:
   `readValue()` calls `fwdReader.createContext()` (and `getDictionary()`) for every key on every docId, and `getMapValue` runs per-doc in `PinotSegmentRecordReader` (merge-rollup, refresh, compaction). That's O(docs × keys) context allocations on large segments. Could the per-key contexts be created once and reused across docs, or is this path not hot enough to matter for v1?



-- 
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] [WIP] OPEN_STRUCT storage layer — columnar two-tier dense/sparse index (PR 2/4) [pinot]

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


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/indexsegment/immutable/ImmutableSegmentImpl.java:
##########
@@ -98,13 +104,44 @@ public ImmutableSegmentImpl(
     _dataSources =
         new Object2ObjectOpenHashMap<>(segmentMetadata.getColumnMetadataMap().size());
 
+    Map<String, Map<String, DataSource>> openStructDenseChildren = new HashMap<>();

Review Comment:
   Use Map.of() for all



-- 
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] OPEN_STRUCT storage layer — columnar two-tier dense/sparse index (PR 2b/4) [pinot]

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


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/creator/impl/openstruct/OpenStructColumnSplitter.java:
##########
@@ -0,0 +1,538 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.segment.local.segment.creator.impl.openstruct;
+
+import com.google.common.base.Utf8;
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import javax.annotation.Nullable;
+import org.apache.commons.configuration2.PropertiesConfiguration;
+import org.apache.pinot.common.utils.DataSchema.ColumnDataType;
+import org.apache.pinot.segment.local.segment.creator.impl.BaseSegmentCreator;
+import org.apache.pinot.segment.local.segment.creator.impl.SegmentDictionaryCreator;
+import org.apache.pinot.segment.local.segment.creator.impl.fwd.SingleValueVarByteRawIndexCreator;
+import org.apache.pinot.segment.local.segment.creator.impl.nullvalue.NullValueVectorCreator;
+import org.apache.pinot.segment.local.segment.creator.impl.stats.AbstractColumnStatisticsCollector;
+import org.apache.pinot.segment.local.segment.creator.impl.stats.StatsCollectorUtil;
+import org.apache.pinot.segment.local.segment.index.dictionary.DictionaryIndexType;
+import org.apache.pinot.segment.local.segment.index.openstruct.OpenStructSupportedIndexes;
+import org.apache.pinot.segment.spi.V1Constants;
+import org.apache.pinot.segment.spi.compression.ChunkCompressionType;
+import org.apache.pinot.segment.spi.creator.IndexCreationContext;
+import org.apache.pinot.segment.spi.index.DictionaryIndexConfig;
+import org.apache.pinot.segment.spi.index.FieldIndexConfigs;
+import org.apache.pinot.segment.spi.index.FieldIndexConfigsUtil;
+import org.apache.pinot.segment.spi.index.ForwardIndexConfig;
+import org.apache.pinot.segment.spi.index.IndexCreator;
+import org.apache.pinot.segment.spi.index.IndexService;
+import org.apache.pinot.segment.spi.index.IndexType;
+import org.apache.pinot.segment.spi.index.StandardIndexes;
+import org.apache.pinot.segment.spi.index.creator.ColumnarOpenStructIndexCreator;
+import org.apache.pinot.spi.config.table.FieldConfig;
+import org.apache.pinot.spi.config.table.IndexConfig;
+import org.apache.pinot.spi.config.table.IndexingConfig;
+import org.apache.pinot.spi.config.table.OpenStructIndexConfig;
+import org.apache.pinot.spi.data.ComplexFieldSpec;
+import org.apache.pinot.spi.data.DimensionFieldSpec;
+import org.apache.pinot.spi.data.FieldSpec;
+import org.apache.pinot.spi.data.FieldSpec.DataType;
+import org.apache.pinot.spi.data.OpenStructNaming;
+import org.apache.pinot.spi.data.OpenStructTypeInference;
+import org.apache.pinot.spi.utils.JsonUtils;
+import org.apache.pinot.spi.utils.PinotDataType;
+import org.roaringbitmap.RoaringBitmap;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/// Splits an OPEN_STRUCT column into per-key materialized columns using standard Pinot index
+/// creators. Dense keys become independent virtual columns; remaining keys go into a single
+/// synthetic JSON column for sparse storage.
+///
+/// Lifecycle: instantiated by `BaseSegmentCreator` for OPEN_STRUCT columns. Receives
+/// per-doc `Map<String, Object>` values via [#add(Map, int)], accumulates in memory,
+/// then on [#seal()] writes per-key column files using standard creators.
+public class OpenStructColumnSplitter implements ColumnarOpenStructIndexCreator {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(OpenStructColumnSplitter.class);
+
+  private final File _indexDir;
+  private final String _columnName;
+  private final Map<String, FieldSpec> _childFieldSpecs;
+  private final OpenStructIndexConfig _config;
+  private final int _maxDenseKeys;
+
+  // Per-key accumulation
+  private final Map<String, RoaringBitmap> _presenceBitmaps = new HashMap<>();
+  private final Map<String, List<Object>> _values = new HashMap<>();
+  private final Map<String, DataType> _inferredTypes = new HashMap<>();
+  private int _numDocs;
+
+  // Resolved at seal time
+  @Nullable
+  private Set<String> _resolvedDenseKeys;
+  private final Map<String, PropertiesConfiguration> _materializedColumnMetadata = new LinkedHashMap<>();
+
+  public OpenStructColumnSplitter(File indexDir, String columnName, FieldSpec fieldSpec,
+      OpenStructIndexConfig config) {
+    _indexDir = indexDir;
+    _columnName = columnName;
+    _config = config;
+    _maxDenseKeys = config.getMaxDenseKeys();
+
+    Map<String, FieldSpec> childFieldSpecs = null;
+    if (fieldSpec instanceof ComplexFieldSpec) {
+      ComplexFieldSpec complexSpec = (ComplexFieldSpec) fieldSpec;
+      childFieldSpecs = complexSpec.getChildFieldSpecs();
+    }
+    _childFieldSpecs = childFieldSpecs != null ? new HashMap<>(childFieldSpecs) : new HashMap<>();
+  }
+
+  @Override
+  public void add(Object value, int docId)
+      throws IOException {
+    if (value instanceof Map) {
+      @SuppressWarnings("unchecked")
+      Map<String, Object> map = (Map<String, Object>) value;
+      addMap(map);
+    } else {
+      addMap(null);
+    }
+  }
+
+  @Override
+  public void add(Map<String, Object> openStructValue, int docId)
+      throws IOException {
+    addMap(openStructValue);
+  }
+
+  @Override
+  public void add(Object[] values, @Nullable int[] dictIds)
+      throws IOException {
+    throw new UnsupportedOperationException("OPEN_STRUCT index is single-value only");
+  }
+
+  /// Returns the resolved dense-key set after [#seal()] or [#classify()].
+  /// Returns an empty set before resolution.
+  public Set<String> getResolvedDenseKeys() {
+    return _resolvedDenseKeys != null ? Collections.unmodifiableSet(_resolvedDenseKeys) : Set.of();
+  }
+
+  /// Resolves dense vs sparse keys without writing any files. Exposed for testing and for callers
+  /// that need the classification independent of file output. [#seal()] calls this internally.
+  public Set<String> classify() {
+    if (_resolvedDenseKeys != null) {
+      return _resolvedDenseKeys;
+    }
+    if (_numDocs == 0 || _presenceBitmaps.isEmpty()) {
+      _resolvedDenseKeys = new LinkedHashSet<>();
+      return _resolvedDenseKeys;
+    }
+    List<String> allKeys = new ArrayList<>(_presenceBitmaps.keySet());
+    allKeys.sort((a, b) -> {
+      double fillA = (double) _presenceBitmaps.get(a).getCardinality() / _numDocs;
+      double fillB = (double) _presenceBitmaps.get(b).getCardinality() / _numDocs;
+      int cmp = Double.compare(fillB, fillA);
+      return cmp != 0 ? cmp : a.compareTo(b);
+    });
+
+    double minFillRate = _config.getDenseKeyMinFillRate();
+    _resolvedDenseKeys = new LinkedHashSet<>();
+
+    Set<String> configuredDenseKeys = _config.getDenseKeys();
+    for (String key : configuredDenseKeys) {
+      if (_presenceBitmaps.containsKey(key) && (_maxDenseKeys < 0 || _resolvedDenseKeys.size() < _maxDenseKeys)) {
+        _resolvedDenseKeys.add(key);
+      }
+    }
+
+    for (String key : allKeys) {
+      if (_resolvedDenseKeys.contains(key)) {
+        continue;
+      }
+      double fillRate = (double) _presenceBitmaps.get(key).getCardinality() / _numDocs;

Review Comment:
   A key's type is locked to the first value seen (`computeIfAbsent`/first-row inference) here and in `MutableOpenStructIndex.index`. A later value that fails coercion to that type is dropped — `bitmap.remove()` + `continue`, only a `LOGGER.warn`. For a *dense* key this is quiet correctness loss on heterogeneous JSON (`{"x": 5}` then `{"x": "hello"}`). Is that intended for dense keys too, and should we surface it via a metric/counter rather than just a log line?



-- 
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] OPEN_STRUCT storage layer — columnar two-tier dense/sparse index (PR 2b/4) [pinot]

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


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/creator/impl/SegmentColumnarIndexCreator.java:
##########
@@ -135,6 +147,34 @@ public void indexColumn(String columnName, @Nullable int[] sortedDocIds, IndexSe
     }

Review Comment:
   Agreed — a shared `CompositeDataSource` interface would be cleaner than per-type `instanceof` forks. I'd prefer to tackle it as a follow-up after the OPEN_STRUCT stack lands, since it would also touch the MAP code paths. 
   



-- 
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] OPEN_STRUCT storage layer — columnar two-tier dense/sparse index (PR 2b/4) [pinot]

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


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/creator/impl/BaseSegmentCreator.java:
##########
@@ -552,6 +553,31 @@ protected void writeMetadata()
           hasDictionary, dictionaryElementSize, fwdConfig.getEncodingType(), false);
     }
 
+    // OPEN_STRUCT splitters produce per-key materialized child columns (col$key, col$__sparse__) that
+    // are not in _columnStatisticsMap. Merge their pre-built metadata into the segment properties so
+    // each child appears as its own column at load time, and register them as dimensions so the V3
+    // converter and SegmentMetadataImpl discover their index files.
+    List<String> openStructChildColumns = new ArrayList<>();
+    for (ColumnIndexCreators columnIndexCreators : _colIndexes.values()) {
+      for (IndexCreator indexCreator : columnIndexCreators.getIndexCreators()) {
+        if (indexCreator instanceof ColumnarOpenStructIndexCreator) {
+          ColumnarOpenStructIndexCreator splitter = (ColumnarOpenStructIndexCreator) indexCreator;
+          for (Map.Entry<String, PropertiesConfiguration> childEntry
+              : splitter.getMaterializedColumnMetadata().entrySet()) {
+            String childCol = childEntry.getKey();
+            PropertiesConfiguration childProps = childEntry.getValue();
+            childProps.getKeys().forEachRemaining(key -> properties.setProperty(key, childProps.getProperty(key)));
+            openStructChildColumns.add(childCol);
+          }
+        }
+      }
+    }
+    if (!openStructChildColumns.isEmpty()) {
+      List<String> dimensions = new ArrayList<>(_config.getDimensions());
+      dimensions.addAll(openStructChildColumns);
+      properties.setProperty(DIMENSIONS, dimensions);

Review Comment:
   The materialized children are appended to DIMENSIONS because that's how the segment loader discovers columns to load — it iterates the dimensions list. If they're absent, the loader skips them and the segment loads without its OPEN_STRUCT child columns.
    
   Consumers that reconcile DIMENSIONS against the schema will see unknown columns, but this is already handled: `ImmutableSegmentLoader` has a 9-line exemption that skips columns whose `parentColumn` metadata points to a valid OPEN_STRUCT schema field. `ColumnMetadataImpl.isMaterializedChild()` is the signal that a column is synthetic.
   



-- 
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] [WIP] OPEN_STRUCT storage layer — columnar two-tier dense/sparse index (PR 2/4) [pinot]

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

   ## [Codecov](https://app.codecov.io/gh/apache/pinot/pull/18643?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :x: Patch coverage is `5.06799%` with `768 lines` in your changes missing coverage. Please review.
   :white_check_mark: Project coverage is 56.52%. Comparing base ([`30b3b31`](https://app.codecov.io/gh/apache/pinot/commit/30b3b312f8adf3aa823d70c5be74e26393d4b22e?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`aea6b80`](https://app.codecov.io/gh/apache/pinot/commit/aea6b8012063f87aa0a3816f4983a3d221b44426?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/18643?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [...ator/impl/openstruct/OpenStructColumnSplitter.java](https://app.codecov.io/gh/apache/pinot/pull/18643?src=pr&el=tree&filepath=pinot-segment-local%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpinot%2Fsegment%2Flocal%2Fsegment%2Fcreator%2Fimpl%2Fopenstruct%2FOpenStructColumnSplitter.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cGlub3Qtc2VnbWVudC1sb2NhbC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3Qvc2VnbWVudC9sb2NhbC9zZWdtZW50L2NyZWF0b3IvaW1wbC9vcGVuc3RydWN0L09wZW5TdHJ1Y3RDb2x1bW5TcGxpdHRlci5qYXZh) | 0.00% | [430 Missing :warning: ](https://app.codecov.io/gh/apache/pinot/pull/18643?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [...gment/index/openstruct/MutableOpenStructIndex.java](https://app.codecov.io/gh/apache/pinot/pull/18643?src=pr&el=tree&filepath=pinot-segment-local%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpinot%2Fsegment%2Flocal%2Fsegment%2Findex%2Fopenstruct%2FMutableOpenStructIndex.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cGlub3Qtc2VnbWVudC1sb2NhbC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3Qvc2VnbWVudC9sb2NhbC9zZWdtZW50L2luZGV4L29wZW5zdHJ1Y3QvTXV0YWJsZU9wZW5TdHJ1Y3RJbmRleC5qYXZh) | 0.00% | [104 Missing :warning: ](https://app.codecov.io/gh/apache/pinot/pull/18643?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [...cal/segment/index/openstruct/MutableKeyColumn.java](https://app.codecov.io/gh/apache/pinot/pull/18643?src=pr&el=tree&filepath=pinot-segment-local%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpinot%2Fsegment%2Flocal%2Fsegment%2Findex%2Fopenstruct%2FMutableKeyColumn.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cGlub3Qtc2VnbWVudC1sb2NhbC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3Qvc2VnbWVudC9sb2NhbC9zZWdtZW50L2luZGV4L29wZW5zdHJ1Y3QvTXV0YWJsZUtleUNvbHVtbi5qYXZh) | 0.00% | [40 Missing :warning: ](https://app.codecov.io/gh/apache/pinot/pull/18643?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [.../index/openstruct/MutableOpenStructDataSource.java](https://app.codecov.io/gh/apache/pinot/pull/18643?src=pr&el=tree&filepath=pinot-segment-local%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpinot%2Fsegment%2Flocal%2Fsegment%2Findex%2Fopenstruct%2FMutableOpenStructDataSource.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cGlub3Qtc2VnbWVudC1sb2NhbC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3Qvc2VnbWVudC9sb2NhbC9zZWdtZW50L2luZGV4L29wZW5zdHJ1Y3QvTXV0YWJsZU9wZW5TdHJ1Y3REYXRhU291cmNlLmphdmE=) | 0.00% | [40 Missing :warning: ](https://app.codecov.io/gh/apache/pinot/pull/18643?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [...ndex/openstruct/ImmutableOpenStructDataSource.java](https://app.codecov.io/gh/apache/pinot/pull/18643?src=pr&el=tree&filepath=pinot-segment-local%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpinot%2Fsegment%2Flocal%2Fsegment%2Findex%2Fopenstruct%2FImmutableOpenStructDataSource.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cGlub3Qtc2VnbWVudC1sb2NhbC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3Qvc2VnbWVudC9sb2NhbC9zZWdtZW50L2luZGV4L29wZW5zdHJ1Y3QvSW1tdXRhYmxlT3BlblN0cnVjdERhdGFTb3VyY2UuamF2YQ==) | 0.00% | [32 Missing :warning: ](https://app.codecov.io/gh/apache/pinot/pull/18643?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [...segment/index/openstruct/SimpleColumnMetadata.java](https://app.codecov.io/gh/apache/pinot/pull/18643?src=pr&el=tree&filepath=pinot-segment-local%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpinot%2Fsegment%2Flocal%2Fsegment%2Findex%2Fopenstruct%2FSimpleColumnMetadata.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cGlub3Qtc2VnbWVudC1sb2NhbC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3Qvc2VnbWVudC9sb2NhbC9zZWdtZW50L2luZGV4L29wZW5zdHJ1Y3QvU2ltcGxlQ29sdW1uTWV0YWRhdGEuamF2YQ==) | 0.00% | [26 Missing :warning: ](https://app.codecov.io/gh/apache/pinot/pull/18643?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [...local/indexsegment/mutable/MutableSegmentImpl.java](https://app.codecov.io/gh/apache/pinot/pull/18643?src=pr&el=tree&filepath=pinot-segment-local%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpinot%2Fsegment%2Flocal%2Findexsegment%2Fmutable%2FMutableSegmentImpl.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cGlub3Qtc2VnbWVudC1sb2NhbC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3Qvc2VnbWVudC9sb2NhbC9pbmRleHNlZ21lbnQvbXV0YWJsZS9NdXRhYmxlU2VnbWVudEltcGwuamF2YQ==) | 13.04% | [15 Missing and 5 partials :warning: ](https://app.codecov.io/gh/apache/pinot/pull/18643?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [...dex/openstruct/ImmutableOpenStructIndexReader.java](https://app.codecov.io/gh/apache/pinot/pull/18643?src=pr&el=tree&filepath=pinot-segment-local%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpinot%2Fsegment%2Flocal%2Fsegment%2Findex%2Fopenstruct%2FImmutableOpenStructIndexReader.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cGlub3Qtc2VnbWVudC1sb2NhbC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3Qvc2VnbWVudC9sb2NhbC9zZWdtZW50L2luZGV4L29wZW5zdHJ1Y3QvSW1tdXRhYmxlT3BlblN0cnVjdEluZGV4UmVhZGVyLmphdmE=) | 0.00% | [20 Missing :warning: ](https://app.codecov.io/gh/apache/pinot/pull/18643?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [...l/indexsegment/immutable/ImmutableSegmentImpl.java](https://app.codecov.io/gh/apache/pinot/pull/18643?src=pr&el=tree&filepath=pinot-segment-local%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpinot%2Fsegment%2Flocal%2Findexsegment%2Fimmutable%2FImmutableSegmentImpl.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cGlub3Qtc2VnbWVudC1sb2NhbC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3Qvc2VnbWVudC9sb2NhbC9pbmRleHNlZ21lbnQvaW1tdXRhYmxlL0ltbXV0YWJsZVNlZ21lbnRJbXBsLmphdmE=) | 25.00% | [16 Missing and 2 partials :warning: ](https://app.codecov.io/gh/apache/pinot/pull/18643?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [.../segment/index/openstruct/OpenStructIndexType.java](https://app.codecov.io/gh/apache/pinot/pull/18643?src=pr&el=tree&filepath=pinot-segment-local%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpinot%2Fsegment%2Flocal%2Fsegment%2Findex%2Fopenstruct%2FOpenStructIndexType.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cGlub3Qtc2VnbWVudC1sb2NhbC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3Qvc2VnbWVudC9sb2NhbC9zZWdtZW50L2luZGV4L29wZW5zdHJ1Y3QvT3BlblN0cnVjdEluZGV4VHlwZS5qYXZh) | 44.00% | [12 Missing and 2 partials :warning: ](https://app.codecov.io/gh/apache/pinot/pull/18643?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | ... and [5 more](https://app.codecov.io/gh/apache/pinot/pull/18643?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 (30b3b31) and HEAD (aea6b80). Click for more details.
   > 
   > <details><summary>HEAD has 12 uploads less than BASE</summary>
   >
   >| Flag | BASE (30b3b31) | HEAD (aea6b80) |
   >|------|------|------|
   >|java-21|4|1|
   >|unittests|2|1|
   >|temurin|4|1|
   >|integration|2|0|
   >|integration1|1|0|
   >|unittests2|1|0|
   >|custom-integration1|1|0|
   ></details>
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@             Coverage Diff              @@
   ##             master   #18643      +/-   ##
   ============================================
   - Coverage     64.41%   56.52%   -7.89%     
   + Complexity     1282        1    -1281     
   ============================================
     Files          3362     2585     -777     
     Lines        207907   150355   -57552     
     Branches      32463    24298    -8165     
   ============================================
   - Hits         133923    84988   -48935     
   + Misses        63221    58168    -5053     
   + Partials      10763     7199    -3564     
   ```
   
   | [Flag](https://app.codecov.io/gh/apache/pinot/pull/18643/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/18643/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/18643/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/18643/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/18643/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `56.52% <5.06%> (-7.89%)` | :arrow_down: |
   | [temurin](https://app.codecov.io/gh/apache/pinot/pull/18643/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `56.52% <5.06%> (-7.89%)` | :arrow_down: |
   | [unittests](https://app.codecov.io/gh/apache/pinot/pull/18643/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `56.52% <5.06%> (-7.89%)` | :arrow_down: |
   | [unittests1](https://app.codecov.io/gh/apache/pinot/pull/18643/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `56.52% <5.06%> (-0.29%)` | :arrow_down: |
   | [unittests2](https://app.codecov.io/gh/apache/pinot/pull/18643/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/18643?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>
   
   - :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