kszucs commented on code in PR #2375: URL: https://github.com/apache/iceberg-rust/pull/2375#discussion_r3220102210
########## bindings/python/tests/test_hf_and_cdc.py: ########## @@ -0,0 +1,211 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""Tests for HuggingFace Hub URI support and CDC (content-defined chunking) options. + +CDC options are standard Iceberg table properties and work in both Rust and PyIceberg +automatically — no special API is required beyond setting string properties. + +HF credentials are passed as file_io_properties to IcebergDataFusionTable. +Tests requiring a real HF token are skipped when HF_OPENDAL_TOKEN is not set. +""" + +import os +import pytest +import pyarrow as pa +import datafusion +from packaging.version import Version +from pyiceberg.catalog import load_catalog + +requires_datafusion_53 = pytest.mark.skipif( + Version(datafusion.__version__) < Version("53.0.0"), + reason="IcebergDataFusionTable requires datafusion>=53 for FFI compatibility", +) + +# Property name constants — same strings as the Rust TableProperties constants. +HF_TOKEN = "hf.token" +HF_ENDPOINT = "hf.endpoint" +HF_REVISION = "hf.revision" + +PARQUET_CDC_MIN_CHUNK_SIZE = "parquet.cdc.min_chunk_size" +PARQUET_CDC_MAX_CHUNK_SIZE = "parquet.cdc.max_chunk_size" +PARQUET_CDC_NORM_LEVEL = "parquet.cdc.norm_level" + + +# --------------------------------------------------------------------------- +# CDC tests — run without any external credentials +# --------------------------------------------------------------------------- + + [email protected](scope="module") +def local_catalog(tmp_path_factory: pytest.TempPathFactory): + warehouse = tmp_path_factory.mktemp("cdc_warehouse") + return load_catalog( + "default", + **{ + "uri": f"sqlite:///{warehouse}/pyiceberg_catalog.db", + "warehouse": f"file://{warehouse}", + }, + ) + + [email protected](scope="module") +def sample_table() -> pa.Table: + return pa.table( + { + "id": pa.array(list(range(1000)), type=pa.int32()), + "payload": pa.array( + [f"row-{i:06d}" for i in range(1000)], type=pa.large_utf8() + ), + } + ) + + +def test_cdc_table_properties_are_persisted(local_catalog, sample_table): + """Table properties with CDC options are stored and returned as-is.""" + local_catalog.create_namespace_if_not_exists("cdc_ns") + + tbl = local_catalog.create_table_if_not_exists( + "cdc_ns.cdc_persist", + schema=sample_table.schema, + properties={ + PARQUET_CDC_MIN_CHUNK_SIZE: "131072", Review Comment: These are the defaults, should test with non-defaults. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
