Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

SEA: preliminary complex types support#655

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
varun-edachali-dbx wants to merge5 commits intomain
base:main
Choose a base branch
Loading
fromcomplex-types-sea
Open
Show file tree
Hide file tree
Changes fromall 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
46 changes: 46 additions & 0 deletionssrc/databricks/sql/backend/sea/result_set.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import json
from typing import Any, List, Optional, TYPE_CHECKING

import logging
Expand All@@ -26,6 +27,8 @@
class SeaResultSet(ResultSet):
"""ResultSet implementation for SEA backend."""

backend: SeaDatabricksClient

def __init__(
self,
connection: Connection,
Expand DownExpand Up@@ -82,6 +85,43 @@ def __init__(
arrow_schema_bytes=execute_response.arrow_schema_bytes,
)

def _convert_complex_types_to_string(
self, rows: "pyarrow.Table"
) -> "pyarrow.Table":
"""
Convert complex types (array, struct, map) to string representation.
Args:
rows: Input PyArrow table
Returns:
PyArrow table with complex types converted to strings
"""

if not pyarrow:
raise ImportError(
"PyArrow is not installed: _use_arrow_native_complex_types = False requires pyarrow"
)

def convert_complex_column_to_string(col: "pyarrow.Array") -> "pyarrow.Array":
python_values = col.to_pylist()
json_strings = [
(json.dumps(val) if val is not None else None) for val in python_values
]
return pyarrow.array(json_strings, type=pyarrow.string())

converted_columns = []
for col in rows.columns:
converted_col = col
if (
pyarrow.types.is_list(col.type)
or pyarrow.types.is_large_list(col.type)
or pyarrow.types.is_struct(col.type)
or pyarrow.types.is_map(col.type)
):
converted_col = convert_complex_column_to_string(col)
converted_columns.append(converted_col)

return pyarrow.Table.from_arrays(converted_columns, names=rows.column_names)

def _convert_json_types(self, row: List[str]) -> List[Any]:
"""
Convert string values in the row to appropriate Python types based on column metadata.
Expand DownExpand Up@@ -199,6 +239,9 @@ def fetchmany_arrow(self, size: int) -> "pyarrow.Table":
if isinstance(self.results, JsonQueue):
results = self._convert_json_to_arrow_table(results)

if not self.backend._use_arrow_native_complex_types:
results = self._convert_complex_types_to_string(results)

self._next_row_index += results.num_rows

return results
Expand All@@ -212,6 +255,9 @@ def fetchall_arrow(self) -> "pyarrow.Table":
if isinstance(self.results, JsonQueue):
results = self._convert_json_to_arrow_table(results)

if not self.backend._use_arrow_native_complex_types:
results = self._convert_complex_types_to_string(results)

self._next_row_index += results.num_rows

return results
Expand Down
27 changes: 21 additions & 6 deletionstests/e2e/test_complex_types.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -56,10 +56,19 @@ def table_fixture(self, connection_details):
("map_array_col", list),
],
)
def test_read_complex_types_as_arrow(self, field, expected_type, table_fixture):
@pytest.mark.parametrize(
"backend_params",
[
{},
{"use_sea": True},
],
)
def test_read_complex_types_as_arrow(
self, field, expected_type, table_fixture, backend_params
):
"""Confirms the return types of a complex type field when reading as arrow"""

with self.cursor() as cursor:
with self.cursor(extra_params=backend_params) as cursor:
result = cursor.execute(
"SELECT * FROM pysql_test_complex_types_table LIMIT 1"
).fetchone()
Expand All@@ -77,11 +86,17 @@ def test_read_complex_types_as_arrow(self, field, expected_type, table_fixture):
("map_array_col"),
],
)
def test_read_complex_types_as_string(self, field, table_fixture):
@pytest.mark.parametrize(
"backend_params",
[
{},
{"use_sea": True},
],
)
def test_read_complex_types_as_string(self, field, table_fixture, backend_params):
"""Confirms the return type of a complex type that is returned as a string"""
with self.cursor(
extra_params={"_use_arrow_native_complex_types": False}
) as cursor:
extra_params = {**backend_params, "_use_arrow_native_complex_types": False}
with self.cursor(extra_params=extra_params) as cursor:
result = cursor.execute(
"SELECT * FROM pysql_test_complex_types_table LIMIT 1"
).fetchone()
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp