Skip to content

[core] Support array row fields in multivalue indexes - #11706

Open
XiaoHongbo-Hope wants to merge 32 commits into
apache:masterfrom
XiaoHongbo-Hope:feat/nested-multivalue-index
Open

XiaoHongbo-Hope wants to merge 32 commits into
apache:masterfrom
XiaoHongbo-Hope:feat/nested-multivalue-index

Conversation

@XiaoHongbo-Hope

@XiaoHongbo-Hope XiaoHongbo-Hope commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

Purpose

Support membership queries on selected scalar children of ARRAY<ROW> with multivalue indexes. Expose arrayField(index, child) and reuse existing array predicates; arrayContains("tags.id", value) is a shorthand.

Select children per column with fields.<column>.index-options, for example {"fields":"id,value"}. Initial builds and incremental refreshes use the same configuration. Separate predicates may match different array elements.

Retain row filtering and IndexedSplit v1. Build indexes with Flink; Spark rejects this index shape.

Validation

308 targeted Common/Core tests passed, covering membership, serialization, schema evolution, and full-text/vector filtering with mixed child-index coverage. Checkstyle, Spotless and git diff --check passed. Flink initial and incremental builds were also tested.

Seven regression cases fail on the previous head and pass with the fixes: primary-key child type widening and mixed child coverage in fast/full/detail searches.

@XiaoHongbo-Hope
XiaoHongbo-Hope marked this pull request as draft December 5, 2026 08:57
@XiaoHongbo-Hope
XiaoHongbo-Hope marked this pull request as ready for review December 5, 2026 15:47
@XiaoHongbo-Hope
XiaoHongbo-Hope marked this pull request as draft December 6, 2026 06:52
@XiaoHongbo-Hope
XiaoHongbo-Hope marked this pull request as ready for review December 6, 2026 12:21

@JingsongLi JingsongLi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reproduced three cases where matching rows are dropped on ce90fe82c4.

Optional.of(GlobalIndexResult.createEmpty()));
}
DataField child = ((RowType) elementType).getField(fieldId);
KeySerializer serializer = KeySerializer.create(child.type());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Check the indexed child type after primary-key schema evolution

On a primary-key table with deletion vectors enabled, set global-index.multivalue.index-columns=tags and multivalue-index.fields=tag_id. Write id=1 with tag_id=7 in tags ARRAY<ROW<tag_id INT>> and a second row with tag_id=9. Compact to build the index, then use SchemaChange.updateColumnType to widen tags.element.tag_id to BIGINT without rewriting the data files.

arrayFieldContains(1, "tag_id", 7L) returned [] with the existing index and [1] with global-index.enabled=false. The child ID survives widening, so the reader uses the current 8-byte key encoding against postings written with the old 4-byte encoding. Please validate the child type against the build schema and fall back to reading the affected rows until the index is rebuilt.

@Override
public CompletableFuture<Optional<GlobalIndexResult>> visitArrayField(
FieldRef fieldRef, int fieldId, LeafFunction function, List<Object> literals) {
return unionAsync(reader -> reader.visitArrayField(fieldRef, fieldId, function, literals));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Preserve ranked matches from ranges that index the requested child

On a Data Evolution table, write two documents that match the same full-text query. Give both a tags element with key=1 and value=7. Build a full-text index over both rows and multivalue shards for row IDs 0 and 1 with multivalue-index.fields=key and key,value, respectively.

With scalar-index.prefilter.search-mode=fast, a full-text search filtered by arrayFieldContains(2, "value", 7) returned [], even though row ID 1 is fully covered and should be returned. With full or detail and the default global-index.filter.refine-from-data=false, the conjunction of arrayFieldContains(2, "key", 1) and arrayFieldContains(2, "value", 7) also returned []. The expected row IDs were [0, 1].

The first shard returns Optional.empty() for value, so unionAsync discards the exact result from the second shard. Coverage tracked by the top-level tags column also hides the first shard's value gap from full and detail. Please track coverage by child and row-ID range so the search can keep exact matches and apply the configured fallback to uncovered rows.

RowType element = (RowType) ((ArrayType) field.type()).getElementType();
DataField child = element.getField(fieldName);
DataType childType = child.type();
List<Object> normalized = new ArrayList<>(literals.size());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Normalize Decimal literals from the generic Transform overloads

On a Data Evolution table with global-index.query-in-reader.enabled=true, store 1.20 in an indexed DECIMAL(10,2) array child on the row with id=7. Build the predicate through arrayContains(Transform, Object) with an ArrayFieldTransform and Decimal.fromBigDecimal(new BigDecimal("1.200"), 10, 3).

The original IndexQuerySplit returned [7]. Serializing and deserializing only that split with InstantiationUtil returned [] while using the same reader filter. The generic overload bypasses the normalization here, so the literal's unscaled value of 1200 is read at the child field's scale 2 and becomes 12.00. The index lookup prunes the matching row before the reader can filter it.

Please normalize membership literals in the shared predicate construction path and add a split round-trip test through the generic overload.

@JingsongLi

Copy link
Copy Markdown
Contributor

Reuse the existing array predicates. I’d expose the child projection through a builder method such as arrayField(int arrayIndex, String childName) and compose it with the existing Transform overloads.

Transform tagIds = predicates.arrayField(tagsFieldIndex, "tag_id");
Predicate filter = predicates.arrayContains(tagIds, 123L);

arraysOverlap and arrayContainsAll can take the same projection. Any arrayField* convenience methods can delegate to those overloads, with literal normalization handled in the shared predicate construction path. This matches the shape of Spark SQL’s array_contains(tags.tag_id, 123L), where tags.tag_id projects the child values before the ordinary membership test. Spark’s array-of-struct projection, Spark’s array_contains.

Make indexed child selection column-scoped. I’d make fields.<column>.index-options the sole public configuration for choosing the indexed children.

ALTER TABLE db.my_table SET (
    'fields.tags.index-options' = '{"fields":"tag_id,tag_value"}',
    'fields.actors.index-options' = '{"fields":"role"}'
);

The sorted writer already uses CoreOptions.globalIndexOptions to resolve options for the indexed column. Keeping the child list there lets each array column define its own index and gives initial builds and incremental refreshes the same configuration. MongoDB provides a comparable example of selecting a specific array child with a multikey index, such as createIndex({ "tags.tag_id": 1 }). MongoDB’s multikey index on an embedded array field.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants