sanity-io / GROQ

Specification for GROQ - The Query Language for JSON
https://groq.dev
MIT License
398 stars 15 forks source link

Support for behavior like Array.join()? #44

Closed floer32 closed 2 years ago

floer32 commented 3 years ago

I think it seems reasonable to consider this because groq already has ways of restructuring (and reformatting) data; i.e. projections, functions, coalescing, and certain kinds of concatenation.

It's pretty common to want to stringify an array with a separator in between (like ,). In Python, that's [...].join(", "). In JS, it's Array.join([...], ", "). (Putting those partly for sake of searches if someone looks for those and groq, that's what I searched for initially.) There's CONCAT_WS in SQL.

I figure this is a Function. I think it'd be consistent with the existing syntax to implement it like join(<array>, ", ") -- but to avoid confusion with database JOINs, maybe it would be better to name it strjoin(<array>, ", ").

Thoughts?

judofyr commented 3 years ago

This is definitely something we want to add!

Following the existing naming convention (e.g. round) I think it makes most sense to use join for this function, although I share your concern about it potentially being confusing.

We've briefly discussed that having namespaces would be useful (something like string::join(…)), and maybe time has come to introduce it.

However, considering how common this function is I think it's fine to introduce it as join(…) now and then later make it fit into a namespace.

Thoughts @atombender and @j33ty?

atombender commented 3 years ago

I'm fine with join() until the day we will consider adding "modules" to collect functions.

atombender commented 2 years ago

Hi! We have now launched this functionality as array::join(), along with a bunch more stuff.

We have also launched a new GROQ spec, which you can read about in our blog: Content is Queryable: (Re)Introducing GROQ.