Skip to content

Commit c540987

Browse files
working example script
Signed-off-by: varun-edachali-dbx <varun.edachali@databricks.com>
1 parent f0d9c65 commit c540987

File tree

2 files changed

+4
-155
lines changed

2 files changed

+4
-155
lines changed

examples/experimental/sea_connector_test.py

Lines changed: 3 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,17 @@ def test_sea_result_set_json_array_inline():
3737
catalog=catalog,
3838
schema="default",
3939
use_sea=True,
40+
use_cloud_fetch=False, # trigger INLINE + JSON_ARRAY
4041
user_agent_entry="SEA-Test-Client",
42+
enable_query_result_lz4_compression=False,
4143
)
4244

4345
logger.info(
4446
f"Successfully opened SEA session with ID: {connection.get_session_id_hex()}"
4547
)
4648

4749
# Create cursor
48-
cursor = connection.cursor()
50+
cursor = connection.cursor(arraysize=0, buffer_size_bytes=0)
4951

5052
# Execute a query that returns a small result set (will use INLINE disposition)
5153
logger.info("Executing query: SELECT * FROM range(1, 10) AS id")
@@ -97,159 +99,6 @@ def test_sea_result_set_json_array_inline():
9799
logger.info("SEA result set test with JSON_ARRAY format and INLINE disposition completed successfully")
98100

99101

100-
def test_sea_query_execution_with_compression():
101-
"""
102-
Test executing a query using the SEA backend with result compression.
103-
104-
This function connects to a Databricks SQL endpoint using the SEA backend,
105-
executes a simple query with result compression enabled and disabled,
106-
and verifies that execution completes successfully.
107-
"""
108-
server_hostname = os.environ.get("DATABRICKS_SERVER_HOSTNAME")
109-
http_path = os.environ.get("DATABRICKS_HTTP_PATH")
110-
access_token = os.environ.get("DATABRICKS_TOKEN")
111-
catalog = os.environ.get("DATABRICKS_CATALOG")
112-
113-
if not all([server_hostname, http_path, access_token]):
114-
logger.error("Missing required environment variables.")
115-
logger.error(
116-
"Please set DATABRICKS_SERVER_HOSTNAME, DATABRICKS_HTTP_PATH, and DATABRICKS_TOKEN."
117-
)
118-
sys.exit(1)
119-
120-
try:
121-
# Test with compression enabled
122-
logger.info("Creating connection with LZ4 compression enabled")
123-
connection = Connection(
124-
server_hostname=server_hostname,
125-
http_path=http_path,
126-
access_token=access_token,
127-
catalog=catalog,
128-
schema="default",
129-
use_sea=True,
130-
user_agent_entry="SEA-Test-Client",
131-
use_cloud_fetch=True, # Enable cloud fetch to use compression
132-
enable_query_result_lz4_compression=True, # Enable LZ4 compression
133-
)
134-
135-
logger.info(
136-
f"Successfully opened SEA session with ID: {connection.get_session_id_hex()}"
137-
)
138-
logger.info(f"backend type: {type(connection.session.backend)}")
139-
140-
# Execute a simple query with compression enabled
141-
cursor = connection.cursor(arraysize=0, buffer_size_bytes=0)
142-
logger.info("Executing query with LZ4 compression: SELECT 1 as test_value")
143-
cursor.execute("SELECT 1 as test_value")
144-
logger.info("Query with compression executed successfully")
145-
cursor.close()
146-
connection.close()
147-
logger.info("Successfully closed SEA session with compression enabled")
148-
149-
# Test with compression disabled
150-
logger.info("Creating connection with LZ4 compression disabled")
151-
connection = Connection(
152-
server_hostname=server_hostname,
153-
http_path=http_path,
154-
access_token=access_token,
155-
catalog=catalog,
156-
schema="default",
157-
use_sea=True,
158-
user_agent_entry="SEA-Test-Client",
159-
use_cloud_fetch=False, # Enable cloud fetch
160-
enable_query_result_lz4_compression=False, # Disable LZ4 compression
161-
)
162-
163-
logger.info(
164-
f"Successfully opened SEA session with ID: {connection.get_session_id_hex()}"
165-
)
166-
167-
# Execute a simple query with compression disabled
168-
cursor = connection.cursor(arraysize=0, buffer_size_bytes=0)
169-
logger.info("Executing query without compression: SELECT 1 as test_value")
170-
cursor.execute("SELECT 1 as test_value")
171-
logger.info("Query without compression executed successfully")
172-
cursor.close()
173-
connection.close()
174-
logger.info("Successfully closed SEA session with compression disabled")
175-
176-
except Exception as e:
177-
logger.error(f"Error during SEA query execution test: {str(e)}")
178-
import traceback
179-
180-
logger.error(traceback.format_exc())
181-
sys.exit(1)
182-
183-
logger.info("SEA query execution test with compression completed successfully")
184-
185-
186-
def test_sea_session():
187-
"""
188-
Test opening and closing a SEA session using the connector.
189-
190-
This function connects to a Databricks SQL endpoint using the SEA backend,
191-
opens a session, and then closes it.
192-
193-
Required environment variables:
194-
- DATABRICKS_SERVER_HOSTNAME: Databricks server hostname
195-
- DATABRICKS_HTTP_PATH: HTTP path for the SQL endpoint
196-
- DATABRICKS_TOKEN: Personal access token for authentication
197-
"""
198-
server_hostname = os.environ.get("DATABRICKS_SERVER_HOSTNAME")
199-
http_path = os.environ.get("DATABRICKS_HTTP_PATH")
200-
access_token = os.environ.get("DATABRICKS_TOKEN")
201-
catalog = os.environ.get("DATABRICKS_CATALOG")
202-
203-
if not all([server_hostname, http_path, access_token]):
204-
logger.error("Missing required environment variables.")
205-
logger.error(
206-
"Please set DATABRICKS_SERVER_HOSTNAME, DATABRICKS_HTTP_PATH, and DATABRICKS_TOKEN."
207-
)
208-
sys.exit(1)
209-
210-
logger.info(f"Connecting to {server_hostname}")
211-
logger.info(f"HTTP Path: {http_path}")
212-
if catalog:
213-
logger.info(f"Using catalog: {catalog}")
214-
215-
try:
216-
logger.info("Creating connection with SEA backend...")
217-
connection = Connection(
218-
server_hostname=server_hostname,
219-
http_path=http_path,
220-
access_token=access_token,
221-
catalog=catalog,
222-
schema="default",
223-
use_sea=True,
224-
user_agent_entry="SEA-Test-Client", # add custom user agent
225-
)
226-
227-
logger.info(
228-
f"Successfully opened SEA session with ID: {connection.get_session_id_hex()}"
229-
)
230-
logger.info(f"backend type: {type(connection.session.backend)}")
231-
232-
# Close the connection
233-
logger.info("Closing the SEA session...")
234-
connection.close()
235-
logger.info("Successfully closed SEA session")
236-
237-
except Exception as e:
238-
logger.error(f"Error testing SEA session: {str(e)}")
239-
import traceback
240-
241-
logger.error(traceback.format_exc())
242-
sys.exit(1)
243-
244-
logger.info("SEA session test completed successfully")
245-
246-
247102
if __name__ == "__main__":
248-
# Test session management
249-
test_sea_session()
250-
251-
# Test query execution with compression
252-
test_sea_query_execution_with_compression()
253-
254103
# Test result set implementation
255104
test_sea_result_set_json_array_inline()

src/databricks/sql/backend/sea_backend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ def execute_command(
277277

278278
format = "ARROW_STREAM" if use_cloud_fetch else "JSON_ARRAY"
279279
disposition = "EXTERNAL_LINKS" if use_cloud_fetch else "INLINE"
280-
result_compression = "LZ4_FRAME" if lz4_compression else "NONE"
280+
result_compression = "LZ4_FRAME" if lz4_compression else None
281281

282282
request = ExecuteStatementRequest(
283283
warehouse_id=self.warehouse_id,

0 commit comments

Comments
 (0)