示例#1
0
    def update(self, data):
        '''Update the Table with new data.

        Updates on tables without an explicit `index` are treated as appends.

        Updates on tables with an explicit `index` should have the index as part of the `data` param, as this instructs the engine
        to locate the indexed row and write into it. If an index is not provided, the update is treated as an append.

        Example:
            - to update the row with primary key "abc" on a Table with {"index": "a"}, `data` should be [{"a": "abc", "b": "new data"}]

        Params:
            data (dict|list|dataframe) : the data with which to update the Table
        '''
        columns = self.columns()
        types = self._table.get_schema().types()
        self._accessor = _PerspectiveAccessor(data)
        self._accessor._names = columns + [name for name in self._accessor._names if name == "__INDEX__"]
        self._accessor._types = types[:len(columns)]

        if "__INDEX__" in self._accessor._names:
            if self._index != "":
                index_pos = self._accessor._names.index(self._index)
                index_dtype = self._accessor._types[index_pos]
                self._accessor._types.append(index_dtype)
            else:
                self._accessor._types.append(t_dtype.DTYPE_INT32)

        self._table = make_table(self._table, self._accessor, None, self._limit, self._index, t_op.OP_INSERT, True, False)
示例#2
0
 def test_make_view_two(self):
     accessor = _PerspectiveAccessor([{"a": 1, "b": 2}, {"a": 3, "b": 4}])
     view_config = ViewConfig({"row_pivots": ["a"], "column_pivots": ["b"]})
     tbl = make_table(None, accessor, None, 4294967295, '', t_op.OP_INSERT,
                      False, False)
     view = make_view_two(tbl, "view2", "|", view_config,
                          accessor._date_validator)
     assert view.num_rows() == 3
示例#3
0
    def remove(self, pkeys):
        '''Removes the rows with the primary keys specified in `pkeys`.

        If the table does not have an index, `remove()` has no effect. Removes propagate to views derived from the table.

        Example:
            - to remove rows with primary keys "abc" and "def", provide ["abc", "def"].

        Params:
            pkeys (list) : a list of primary keys to indicate the rows that should be removed.
        '''
        if self._index == "":
            return
        pkeys = list(map(lambda idx: {self._index: idx}, pkeys))
        types = [self._table.get_schema().get_dtype(self._index)]
        self._accessor = _PerspectiveAccessor(pkeys)
        self._accessor._names = [self._index]
        self._accessor._types = types
        make_table(self._table, self._accessor, None, self._limit, self._index, t_op.OP_DELETE, True, False)
示例#4
0
    def update(self, data):
        '''Update the Table with new data.

        Updates on tables without an explicit `index` are treated as appends.

        Updates on tables with an explicit `index` should have the index as part of the `data` param, as this instructs the engine
        to locate the indexed row and write into it. If an index is not provided, the update is treated as an append.

        Example:
            - to update the row with primary key "abc" on a Table with {"index": "a"}, `data` should be [{"a": "abc", "b": "new data"}]

        Params:
            data (dict|list|dataframe) : the data with which to update the Table
        '''
        types = self._table.get_schema().types()
        self._accessor = _PerspectiveAccessor(data)
        self._accessor._types = types[:len(self._accessor.names())]
        self._table = make_table(self._table, self._accessor, None,
                                 self._limit, self._index, t_op.OP_INSERT,
                                 True, False)
示例#5
0
    def __init__(self, data_or_schema, config=None):
        '''Construct a Table using the provided data or schema and optional configuration dictionary.

        Tables are immutable - column names and data types cannot be changed after creation.

        If a schema is provided, the table will be empty. Subsequent updates MUST conform to the column names and data types provided in the schema.

        Params:
            data_or_schema (dict/list/dataframe)
            config (dict) : optional configurations for the Table:
                - limit (int) : the maximum number of rows the Table should have. Updates past the limit will begin writing at row 0.
                - index (string) : a string column name to use as the Table's primary key.
        '''
        config = config or {}
        self._accessor = _PerspectiveAccessor(data_or_schema)
        self._limit = config.get("limit", 4294967295)
        self._index = config.get("index", "")
        self._table = make_table(None, self._accessor, None, self._limit,
                                 self._index, t_op.OP_INSERT, False, False)
        self._gnode_id = self._table.get_gnode().get_id()
        self._callbacks = []
示例#6
0
 def test_make_table(self):
     data = _PerspectiveAccessor([{"a": 1, "b": 2}, {"a": 3, "b": 3}])
     tbl = make_table(None, data, None, 4294967295, '', t_op.OP_INSERT,
                      False, False)
     assert tbl.size() == 2