Skip to content

fix(arrow): project date columns promoted to timestamp - #3485

Open
ump45nose wants to merge 3 commits into
apache:mainfrom
ump45nose:fix/date-to-timestamp-projection
Open

ump45nose wants to merge 3 commits into
apache:mainfrom
ump45nose:fix/date-to-timestamp-projection

Conversation

@ump45nose

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

What changes are included in this PR?

type_promotion_is_valid in the field-id projection path had no arm for the v3 date -> timestamp / timestamp_ns promotions. When another column was projected in the same read, the date leaf was left out of the projection mask, so the column came back as NULL (or failed with Missing required field when required). Projecting it alone happened to work only because the mask fell back to ProjectionMask::all().

This adds the two promotions to the match, so the leaf is read and RecordBatchTransformer casts it as it already does in the single-column case.

The out-of-range case from the issue (a date that overflows timestamp_ns reads as NULL instead of failing) comes from the safe cast in the Promote path and is not addressed here.

Are these changes tested?

Yes. A new test in arrow::reader::projection writes a file with two date columns and an int column and reads it through a schema that promotes them to optional timestamp and required timestamp_ns, projecting all three. It fails on main (the required column is reported missing) and passes with the change. The iceberg lib tests and clippy pass locally.

AI Disclosure

I used an AI assistant to help locate the cause and write the test, then reviewed and ran it myself. The fix follows the one suggested in the issue. One thing worth a look: the match does not check the table's format version, same as the existing int/float/decimal arms, so a pre-v3 table with this promotion would also be read rather than rejected.

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

The fix is right, and I confirmed the new test fails on main.

Two things, both outside the change itself:

  • Java doesn't allow this promotion yet. TypeUtil.isPromotionAllowed in iceberg-java main has only int→long, float→double and decimal precision. So this follows the v3 spec table rather than Java.
  • On the out-of-range case you mention: the spec says those values "must result in a runtime failure". I tried 200_000 days (year 2517) through this test. In the required timestamp_ns column the read fails, but with Column 'e' is declared as non-nullable but contains null values. That's a failure, but nothing points at the date. In an optional column it would read as NULL. Both come from the safe cast. Maybe worth a line in #3404 for whoever picks that up.

Copilot AI balanced review requested due to automatic review settings November 11, 2026 13:40

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

3 open issues
What changed in this PR

Fixes Iceberg Arrow projection masking when promoting date columns to timestamp / timestamp_ns so promoted leaves aren’t dropped when projecting alongside other columns (closes #3404).

Changes:

  • Add missing date -> timestamp|timestamp_ns arms to type_promotion_is_valid in the field-id projection path.
  • Add a regression test that reads a Parquet file with two date columns promoted to timestamp/timestamp_ns while projecting an additional unpromoted column.
File Description
crates/​iceberg/​src/​arrow/​reader/​projection.rs Extends promotion validation for date→timestamp* and adds a regression test covering multi-column projections.

Review effort: Lite

Comment on lines +3142 to +3146
let tasks = Box::pin(futures::stream::iter(
vec![Ok(FileScanTask::builder()
.with_file_size_in_bytes(std::fs::metadata(&file_path).unwrap().len())
.with_start(0)
.with_length(0)
Comment on lines +3117 to +3126
let micros: Vec<i64> = days
.iter()
.map(|d| i64::from(*d) * 86_400_000_000)
.collect();
let expected = RecordBatch::try_new(
Arc::new(schema_to_arrow_schema(&new_schema).unwrap()),
vec![
Arc::new(TimestampMicrosecondArray::from(micros.clone())),
Arc::new(TimestampNanosecondArray::from(
micros.iter().map(|us| us * 1000).collect::<Vec<_>>(),
Comment on lines +3133 to +3136
let tmp_dir = TempDir::new().unwrap();
let file_path = format!("{}/date.parquet", tmp_dir.path().to_str().unwrap());
let mut writer =
ArrowWriter::try_new(File::create(&file_path).unwrap(), old_batch.schema(), None)
The promoted-date regression test built its `FileScanTask` with
`length(0)` while reporting the real `file_size_in_bytes`, so a reader that
trusts `length` would see an empty task; take both from the file's metadata.
Route the day/microsecond/nanosecond conversions through named constants and
build the temporary path with `Path::join` instead of string formatting, so the
test stays readable and platform independent.

Signed-off-by: yuwk <[email protected]>
@ump45nose

Copy link
Copy Markdown
Contributor Author

The three test findings are addressed in fbe43f37.

  • FileScanTask now takes both file_size_in_bytes and length from the written file's metadata; length(0) described an empty task while the size field named the whole file.
  • The day/microsecond/nanosecond conversions go through MICROS_PER_DAY and NANOS_PER_MICRO in the test module instead of literals.
  • The temporary file path is built with Path::join and converted once for the String field, instead of format!("{}/…") on a to_str().unwrap().

Local: cargo test -p iceberg --lib arrow::reader::projection → 23 passed, cargo fmt -p iceberg -- --check clean, cargo clippy -p iceberg --all-targets -- -D warnings clean.

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

Thanks @ump45nose, all three are addressed in fbe43f3 and the arrow tests pass. LGTM.

This branch has not been deployed

No deployments
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.

Date-to-timestamp promoted column reads as NULL when another column is projected

3 participants