Skip to content

Commit dbd37d2

Browse files
committed
refined fetch table function
1 parent 7c053cd commit dbd37d2

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/webapp/databricks.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
from .utilities import databricksify_inst_name, SchemaType
1717
from typing import List, Any, Dict, IO, cast, Optional
1818
from fastapi import HTTPException
19-
import json
20-
import time
2119
import requests
2220

2321
try:
@@ -347,11 +345,19 @@ def fetch_table_data(
347345
# No client-side polling; require SUCCEEDED within 30s.
348346
if not resp.status or resp.status.state != "SUCCEEDED":
349347
state = resp.status.state if resp.status else "UNKNOWN"
350-
msg = resp.status.error.message if (resp.status and resp.status.error) else "Query not finished within wait_timeout"
351-
raise TimeoutError(f"Statement {stmt_id} not finished (state={state}): {msg}")
348+
msg = (
349+
resp.status.error.message
350+
if (resp.status and resp.status.error)
351+
else "Query not finished within wait_timeout"
352+
)
353+
raise TimeoutError(
354+
f"Statement {stmt_id} not finished (state={state}): {msg}"
355+
)
352356

353357
# Columns (ensure List[str] for type-checkers)
354-
if not (resp.manifest and resp.manifest.schema and resp.manifest.schema.columns):
358+
if not (
359+
resp.manifest and resp.manifest.schema and resp.manifest.schema.columns
360+
):
355361
raise ValueError("Schema/columns missing (EXTERNAL_LINKS).")
356362
cols: List[str] = []
357363
for c in resp.manifest.schema.columns:
@@ -375,7 +381,9 @@ def _consume_chunk(chunk_obj: Any) -> int | None:
375381
r.raise_for_status()
376382
rows = r.json()
377383
if not isinstance(rows, list):
378-
raise ValueError("Unexpected external link payload (expected JSON array).")
384+
raise ValueError(
385+
"Unexpected external link payload (expected JSON array)."
386+
)
379387
for row in rows:
380388
if not isinstance(row, list):
381389
raise ValueError("Unexpected row shape (expected list).")
@@ -397,7 +405,6 @@ def _consume_chunk(chunk_obj: Any) -> int | None:
397405

398406
return records
399407

400-
401408
def get_key_for_file(
402409
self, mapping: Dict[str, Any], file_name: str
403410
) -> Optional[str]:

0 commit comments

Comments
 (0)