Repository navigation
Pipelines, groups, prql fmt and semantic rewrite - #398
Conversation
I'm planning to put a `dialect.rs` here
language changes: - aggregate must have two positional args, it won't default to empty list - transforms cannot use named exprs without braces or parenthesis: `select [a: b + c]`
language changes: - function calls within expressions must be wrapped by ()
language changes: - transforms can use named exprs without braces or parenthesis again: `select a: b + c`
| table_0.ct, | ||
| countries.*, | ||
| country_code, | ||
| true AS always_true, |
There was a problem hiding this comment.
We don't parse boolean literals yet, so this was parsed as ident. Which now got resolved :D
| AVG(salary), | ||
| AVG(salary + payroll_tax), | ||
| SUM(salary), | ||
| SUM(salary + payroll_tax), | ||
| AVG(salary + payroll_tax + benefits_cost), | ||
| sum_gross_cost, |
There was a problem hiding this comment.
This still has to be fixed, but can I do it a separate PR?
There was a problem hiding this comment.
What's wrong with it now? That there could be a countries.sum_gross_cost?
There was a problem hiding this comment.
That and the fact that these aggregation functions should not be here. Instead there should be columns referenced by name.
There was a problem hiding this comment.
Ah, sorry, I was myopically looking at just that line. Makes sense now
|
This looks extremely impressive @aljazerzen !! I will look in more detail later today |
| inline_pipeline = { "(" ~ expr ~ (pipe ~ func_curry)+ ~ ")" } | ||
|
|
||
| ident = @{ !operator ~ (ASCII_ALPHA | "$") ~ (ASCII_ALPHANUMERIC | "." | "_" | "*" )* } | ||
| ident = @{ !operator ~ !keyword ~ (ASCII_ALPHA | "$") ~ (ASCII_ALPHANUMERIC | "." | "_" | "*" )* } |
There was a problem hiding this comment.
| ident = @{ !operator ~ !keyword ~ (ASCII_ALPHA | "$") ~ (ASCII_ALPHANUMERIC | "." | "_" | "*" )* } | |
| // `$` is for SQL params | |
| ident = @{ !operator ~ !keyword ~ (ASCII_ALPHA | "$") ~ (ASCII_ALPHANUMERIC | "." | "_" | "*" )* } |
| operator_unary = ${ "-" } | ||
| operator_mul = ${ "*" | "/" | "%" } | ||
| operator_add = ${ "+" | "-" } | ||
| operator_compare = ${ "==" | "!=" | "=" | ">" | "<" | ">=" | "<=" } |
There was a problem hiding this comment.
I guess if we're doing these properly now, we could exclude ==? (or close and we can assess separately if this isn't unambiguous)
| operator_compare = ${ "==" | "!=" | "=" | ">" | "<" | ">=" | "<=" } | |
| operator_compare = ${ "!=" | "=" | ">" | "<" | ">=" | "<=" } |
| } | ||
|
|
||
| /// Loads `internal.prql` which contains type definitions of transforms | ||
| pub fn init_context() -> Context { |
There was a problem hiding this comment.
WDYT about making this the impl for Default?
Zooming out: one thing I worry about is that as the code gets more powerful, it becomes more coupled — it's harder to trace through how a simple query gets parsed, resolved & translated.
I'll think more about this. To some extent, the complication is an inevitable cost of progress, but sometimes there are things we can do so that the simple case is more obvious — possible making default impls is one (I even went through a phase a month ago of reorganizing files so the important functions were at the top of files, as an example of another).
There was a problem hiding this comment.
I had that as a default trait, but default is usually used for a few assignes to fields and that's it.
This function actually parses a prql file with type definition for transforms, so it feelt too big for a drfault trait. Note that you dont have to call it yourself, it will get called if you pass contex = None to resolve function.
There was a problem hiding this comment.
I agree that modules should be decupled and should have one major function that you can call, and thats it. Thats the objective, that we currently slightly diviate from.
| } | ||
|
|
||
| /// Traverses AST and replaces transforms with nested pipelines with the pipeline | ||
| struct UnGrouper {} |
There was a problem hiding this comment.
I'm trying to think of a better name, so far unsuccessfully...
There was a problem hiding this comment.
UnNester? DeNester? Flatten?
| @@ -1,164 +0,0 @@ | |||
| use insta::assert_snapshot; | |||
There was a problem hiding this comment.
How come we lost these test files? Is it that they're redundant given our unit tests?
There was a problem hiding this comment.
Oh yeah, I was fixing these tests and noticed that they are duplicates with unit tests and reference tests.
There is no reason to have duplicate tests if we have to maintain them over langugae changes
| .comparison { | ||
| table-layout: fixed; | ||
| display: flex; | ||
| justify-content: center; |
There was a problem hiding this comment.
Do these make any practical difference? (I have no strong bond to the existing JS; I'm curious because I'm trying to learn how to make these better)
There was a problem hiding this comment.
I added a container div, so the editor can be wider than the content column.
This is css for centering the table, even when it overflows.
| } | ||
|
|
||
| fn separate_pipeline(query: &Query) -> Result<(Vec<Table>, Vec<Node>, Vec<Pipeline>)> { | ||
| fn into_tables(nodes: Vec<Node>) -> Result<Vec<Table>> { |
There was a problem hiding this comment.
The convention has been tables_of_nodes, though no strong view on the exact convention; it is nice to have one though
| Ok(match item { | ||
| Item::Expr(_) | Item::SString(_) | Item::FString(_) | Item::Ident(_) | Item::Raw(_) => { | ||
| SelectItem::UnnamedExpr(TryInto::<Expr>::try_into(item)?) | ||
| SelectItem::UnnamedExpr(Expr::try_from(item)?) |
|
Overall — very impressive! Another great step forward. I've reviewed:
I don't have particularly helpful code suggestions at the moment; I'll continue going through the code after we merge, and will engage more with it as I'm adding features. As I wrote above, I will reflect on keeping the codebase as simple and modular as possible. I didn't quite get why the test needed fixing, if it's as simple as qualifying a preceding CTE, then that can definitely go into another PR. Good to go from my end, thank you @aljazerzen ! |
Co-authored-by: Maximilian Roos <[email protected]>
I started to work on #300, broke most of the tests and then repeatably found out I needed just one more refactor/feature before tests start working again. Result is this branch with 3441 insertions(+) and 2785 deletions(-).
Work done:
grouptransforms, their pipelines and infer context within these pipelines Orthogonal treatment of groups (nee Window functions) #300,::semantic, but I'm happier with it now. It's not exacly readable yet, but it's a step closer.Displaytrait toItem, which means that we can print PRQL queries. Combined with parsing, this is a formatter and a step toward Transpiling from SQL to PRQL #130 . Can be used asprql compile -f fmt(now I see this should be a separate command).astandsqlmodules (includingast::dialect). Just splitting ~1000 lines into ~3x300 lines.Language changes:
There is a test case that has not been fixed yet, see below.