Skip to content

DayTransform failure for downcasted timestamp column #1619

Closed as not planned
Closed as not planned

Description

@b-phi

Apache Iceberg version

0.8.1 (latest release)

Please describe the bug 🐞

Given a simple schema with a DayTransform over a Timestamp column, an error is thrown during write related to mixing downcasted and non-downcasted timestamps.

This would also be resolved with support for nanosecond timestamp types.

schema = Schema(
    NestedField(field_id=1, name='timestamp', field_type=TimestampType(), required=False),
)
partition_spec = PartitionSpec(
    PartitionField(source_id=1, field_id=1001, transform=DayTransform(), name='date'),
)

schema = pa.schema([pa.field('timestamp', pa.timestamp('ns'))])
data = pa.Table.from_pydict({'timestamp': [1]}, schema=schema)
table.append(data)

.local/lib/python3.10/site-packages/pyiceberg/table/init.py:984: in append
tx.append(df=df, snapshot_properties=snapshot_properties)
.local/lib/python3.10/site-packages/pyiceberg/table/init.py:417: in append
for data_file in data_files:
.local/lib/python3.10/site-packages/pyiceberg/io/pyarrow.py:2636: in _dataframe_to_data_files
partitions = _determine_partitions(spec=table_metadata.spec(), schema=table_metadata.schema(), arrow_table=df)
.local/lib/python3.10/site-packages/pyiceberg/io/pyarrow.py:2715: in _determine_partitions
partition_values_table = pa.table({
.local/lib/python3.10/site-packages/pyiceberg/io/pyarrow.py:2716: in
str(partition.field_id): partition.transform.pyarrow_transform(field.field_type)(arrow_table[field.name])
.local/lib/python3.10/site-packages/pyiceberg/transforms.py:560: in
return lambda v: pc.days_between(pa.scalar(epoch), v) if v is not None else None
.local/lib/python3.10/site-packages/pyarrow/compute.py:247: in wrapper
return func.call(args, None, memory_pool)
pyarrow/_compute.pyx:393: in pyarrow._compute.Function.call
???
pyarrow/error.pxi:155: in pyarrow.lib.pyarrow_internal_check_status
???
E pyarrow.lib.ArrowNotImplementedError: Function 'days_between' has no kernel matching input types (timestamp[us], timestamp[ns])
pyarrow/error.pxi:92: ArrowNotImplementedError

Willingness to contribute

  • I can contribute a fix for this bug independently
  • I would be willing to contribute a fix for this bug with guidance from the Iceberg community
  • I cannot contribute a fix for this bug at this time

Activity

  1. kevinjqliu commented on Feb 8, 2025

    @kevinjqliu
    Contributor

    Currently Iceberg does not have nanosecond support
    https://py.iceberg.apache.org/configuration/#nanoseconds-support

    To compensate, we can automatically downcast to microsecond on write by setting the config described in the doc

  2. b-phi commented on Feb 10, 2025

    @b-phi
    ContributorAuthor

    Thanks Kevin, I should have been more clear. I am using the downcasting functionality, which works great for unpartitioned tables. Even an IdentityTransform() partition over a downcasted timestamp column works fine, but any of the time truncations like DayTransform or YearTransform result in the arrow kernel error above.

    A table with the partition spec will handle downcasting timestamps correctly on write

    partition_spec = PartitionSpec(
        PartitionField(source_id=1, field_id=1001, transform=IdentityTransform(), name='ts'),
    )

    But this partition spec throws the error

    partition_spec = PartitionSpec(
        PartitionField(source_id=1, field_id=1001, transform=DayTransform(), name='date'),
    )

    The write code

    os.environ['PYICEBERG_DOWNCAST_NS_TIMESTAMP_TO_US_ON_WRITE'] = '1'
    schema = pa.schema([pa.field('timestamp', pa.timestamp('ns'))])
    data = pa.Table.from_pydict({'timestamp': [1]}, schema=schema)
    table.append(data)
  3. codrut20 commented on Apr 11, 2025

    @codrut20

    I had the same issue with all types of Time partitions and data with ns unit. Looking at the code it seems that the downcast property is used when checking then schema and when writing the table data, but not when determining the partitions, so I get errors like :

    Function 'years_between' has no kernel matching input types (timestamp[us], timestamp[ns])

  4. jmontalvo94 commented on Jul 16, 2025

    @jmontalvo94

    I have the exact same error, trying to append a table with timestamp[ns] into an Iceberg table with timestamp (so, trying to use the automatic downcast) but it fails since the PartitionSpec also includes a DayTransform() as OP suggested.

    # .pyiceberg.yaml
    # ...
    downcast-ns-timestamp-to-us-on-write: true
    
    Iceberg does not yet support 'ns' timestamp precision. Downcasting to 'us'.
    Function 'days_between' has no kernel matching input types (timestamp[us], timestamp[ns])
    
  5. github-actions commented on Jan 14, 2026

    @github-actions

    This issue has been automatically marked as stale because it has been open for 180 days with no activity. It will be closed in next 14 days if no further activity occurs. To permanently prevent this issue from being considered stale, add the label 'not-stale', but commenting on the issue is preferred when possible.

  6. github-actions commented on Jan 28, 2026

    @github-actions

    This issue has been closed because it has not received any activity in the last 14 days since being marked as 'stale'

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions