mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) Nice summary table IDs
Summary: Changes auto-generated summary table IDs from e.g. `GristSummary_6_Table1` to `Table1_summary_A_B` (meaning `Table1` grouped by `A` and `B`). This makes it easier to write formulas involving summary tables, make API requests, understand logs, etc. Because these don't encode the source table ID as reliably as before, `decode_summary_table_name` now uses the summary table schema info, not just the summary table ID. Specifically, it looks at the type of the `group` column, which is `RefList:<source table id>`. Renaming a source table renames the summary table as before, and now renaming a groupby column renames the summary table as well. Conflicting table names are resolved in the usual way by adding a number at the end, e.g. `Table1_summary_A_B2`. These summary tables are not automatically renamed when the disambiguation is no longer needed. A new migration renames all summary tables to the new scheme, and updates formulas using summary tables with a simple regex. Test Plan: Updated many tests to use the new style of name. Added new Python tests to for resolving conflicts when renaming source tables and groupby columns. Added a test for the migration, including renames in formulas. Reviewers: georgegevoian Reviewed By: georgegevoian Differential Revision: https://phab.getgrist.com/D3508
This commit is contained in:
@@ -128,7 +128,7 @@ class GenCode(object):
|
||||
If filter_for_user is True, includes only user-visible columns.
|
||||
"""
|
||||
table_id = table_info.tableId
|
||||
source_table_id = summary.decode_summary_table_name(table_id)
|
||||
source_table_id = summary.decode_summary_table_name(table_info)
|
||||
|
||||
# Sort columns by "isFormula" to output all data columns before all formula columns.
|
||||
columns = sorted(six.itervalues(table_info.columns), key=lambda c: c.isFormula)
|
||||
@@ -156,7 +156,7 @@ class GenCode(object):
|
||||
# Collect summary tables to group them by source table.
|
||||
summary_tables = {}
|
||||
for table_info in six.itervalues(schema):
|
||||
source_table_id = summary.decode_summary_table_name(table_info.tableId)
|
||||
source_table_id = summary.decode_summary_table_name(table_info)
|
||||
if source_table_id:
|
||||
summary_tables.setdefault(source_table_id, []).append(table_info)
|
||||
|
||||
@@ -167,7 +167,10 @@ class GenCode(object):
|
||||
for table_info in six.itervalues(schema):
|
||||
fullparts.append("\n\n")
|
||||
fullparts.append(self._make_table_model(table_info, summary_tables.get(table_info.tableId)))
|
||||
if not _is_special_table(table_info.tableId):
|
||||
if not (
|
||||
_is_special_table(table_info.tableId) or
|
||||
summary.decode_summary_table_name(table_info)
|
||||
):
|
||||
userparts.append("\n\n")
|
||||
userparts.append(self._make_table_model(table_info, summary_tables.get(table_info.tableId),
|
||||
filter_for_user=True))
|
||||
@@ -193,7 +196,7 @@ class GenCode(object):
|
||||
|
||||
|
||||
def _is_special_table(table_id):
|
||||
return table_id.startswith("_grist_") or bool(summary.decode_summary_table_name(table_id))
|
||||
return table_id.startswith("_grist_")
|
||||
|
||||
|
||||
def exec_module_text(module_text):
|
||||
|
||||
Reference in New Issue
Block a user