gigl.common.data.parquet_manifest#

Row-count manifest of a directory of Parquet files.

Reading the footer of every Parquet file of an entity to learn its row-group sizes costs one storage request per file on every rank. The manifest _row_counts.json is written once, next to the data files, and holds the same information:

{"version": 2,
 "files": {"part-00000-of-00002.parquet": {"row_groups": [100000, 100000, 523], "size_bytes": 81234567},
           ...}}

Keys are file names relative to the directory. Each value holds:

  • row_groups: the row counts of the file’s row groups, in order.

  • size_bytes: the file’s size. Reading the manifest compares it with the size in the directory listing, so a file rewritten after the manifest was written fails the read unless its size is unchanged. Listings already return sizes, so the check costs no extra storage requests.

The name does not end in .parquet, so file listings of the data never include it.

The data preprocessor writes one directory per node type and per edge type. The manifest sits next to the data files:

  • Node type user:

    gs://<temp bucket>/<job name>/data_preprocess/staging/transformed_node_features_dir/user/parquet/_row_counts.json
    gs://<temp bucket>/<job name>/data_preprocess/staging/transformed_node_features_dir/user/parquet/part-00000-of-00042.parquet
    gs://<temp bucket>/<job name>/data_preprocess/staging/transformed_node_features_dir/user/parquet/part-00001-of-00042.parquet
    
  • Edge type user-follows-user. The directory below the edge type is the edge usage type: main for the graph edges, positive and negative for label edges:

    gs://<temp bucket>/<job name>/data_preprocess/staging/transformed_edge_features_dir/user-follows-user/main/parquet/_row_counts.json
    gs://<temp bucket>/<job name>/data_preprocess/staging/transformed_edge_features_dir/user-follows-user/main/parquet/part-00000-of-00042.parquet
    

Attributes#

Functions#

build_manifest(uri_prefix[, num_threads])

Builds the manifest of the Parquet files under uri_prefix by reading each footer once.

filesystem_and_path(uri)

Returns the filesystem for uri and the path of uri within it.

list_parquet_files(fs, path)

Returns the Parquet data files directly under path, sorted by path.

manifest_path(path)

Returns the path of the manifest in the directory path.

read_manifest_row_groups(fs, path, files)

Returns the row-group row counts of files (as listed under path) from the manifest under path.

write_manifest(uri_prefix[, num_threads])

Builds the manifest of the Parquet files under uri_prefix and writes it there.

Module Contents#

gigl.common.data.parquet_manifest.build_manifest(uri_prefix, num_threads=_DEFAULT_THREADS)[source]#

Builds the manifest of the Parquet files under uri_prefix by reading each footer once.

Parameters:
  • uri_prefix (Uri) – The directory that holds the Parquet files.

  • num_threads (int) – The number of threads that read footers in parallel.

Returns:

The manifest, with the keys version and files.

Return type:

dict[str, Any]

Raises:

ValueError – If the listing does not report a file’s size.

gigl.common.data.parquet_manifest.filesystem_and_path(uri)[source]#

Returns the filesystem for uri and the path of uri within it.

GCS URIs get a GCS filesystem with a longer retry limit, and the path is <bucket>/<object path>. Any other URI is resolved by pyarrow.

Parameters:

uri (Uri) – The location of the directory or file.

Returns:

The filesystem and the scheme-less path within it, such as my-bucket/my_job/parquet/.

Return type:

tuple[pafs.FileSystem, str]

gigl.common.data.parquet_manifest.list_parquet_files(fs, path)[source]#

Returns the Parquet data files directly under path, sorted by path.

Parameters:
  • fs (pafs.FileSystem) – The filesystem that holds path.

  • path (str) – The scheme-less directory path within fs.

Returns:

The files that end in .parquet, sorted by full path. Each has the path and

size from the listing. The manifest itself is not included.

Return type:

list[pafs.FileInfo]

gigl.common.data.parquet_manifest.manifest_path(path)[source]#

Returns the path of the manifest in the directory path.

Parameters:

path (str) – The scheme-less directory path, with or without a trailing slash.

Returns:

path joined with the manifest file name.

Return type:

str

gigl.common.data.parquet_manifest.read_manifest_row_groups(fs, path, files)[source]#

Returns the row-group row counts of files (as listed under path) from the manifest under path.

Parameters:
  • fs (pafs.FileSystem) – The filesystem that holds path.

  • path (str) – The scheme-less directory path within fs.

  • files (list[pafs.FileInfo]) – The data files listed under path, as returned by list_parquet_files.

Returns:

One list of row-group row counts per entry of files, in the same order.

Return type:

list[list[int]]

Raises:
  • FileNotFoundError – If there is no manifest.

  • ValueError – If the manifest is malformed, has an unknown version, does not list exactly files, or lists a size that differs from a file’s listed size.

gigl.common.data.parquet_manifest.write_manifest(uri_prefix, num_threads=_DEFAULT_THREADS)[source]#

Builds the manifest of the Parquet files under uri_prefix and writes it there.

Parameters:
  • uri_prefix (Uri) – The directory that holds the Parquet files.

  • num_threads (int) – The number of threads that read footers in parallel.

Returns:

The manifest that was written.

Return type:

dict[str, Any]

Raises:

ValueError – If the listing does not report a file’s size.

gigl.common.data.parquet_manifest.GCS_RETRY_TIME_LIMIT: Final[datetime.timedelta][source]#
gigl.common.data.parquet_manifest.MANIFEST_FILE_NAME: Final[str] = '_row_counts.json'[source]#
gigl.common.data.parquet_manifest.MANIFEST_VERSION: Final[int] = 2[source]#
gigl.common.data.parquet_manifest.logger[source]#