|
2 | 2 | from __future__ import annotations |
3 | 3 |
|
4 | 4 | import logging |
5 | | -from typing import Any, Union |
| 5 | +from typing import TYPE_CHECKING, Any, Union |
| 6 | + |
| 7 | +if TYPE_CHECKING: |
| 8 | + import pyarrow |
6 | 9 |
|
7 | 10 | from attrs import define, field |
8 | 11 | from attrs.setters import frozen as frozen_attr |
|
11 | 14 | from gooddata_api_client.model.afm_cancel_tokens import AfmCancelTokens |
12 | 15 | from gooddata_api_client.model.result_spec import ResultSpec |
13 | 16 |
|
| 17 | +try: |
| 18 | + import pyarrow as _pyarrow |
| 19 | + from pyarrow import ipc as _ipc |
| 20 | +except ImportError: |
| 21 | + _pyarrow = None # type: ignore |
| 22 | + _ipc = None # type: ignore |
| 23 | + |
14 | 24 | from gooddata_sdk.client import GoodDataApiClient |
15 | 25 | from gooddata_sdk.compute.model.attribute import Attribute |
16 | 26 | from gooddata_sdk.compute.model.filter import Filter |
@@ -372,6 +382,31 @@ def read_result( |
372 | 382 | ) |
373 | 383 | return ExecutionResult(execution_result) |
374 | 384 |
|
| 385 | + def read_result_arrow(self) -> pyarrow.Table: |
| 386 | + """ |
| 387 | + Reads the full execution result as a pyarrow Table. |
| 388 | +
|
| 389 | + The binary endpoint returns the complete result in one shot (no paging). |
| 390 | + Requires pyarrow to be installed (pip install gooddata-sdk[arrow]). |
| 391 | + """ |
| 392 | + if _ipc is None: |
| 393 | + raise ImportError( |
| 394 | + "pyarrow is required to use read_result_arrow(). Install it with: pip install gooddata-sdk[arrow]" |
| 395 | + ) |
| 396 | + import io |
| 397 | + |
| 398 | + response = self._actions_api.retrieve_result_binary( |
| 399 | + workspace_id=self._workspace_id, |
| 400 | + result_id=self.result_id, |
| 401 | + _preload_content=False, |
| 402 | + **({"x_gdc_cancel_token": self.cancel_token} if self.cancel_token else {}), |
| 403 | + ) |
| 404 | + try: |
| 405 | + buf = io.BytesIO(response.read()) |
| 406 | + finally: |
| 407 | + response.release_conn() |
| 408 | + return _ipc.open_file(buf).read_all() |
| 409 | + |
375 | 410 | def cancel(self) -> None: |
376 | 411 | """ |
377 | 412 | Cancels the execution backing this execution result. |
|
0 commit comments