How to use the pyhive.presto function in PyHive

To help you get started, we’ve selected a few PyHive examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github apache / incubator-superset / superset / db_engines / presto.py View on Github external
def cancel(self):
    if self._state == self._STATE_NONE:
        raise presto.ProgrammingError('No query yet')
    if self._nextUri is None:
        assert self._state == self._STATE_FINISHED, \
            'Should be finished if nextUri is None'
        return

    response = presto.requests.delete(self._nextUri)

    # pylint: disable=no-member
    if response.status_code != presto.requests.codes.no_content:
        fmt = 'Unexpected status code after cancel {}\n{}'
        raise presto.OperationalError(
            fmt.format(response.status_code, response.content))
    self._state = self._STATE_FINISHED
    return
github apache / incubator-superset / superset / db_engines / presto.py View on Github external
def cancel(self):
    if self._state == self._STATE_NONE:
        raise presto.ProgrammingError('No query yet')
    if self._nextUri is None:
        assert self._state == self._STATE_FINISHED, \
            'Should be finished if nextUri is None'
        return

    response = presto.requests.delete(self._nextUri)

    # pylint: disable=no-member
    if response.status_code != presto.requests.codes.no_content:
        fmt = 'Unexpected status code after cancel {}\n{}'
        raise presto.OperationalError(
            fmt.format(response.status_code, response.content))
    self._state = self._STATE_FINISHED
    return
github dropbox / PyHive / pyhive / sqlalchemy_presto.py View on Github external
def _get_table_columns(self, connection, table_name, schema):
        full_table = self.identifier_preparer.quote_identifier(table_name)
        if schema:
            full_table = self.identifier_preparer.quote_identifier(schema) + '.' + full_table
        try:
            return connection.execute('SHOW COLUMNS FROM {}'.format(full_table))
        except (presto.DatabaseError, exc.DatabaseError) as e:
            # Normally SQLAlchemy should wrap this exception in sqlalchemy.exc.DatabaseError, which
            # it successfully does in the Hive version. The difference with Presto is that this
            # error is raised when fetching the cursor's description rather than the initial execute
            # call. SQLAlchemy doesn't handle this. Thus, we catch the unwrapped
            # presto.DatabaseError here.
            # Does the table exist?
            msg = (
                e.args[0].get('message') if e.args and isinstance(e.args[0], dict)
                else e.args[0] if e.args and isinstance(e.args[0], str)
                else None
            )
            regex = r"Table\ \'.*{}\'\ does\ not\ exist".format(re.escape(table_name))
            if msg and re.search(regex, msg):
                raise exc.NoSuchTableError(table_name)
            else:
                raise