Skip to content

fix(spec): format dropped-source integer partition values - #3432

Merged
laskoviymishka merged 8 commits into
apache:mainfrom
jopdorp:fix-dropped-partition-format
Oct 30, 2026
Merged

laskoviymishka merged 8 commits into
apache:mainfrom
jopdorp:fix-dropped-partition-format

Conversation

@jopdorp

@jopdorp jopdorp commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Addresses #3381.

What changes are included in this PR?

We format partition values whose source column has been dropped instead of panicking, for the identity and truncate cases in the issue and for uuid and decimal. Decimal prints the unscaled value, since the scale only lived on the dropped column.

Are these changes tested?

the regression panics without the fix. the library suite, fmt and clippy pass.

AI Disclosure

The implementation and regression test were generated with an AI coding assistant and reviewed by a second coding assistant. The regression reproduces the panic without the fix; the library suite, fmt and clippy pass.

@JeonDaehong

JeonDaehong commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for picking this up!

I ran the same setup on this branch with other source types. int/long/date/bool/binary now work, but identity(decimal), truncate(decimal) and identity(uuid) still hit the unreachable!() in Display for Datum (Int128/UInt128 with Unknown type).

I missed these in #3381, sorry. uuid could reuse the Uuid formatting; decimal is trickier since Unknown loses the scale. Would a non-panicking fallback arm make sense here?

@JeonDaehong

Copy link
Copy Markdown
Contributor

Following up on the decimal/uuid part, I checked what Java writes here (iceberg-api, JDK 21). Once the source is dropped, Java sees UnknownType and just uses value.toString():

source present source dropped
identity(decimal(9,2)) 1.23 p=1.23 p=1.23
truncate[10](decimal(9,2)) 1.20 p=1.20 p=1.20
identity(uuid) p=f79c3e09-… p=f79c3e09-…
identity(date) 19000 p=2022-01-08 p=19000

uuid should be easy to match by formatting the UInt128 as a UUID. decimal is the tricky one: BigDecimal keeps its scale, but on our side only the unscaled Int128 is left, so any fallback would write p=123 where Java writes p=1.23. date already gives 19000 on this branch, same as Java.

@jopdorp

jopdorp commented Oct 16, 2026

Copy link
Copy Markdown
Contributor Author

@JeonDaehong thanks for checking these and for the Java table, that helped a lot.

We pushed b765bbf so uuid and decimal no longer panic. uuid prints like Java (p=f79c3e09-…). decimal prints the unscaled value, so p=123 where Java writes p=1.23, because the scale lives on the dropped source type and the partition value only carries the unscaled Int128. We added both cases to the existing dropped-source test. Happy to adjust if you'd rather handle decimal differently.

@JeonDaehong JeonDaehong 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.

Checked b765bbf: it merges cleanly with main, and the spec::partition and spec::values tests pass (167). No more unreachable!() for dropped decimal/uuid sources, and uuid matches Java.

Printing the unscaled decimal is fine with me. The scale is not lost everywhere, though: a manifest is decoded with the schema stored in it, where the source still exists, so the value arrives as Int128 and only the path formatting (which uses the current schema) has no scale. Matching Java exactly would mean formatting with the manifest's schema, which is a separate change. LGTM.

@jopdorp

jopdorp commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

@laskoviymishka CI is green and JeonDaehong approved this. Could you take a look and merge if it’s ready?

@laskoviymishka

Copy link
Copy Markdown
Contributor

@jopdorp - let's me get one more pass, and i think there is new conflict. Will try to make it on a weekend

@laskoviymishka
laskoviymishka self-requested a review October 23, 2026 18:03

@laskoviymishka laskoviymishka 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.

Thanks @JeonDaehong for the Java table. With a dropped source, int, long and uuid now print what Java and Go print. Decimal is the one I'd like changed before merge, and I'm taking @jopdorp up on the offer to handle it differently. Java's formatter and Go both keep the scale, so p=123 would leave Rust as the only client writing that value. Details inline. This also needs a rebase on main for the new conflict.

write!(f, "{}", decimal_from_i128_with_scale(*val, *scale))
}
// The scale lives on the dropped source type, so only the unscaled value is left.
(PrimitiveType::Unknown, PrimitiveLiteral::Int128(val)) => write!(f, "{val}"),

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.

Could we format decimal with a schema that still has the source, or leave the decimal arm out of this PR? Java's toHumanString falls back to value.toString(), which keeps the BigDecimal scale. Go's manifest reader keeps the Avro scale in DecimalLiteral and prints it scaled. Both give p=1.23 where this writes p=123.

To me, @JeonDaehong's manifest-schema point is the fix, not a follow-up. PartitionSpec has no schema, but a caller holding the manifest can pass ManifestMetadata::schema(). Int, long and uuid don't need to wait on this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Took the first option: the commit path now formats deleted files with the newest schema that still has their partition sources, so a dropped decimal source prints p=1.23 like Java and Go, in 1401292. The unscaled arm stays only so a direct partition_to_path call with a schema missing the source does not panic, happy to drop it if you would rather.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

One more in 00309a0: with the older schema picked, a sibling source promoted int to long could pair a long literal with an int type and hit the unreachable!(), so the int and long arms now print across the promotion either way. The test covers it.

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.

thx, resolved

@jopdorp

jopdorp commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

@laskoviymishka decimal keeps its scale now and main is merged in for the conflict. Ready for your pass.

@laskoviymishka laskoviymishka 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.

Thanks @jopdorp, picking the newest schema that still has the sources keeps the decimal scale, and the widened int/long arms also fix the (Long, Int) panic main hits today for files written before an int→long promotion.

One ask on the test, then this is good to merge.

scale: 2,
}),
);
let x = NestedField::required(1, "x", Type::Primitive(PrimitiveType::Int));

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.

Could this build the history in the order a real table would? x is long in the minimal table, so with_d declaring it int is a long→int demotion Iceberg doesn't allow, and the test only exercises (Int, Long). The realistic case is a file written before the promotion: {d, x: int} → promote x to long → drop d, with Literal::int(5) for x, which hits (Long, Int). The same d=1.23/x=5 assertion should hold.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Rebuilt the test in 5510b0b the way a real table gets there: {d: decimal(9,2), x: int} under the original spec, then x promoted to long, then d dropped, with the deleted file carrying Literal::int(5) so it hits (Long, Int). Still expects partitions.d=1.23/x=5.

// A dropped source column keeps its type, such as a decimal's scale, only in an
// older schema.
let schema = table_metadata
.schemas_iter()

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.

nit: this only depends on the spec, so it could be resolved once per partition_spec_id instead of per removed file. A large delete rescans every schema for every file.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point, 1c126a2 resolves the schema once per partition_spec_id and reuses it for every removed file of that spec.

@jopdorp

jopdorp commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

@laskoviymishka both in, and main merged again (the snapshot module moved, so the change now lives in transaction/snapshot/mod.rs).

@laskoviymishka
laskoviymishka added this pull request to the merge queue Oct 30, 2026
Merged via the queue into apache:main with commit 1ee5c72 Oct 30, 2026
24 checks passed
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.

3 participants