Skip to content
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

Feature: configurable BigQuery offline store export parquet file size #12

Merged
Changes from all 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
31 changes: 29 additions & 2 deletions sdk/python/feast/infra/offline_stores/bigquery.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import contextlib
import os
import tempfile
import uuid
from datetime import date, datetime, timedelta
Expand Down Expand Up @@ -74,7 +75,8 @@ def get_http_client_info():

class BigQueryTableCreateDisposition(ConstrainedStr):
"""Custom constraint for table_create_disposition. To understand more, see:
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.create_disposition"""
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.create_disposition
"""

values = {"CREATE_NEVER", "CREATE_IF_NEEDED"}

Expand Down Expand Up @@ -571,12 +573,37 @@ def to_remote_storage(self) -> List[str]:

table = self.to_bigquery()

parquet_file_size_mb = os.getenv("BQ_EXPORT_PARQUET_FILE_SIZE_MB")
KarolisKont marked this conversation as resolved.
Show resolved Hide resolved
if parquet_file_size_mb is not None:
KarolisKont marked this conversation as resolved.
Show resolved Hide resolved
if not parquet_file_size_mb.isdigit():
raise ValueError(
"The value for the BQ_EXPORT_PARQUET_FILE_SIZE_MB environment variable must "
"be a numeric digit, but it was set to: %s",
parquet_file_size_mb,
)

parquet_file_size_mb_int = int(parquet_file_size_mb)
if parquet_file_size_mb_int > 1000:
raise ValueError(
"The value for the BQ_EXPORT_PARQUET_FILE_SIZE_MB environment variable cannot "
"exceed 1000; however, it was set to: %s.",
parquet_file_size_mb_int,
)

table_size_in_mb = self.client.get_table(table).num_bytes / 1024 / 1024
vstrimaitis marked this conversation as resolved.
Show resolved Hide resolved
number_of_files = max(1, table_size_in_mb // parquet_file_size_mb_int)
destination_uris = [
f"{self._gcs_path}/{n:0>12}.parquet" for n in range(number_of_files)
]
else:
destination_uris = [f"{self._gcs_path}/*.parquet"]

job_config = bigquery.job.ExtractJobConfig()
job_config.destination_format = "PARQUET"

extract_job = self.client.extract_table(
table,
destination_uris=[f"{self._gcs_path}/*.parquet"],
destination_uris=destination_uris,
location=self.config.offline_store.location,
job_config=job_config,
)
Expand Down
Loading