Connection to Impala using the impyla client connecting to HS2 endpoint. impyla implements the standard Python dbabi: https://www.python.org/dev/peps/pep-0249/ plus Impala-specific extensions, e.g. for fetching runtime profiles. TODO: implement support for kerberos, SSL, etc.
| 520 | |
| 521 | |
| 522 | class ImpylaHS2Connection(ImpalaConnection): |
| 523 | """Connection to Impala using the impyla client connecting to HS2 endpoint. |
| 524 | impyla implements the standard Python dbabi: https://www.python.org/dev/peps/pep-0249/ |
| 525 | plus Impala-specific extensions, e.g. for fetching runtime profiles. |
| 526 | TODO: implement support for kerberos, SSL, etc. |
| 527 | """ |
| 528 | |
| 529 | # ClientRequestState::TOperationState() |
| 530 | OPERATION_STATE_TO_EXEC_STATE = { |
| 531 | 'INITIALIZED_STATE': INITIALIZED, |
| 532 | 'PENDING_STATE': PENDING, |
| 533 | 'RUNNING_STATE': RUNNING, |
| 534 | 'FINISHED_STATE': FINISHED, |
| 535 | 'ERROR_STATE': ERROR, |
| 536 | # These are not official ExecState, but added to complete mapping. |
| 537 | 'CANCELED_STATE': 'UNIMPLEMENTED_CANCELLED', |
| 538 | 'CLOSED_STATE': 'UNIMPLEMENTED_CLOSED', |
| 539 | 'UKNOWN_STATE': 'UNIMPLEMENTED_UNKNOWN' |
| 540 | } |
| 541 | |
| 542 | def __init__(self, host_port, use_kerberos=False, is_hive=False, |
| 543 | use_http_transport=False, http_path="", use_ssl=False, |
| 544 | collect_profile_and_log=True, user=None): |
| 545 | self.__host_port = host_port |
| 546 | self.__use_http_transport = use_http_transport |
| 547 | self.__http_path = http_path |
| 548 | self.__use_ssl = use_ssl |
| 549 | if use_kerberos: |
| 550 | raise NotImplementedError("Kerberos support not yet implemented") |
| 551 | # Impyla connection and cursor is initialised in connect(). We need to reuse the same |
| 552 | # cursor for different operations (as opposed to creating a new cursor per operation) |
| 553 | # so that the session is preserved. This means that we can only execute one operation |
| 554 | # at a time per connection, which is a limitation also imposed by the Beeswax API. |
| 555 | # However, for ease of async query testing, opening multiple cursors through single |
| 556 | # ImpylaHS2Connection is allowed if executing query through execute_async() or |
| 557 | # execute() with user parameter that is different than self.__user. Do note though |
| 558 | # that they will not share the same session with self.__cursor. |
| 559 | self.__impyla_conn = None |
| 560 | self.__cursor = None |
| 561 | # List of all cursors that created through execute_async. |
| 562 | self.__async_cursors = list() |
| 563 | # Query options to send along with each query. |
| 564 | self.__query_options = {} |
| 565 | self._is_hive = is_hive |
| 566 | # Some Hive HS2 protocol, such as custom Calcite planner, may be able to collect |
| 567 | # profile and log from Impala. |
| 568 | self._collect_profile_and_log = collect_profile_and_log |
| 569 | self.__user = user |
| 570 | |
| 571 | def get_test_protocol(self): |
| 572 | if self.__http_path: |
| 573 | return HS2_HTTP |
| 574 | else: |
| 575 | return HS2 |
| 576 | |
| 577 | def get_host_port(self): |
| 578 | return self.__host_port |
| 579 |
no outgoing calls
no test coverage detected