deephaven / deephaven-core

Deephaven Community Core
Other
254 stars 80 forks source link

Enable negative array/vector indices for grabbing array/vector values in query strings #3800

Open jjbrosnan opened 1 year ago

jjbrosnan commented 1 year ago

As a user, it would be nice to have the option of using negative array indices to grab data near the end of an array or vector in the query language. Right now, you have to do vec.get(vec.size() - n) (or vec.length()) to get the nth last element of an array/vector. It would be nice to enable negative indices like in Python: vec[-1] to get the last element of an array/list.

Even if it doesn't use the square brackets, maybe an array/vector method like getVal, which can take negative indices.

niloc132 commented 1 year ago

With update_by and rolling group, we support negative indexes, and it seems that each Vector.get's implementation could test for negative values, or perhaps the query parser itself could identify negative literals (which means you couldn't use another variable/column to contain the index).