Skip to content

feat: Add a parquet uuid calculation #3440

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
May 1, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions src/awkward/operations/ak_from_parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

from __future__ import annotations

import hashlib
import json

import fsspec.parquet

import awkward as ak
Expand Down Expand Up @@ -65,11 +68,8 @@ def from_parquet(
See also #ak.to_parquet, #ak.metadata_from_parquet.
"""

parquet_columns, subform, actual_paths, fs, subrg, row_counts, meta = metadata(
path,
storage_options,
row_groups,
columns,
parquet_columns, subform, actual_paths, fs, subrg, row_counts, meta, uuid = (
metadata(path, storage_options, row_groups, columns, calculate_uuid=True)
)
return _load(
actual_paths,
Expand All @@ -95,6 +95,7 @@ def metadata(
columns=None,
ignore_metadata=False,
scan_files=True,
calculate_uuid=False,
):
# early exit if missing deps
pyarrow_parquet = awkward._connect.pyarrow.import_pyarrow_parquet("ak.from_parquet")
Expand Down Expand Up @@ -193,6 +194,25 @@ def metadata(
list_indicator=list_indicator, column_prefix=column_prefix
)

# generate hash from the col_counts, first row_group and last row_group to calculate approximate parquet uuid
uuid = None
if calculate_uuid:
uuids = [str(col_counts)]
for row_group_index in (0, metadata.num_row_groups - 1):
row_group_info = metadata.row_group(row_group_index)
uuids.append(repr(row_group_info.to_dict()))
uuid = hashlib.sha256(json.dumps(",".join(uuids)).encode()).hexdigest()
return (
parquet_columns,
subform,
actual_paths,
fs,
subrg,
col_counts,
metadata,
uuid,
)

return parquet_columns, subform, actual_paths, fs, subrg, col_counts, metadata


Expand Down
13 changes: 11 additions & 2 deletions src/awkward/operations/ak_metadata_from_parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,25 @@ def _impl(
path, storage_options, row_groups=None, ignore_metadata=False, scan_files=True
):
results = ak.operations.ak_from_parquet.metadata(
path, storage_options, row_groups, None, ignore_metadata, scan_files
path,
storage_options,
row_groups,
None,
ignore_metadata,
scan_files,
calculate_uuid=True,
)
parquet_columns, subform, actual_paths, fs, subrg, col_counts, metadata, uuid = (
results
)
parquet_columns, subform, actual_paths, fs, subrg, col_counts, metadata = results

out = {
"form": subform,
"fs": fs,
"paths": actual_paths,
"col_counts": col_counts,
"columns": parquet_columns,
"uuid": uuid,
}
if col_counts:
out["num_rows"] = sum(col_counts)
Expand Down
56 changes: 56 additions & 0 deletions tests/test_3440_calculate_parquet_uuid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/awkward/blob/main/LICENSE

from __future__ import annotations

import pathlib

import pytest

import awkward

metadata_from_parquet_submodule = pytest.importorskip(
"awkward.operations.ak_metadata_from_parquet"
)
metadata_from_parquet = metadata_from_parquet_submodule.metadata_from_parquet

SAMPLES_DIR = pathlib.Path(__file__).parent / "samples"
input = SAMPLES_DIR / "nullable-record-primitives.parquet"


def test_parquet_uuid():
meta = metadata_from_parquet(input)

Check failure on line 21 in tests/test_3440_calculate_parquet_uuid.py

View workflow job for this annotation

GitHub Actions / Run Tests (pypy3.9, x64, ubuntu-latest, pypy)

test_parquet_uuid ImportError: to use ak.from_parquet, you must install pyarrow: pip install pyarrow or conda install -c conda-forge pyarrow This error occurred while calling ak.metadata_from_parquet( PosixPath-instance )

Check failure on line 21 in tests/test_3440_calculate_parquet_uuid.py

View workflow job for this annotation

GitHub Actions / Run Tests (ubuntu-latest, 3.13, x64, full)

test_parquet_uuid ImportError: to use ak.from_parquet, you must install pyarrow: pip install pyarrow or conda install -c conda-forge pyarrow This error occurred while calling ak.metadata_from_parquet( PosixPath-instance )

Check failure on line 21 in tests/test_3440_calculate_parquet_uuid.py

View workflow job for this annotation

GitHub Actions / Run Tests (3.13t, x64, ubuntu-latest, nogil)

test_parquet_uuid ImportError: to use ak.from_parquet, you must install pyarrow: pip install pyarrow or conda install -c conda-forge pyarrow This error occurred while calling ak.metadata_from_parquet( PosixPath-instance )

Check failure on line 21 in tests/test_3440_calculate_parquet_uuid.py

View workflow job for this annotation

GitHub Actions / Run Tests (3.11, x64, ubuntu-latest, ml)

test_parquet_uuid ImportError: to use ak.from_parquet, you must install pyarrow: pip install pyarrow or conda install -c conda-forge pyarrow This error occurred while calling ak.metadata_from_parquet( PosixPath-instance )

Check failure on line 21 in tests/test_3440_calculate_parquet_uuid.py

View workflow job for this annotation

GitHub Actions / Run Tests (macos-13, 3.13, x64, full)

test_parquet_uuid ImportError: to use ak.from_parquet, you must install pyarrow: pip install pyarrow or conda install -c conda-forge pyarrow This error occurred while calling ak.metadata_from_parquet( PosixPath-instance )
assert (

Check failure on line 22 in tests/test_3440_calculate_parquet_uuid.py

View workflow job for this annotation

GitHub Actions / Run Tests (3.9, x64, ubuntu-latest, minimal)

test_parquet_uuid AssertionError: assert 'adc236484e10384ad680a1ae2ce1fc675f6f9f0a84a02c651ed91ad97fba41c0' == '93fd596534251b1ac750f359d9d55418b02bcddcc79cd5ab1e3d9735941fbcae' - 93fd596534251b1ac750f359d9d55418b02bcddcc79cd5ab1e3d9735941fbcae + adc236484e10384ad680a1ae2ce1fc675f6f9f0a84a02c651ed91ad97fba41c0
meta["uuid"]
== "93fd596534251b1ac750f359d9d55418b02bcddcc79cd5ab1e3d9735941fbcae"
)


@pytest.mark.parametrize("calculate_uuid", [True, False])
def test_return_tuple_with_or_without_uuid(calculate_uuid):
results = awkward.operations.ak_from_parquet.metadata(

Check failure on line 30 in tests/test_3440_calculate_parquet_uuid.py

View workflow job for this annotation

GitHub Actions / Run Tests (pypy3.9, x64, ubuntu-latest, pypy)

test_return_tuple_with_or_without_uuid[False] ImportError: to use ak.from_parquet, you must install pyarrow: pip install pyarrow or conda install -c conda-forge pyarrow This error occurred while calling ak.metadata( PosixPath-instance {} None None False True calculate_uuid = False )

Check failure on line 30 in tests/test_3440_calculate_parquet_uuid.py

View workflow job for this annotation

GitHub Actions / Run Tests (pypy3.9, x64, ubuntu-latest, pypy)

test_return_tuple_with_or_without_uuid[True] ImportError: to use ak.from_parquet, you must install pyarrow: pip install pyarrow or conda install -c conda-forge pyarrow This error occurred while calling ak.metadata( PosixPath-instance {} None None False True calculate_uuid = True )

Check failure on line 30 in tests/test_3440_calculate_parquet_uuid.py

View workflow job for this annotation

GitHub Actions / Run Tests (ubuntu-latest, 3.13, x64, full)

test_return_tuple_with_or_without_uuid[False] ImportError: to use ak.from_parquet, you must install pyarrow: pip install pyarrow or conda install -c conda-forge pyarrow This error occurred while calling ak.metadata( PosixPath-instance {} None None False True calculate_uuid = False )

Check failure on line 30 in tests/test_3440_calculate_parquet_uuid.py

View workflow job for this annotation

GitHub Actions / Run Tests (ubuntu-latest, 3.13, x64, full)

test_return_tuple_with_or_without_uuid[True] ImportError: to use ak.from_parquet, you must install pyarrow: pip install pyarrow or conda install -c conda-forge pyarrow This error occurred while calling ak.metadata( PosixPath-instance {} None None False True calculate_uuid = True )

Check failure on line 30 in tests/test_3440_calculate_parquet_uuid.py

View workflow job for this annotation

GitHub Actions / Run Tests (3.13t, x64, ubuntu-latest, nogil)

test_return_tuple_with_or_without_uuid[False] ImportError: to use ak.from_parquet, you must install pyarrow: pip install pyarrow or conda install -c conda-forge pyarrow This error occurred while calling ak.metadata( PosixPath-instance {} None None False True calculate_uuid = False )

Check failure on line 30 in tests/test_3440_calculate_parquet_uuid.py

View workflow job for this annotation

GitHub Actions / Run Tests (3.13t, x64, ubuntu-latest, nogil)

test_return_tuple_with_or_without_uuid[True] ImportError: to use ak.from_parquet, you must install pyarrow: pip install pyarrow or conda install -c conda-forge pyarrow This error occurred while calling ak.metadata( PosixPath-instance {} None None False True calculate_uuid = True )

Check failure on line 30 in tests/test_3440_calculate_parquet_uuid.py

View workflow job for this annotation

GitHub Actions / Run Tests (3.11, x64, ubuntu-latest, ml)

test_return_tuple_with_or_without_uuid[False] ImportError: to use ak.from_parquet, you must install pyarrow: pip install pyarrow or conda install -c conda-forge pyarrow This error occurred while calling ak.metadata( PosixPath-instance {} None None False True calculate_uuid = False )

Check failure on line 30 in tests/test_3440_calculate_parquet_uuid.py

View workflow job for this annotation

GitHub Actions / Run Tests (3.11, x64, ubuntu-latest, ml)

test_return_tuple_with_or_without_uuid[True] ImportError: to use ak.from_parquet, you must install pyarrow: pip install pyarrow or conda install -c conda-forge pyarrow This error occurred while calling ak.metadata( PosixPath-instance {} None None False True calculate_uuid = True )

Check failure on line 30 in tests/test_3440_calculate_parquet_uuid.py

View workflow job for this annotation

GitHub Actions / Run Tests (macos-13, 3.13, x64, full)

test_return_tuple_with_or_without_uuid[False] ImportError: to use ak.from_parquet, you must install pyarrow: pip install pyarrow or conda install -c conda-forge pyarrow This error occurred while calling ak.metadata( PosixPath-instance {} None None False True calculate_uuid = False )

Check failure on line 30 in tests/test_3440_calculate_parquet_uuid.py

View workflow job for this annotation

GitHub Actions / Run Tests (macos-13, 3.13, x64, full)

test_return_tuple_with_or_without_uuid[True] ImportError: to use ak.from_parquet, you must install pyarrow: pip install pyarrow or conda install -c conda-forge pyarrow This error occurred while calling ak.metadata( PosixPath-instance {} None None False True calculate_uuid = True )
input,
{},
None,
None,
False,
True,
calculate_uuid=calculate_uuid,
)
if calculate_uuid:
assert len(results) == 8, "Expected 8 items in the result tuple"
(
parquet_columns,
subform,
actual_paths,
fs,
subrg,
col_counts,
metadata,
uuid,
) = results
assert uuid is not None, "UUID should be present when calculate_uuid is True"
else:
assert len(results) == 7, "Expected 7 items in the result tuple"
parquet_columns, subform, actual_paths, fs, subrg, col_counts, metadata = (
results
)
Loading