geruh commented on code in PR #2861: URL: https://github.com/apache/iceberg-python/pull/2861#discussion_r2648883092
########## pyiceberg/catalog/rest/scan_planning.py: ########## @@ -0,0 +1,208 @@ +# 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. +from __future__ import annotations + +from datetime import date, datetime, time +from decimal import Decimal +from typing import Annotated, Generic, Literal, TypeAlias, TypeVar +from uuid import UUID + +from pydantic import Field, model_validator + +from pyiceberg.catalog.rest.response import ErrorResponseMessage +from pyiceberg.expressions import BooleanExpression +from pyiceberg.manifest import FileFormat +from pyiceberg.typedef import IcebergBaseModel + +# Primitive types that can appear in partition values and bounds +PrimitiveTypeValue: TypeAlias = bool | int | float | str | Decimal | UUID | date | time | datetime | bytes + +V = TypeVar("V") + + +class KeyValueMap(IcebergBaseModel, Generic[V]): + """Map serialized as parallel key/value arrays for column statistics.""" + + keys: list[int] = Field(default_factory=list) + values: list[V] = Field(default_factory=list) + + @model_validator(mode="after") + def _validate_lengths_match(self) -> KeyValueMap[V]: + if len(self.keys) != len(self.values): + raise ValueError(f"keys and values must have same length: {len(self.keys)} != {len(self.values)}") + return self + + def to_dict(self) -> dict[int, V]: + """Convert to dictionary mapping field ID to value.""" + return dict(zip(self.keys, self.values, strict=True)) + + +class CountMap(KeyValueMap[int]): + """Map of field IDs to counts.""" + + +class ValueMap(KeyValueMap[PrimitiveTypeValue]): + """Map of field IDs to primitive values (for lower/upper bounds).""" + + +class StorageCredential(IcebergBaseModel): + """Storage credential for accessing content files.""" + + prefix: str = Field(description="Storage location prefix this credential applies to") + config: dict[str, str] = Field(default_factory=dict) + + +class RESTContentFile(IcebergBaseModel): + """Base model for data and delete files from REST API.""" + + spec_id: int = Field(alias="spec-id") + partition: list[PrimitiveTypeValue] = Field(default_factory=list) + content: Literal["data", "position-deletes", "equality-deletes"] + file_path: str = Field(alias="file-path") + file_format: FileFormat = Field(alias="file-format") + file_size_in_bytes: int = Field(alias="file-size-in-bytes") + record_count: int = Field(alias="record-count") + key_metadata: str | None = Field(alias="key-metadata", default=None) + split_offsets: list[int] | None = Field(alias="split-offsets", default=None) + sort_order_id: int | None = Field(alias="sort-order-id", default=None) + + +class RESTDataFile(RESTContentFile): + """Data file from REST API.""" + + content: Literal["data"] = Field(default="data") + first_row_id: int | None = Field(alias="first-row-id", default=None) + column_sizes: CountMap | None = Field(alias="column-sizes", default=None) + value_counts: CountMap | None = Field(alias="value-counts", default=None) + null_value_counts: CountMap | None = Field(alias="null-value-counts", default=None) + nan_value_counts: CountMap | None = Field(alias="nan-value-counts", default=None) + lower_bounds: ValueMap | None = Field(alias="lower-bounds", default=None) + upper_bounds: ValueMap | None = Field(alias="upper-bounds", default=None) + + +class RESTPositionDeleteFile(RESTContentFile): + """Position delete file from REST API.""" + + content: Literal["position-deletes"] = Field(default="position-deletes") + referenced_data_file: str | None = Field(alias="referenced-data-file", default=None) Review Comment: let's omit this for now, as its redundant with the `delete-file-references`. -- 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]
