badalprasadsingh commented on code in PR #1214: URL: https://github.com/apache/iceberg-go/pull/1214#discussion_r3528867487
########## table/data_file_meta.go: ########## @@ -0,0 +1,349 @@ +// 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. + +package table + +import ( + "errors" + "fmt" + + "github.com/apache/arrow-go/v18/parquet/metadata" + "github.com/apache/iceberg-go" + tblutils "github.com/apache/iceberg-go/table/internal" +) + +// DataFileArgs collects everything needed to compute a fully populated +// [iceberg.DataFile] (data, equality-delete, or positional-delete) from +// a file's in-memory, format-specific metadata object without performing +// any filesystem reads. +type DataFileArgs struct { + // Schema is the Iceberg schema the file's contents conform to. + // Per-column statistics are matched by leaf-column path: each file + // column's dotted path MUST equal the path derived from this schema's + // field names. Embedded field-id metadata in the file (e.g. the Parquet + // "PARQUET:field_id" key) is not consulted, so a column renamed relative + // to the file will not resolve. + Schema *iceberg.Schema + + // Spec is the partition spec the resulting DataFile is bound to — + // typically tbl.Spec(). The zero value [iceberg.PartitionSpec]{} is + // equivalent to *iceberg.UnpartitionedSpec and is accepted for + // unpartitioned tables. + Spec iceberg.PartitionSpec + + // Format identifies the on-disk file format and selects the internal + // FileFormat implementation used to extract per-column statistics from + // Metadata. It must match the concrete type of Metadata: the only supported + // combination today is [iceberg.ParquetFile] with a *metadata.FileMetaData. + Format iceberg.FileFormat + + // Metadata is the format-specific, in-memory file metadata object produced + // by the external writer. + // + // Today only Format == [iceberg.ParquetFile] with *metadata.FileMetaData is supported + Metadata any + + // FilePath is the fully qualified location the file bytes were + // written to (the same path that will be recorded in the manifest entry). + FilePath string + + // FileSize is the byte length of the object at FilePath. Must be + // greater than zero. + FileSize int64 + + // Content selects which manifest-entry kind to produce — one of + // [iceberg.EntryContentData], [iceberg.EntryContentEqDeletes] or + // [iceberg.EntryContentPosDeletes]. + Content iceberg.ManifestEntryContent + + // PartitionValues maps spec field ID → partition value. Every spec field + // must be present; leave nil/empty for unpartitioned tables, where any + // supplied value is rejected. + // + // Values must already be the transform results in the expected Go types. + // A nil value is treated as "not supplied" and is inferred from the file's + // column statistics; void-transform fields therefore should be nil (the + // void transform always yields null), though this is not enforced. + // + // This helper validates only that the supplied field IDs match the spec + // (every field present, no stray IDs); it does not coerce or type-check + // the values themselves. Callers are responsible for supplying values of + // the correct type. + PartitionValues map[int]any + + // SortOrderID is the sort-order ID recorded on the manifest entry, + // typically tbl.SortOrder().OrderID(). Zero means "unsorted". + SortOrderID int + + // Properties are consulted only for write-side metrics-mode keys + // (write.metadata.metrics.default and per-column + // write.metadata.metrics.column.<name> overrides) that decide + // which columns get full vs truncated vs no statistics. Pass + // tbl.Properties() for table-default behavior; nil is safe. + Properties iceberg.Properties + + // EqualityFieldIDs lists the schema field IDs that an equality + // delete file matches on. Required when + // Content == [iceberg.EntryContentEqDeletes] and MUST be empty + // for every other Content value. Every listed ID must be present in Schema. + EqualityFieldIDs []int + + // FirstRowID sets the data file's first_row_id (row lineage, v3+). + // + // Leave it nil for newly-written files — row IDs are assigned by inheritance at commit; + // set only when re-registering an existing file whose first_row_id was previously assigned; + // always nil for delete files. + FirstRowID *int64 + + // ReferencedDataFile, when non-nil, records the single data file that a Review Comment: Done. 1. `FirstRowID` is now REQUIRED only for `v3` spec. 2. Explicitly pointed out in the spec when should the caller supply its value and when it can pass nil and let it get supplied from inheritance. 3. Added the test `TestDataFileFromMetadata_V3AddDataFilesRequiresFirstRowID` for the same. -- 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]
