feat(bigquery): Support queryResultsFormat and compressionCodec in query_and_wait()

Abierto
#18,047 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
52/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Tranquilo
Stack tecnológico
python
Área
api, data

Línea de trabajo

Empieza en Client.query_and_wait() y sigue después _job_helpers.py para localizar el payload de la solicitud de BigQuery, y table.py para RowIterator y el análisis de Arrow. Compara el PR relacionado 18027 y verifica que ambas opciones se acepten, se envíen a la API y que los resultados de Arrow comprimidos admitan los casos de uso indicados de to_arrow() y to_dataframe().

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

api: bigquery priority: p3 type: feature request
Determine this is the right repository
  • I determined this is the correct repository in which to report this feature request.
Summary of the feature request
Feature Description

Add support for query_results_format (e.g., "ARROW") and compression_codec (e.g., "LZ4_FRAME") in Client.query_and_wait() and related job helper functions in google-cloud-bigquery.

Use Case & Problem Statement

Currently, Client.query_and_wait() executes a query and fetches results, but does not allow callers to request the underlying query results format as Apache Arrow streams or specify compression options directly during the fetch process.

For high-performance data processing pipelines using Apache Arrow or PyArrow, requesting query results in Arrow format with compression significantly reduces network payload size, deserialization overhead, and total query result fetch latency.

Proposed Solution
  1. Update google.cloud.bigquery.client.Client.query_and_wait() to accept optional parameters:
    • query_results_format: Optional string specifying result serialization format (e.g. "ARROW").
    • compression_codec: Optional string specifying compression algorithm
  2. Update underlying helper functions in _job_helpers.py to populate these options in the request payload sent to the BigQuery API.
  3. Update RowIterator and Arrow parsing logic in table.py to seamlessly handle Arrow record batch streams when query_results_format="ARROW" is specified.
Alternative Approaches Considered
  • Manually constructing custom QueryJob instances and extracting Arrow record batches post-execution, which requires boilerplate code and loses the convenience of query_and_wait().
Additional Context

Related PR: https://github.com/googleapis/google-cloud-python/pull/18027

Desired code experience

from google.cloud import bigquery

client = bigquery.Client()

query = "SELECT * FROM bigquery-public-data.usa_names.usa_1910_2013 LIMIT 10000"

Request query results directly in Apache Arrow format with LZ4_FRAME compression

results = client.query_and_wait(
query,
query_results_format="ARROW",
compression_codec="LZ4_FRAME",
)

Convert directly to PyArrow Table or Pandas DataFrame

arrow_table = results.to_arrow()
df = results.to_dataframe()

Expected results
  1. Client.query_and_wait() accepts query_results_format and compression_codec parameters.
  2. The BigQuery API receives these parameters in the job execution request.
  3. Query results are returned and parsed efficiently via compressed Apache Arrow streams into the resulting RowIterator / Arrow table without client errors.
API client name and version

No response

Use case

e.g. This feature would be useful in a scenario where I need to process large amounts of data efficiently.

Additional context

https://github.com/googleapis/google-cloud-python/pull/18027

Lenguaje dominante
Python
Estrellas
5.4k
Forks
1.8k
Merge medio
2 d 7 h
PR fusionados (30 d)
173

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de googleapis/google-cloud-python

Todos los issues de googleapis/google-cloud-python

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.