prql icon indicating copy to clipboard operation
prql copied to clipboard

Keywords and Builtin functions for PRQL

Open qorrect opened this issue 4 years ago • 7 comments

Just trying to capture this somewhere, so far I have:

Builtins

  • from
  • join (side)
  • select
  • aggregate (by)
  • sort (order)
  • take
  • derive
  • func
  • table
  • value
  • let

Aggregate functions

  • count
  • sum
  • min
  • max
  • average
  • stddev
  • variance

Operators

  • [ ] , lists
  • ( ), code body
  • x:y , passing named argument x value y
  • |, pipes results to next function

What's missing ?

qorrect avatar Feb 13 '22 14:02 qorrect

Thanks for doing the list!

We now have table as of today!

And then I expect they'll be a long list of simple functions like stddev etc.

Those could be PRQL functions rather than written in rust, since they'll generally transpile to `func(foo)‘

max-sixty avatar Feb 13 '22 20:02 max-sixty

I'm all for making them PRQL functions, easier to share across implementations.

qorrect avatar Feb 13 '22 20:02 qorrect

Closing this till we get a full list which can put in the docs somewhere.

qorrect avatar Feb 16 '22 19:02 qorrect

OK — feel free to PR a partial list for the meantime, and if you have the prql code then awesome (re your screenshots on discord). Thanks @qorrect

max-sixty avatar Feb 16 '22 19:02 max-sixty

Ok will do, I'm hoping to provide a PR for the standard library below, and a bunch of queries for testing, I'm not sure the right place for them so I'll let you place them.


# Aggregate Functions

func min column = f"MIN({column})"
func max column = f"MAX({column})"
func sum column = f"SUM({column})"
func avg column = f"AVG({column})"
func stddev column = f"STDDEV({column})"
func average column = f"AVG({column})"
func count = f"COUNT(*)"
func count column = f"COUNT({column})"
func count_distinct column = f"COUNT(DISTINCT `{column}`)"

# Casting functions

func float column = f'CAST({column} AS FLOAT)'
func int column = f'CAST({column} AS INT)'
func string column = f'CAST({column} AS CHAR)'
func date column = f'CAST({column} AS DATE)'
func datetime column = f'CAST({column} AS DATETIME)'
func timestamp column = f'CAST({column} AS TIMESTAMP)'
func time column = f'CAST({column} AS TIME)'
func boolean column = f'CAST({column} AS BOOLEAN)'
func decimal column = f'CAST({column} AS DECIMAL)'
func double column = f'CAST({column} AS DOUBLE)'

from null

qorrect avatar Feb 16 '22 19:02 qorrect

That's great! We could add this to a file functions.pest initially? I'm sure it'll move around but I'm very up for adding it and then we can build on it.

For the Casting — I though the plan for as that we had in discord was good? So it would just be a single func, if you agree...

max-sixty avatar Feb 16 '22 20:02 max-sixty

Yes agreed, I'll update it.

qorrect avatar Feb 16 '22 21:02 qorrect