gigl.src.data_preprocessor.lib.transform.parquet_writer#

Writes TFT output record batches as dense Parquet files.

The column layout and file naming are described in gigl.common.data.parquet_format.

features slots follow feature_keys order, with every feature cast to float32 and vectors flattened, matching the tensors the TFRecord loader builds. Each label key is its own column (float32 for scalar labels, FixedSizeList<float32> for vector labels). Quantized features are one FixedSizeBinary column of packed bytes per row, named after the packed feature key recorded in the quantization metadata.

A node entity with three features (one scalar, one 3-vector, one scalar), a packed column and a label has the schema:

node_id: int64
features: fixed_size_list<item: float>[5]
node_packed_features: fixed_size_binary[16]
label: float

An edge entity with features and no label has the schema:

src: int64
dst: int64
features: fixed_size_list<item: float>[5]

Attributes#

Classes#

RecordBatchToDenseArrowTable

Converts a TFT pa.RecordBatch into a pa.Table with the dense Parquet schema.

WriteDenseParquet

Writes TFT output record batches to <parquet_uri_prefix>part-XXXXX-of-YYYYY.parquet files.

Module Contents#

class gigl.src.data_preprocessor.lib.transform.parquet_writer.RecordBatchToDenseArrowTable(id_keys, id_columns, feature_keys, label_keys, packed_feature_key=None, packed_feature_dim=0)[source]#

Bases: apache_beam.DoFn

Converts a TFT pa.RecordBatch into a pa.Table with the dense Parquet schema.

Initializes the converter.

Parameters:
  • id_keys (Sequence[str]) – TFT output names of the id columns, in output order ([node_id_key] or [src_key, dst_key]).

  • id_columns (Sequence[str]) – Parquet column names for id_keys.

  • feature_keys (Sequence[str]) – TFT output names concatenated, in order, into the features column.

  • label_keys (Sequence[str]) – TFT output names written as one float32 column each.

  • packed_feature_key (Optional[str]) – TFT output name of the packed quantized bytes, written as a FixedSizeBinary column of the same name. None when features are not quantized.

  • packed_feature_dim (int) – Number of packed bytes per row. Required when packed_feature_key is set.

process(batch)[source]#

Converts one record batch.

Parameters:

batch (pyarrow.RecordBatch) – A TFT output batch in which every column holds one list (or one scalar) per row.

Yields:

One table with the id, features, packed and label columns. Nothing for an empty batch.

Raises:

ValueError – If a column holds nulls or a packed value is not packed_feature_dim bytes long.

Return type:

Iterator[pyarrow.Table]

class gigl.src.data_preprocessor.lib.transform.parquet_writer.WriteDenseParquet(parquet_uri_prefix, id_keys, id_columns, feature_keys, label_keys, num_shards, packed_feature_key=None, packed_feature_dim=0)[source]#

Bases: apache_beam.PTransform

Writes TFT output record batches to <parquet_uri_prefix>part-XXXXX-of-YYYYY.parquet files.

Initializes the transform.

Parameters:
  • parquet_uri_prefix (str) – Directory prefix (ending in /) of the output files.

  • id_keys (Sequence[str]) – TFT output names of the id columns (one for nodes, two for edges).

  • id_columns (Sequence[str]) – Parquet column names for id_keys.

  • feature_keys (Sequence[str]) – TFT output names concatenated into the features column. Empty for no features.

  • label_keys (Sequence[str]) – TFT output names written as one float32 column each.

  • num_shards (int) – Number of output files. 0 starts a new file whenever the current one holds TARGET_BYTES_PER_PARQUET_FILE of uncompressed data.

  • packed_feature_key (Optional[str]) – TFT output name of the packed quantized bytes. None when features are not quantized.

  • packed_feature_dim (int) – Number of packed bytes per row. Required when packed_feature_key is set.

expand(record_batches)[source]#

Converts the record batches and writes them to Parquet files.

Parameters:

record_batches (apache_beam.PCollection[pyarrow.RecordBatch]) – TFT output record batches.

Returns:

The result of the Parquet write.

Return type:

apache_beam.pvalue.PDone

gigl.src.data_preprocessor.lib.transform.parquet_writer.EDGE_ROW_GROUP_ROWS: Final[int] = 1000000[source]#
gigl.src.data_preprocessor.lib.transform.parquet_writer.NODE_ROW_GROUP_ROWS: Final[int] = 100000[source]#
gigl.src.data_preprocessor.lib.transform.parquet_writer.PARQUET_CODEC: Final[str] = 'zstd'[source]#
gigl.src.data_preprocessor.lib.transform.parquet_writer.PARQUET_FILE_PREFIX: Final[str] = 'part'[source]#
gigl.src.data_preprocessor.lib.transform.parquet_writer.PARQUET_USE_DICTIONARY: Final[bool] = False[source]#
gigl.src.data_preprocessor.lib.transform.parquet_writer.TARGET_BYTES_PER_PARQUET_FILE: Final[int] = 1000000000[source]#