gristlabs_grist-core/sandbox
Dmitry S f0d0a07295 (core) Implement PREVIOUS/NEXT/RANK and lookupRecords().find.* methods.
Summary:
- `lookupRecords()` now allows efficient search in sorted results, with
  the syntax  `lookupRecords(..., order_by="-Date").find.le($Date)`. This will find the record with the nearest date that's <= `$Date`.
- The `find.*` methods are `le`, `lt`, `ge`, `gt`, and `eq`. All have O(log N) performance.
- `PREVIOUS(rec, group_by=..., order_by=...)` finds the previous record to rec, according to `group_by` / `order_by`, in amortized O(log N) time. For example, `PREVIOUS(rec, group_by="Account", order_by="Date")`.
- `PREVIOUS(rec, order_by=None)` finds the previous record in the full table, sorted by the `manualSort` column, to match the order visible in the unsorted table.
- `NEXT(...)` is just like `PREVIOUS(...)` but finds the next record.
- `RANK(rec, group_by=..., order_by=..., order="asc")` returns the rank of the record within the group, starting with 1. Order can be `"asc"` (default) or `"desc"`.
- The `order_by` argument in `lookupRecords`, and the new functions now supports tuples, as well as the "-" prefix to reverse order, e.g. `("Category", "-Date")`.
- New functions are only available in Python3, for a minor reason (to support keyword-only arguments for `group_by` and `order_by`) and also as a nudge to Python2 users to update.

- Includes fixes for several situations related to lookups that used to cause quadratic complexity.

Test Plan:
- New performance check that sorted lookups don't add quadratic complexity.
- Tests added for lookup find.* methods, and for PREVIOUS/NEXT/RANK.
- Tests added that renaming columns updates `order_by` and `group_by` arguments, and attributes on results (e.g. `PREVIOUS(...).ColId`) appropriately.
- Python3 tests can now produce verbose output when VERBOSE=1 and -v are given.

Reviewers: jarek, georgegevoian

Reviewed By: jarek, georgegevoian

Subscribers: paulfitz, jarek

Differential Revision: https://phab.getgrist.com/D4265
2024-07-17 12:00:55 -04:00
..
docker (core) Upgrade to Python 3.11 2023-08-04 18:19:40 +02:00
grist (core) Implement PREVIOUS/NEXT/RANK and lookupRecords().find.* methods. 2024-07-17 12:00:55 -04:00
gvisor Check gvisor on startup of run.sh, and clean up scripts related to gvisor flags (#760) 2023-11-27 16:20:43 -05:00
pyodide fix shebang in various bash scripts (#910) 2024-03-25 09:55:20 -04:00
bundle_as_wheel.sh fix shebang in various bash scripts (#910) 2024-03-25 09:55:20 -04:00
docker_entrypoint.sh Makes docker images default to non-root execution (#1031) 2024-06-27 14:24:32 +01:00
gen_js_schema.py add a script for copying schema information from python to typescript 2023-01-17 15:54:41 -05:00
install_tz.js (core) apply some dependabot suggestions 2022-09-07 14:15:34 -04:00
MANIFEST.in support other SQLite wrappers, and various hooks needed by grist-static (#516) 2023-05-23 15:17:28 -04:00
requirements3.in (core) Upgrade to Python 3.11 2023-08-04 18:19:40 +02:00
requirements3.txt (core) Fix updating attributes inside f-strings when columns are renamed 2023-09-11 14:41:30 +02:00
requirements.txt (core) Fix updating attributes inside f-strings when columns are renamed 2023-09-11 14:41:30 +02:00
run.sh Fix docker graceful shutdown (#830) 2024-01-30 10:00:59 -05:00
setup.py support other SQLite wrappers, and various hooks needed by grist-static (#516) 2023-05-23 15:17:28 -04:00
supervisor.mjs supervisor: new file 2024-06-19 11:56:45 -04:00
watch.sh reconcile boot and admin pages further (#963) 2024-05-23 16:40:31 -04:00