Skip to content

Commit b0b58fb

Browse files
nit: reduce repetition
Signed-off-by: varun-edachali-dbx <varun.edachali@databricks.com>
1 parent 639bafa commit b0b58fb

File tree

2 files changed

+30
-29
lines changed

2 files changed

+30
-29
lines changed

src/databricks/sql/backend/sea/result_set.py

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def __init__(
8484
)
8585

8686
self._metadata_columns: Optional[List[ResultColumn]] = None
87-
# new index -> old index
87+
# new index -> old index
8888
self._column_index_mapping: Optional[Dict[int, Union[int, None]]] = None
8989

9090
def _convert_json_types(self, row: List[str]) -> List[Any]:
@@ -287,7 +287,7 @@ def prepare_metadata_columns(self, metadata_columns: List[ResultColumn]) -> None
287287
def _prepare_column_mapping(self) -> None:
288288
"""
289289
Prepare column index mapping for metadata queries.
290-
Updates description to use JDBC column names.
290+
Updates description to use Thrift column names.
291291
"""
292292
# Ensure description is available
293293
if not self.description:
@@ -303,40 +303,41 @@ def _prepare_column_mapping(self) -> None:
303303
self._column_index_mapping = {} # Maps new index -> old index
304304

305305
for new_idx, result_column in enumerate(self._metadata_columns or []):
306-
# Find the corresponding SEA column
306+
# Determine the old index and get column metadata
307307
if (
308308
result_column.sea_col_name
309309
and result_column.sea_col_name in sea_column_indices
310310
):
311311
old_idx = sea_column_indices[result_column.sea_col_name]
312-
self._column_index_mapping[new_idx] = old_idx
313-
# Use the original column metadata but with JDBC name
314312
old_col = self.description[old_idx]
315-
new_description.append(
316-
(
317-
result_column.thrift_col_name, # JDBC name
318-
result_column.thrift_col_type, # Expected type
319-
old_col[2], # display_size
320-
old_col[3], # internal_size
321-
old_col[4], # precision
322-
old_col[5], # scale
323-
old_col[6], # null_ok
324-
)
325-
)
313+
# Use original column metadata
314+
display_size, internal_size, precision, scale, null_ok = old_col[2:7]
326315
else:
327-
# Column doesn't exist in SEA - add with None values
328-
new_description.append(
329-
(
330-
result_column.thrift_col_name,
331-
result_column.thrift_col_type,
332-
None,
333-
None,
334-
None,
335-
None,
336-
True,
337-
)
316+
old_idx = None
317+
# Use None values for missing columns
318+
display_size, internal_size, precision, scale, null_ok = (
319+
None,
320+
None,
321+
None,
322+
None,
323+
True,
324+
)
325+
326+
# Set the mapping
327+
self._column_index_mapping[new_idx] = old_idx
328+
329+
# Create the new description entry
330+
new_description.append(
331+
(
332+
result_column.thrift_col_name, # Thrift (normalised) name
333+
result_column.thrift_col_type, # Expected type
334+
display_size,
335+
internal_size,
336+
precision,
337+
scale,
338+
null_ok,
338339
)
339-
self._column_index_mapping[new_idx] = None
340+
)
340341

341342
self.description = new_description
342343

src/databricks/sql/backend/sea/utils/result_column.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
@dataclass(frozen=True)
66
class ResultColumn:
77
"""
8-
Represents a mapping between JDBC specification column names and actual result set column names.
8+
Represents a mapping between Thrift specification column names and SEA column names.
99
1010
Attributes:
1111
thrift_col_name: Column name as returned by Thrift (e.g., "TABLE_CAT")

0 commit comments

Comments
 (0)