Get a cursor to an impalad Args: impalad: A string in form 'hostname:port' or 'hostname' use_kerberos: boolean indication whether to get a secure connection. database: default db to use in the connection. Returns: HiveServer2Cursor if the connection suceeds, None otherwise.
(impalad, use_kerberos=False, database=None)
| 83 | |
| 84 | |
| 85 | def get_hs2_impala_cursor(impalad, use_kerberos=False, database=None): |
| 86 | """Get a cursor to an impalad |
| 87 | |
| 88 | Args: |
| 89 | impalad: A string in form 'hostname:port' or 'hostname' |
| 90 | use_kerberos: boolean indication whether to get a secure connection. |
| 91 | database: default db to use in the connection. |
| 92 | |
| 93 | Returns: |
| 94 | HiveServer2Cursor if the connection suceeds, None otherwise. |
| 95 | """ |
| 96 | try: |
| 97 | host, port = impalad.split(":") |
| 98 | except ValueError: |
| 99 | host, port = impalad, DEFAULT_HS2_PORT |
| 100 | cursor = None |
| 101 | try: |
| 102 | conn = connect(host=host, |
| 103 | port=port, |
| 104 | database=database, |
| 105 | auth_mechanism="GSSAPI" if use_kerberos else "NOSASL") |
| 106 | cursor = conn.cursor() |
| 107 | LOG.info("Connected to {0}:{1}".format(host, port)) |
| 108 | except Exception as e: |
| 109 | LOG.error("Error connecting: {0}".format(str(e))) |
| 110 | return cursor |
| 111 | |
| 112 | |
| 113 | def execute_using_impala_hs2(query, query_config): |
no test coverage detected