Esempio n. 1
0
            new_logs = _unwrap_column(response.results.columns[0])
            logs += new_logs

            if not new_logs:
                break

        return logs


#
# Type Objects and Constructors
#

for type_id in constants.PRIMITIVE_TYPES:
    name = ttypes.TTypeId._VALUES_TO_NAMES[type_id]
    setattr(sys.modules[__name__], name, DBAPITypeObject([name]))

#
# Private utilities
#


def _unwrap_column(col):
    """Return a list of raw values from a TColumn instance."""
    for attr, wrapper in col.__dict__.iteritems():
        if wrapper is not None:
            values = wrapper.values
            nulls = wrapper.nulls  # bit set describing what's null
            assert isinstance(nulls, str)
            if attr == 'stringVal':
                result = [val.decode('utf-8') for val in values]
Esempio n. 2
0
        """Given the JSON response from Presto's REST API, update the internal state with the next
        URI and any data from the response
        """
        # TODO handle HTTP 503
        if response.status_code != requests.codes.ok:
            fmt = "Unexpected status code {}\n{}"
            raise OperationalError(
                fmt.format(response.status_code, response.content))
        response_json = response.json()
        _logger.debug("Got response %s", response_json)
        assert self._state == self._STATE_RUNNING, "Should be running if processing response"
        self._nextUri = response_json.get('nextUri')
        self._columns = response_json.get('columns')
        self._data += response_json.get('data', [])
        if 'nextUri' not in response_json:
            self._state = self._STATE_FINISHED
        if 'error' in response_json:
            assert not self._nextUri, "Should not have nextUri if failed"
            raise DatabaseError(response_json['error'])


#
# Type Objects and Constructors
#

# See types in presto-main/src/main/java/com/facebook/presto/tuple/TupleInfo.java
FIXED_INT_64 = DBAPITypeObject(['bigint'])
VARIABLE_BINARY = DBAPITypeObject(['varchar'])
DOUBLE = DBAPITypeObject(['double'])
BOOLEAN = DBAPITypeObject(['boolean'])