(core) Just return a list from _get_col_subset, remove ColumnView class

Summary: Just return a list from _get_col_subset, remove ColumnView class

Test Plan: none

Reviewers: dsagal, georgegevoian

Reviewed By: dsagal, georgegevoian

Subscribers: georgegevoian

Differential Revision: https://phab.getgrist.com/D2975
This commit is contained in:
Alex Hall 2021-08-12 02:36:59 +02:00
parent 0d1a285129
commit 4cd888c342
4 changed files with 9 additions and 48 deletions

View File

@ -183,7 +183,7 @@ def encode_object(value):
return ['d', moment.date_to_ts(value)] return ['d', moment.date_to_ts(value)]
elif isinstance(value, RaisedException): elif isinstance(value, RaisedException):
return ['E'] + value.encode_args() return ['E'] + value.encode_args()
elif isinstance(value, (list, tuple, RecordList, records.ColumnView)): elif isinstance(value, (list, tuple, RecordList)):
return ['L'] + [encode_object(item) for item in value] return ['L'] + [encode_object(item) for item in value]
elif isinstance(value, records.RecordSet): elif isinstance(value, records.RecordSet):
# Represent RecordSet (e.g. result of lookupRecords) in the same way as a RecordList. # Represent RecordSet (e.g. result of lookupRecords) in the same way as a RecordList.

View File

@ -192,31 +192,6 @@ class RecordSet(object):
sort_by=self._sort_by) sort_by=self._sort_by)
class ColumnView(object):
"""
ColumnView is an iterable that represents one column of a RecordSet. You may iterate through
its values and see its size, but it provides no other interface.
"""
def __init__(self, column_obj, row_ids, relation):
self._column = column_obj
self._row_ids = row_ids
self._source_relation = relation
def __len__(self):
return len(self._row_ids)
def __iter__(self):
for row_id in self._row_ids:
yield adjust_record(self._source_relation, self._column.get_cell_value(row_id))
def __eq__(self, other):
return (isinstance(other, ColumnView) and
(self._column, self._row_ids) == (other._column, other._row_ids))
def __ne__(self, other):
return not self.__eq__(other)
def adjust_record(relation, value): def adjust_record(relation, value):
""" """
Helper to adjust a Record's source relation to be the composition with the given relation. This Helper to adjust a Record's source relation to be the composition with the given relation. This

View File

@ -547,26 +547,19 @@ class Table(object):
# TODO: document everything here. # TODO: document everything here.
def _use_column(self, col_id, relation, row_ids):
"""
relation - Describes how the record was obtained, on which col_id is being accessed.
"""
col = self.all_columns[col_id]
# The _use_node call both creates a dependency and brings formula columns up-to-date.
self._engine._use_node(col.node, relation, row_ids)
return col
# Called when record.foo is accessed # Called when record.foo is accessed
def _get_col_value(self, col_id, row_id, relation): def _get_col_value(self, col_id, row_id, relation):
return records.adjust_record(relation, [value] = self._get_col_subset(col_id, [row_id], relation)
self._use_column(col_id, relation, [row_id]).get_cell_value(row_id)) return value
def _attribute_error(self, col_id, relation): def _attribute_error(self, col_id, relation):
self._engine._use_node(self._new_columns_node, relation) self._engine._use_node(self._new_columns_node, relation)
raise AttributeError("Table '%s' has no column '%s'" % (self.table_id, col_id)) raise AttributeError("Table '%s' has no column '%s'" % (self.table_id, col_id))
# Called when record_set.foo is accessed. Should return something like a ColumnView. # Called when record_set.foo is accessed
def _get_col_subset(self, col_id, row_ids, relation): def _get_col_subset(self, col_id, row_ids, relation):
# TODO: when column is a reference, we ought to return RecordSet. Otherwise ColumnView col = self.all_columns[col_id]
# looks like a RecordSet (returns Records), but doesn't support property access. # creates a dependency and brings formula columns up-to-date.
return records.ColumnView(self._use_column(col_id, relation, row_ids), row_ids, relation) self._engine._use_node(col.node, relation, row_ids)
# TODO: when column is a reference, support property access in return value
return [records.adjust_record(relation, col.get_cell_value(row_id)) for row_id in row_ids]

View File

@ -226,13 +226,6 @@ class TestRenames(test_engine.EngineTestCase):
"People.lookupOne(addr=$id, city=$city).nombre", "People.lookupOne(addr=$id, city=$city).nombre",
"People.lookupRecords(addr=$id).nombre"] "People.lookupRecords(addr=$id).nombre"]
}], }],
# TODO This is a symptom of comparing before and after values using rich values that refer
# to a destroyed column (a ColumnView). In reality, the values before and after after the
# same, but here the attempt to encode the previous value produces an incorrect result.
# (It's a bug, but not easy to fix and hopefully hard to run into.)
["BulkUpdateRecord", "Address", [11, 12, 13],
{"people2": [["L", "Sam"], ["L", "Bob", "Doug"], ["L", "Alice"]]
}],
]}) ]})
def test_rename_lookup_ref_attr(self): def test_rename_lookup_ref_attr(self):