kevinjqliu commented on code in PR #1615:
URL: https://github.com/apache/iceberg-python/pull/1615#discussion_r1947913465
##########
pyiceberg/table/inspect.py:
##########
@@ -657,3 +717,19 @@ def all_manifests(self) -> "pa.Table":
lambda args: self._generate_manifests_table(*args), [(snapshot,
True) for snapshot in snapshots]
)
return pa.concat_tables(manifests_by_snapshots)
+
+ def position_deletes(self) -> "pa.Table":
Review Comment:
nit: for any metadata tables referencing the current snapshot, let's add an
optional param to allow querying for any given snapshot id.
##########
pyiceberg/table/inspect.py:
##########
@@ -384,6 +384,41 @@ def _get_all_manifests_schema(self) -> "pa.Schema":
all_manifests_schema =
all_manifests_schema.append(pa.field("reference_snapshot_id", pa.int64(),
nullable=False))
return all_manifests_schema
+ def _get_positional_file_schema(self) -> "pa.Schema":
+ import pyarrow as pa
+
+ from pyiceberg.io.pyarrow import schema_to_pyarrow
+
+ pa_row_struct = schema_to_pyarrow(self.tbl.schema().as_struct())
+ positinal_delete_schema = pa.schema(
+ [
+ pa.field("file_path", pa.string(), nullable=False),
+ pa.field("pos", pa.int64(), nullable=False),
+ pa.field("row", pa_row_struct, nullable=True),
+ ]
+ )
+ return positinal_delete_schema
+
+ def _get_positional_deletes_schema(self) -> "pa.Schema":
+ import pyarrow as pa
+
+ from pyiceberg.io.pyarrow import schema_to_pyarrow
+
+ partition_record = self.tbl.metadata.specs_struct()
+ pa_partition_struct = schema_to_pyarrow(partition_record)
+ pa_row_struct = schema_to_pyarrow(self.tbl.schema().as_struct())
+ positinal_delete_schema = pa.schema(
Review Comment:
```suggestion
positional_delete_schema = pa.schema(
```
##########
pyiceberg/table/inspect.py:
##########
@@ -384,6 +384,41 @@ def _get_all_manifests_schema(self) -> "pa.Schema":
all_manifests_schema =
all_manifests_schema.append(pa.field("reference_snapshot_id", pa.int64(),
nullable=False))
return all_manifests_schema
+ def _get_positional_file_schema(self) -> "pa.Schema":
+ import pyarrow as pa
+
+ from pyiceberg.io.pyarrow import schema_to_pyarrow
+
+ pa_row_struct = schema_to_pyarrow(self.tbl.schema().as_struct())
+ positinal_delete_schema = pa.schema(
+ [
+ pa.field("file_path", pa.string(), nullable=False),
+ pa.field("pos", pa.int64(), nullable=False),
+ pa.field("row", pa_row_struct, nullable=True),
+ ]
+ )
+ return positinal_delete_schema
+
+ def _get_positional_deletes_schema(self) -> "pa.Schema":
+ import pyarrow as pa
+
+ from pyiceberg.io.pyarrow import schema_to_pyarrow
+
+ partition_record = self.tbl.metadata.specs_struct()
+ pa_partition_struct = schema_to_pyarrow(partition_record)
+ pa_row_struct = schema_to_pyarrow(self.tbl.schema().as_struct())
+ positinal_delete_schema = pa.schema(
+ [
+ pa.field("file_path", pa.string(), nullable=False),
+ pa.field("pos", pa.int64(), nullable=False),
+ pa.field("row", pa_row_struct, nullable=True),
+ pa.field("partition", pa_partition_struct, nullable=False),
+ pa.field("spec_id", pa.int64(), nullable=True),
+ pa.field("delete_file_path", pa.string(), nullable=False),
+ ]
+ )
+ return positinal_delete_schema
Review Comment:
```suggestion
return positional_delete_schema
```
##########
pyiceberg/table/inspect.py:
##########
@@ -384,6 +384,41 @@ def _get_all_manifests_schema(self) -> "pa.Schema":
all_manifests_schema =
all_manifests_schema.append(pa.field("reference_snapshot_id", pa.int64(),
nullable=False))
return all_manifests_schema
+ def _get_positional_file_schema(self) -> "pa.Schema":
+ import pyarrow as pa
+
+ from pyiceberg.io.pyarrow import schema_to_pyarrow
+
+ pa_row_struct = schema_to_pyarrow(self.tbl.schema().as_struct())
+ positinal_delete_schema = pa.schema(
+ [
+ pa.field("file_path", pa.string(), nullable=False),
+ pa.field("pos", pa.int64(), nullable=False),
+ pa.field("row", pa_row_struct, nullable=True),
+ ]
+ )
+ return positinal_delete_schema
+
+ def _get_positional_deletes_schema(self) -> "pa.Schema":
+ import pyarrow as pa
+
+ from pyiceberg.io.pyarrow import schema_to_pyarrow
+
+ partition_record = self.tbl.metadata.specs_struct()
Review Comment:
also nit: naming, this is a structtype, not the underlying record
##########
pyiceberg/io/pyarrow.py:
##########
@@ -889,6 +889,12 @@ def _construct_fragment(fs: FileSystem, data_file:
DataFile, file_format_kwargs:
return _get_file_format(data_file.file_format,
**file_format_kwargs).make_fragment(path, fs)
+def _read_delete_file(fs: FileSystem, data_file: DataFile, schema:
"pa.Schema") -> pa.Table:
+ delete_fragment = _construct_fragment(fs, data_file,
file_format_kwargs={"pre_buffer": True, "buffer_size": ONE_MEGABYTE})
+ table = ds.Scanner.from_fragment(fragment=delete_fragment,
schema=schema).to_table()
+ return table
Review Comment:
nit: this might be a good place to start introducing a `PositionalDelete`
class and we can get rid of the custom `_get_positional_file_schema` function
##########
pyiceberg/table/inspect.py:
##########
@@ -384,6 +384,41 @@ def _get_all_manifests_schema(self) -> "pa.Schema":
all_manifests_schema =
all_manifests_schema.append(pa.field("reference_snapshot_id", pa.int64(),
nullable=False))
return all_manifests_schema
+ def _get_positional_file_schema(self) -> "pa.Schema":
+ import pyarrow as pa
+
+ from pyiceberg.io.pyarrow import schema_to_pyarrow
+
+ pa_row_struct = schema_to_pyarrow(self.tbl.schema().as_struct())
+ positinal_delete_schema = pa.schema(
+ [
+ pa.field("file_path", pa.string(), nullable=False),
+ pa.field("pos", pa.int64(), nullable=False),
+ pa.field("row", pa_row_struct, nullable=True),
+ ]
+ )
+ return positinal_delete_schema
+
+ def _get_positional_deletes_schema(self) -> "pa.Schema":
+ import pyarrow as pa
+
+ from pyiceberg.io.pyarrow import schema_to_pyarrow
+
+ partition_record = self.tbl.metadata.specs_struct()
Review Comment:
nit: `specs_struct()` looks at all PartitionSpecs, do we just need the
current partition spec here?
--
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]