예제 #1
0
    def __init__(self, Table, **config):
        '''Private constructor for a View object - use the Table.view() method to create Views.

        A View object represents a specific transform (configuration or pivot,
        filter, sort, etc) configuration on an underlying Table. A View
        receives all updates from the Table from which it is derived, and
        can be serialized to JSON or trigger a callback when it is updated.

        View objects are immutable, and will remain in memory and actively process
        updates until its delete() method is called.
        '''
        self._name = "py_" + str(random())
        self._table = Table
        self._config = ViewConfig(**config)
        self._sides = self.sides()

        date_validator = self._table._accessor._date_validator
        if self._sides == 0:
            self._view = make_view_zero(self._table._table, self._name,
                                        COLUMN_SEPARATOR_STRING, self._config,
                                        date_validator)
        elif self._sides == 1:
            self._view = make_view_one(self._table._table, self._name,
                                       COLUMN_SEPARATOR_STRING, self._config,
                                       date_validator)
        else:
            self._view = make_view_two(self._table._table, self._name,
                                       COLUMN_SEPARATOR_STRING, self._config,
                                       date_validator)

        self._column_only = self._view.is_column_only()
        self._callbacks = self._table._callbacks
        self._delete_callbacks = _PerspectiveCallBackCache()
예제 #2
0
 def test_make_view_zero(self):
     accessor = _PerspectiveAccessor([{"a": 1, "b": 2}, {"a": 3, "b": 4}])
     view_config = ViewConfig({})
     tbl = make_table(None, accessor, None, 4294967295, '', t_op.OP_INSERT,
                      False, False)
     view = make_view_zero(tbl, "view0", "|", view_config,
                           accessor._date_validator)
     assert view.num_rows() == 2