Comments (2)
There are a few conflated issues here.
-
First off, the
index()
function appears to have some issues with real-time data, specifically, Perspective'sTable.update()
method has an exception for the example on Perspective's homepage, whereby simply creating theView
withindex()
as an expression works fine. This is a straight-up bug in Perspective, I've an Issue #2627. This bug will prevent the usage of this function with real-time data. -
In the loop condition
for (idx <= index(); idx += 1;) {
, your semicolons are in the wrong place. This line should readfor (; idx <= index(); idx + 1) {
, but as written this is an infinite loop as the conditionidx + 1
is always true (the condition should beidx <= index()
instead). Perspective 2.10.1 uses a portion of the ExprTK eval code to perform type checking, and while it does not naively evaluate loops, this particular infinite loop locks the engine (due to inability to inferidx + 1
is const true) when it tries to validate the expression, e.g. as you type. This is a curious state for Perspective though, as only the engine is locked - the UI will continue to function, but no queries will complete (and no further expression validation errors will be reported) TL;DR, if you type this expression into Perspective, the engine will go into an infinite loop immediately and no further errors will show up in the UI, meaning the error you see is not necessarily the real error!
So a few issues here, the type checker is both not providing the feedback that thefor
loop syntax is wrong and it is locking on syntax, Issue #2626. -
In the expression
vlookup("bid", idx)
,vlookup()
takes a column name as an argument, not a column value. In Perspective ExprTK 2.10, double quotes"
denote the value of that column when the expression is evaluated for a row, and thus the expressionvlookup("bid", idx)
is passing the value of the "bid" column tovlookup()
, not the column name'bid'
with single quotes, which is Perspective ExprTK's string literal syntax. -
for
loops have a syntax ambiguity in ExprTK, as afor
loop is an expression itself, equal to whatever the last expression in the loop evaluated to. It seems to be able to parsefor ( .. ) { .. } integer(x)
orfor ( .. ) { .. }; x
(with a semicolon), but it does not likefor ( .. ) { .. } x
(without a semicolon). I need to dig into this a bit, not sure if this is a bug in ExprTK itself or our configuration of it.
This version of the expression should work, but you'll need to drag the real-time slider all the way to the left to "paused" because (1) will cause the engine to fail if a real-time update is applied to this expression:
var cum_bid := 0;
for (var idx := 0; idx < index(); idx += 1) {
cum_bid += vlookup('bid', idx);
};
cum_bid
Another thing to note that you will likely run into with this is Perspective ExprTK's handling of numeric types. Numeric literals in Perspective ExprTK are always assumed to be "float"
, unless they come from an "integer"
column or are cast via the integer()
function. In the example on Perspective's homepage, the Table
has a "float"
index type, as it was inferred from JSON input. However, for Table
s without an explicit index
, the internal implicit index
is typed "integer"
. Furthermore, Perspective ExprTK numeric operators do not promote types automatically, so with an implicit index, idx <= index()
would roughly be interpreted as (float value) <= (integer value)
, which will always fail. You can overcome this by unifying the types with the cast function integer()
, as in integer(idx) < index()
and vlookup("bid", integer(idx))
.
We have a plan to improve Perspective ExprTK's error-reporting/type-checking in the near term. However, we also have a plan to resurrect #2102 , which will allow efficient and sort aware cumulative sum calculation, rather than just the native index ordering. We'll elaborate on these plans in a separate Issue.
from perspective.
Hi @texodus,
Thank you for the detailed response! And for the usage tips.
I can confirm the above gives me the desired output for my basic use case (I am not live updating, nor using any sorting ATM), but I will leave this open until #2102 or something similar solves this in the general case.
from perspective.
Related Issues (20)
- Switch project contribution process from CLA to DCO HOT 2
- View::to_arrow_*() crashes when called from python HOT 4
- perspective javascript API view.to_json() is not deterministic 😳 HOT 5
- Issue with Local setup HOT 1
- Creating a table using arrow buffer fails with Table initialization failed: Error: Abort(): Could not load arrow column of type `time64`
- bug report
- Integration of DuckDB-Wasm with FINOS Perspective HOT 1
- Perspective Workspace : Context Menu does *not* overlay content HOT 1
- Infinite loops in ExprTK expressions lock the engine HOT 1
- `index()` ExprTK function fails during `update()`
- render null as null in datagrid
- Feature request : Click + drag to zoom, event/callback to back-end
- Python 3.12 wheels HOT 2
- Charts in inactive viewers do not re-render when their filter fields change
- Uncaught (in promise) RuntimeError: unreachable after update from 2.10.0 to 2.10.1 HOT 3
- Show non-aggregate rows under aggregate group rows HOT 1
- Support extract Apache Arrow Custom Metadata from schema HOT 2
- Support Split Over HOT 1
- The "not in" filter function lacks an autocomplete list HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from perspective.