Table lens: derived expr columns + author sort, computed at read time#23
Open
snudurupati wants to merge 4 commits into
Open
Table lens: derived expr columns + author sort, computed at read time#23snudurupati wants to merge 4 commits into
snudurupati wants to merge 4 commits into
Conversation
Some column values are derived facts that decay with time — a lead's
freshness, an SLA countdown, an age. Storing the decayed value in the
graph means rewriting every row every day; the durable fact is the
date it derives from. This adds:
- column.expr: a tiny safe expression (arithmetic + num()/days_since()/
tier() builtins, no ambient environment) evaluated per row against
the query result at refresh time; result injected under column.key.
column.precision rounds it.
- table.sort {key, dir}: pre-render sort, needed when display order
depends on a derived column the source query cannot order by.
Numeric-aware, stable, nulls last.
Evaluation lives in core (buildRuntimeProps), so web and TUI render
identical values; bad exprs/missing fields blank the cell (null) rather
than rendering NaN or throwing mid-render.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Number(true)/Number(false) coerce to 1/0, letting a boolean field leak into derived scores and sort order. Only pass numbers through and only coerce non-empty strings; everything else is NaN (surfaced as null). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Author
|
Addressed the boolean-coercion review comment in bccc7fe: |
localeCompare() with no locale uses the host default, so author-sorted
string columns could order differently in the Node TUI vs a browser.
Use a shared Intl.Collator("en") for deterministic cross-host order.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
NaN from num() on a boolean/blank field passed tier()'s typeof check, skipped every threshold, and returned the finite default — which then survived evaluateExpr's isFinite guard and rendered instead of blanking the cell. Reject non-finite args so the throw becomes null as intended. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Want your agent to iterate on Greptile's feedback? Try greploops. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Some column values are derived facts that decay with time — the motivating case is a lead's freshness score in the crm Daily-leads table. Freshness is a function of a stored post date and now; storing the score in the graph means rewriting every row every day (1000 leads → 1000 daily touches). The right shape: the graph stores the durable fact (the date), and the notebook derives the current value on every render.
What
column.expr— an optional per-column expression evaluated against each row at query-refresh time; the result is injected under the column'skey(so numeric right-align etc. just work).column.precisionrounds it.The expression language is deliberately tiny and safe — arithmetic, parens, and three builtins; no ambient environment, no property access, not
eval:num("col")— row field as a numberdays_since("col")— fractional days from a date/Z-less-datetime field to nowtier(x, t1,v1, t2,v2, ..., default)— step function for decay tiersWorked example (current lead rank from a stored post date + stored component scores):
table.sort—{key, dir}pre-render sort, needed when display order depends on a derived column the source query cannotorderby. Numeric-aware, stable, nulls last; string comparison is pinned to a fixed locale (Intl.Collator("en")) so order is identical in the Node TUI and any browser.Where
Evaluation happens once in core's
buildRuntimeProps(not in the renderers), so web and TUI show identical values and the components stay presentation-only. Failure mode: a bad expr, unknown function, or missing field yieldsnull(blank cell) — never NaN, never a render-time throw.Tests
New
expr.test.tscovers precedence, the builtins, decay-tier selection, null-on-garbage (includingwindow.alert(1)rejected), derived+sort integration, and no-op passthrough when unauthored. Full workspace: 5 packages build, all suites pass (core 131, web 13 files).🤖 Generated with Claude Code
Greptile Summary
This PR adds read-time derived columns and author sorting for table lenses.
Confidence Score: 5/5
This looks safe to merge.
Important Files Changed
Reviews (4): Last reviewed commit: "expr: tier() rejects non-finite argument..." | Re-trigger Greptile
Context used: