Skip to content

Commit aab33a1

Browse files
select Queue based on format in manifest
Signed-off-by: varun-edachali-dbx <varun.edachali@databricks.com>
1 parent 72100b9 commit aab33a1

File tree

3 files changed

+38
-27
lines changed

3 files changed

+38
-27
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
from databricks.sql.backend.sea.backend import SeaDatabricksClient
77
from databricks.sql.backend.sea.models.base import ResultData, ResultManifest
8+
from databricks.sql.backend.sea.utils.constants import ResultFormat
9+
from databricks.sql.exc import ProgrammingError
810
from databricks.sql.utils import ResultSetQueue
911

1012

@@ -35,15 +37,15 @@ def build_queue(
3537
ResultSetQueue: The appropriate queue for the result data
3638
"""
3739

38-
if sea_result_data.data is not None:
40+
if manifest.format == ResultFormat.JSON_ARRAY.value:
3941
# INLINE disposition with JSON_ARRAY format
4042
return JsonQueue(sea_result_data.data)
41-
elif sea_result_data.external_links is not None:
43+
elif manifest.format == ResultFormat.ARROW_STREAM.value:
4244
# EXTERNAL_LINKS disposition
4345
raise NotImplementedError(
4446
"EXTERNAL_LINKS disposition is not implemented for SEA backend"
4547
)
46-
return JsonQueue([])
48+
raise ProgrammingError("Invalid result format")
4749

4850

4951
class JsonQueue(ResultSetQueue):
@@ -53,7 +55,7 @@ def __init__(self, data_array):
5355
"""Initialize with JSON array data."""
5456
self.data_array = data_array
5557
self.cur_row_index = 0
56-
self.num_rows = len(data_array)
58+
self.num_rows = len(data_array) if data_array else 0
5759

5860
def next_n_rows(self, num_rows):
5961
"""Get the next n rows from the data array."""

tests/unit/test_sea_queue.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from databricks.sql.backend.sea.queue import JsonQueue, SeaResultSetQueueFactory
1111
from databricks.sql.backend.sea.models.base import ResultData, ResultManifest
12+
from databricks.sql.backend.sea.utils.constants import ResultFormat
1213

1314

1415
class TestJsonQueue:
@@ -104,6 +105,15 @@ def mock_description(self):
104105
("col3", "boolean", None, None, None, None, None),
105106
]
106107

108+
def _create_empty_manifest(self, format: ResultFormat):
109+
return ResultManifest(
110+
format=format.value,
111+
schema={},
112+
total_row_count=-1,
113+
total_byte_count=-1,
114+
total_chunk_count=-1,
115+
)
116+
107117
def test_build_queue_with_inline_data(self, mock_sea_client, mock_description):
108118
"""Test building a queue with inline JSON data."""
109119
# Create sample data for inline JSON result
@@ -116,7 +126,7 @@ def test_build_queue_with_inline_data(self, mock_sea_client, mock_description):
116126
result_data = ResultData(data=data, external_links=None, row_count=len(data))
117127

118128
# Create a manifest (not used for inline data)
119-
manifest = None
129+
manifest = self._create_empty_manifest(ResultFormat.JSON_ARRAY)
120130

121131
# Build the queue
122132
queue = SeaResultSetQueueFactory.build_queue(
@@ -140,7 +150,7 @@ def test_build_queue_with_empty_data(self, mock_sea_client, mock_description):
140150
# Build the queue
141151
queue = SeaResultSetQueueFactory.build_queue(
142152
result_data,
143-
None,
153+
self._create_empty_manifest(ResultFormat.JSON_ARRAY),
144154
"test-statement-123",
145155
description=mock_description,
146156
sea_client=mock_sea_client,
@@ -165,7 +175,7 @@ def test_build_queue_with_external_links(self, mock_sea_client, mock_description
165175
):
166176
SeaResultSetQueueFactory.build_queue(
167177
result_data,
168-
None,
178+
self._create_empty_manifest(ResultFormat.ARROW_STREAM),
169179
"test-statement-123",
170180
description=mock_description,
171181
sea_client=mock_sea_client,

tests/unit/test_sea_result_set.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from databricks.sql.backend.sea.result_set import SeaResultSet, Row
1212
from databricks.sql.backend.sea.queue import JsonQueue
13+
from databricks.sql.backend.sea.utils.constants import ResultFormat
1314
from databricks.sql.backend.types import CommandId, CommandState
1415
from databricks.sql.backend.sea.models.base import ResultData, ResultManifest
1516

@@ -59,6 +60,16 @@ def sample_data(self):
5960
["value5", "5", "true"],
6061
]
6162

63+
def _create_empty_manifest(self, format: ResultFormat):
64+
"""Create an empty manifest."""
65+
return ResultManifest(
66+
format=format.value,
67+
schema={},
68+
total_row_count=-1,
69+
total_byte_count=-1,
70+
total_chunk_count=-1,
71+
)
72+
6273
@pytest.fixture
6374
def result_set_with_data(
6475
self, mock_connection, mock_sea_client, execute_response, sample_data
@@ -75,7 +86,7 @@ def result_set_with_data(
7586
execute_response=execute_response,
7687
sea_client=mock_sea_client,
7788
result_data=result_data,
78-
manifest=None,
89+
manifest=self._create_empty_manifest(ResultFormat.JSON_ARRAY),
7990
buffer_size_bytes=1000,
8091
arraysize=100,
8192
)
@@ -88,18 +99,6 @@ def json_queue(self, sample_data):
8899
"""Create a JsonQueue with sample data."""
89100
return JsonQueue(sample_data)
90101

91-
def empty_manifest(self):
92-
"""Create an empty manifest."""
93-
return ResultManifest(
94-
format="JSON_ARRAY",
95-
schema={},
96-
total_row_count=0,
97-
total_byte_count=0,
98-
total_chunk_count=0,
99-
truncated=False,
100-
is_volume_operation=False,
101-
)
102-
103102
def test_init_with_execute_response(
104103
self, mock_connection, mock_sea_client, execute_response
105104
):
@@ -109,7 +108,7 @@ def test_init_with_execute_response(
109108
execute_response=execute_response,
110109
sea_client=mock_sea_client,
111110
result_data=ResultData(data=[]),
112-
manifest=self.empty_manifest(),
111+
manifest=self._create_empty_manifest(ResultFormat.JSON_ARRAY),
113112
buffer_size_bytes=1000,
114113
arraysize=100,
115114
)
@@ -130,7 +129,7 @@ def test_close(self, mock_connection, mock_sea_client, execute_response):
130129
execute_response=execute_response,
131130
sea_client=mock_sea_client,
132131
result_data=ResultData(data=[]),
133-
manifest=self.empty_manifest(),
132+
manifest=self._create_empty_manifest(ResultFormat.JSON_ARRAY),
134133
buffer_size_bytes=1000,
135134
arraysize=100,
136135
)
@@ -152,7 +151,7 @@ def test_close_when_already_closed_server_side(
152151
execute_response=execute_response,
153152
sea_client=mock_sea_client,
154153
result_data=ResultData(data=[]),
155-
manifest=self.empty_manifest(),
154+
manifest=self._create_empty_manifest(ResultFormat.JSON_ARRAY),
156155
buffer_size_bytes=1000,
157156
arraysize=100,
158157
)
@@ -176,7 +175,7 @@ def test_close_when_connection_closed(
176175
execute_response=execute_response,
177176
sea_client=mock_sea_client,
178177
result_data=ResultData(data=[]),
179-
manifest=self.empty_manifest(),
178+
manifest=self._create_empty_manifest(ResultFormat.JSON_ARRAY),
180179
buffer_size_bytes=1000,
181180
arraysize=100,
182181
)
@@ -332,7 +331,7 @@ def test_fetchmany_arrow_not_implemented(
332331
execute_response=execute_response,
333332
sea_client=mock_sea_client,
334333
result_data=ResultData(data=None, external_links=[]),
335-
manifest=self.empty_manifest(),
334+
manifest=self._create_empty_manifest(ResultFormat.ARROW_STREAM),
336335
buffer_size_bytes=1000,
337336
arraysize=100,
338337
)
@@ -352,7 +351,7 @@ def test_fetchall_arrow_not_implemented(
352351
execute_response=execute_response,
353352
sea_client=mock_sea_client,
354353
result_data=ResultData(data=None, external_links=[]),
355-
manifest=self.empty_manifest(),
354+
manifest=self._create_empty_manifest(ResultFormat.ARROW_STREAM),
356355
buffer_size_bytes=1000,
357356
arraysize=100,
358357
)
@@ -370,7 +369,7 @@ def test_is_staging_operation(
370369
execute_response=execute_response,
371370
sea_client=mock_sea_client,
372371
result_data=ResultData(data=[]),
373-
manifest=self.empty_manifest(),
372+
manifest=self._create_empty_manifest(ResultFormat.JSON_ARRAY),
374373
buffer_size_bytes=1000,
375374
arraysize=100,
376375
)

0 commit comments

Comments
 (0)