-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[common] Keep the selected variant schema when its evidence is gone #9532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -574,7 +574,11 @@ private DataType finalizeAdaptiveSchema( | |
| if (current != null && !(current instanceof VariantType)) { | ||
| combined = current; | ||
| } else if (previousSelected != null) { | ||
| combined = previousSelected; | ||
| // This node has no evidence in the current file. A previously selected schema | ||
| // is not evidence - its fields carry no counts - so it cannot be run through | ||
| // admission and retention again; carry it forward as it is, debiting the shared | ||
| // width budget for what it holds. | ||
| return retainSelectedSchema(previousSelected, maxFields); | ||
| } else { | ||
| return DataTypes.VARIANT(); | ||
| } | ||
|
|
@@ -654,6 +658,43 @@ private DataType finalizeAdaptiveSchema( | |
| return selectScalarType(combined, current, previousSelected); | ||
| } | ||
|
|
||
| /** | ||
| * Carries a previously selected schema forward for a node the current file has no evidence for. | ||
| * The selection is already final, so nothing is re-thresholded, but its nodes still consume the | ||
| * shared width budget. The entry unit for this node has already been spent by the caller, so | ||
| * this mirrors what finalizeAdaptiveSchema does from that point on: a child is entered only | ||
| * while budget remains, entering it spends one unit, and a child that exhausts the budget | ||
| * becomes VARIANT while its field or array container is still kept. | ||
| */ | ||
| private DataType retainSelectedSchema(DataType selected, MaxFields maxFields) { | ||
| if (selected instanceof RowType) { | ||
| List<DataField> fields = new ArrayList<>(); | ||
| for (DataField field : ((RowType) selected).getFields()) { | ||
| if (maxFields.remaining <= 0) { | ||
| break; | ||
| } | ||
| maxFields.remaining--; | ||
| DataType retained = | ||
| maxFields.remaining <= 0 | ||
| ? DataTypes.VARIANT() | ||
| : retainSelectedSchema(field.type(), maxFields); | ||
| fields.add(new DataField(fields.size(), field.name(), retained)); | ||
| } | ||
| return fields.isEmpty() ? DataTypes.VARIANT() : new RowType(fields); | ||
| } | ||
| if (selected instanceof ArrayType) { | ||
| maxFields.remaining--; | ||
| DataType element = | ||
| maxFields.remaining <= 0 | ||
| ? DataTypes.VARIANT() | ||
| : retainSelectedSchema( | ||
| ((ArrayType) selected).getElementType(), maxFields); | ||
| return new ArrayType(element); | ||
| } | ||
| maxFields.remaining--; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P2] Do not charge retained VARIANT leaves twice The caller already spends the node entry unit before A minimal boundary case reproduces the regression: use two top-level variant columns with |
||
| return selected; | ||
| } | ||
|
|
||
| private DataType selectScalarType( | ||
| DataType combined, DataType current, DataType previousSelected) { | ||
| if (current == null) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P2] Preserve the retained field/container at the last budget unit
This does not match the evidence-driven walk described above. When one unit remains, that walk enters the child, decrements the unit to zero, returns
VARIANT, and still adds the parentDataField; this helper decrements first and breaks before adding it. If it was the only field, line 678 then collapses the whole retainedRowTypeto the rootVARIANT. The Array branch similarly collapses the array instead of retainingARRAY<VARIANT>.I reproduced this with
maxSchemaWidth = 7and two Variant columns. Round 1 is(1, 5), round 2 is(1, {q:1}), and round 3 is({x:1,y:1}, null). Columnaconsumes five units, leaving exactly the root plus one field unit for retained columnb. The updated code returns an untyped root forband losesq; a focused assertion thatbstill containsqfails.Please mirror
finalizeAdaptiveSchemaat exhaustion: retain the row field/array container and downgrade the exhausted child toVARIANT, rather than breaking/returning before preserving the parent shape.