Repository navigation
Description
@brunorpinho suggested we use backticks for the ClickHouse dialect (https://discord.com/channels/936728116712316989/1030229933299077180). "That'll be super easy" I said. But actually the example presents a more general issue, regardless of the the specific dialect issue.
In SQL, "event.type" is treated as a column name. But it's not currently possible to represent an ident containing a period in PRQL. For example, in:
from github_json
derive [event_type_dotted = `event.type`]`event.type` will be parsed into an event.type ident in the PRQL AST — i.e. a single term with the period. And then later in the compiler, that term will be resolved into a namespace event and a column type. But we want a column name event.type!
I can see two options:
-
Change
Identinto a proper struct — replace https://github.com/prql/prql/blob/10811eb25c0614fe99ff62b55d2a8b389d3bbfe5/prql-compiler/src/ast/mod.rs#L23 with a Struct that can hold a namespace and column name.Then:
event.typeis parsed into{namespace: "event", column: "type"}`event.type`is parsed into{namespace: None, column: "event.type"}
...but we use
Identfor function names / variables / etc at the moment, and the parser deliberately doesn't have the context to discriminate. So we'll be carrying around a{namespace: None, column: "sum"}for thesumfunction1 -
Carry around the backticks where they're supplied in the PRQL query in the
Identstruct until we get to the resolver, rather than parse them. So`event.type`stays as`event.type`in the AST, and then when we get to resolving the name, we check for backticks, and produce the column`event.type`. -
(I don't think this is viable) Have another type
EscapedIdent, which would containevent.type, but knowing that it shouldn't be resolved. But how would`table with space`.columnbe parsed?
If Ident were always a table name, I would suggest the Struct option, even though it would be quite the mindless refactor. But because it's also used for functions, I'm tempted to go with carrying around the backticks, even though it's some violation of the abstraction (now the name resolver is parsing backticks?!).
Any thoughts?
Footnotes
-
though we could rename the
columnfield tonameortermor something ↩
Activity
[-]Include namespace in an idents struct?[/-][+]Handling escaped idents which contain periods[/+]aljazerzen commentedon Oct 16, 2022
As mush as this is a pain in the ass, but it shows that we are not parsing idents correctly.
Correct way would be to separately parse names in idents that are separated with
.. Subsequently,ExprKind::Identshould also contain namespace and varname separately.max-sixty commentedon Oct 16, 2022
OK — to confirm, you're OK having
sumbe parsed into{namespace: None, varname: "sum"}?aljazerzen commentedon Oct 17, 2022
Yeah that's ok. The resolver should figure out that
sumvarname only appears in namespacestdand resolve to that.refactor: Prepare for including a NS with Ident
refactor: Prepare for including a NS with Ident (#1074)
max-sixty commentedon Oct 28, 2022
Closed by #1079 , tested by #1090