-
Notifications
You must be signed in to change notification settings - Fork 128
SI: Implement put operations #67
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
Changes from 10 commits
28c3a59
1b245b1
1239def
b605cce
3ed84d8
57b8a34
7812278
6b76439
3df7c89
8f0a02e
55525cb
157ac3d
0739ccc
d3a3651
72f917e
fba64b7
c27a3d6
19ca706
0167bd9
85e4d7c
713002d
fc06ef8
cafa17d
a508a1c
ce80df0
36885a4
c0c09d4
f612795
e609ef3
cdbe2d6
34a0362
c8a64c7
d48d3f3
e0037e0
3fa5d84
4824b68
469f35f
bdb948a
0261b7a
00d8a49
7a602e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
|
|
||
| import pandas | ||
| import pyarrow | ||
| import requests | ||
|
|
||
| from databricks.sql import __version__ | ||
| from databricks.sql import * | ||
|
|
@@ -297,6 +298,58 @@ def _check_not_closed(self): | |
| if not self.open: | ||
| raise Error("Attempting operation on closed cursor") | ||
|
|
||
| def _handle_staging_operation(self): | ||
| """Make HTTP request using instructions provided by server""" | ||
|
|
||
| row = self.active_result_set.fetchone() | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know if we are using a field member
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm confused by the first part of your question:
I don't believe this is correct.
You're pulling on a valid thread. But I disagree with this assessment. In general pysql works fine with multi-threading. In fact, multi-threading is required if you want to cancel a running query (which is reflected in The specific scenario where |
||
|
|
||
| # TODO: Handle headers. What format will gateway send? json? plaintext? | ||
| operation, presigned_url, local_file, headers = ( | ||
| row.operation, | ||
| row.presignedUrl, | ||
| row.localFile, | ||
| None, | ||
susodapop marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) | ||
|
|
||
| operation_map = { | ||
susodapop marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "PUT": requests.put, | ||
| "GET": requests.get, | ||
| } | ||
|
|
||
| if operation not in operation_map: | ||
| raise Error( | ||
| "Operation {} is not supported. Supported operations are {}".format( | ||
| operation, ",".join(operation_map.keys()) | ||
susodapop marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) | ||
| ) | ||
|
|
||
| req_func = operation_map[operation] | ||
|
|
||
| if local_file: | ||
| raw_data = open(local_file, "rb") | ||
|
||
| else: | ||
| raw_data = None | ||
|
|
||
| rq_func_args = dict(url=presigned_url, data=raw_data) | ||
susodapop marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| logger.debug( | ||
| "Attempting staging operation: {} - {}".format(operation, local_file) | ||
susodapop marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) | ||
|
|
||
| # Call the function | ||
| resp = req_func(**rq_func_args) | ||
|
|
||
| if resp.status_code != 200: | ||
susodapop marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
susodapop marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| raise Error( | ||
| "Staging operation over HTTP was unsuccessful: {}-{}".format( | ||
moderakh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| resp.status_code, resp.text | ||
| ) | ||
| ) | ||
|
|
||
| if operation == "GET": | ||
| with open(local_file, "wb") as fp: | ||
| fp.write(resp.content) | ||
|
|
||
| def execute( | ||
| self, operation: str, parameters: Optional[Dict[str, str]] = None | ||
| ) -> "Cursor": | ||
|
|
@@ -331,6 +384,10 @@ def execute( | |
| self.buffer_size_bytes, | ||
| self.arraysize, | ||
| ) | ||
|
|
||
| if execute_response.is_staging_operation: | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question for reviewers: is there any specifically desired end-state for the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't quite get this question, but the cursor for now will return just one row and we should have reached the end of this cursor.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @susodapop could you please with an a sample code explain how this will provide different experience to the end user? |
||
| self._handle_staging_operation() | ||
|
|
||
| return self | ||
|
|
||
| def executemany(self, operation, seq_of_parameters): | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.