Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 145
[SC-110400] Enabling compression in Python SQL Connector#49
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
7545c75d726a0d2d0f030b258336ed2239b4b5bb53865ce90889dab22b96ca94aaac41023c9db6a43ab28cdf57df3cdf2489e1cc68168c718a8a1b50b4312fFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -4,6 +4,7 @@ | ||
| import math | ||
| import time | ||
| import threading | ||
| import lz4.frame | ||
| from ssl import CERT_NONE, CERT_REQUIRED, create_default_context | ||
| import pyarrow | ||
| @@ -451,7 +452,7 @@ def open_session(self, session_configuration, catalog, schema): | ||
| initial_namespace = None | ||
| open_session_req = ttypes.TOpenSessionReq( | ||
| client_protocol_i64=ttypes.TProtocolVersion.SPARK_CLI_SERVICE_PROTOCOL_V5, | ||
| client_protocol_i64=ttypes.TProtocolVersion.SPARK_CLI_SERVICE_PROTOCOL_V6, | ||
mohitsingla-db marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| client_protocol=None, | ||
| initialNamespace=initial_namespace, | ||
| canUseMultipleCatalogs=True, | ||
| @@ -507,7 +508,7 @@ def _poll_for_status(self, op_handle): | ||
| ) | ||
| return self.make_request(self._client.GetOperationStatus, req) | ||
| def _create_arrow_table(self, t_row_set, schema_bytes, description): | ||
| def _create_arrow_table(self, t_row_set, lz4_compressed, schema_bytes, description): | ||
| if t_row_set.columns is not None: | ||
| ( | ||
| arrow_table, | ||
| @@ -520,7 +521,7 @@ def _create_arrow_table(self, t_row_set, schema_bytes, description): | ||
| arrow_table, | ||
| num_rows, | ||
| ) = ThriftBackend._convert_arrow_based_set_to_arrow_table( | ||
| t_row_set.arrowBatches, schema_bytes | ||
| t_row_set.arrowBatches, lz4_compressed, schema_bytes | ||
| ) | ||
| else: | ||
| raise OperationalError("Unsupported TRowSet instance {}".format(t_row_set)) | ||
| @@ -545,13 +546,20 @@ def _convert_decimals_in_arrow_table(table, description): | ||
| return table | ||
| @staticmethod | ||
| def _convert_arrow_based_set_to_arrow_table(arrow_batches, schema_bytes): | ||
| def _convert_arrow_based_set_to_arrow_table( | ||
| arrow_batches, lz4_compressed, schema_bytes | ||
| ): | ||
| ba = bytearray() | ||
| ba += schema_bytes | ||
| n_rows = 0 | ||
| for arrow_batch in arrow_batches: | ||
| n_rows += arrow_batch.rowCount | ||
| ba += arrow_batch.batch | ||
| if lz4_compressed: | ||
| for arrow_batch in arrow_batches: | ||
| n_rows += arrow_batch.rowCount | ||
| ba += lz4.frame.decompress(arrow_batch.batch) | ||
| else: | ||
| for arrow_batch in arrow_batches: | ||
| n_rows += arrow_batch.rowCount | ||
| ba += arrow_batch.batch | ||
| arrow_table = pyarrow.ipc.open_stream(ba).read_all() | ||
| return arrow_table, n_rows | ||
| @@ -708,7 +716,6 @@ def _results_message_to_execute_response(self, resp, operation_state): | ||
| ] | ||
| ) | ||
| ) | ||
| direct_results = resp.directResults | ||
| has_been_closed_server_side = direct_results and direct_results.closeOperation | ||
| has_more_rows = ( | ||
| @@ -725,12 +732,16 @@ def _results_message_to_execute_response(self, resp, operation_state): | ||
| .serialize() | ||
| .to_pybytes() | ||
| ) | ||
| lz4_compressed = t_result_set_metadata_resp.lz4Compressed | ||
| if direct_results and direct_results.resultSet: | ||
| assert direct_results.resultSet.results.startRowOffset == 0 | ||
| assert direct_results.resultSetMetadata | ||
| arrow_results, n_rows = self._create_arrow_table( | ||
| direct_results.resultSet.results, schema_bytes, description | ||
| direct_results.resultSet.results, | ||
| lz4_compressed, | ||
| schema_bytes, | ||
| description, | ||
| ) | ||
| arrow_queue_opt = ArrowQueue(arrow_results, n_rows, 0) | ||
| else: | ||
| @@ -740,6 +751,7 @@ def _results_message_to_execute_response(self, resp, operation_state): | ||
| status=operation_state, | ||
| has_been_closed_server_side=has_been_closed_server_side, | ||
| has_more_rows=has_more_rows, | ||
| lz4_compressed=lz4_compressed, | ||
| command_handle=resp.operationHandle, | ||
| description=description, | ||
| arrow_schema_bytes=schema_bytes, | ||
| @@ -783,7 +795,9 @@ def _check_direct_results_for_error(t_spark_direct_results): | ||
| t_spark_direct_results.closeOperation | ||
| ) | ||
| def execute_command(self, operation, session_handle, max_rows, max_bytes, cursor): | ||
| def execute_command( | ||
| self, operation, session_handle, max_rows, max_bytes, lz4_compression, cursor | ||
| ): | ||
| assert session_handle is not None | ||
| spark_arrow_types = ttypes.TSparkArrowTypes( | ||
| @@ -802,7 +816,7 @@ def execute_command(self, operation, session_handle, max_rows, max_bytes, cursor | ||
| maxRows=max_rows, maxBytes=max_bytes | ||
| ), | ||
| canReadArrowResult=True, | ||
| canDecompressLZ4Result=False, | ||
| canDecompressLZ4Result=lz4_compression, | ||
| canDownloadResult=False, | ||
| confOverlay={ | ||
| # We want to receive proper Timestamp arrow types. | ||
| @@ -916,6 +930,7 @@ def fetch_results( | ||
| max_rows, | ||
| max_bytes, | ||
| expected_row_start_offset, | ||
| lz4_compressed, | ||
| arrow_schema_bytes, | ||
| description, | ||
| ): | ||
| @@ -941,7 +956,7 @@ def fetch_results( | ||
| ) | ||
| ) | ||
| arrow_results, n_rows = self._create_arrow_table( | ||
| resp.results, arrow_schema_bytes, description | ||
| resp.results, lz4_compressed, arrow_schema_bytes, description | ||
| ) | ||
| arrow_queue = ArrowQueue(arrow_results, n_rows) | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.