Beispiel #1
0
    def __init__(self,
                 resp,
                 all_latency,
                 decode_type='utf-8',
                 timezone_offset: int = 0):
        """Constructor method

        :param resp: the response from the service
        :param all_latency: the execution time from the time the client
        sends the request to the time the response is received and the data is decoded
        :param decode_type: the decode_type for decode binary value, it comes from the service,
        but now the service not return, use utf-8 default
        :param timezone_offset: the timezone offset for calculate local time,
        it comes from the service
        """
        self._decode_type = decode_type
        self._resp = resp
        self._data_set_wrapper = None
        self._all_latency = all_latency
        self._timezone_offset = timezone_offset
        if self._resp.data is not None:
            self._data_set_wrapper = DataSetWrapper(
                data_set=resp.data,
                decode_type=self._decode_type,
                timezone_offset=self._timezone_offset)
Beispiel #2
0
 def compare(self, lhs: DataSetWrapper, rhs: DataSetWrapper):
     if lhs.get_row_size() != rhs.get_row_size():
         return False
     if not lhs.get_col_names() == rhs.get_col_names():
         return False
     if self._order:
         return all(self.compare_row(l, r) for (l, r) in zip(lhs, rhs))
     return self._compare_list(lhs, rhs, self.compare_row)
 def __init__(self, resp, decode_type='utf-8'):
     """
     get data from ResultSet
     """
     self._decode_type = decode_type
     self._resp = resp
     self._data_set_wrapper = None
     if self._resp.data is not None:
         self._data_set_wrapper = DataSetWrapper(resp.data, self._decode_type)
def result_should_be_relax_cmp(result, nba_space):
    rs = nba_space['result_set']
    assert rs.is_succeeded()
    ds = dataset(table(result))
    dsw = DataSetWrapper(ds)
    dscmp = DataSetWrapperComparator(strict=False, order=False)
    assert dscmp(rs._data_set_wrapper, dsw)
Beispiel #5
0
 def __init__(self,
              resp,
              all_latency,
              decode_type='utf-8',
              timezone_offset: int = 0):
     """
     get data from ResultSet
     """
     self._decode_type = decode_type
     self._resp = resp
     self._data_set_wrapper = None
     self._all_latency = all_latency
     self._timezone_offset = timezone_offset
     if self._resp.data is not None:
         self._data_set_wrapper = DataSetWrapper(
             data_set=resp.data,
             decode_type=self._decode_type,
             timezone_offset=self._timezone_offset)
Beispiel #6
0
    def get_data_set_wrapper(self):
        """get DataSetWrapper, it's the wrapper for DataSet value, the string type is str

        :return: DataSetWrapper
        """
        result = None
        for data_set in self._data_sets:
            if result is None:
                result = data_set
                continue
            if len(data_set.column_names) != len(result.column_names):
                raise RuntimeError('Multi DataSets are different col size')
            result.rows.extend(data_set.rows)

        if result is None:
            return None
        return DataSetWrapper(result, self._decode_type)
Beispiel #7
0
class ResultSet(object):
    def __init__(self,
                 resp,
                 all_latency,
                 decode_type='utf-8',
                 timezone_offset: int = 0):
        """Constructor method

        :param resp: the response from the service
        :param all_latency: the execution time from the time the client
        sends the request to the time the response is received and the data is decoded
        :param decode_type: the decode_type for decode binary value, it comes from the service,
        but now the service not return, use utf-8 default
        :param timezone_offset: the timezone offset for calculate local time,
        it comes from the service
        """
        self._decode_type = decode_type
        self._resp = resp
        self._data_set_wrapper = None
        self._all_latency = all_latency
        self._timezone_offset = timezone_offset
        if self._resp.data is not None:
            self._data_set_wrapper = DataSetWrapper(
                data_set=resp.data,
                decode_type=self._decode_type,
                timezone_offset=self._timezone_offset)

    def is_succeeded(self):
        """check the response from the sesrvice is succeeded

        :return: bool
        """
        return self._resp.error_code == ErrorCode.SUCCEEDED

    def error_code(self):
        """if the response is failed, the service return the error code

        :return: nebula2.common.ttypes.ErrorCode
        """
        return self._resp.error_code

    def space_name(self):
        """get the space for the current operation

        :return: space name or ''
        """
        if self._resp.space_name is None:
            return ''
        return self._resp.space_name.decode(self._decode_type)

    def error_msg(self):
        """if the response is failed, the service return the error message

        :return: error message
        """
        if self._resp.error_msg is None:
            return ''
        return self._resp.error_msg.decode(self._decode_type)

    def comment(self):
        """the comment return by service, it maybe some warning message

        :return: comment message
        """
        if self._resp.error_msg is None:
            return ''
        return self._resp.comment.decode(self._decode_type)

    def latency(self):
        """the time the server processes the request

        :return: latency
        """
        return self._resp.latency_in_us

    def whole_latency(self):
        """the execution time from the time the client
        sends the request to the time the response is received and the data is decoded

        :return: all_latency
        """
        return self._all_latency

    def plan_desc(self):
        """get plan desc, whe user want to get the execute plan use `PROFILE` and `EXPLAIN`

        :return:plan desc
        """
        return self._resp.plan_desc

    def is_empty(self):
        """the data of response is empty

        :return: true of false
        """
        return self._data_set_wrapper is None or self._data_set_wrapper.get_row_size(
        ) == 0

    def keys(self):
        """get the column names

        :return: column names
        """
        if self._data_set_wrapper is None:
            return []
        return self._data_set_wrapper.get_col_names()

    def row_size(self):
        """get the row size

        :return: row size
        """
        if self._data_set_wrapper is None:
            return 0
        return len(self._data_set_wrapper.get_rows())

    def col_size(self):
        """get column size

        :return: column size
        """
        if self._data_set_wrapper is None:
            return 0
        return len(self._data_set_wrapper.get_col_names())

    def get_row_types(self):
        """get the value type of the row

        :return: list<int>
          ttypes.Value.__EMPTY__ = 0
          ttypes.Value.NVAL = 1
          ttypes.Value.BVAL = 2
          ttypes.Value.IVAL = 3
          ttypes.Value.FVAL = 4
          ttypes.Value.SVAL = 5
          ttypes.Value.DVAL = 6
          ttypes.Value.TVAL = 7
          ttypes.Value.DTVAL = 8
          ttypes.Value.VVAL = 9
          ttypes.Value.EVAL = 10
          ttypes.Value.PVAL = 11
          ttypes.Value.LVAL = 12
          ttypes.Value.MVAL = 13
          ttypes.Value.UVAL = 14
          ttypes.Value.GVAL = 15
        """
        if self._data_set_wrapper is None:
            return []
        return self._data_set_wrapper.get_row_types()

    def row_values(self, row_index):
        """get row values

        :param row_index:
        :return: list<ValueWrapper>
        """
        if self._data_set_wrapper is None:
            return []
        return self._data_set_wrapper.row_values(row_index)

    def column_values(self, key):
        """get column values

        :param key: the specified column name
        :return: list<ValueWrapper>
        """
        if self._data_set_wrapper is None:
            return []
        return self._data_set_wrapper.column_values(key)

    def rows(self):
        """get all rows

        :return: list<Row>
        """
        if self._data_set_wrapper is None:
            return []
        return self._data_set_wrapper.get_rows()

    def __iter__(self):
        """the iterator for per row

        :return: iter
        """
        return iter(self._data_set_wrapper)

    def __repr__(self):
        return "{}({})".format(self.__class__.__name__, self._data_set_wrapper)

    def __eq__(self, other):
        if not isinstance(other, self.__class__):
            return False

        return self.__dict__ == other.__dict__

    def __ne__(self, other):
        return not (self == other)
class ResultSet(object):
    def __init__(self, resp, decode_type='utf-8'):
        """
        get data from ResultSet
        """
        self._decode_type = decode_type
        self._resp = resp
        self._data_set_wrapper = None
        if self._resp.data is not None:
            self._data_set_wrapper = DataSetWrapper(resp.data, self._decode_type)

    def is_succeeded(self):
        return self._resp.error_code == ttypes.ErrorCode.SUCCEEDED

    def error_code(self):
        return self._resp.error_code

    def space_name(self):
        if self._resp.space_name is None:
            return ''
        return self._resp.space_name.decode(self._decode_type)

    def error_msg(self):
        if self._resp.error_msg is None:
            return ''
        return self._resp.error_msg.decode(self._decode_type)

    def comment(self):
        if self._resp.error_msg is None:
            return ''
        return self._resp.comment.decode(self._decode_type)

    def latency(self):
        """
        unit us
        """
        return self._resp.latency_in_us

    def plan_desc(self):
        return self._resp.plan_desc

    def is_empty(self):
        return self._data_set_wrapper is None or self._data_set_wrapper.get_row_size() == 0

    def keys(self):
        """
        get colNames
        """
        if self._data_set_wrapper is None:
            return []
        return self._data_set_wrapper.get_col_names()

    def row_size(self):
        """
        get one row size
        """
        if self._data_set_wrapper is None:
            return 0
        return len(self._data_set_wrapper.get_rows())

    def col_size(self):
        """
        get one col size
        """
        if self._data_set_wrapper is None:
            return 0
        return len(self._data_set_wrapper.get_col_names())

    def get_row_types(self):
        """
        Get row types
        :param empty
        :return: list<int>
          ttypes.Value.__EMPTY__ = 0
          ttypes.Value.NVAL = 1
          ttypes.Value.BVAL = 2
          ttypes.Value.IVAL = 3
          ttypes.Value.FVAL = 4
          ttypes.Value.SVAL = 5
          ttypes.Value.DVAL = 6
          ttypes.Value.TVAL = 7
          ttypes.Value.DTVAL = 8
          ttypes.Value.VVAL = 9
          ttypes.Value.EVAL = 10
          ttypes.Value.PVAL = 11
          ttypes.Value.LVAL = 12
          ttypes.Value.MVAL = 13
          ttypes.Value.UVAL = 14
          ttypes.Value.GVAL = 15
        """
        if self._data_set_wrapper is None:
            return []
        return self._data_set_wrapper.get_row_types()

    def row_values(self, row_index):
        """
        Get row values
        :param index: the Record index
        :return: list<ValueWrapper>
        """
        if self._data_set_wrapper is None:
            return []
        return self._data_set_wrapper.row_values(row_index)

    def column_values(self, key):
        """
        get column values
        :param key: the col name
        :return: list<ValueWrapper>
        """
        if self._data_set_wrapper is None:
            return []
        return self._data_set_wrapper.column_values(key)

    def rows(self):
        """
        get all rows
        :return: list<Row>
        """
        if self._data_set_wrapper is None:
            return []
        return self._data_set_wrapper.get_rows()

    def __iter__(self):
        return iter(self._data_set_wrapper)

    def __repr__(self):
        return "{}({})".format(self.__class__.__name__, self._data_set_wrapper)

    def __eq__(self, other):
        if not isinstance(other, self.__class__):
            return False

        return self.__dict__ == other.__dict__

    def __ne__(self, other):
        return not (self == other)
Beispiel #9
0
    def test_all(self):
        data_set_warpper1 = DataSetWrapper(self.get_data_set())
        data_set_warpper2 = DataSetWrapper(self.get_data_set())

        # test iterator and compare
        row_count = 0
        for i in range(data_set_warpper1.get_row_size()):
            row_count = row_count + 1
            assert data_set_warpper1.row_values(
                i)[0] == data_set_warpper2.row_values(i)[0]
            assert data_set_warpper1.row_values(
                i)[1] == data_set_warpper2.row_values(i)[1]
            assert data_set_warpper1.row_values(
                i)[2] == data_set_warpper2.row_values(i)[2]
            assert data_set_warpper1.row_values(
                i)[3] == data_set_warpper2.row_values(i)[3]
            assert data_set_warpper1.row_values(
                i)[4] == data_set_warpper2.row_values(i)[4]
            assert data_set_warpper1.row_values(
                i)[5] == data_set_warpper2.row_values(i)[5]
            assert data_set_warpper1.row_values(
                i)[6] == data_set_warpper2.row_values(i)[6]
            assert data_set_warpper1.row_values(
                i)[7] == data_set_warpper2.row_values(i)[7]
            assert data_set_warpper1.row_values(
                i)[8] == data_set_warpper2.row_values(i)[8]
            assert data_set_warpper1.row_values(
                i)[9] == data_set_warpper2.row_values(i)[9]
            assert data_set_warpper1.row_values(
                i)[10] == data_set_warpper2.row_values(i)[10]
            assert data_set_warpper1.row_values(
                i)[11] == data_set_warpper2.row_values(i)[11]
            assert data_set_warpper1.row_values(
                i)[12] == data_set_warpper2.row_values(i)[12]
            assert data_set_warpper1.row_values(
                i)[13] == data_set_warpper2.row_values(i)[13]
            assert data_set_warpper1.row_values(
                i)[14] == data_set_warpper2.row_values(i)[14]
            assert data_set_warpper1.row_values(
                i)[9] != data_set_warpper2.row_values(i)[8]

        assert 2 == row_count
        assert 2 == data_set_warpper1.get_row_size()
        assert len(data_set_warpper1.column_values("col6_string")) == 2
        assert data_set_warpper1.column_values("col6_string")[0].is_string()
        assert data_set_warpper1.column_values(
            "col6_string")[0].as_string() == 'hello world'
        assert data_set_warpper1.column_values(
            "col6_string")[1].as_string() == 'hello world'

        assert data_set_warpper1.row_values(0)[5].is_string()
        assert data_set_warpper1.row_values(1)[5].is_string()
        assert data_set_warpper1.row_values(0)[5].as_string() == 'hello world'
        assert data_set_warpper1.row_values(1)[5].as_string() == 'hello world'