partiql/partiql-lang-kotlin

Remove hard-coded aggregations within the AST

alancai98 opened this issue · 2 comments

There are several places within the partiql-parser and partiql-ast where we specify dedicated aggregation rules and nodes.

In the ANTLR grammar:

aggregate
: func=COUNT PAREN_LEFT ASTERISK PAREN_RIGHT # CountAll
| func=(COUNT|MAX|MIN|SUM|AVG|EVERY|ANY|SOME) PAREN_LEFT setQuantifierStrategy? expr PAREN_RIGHT # AggregateBase
;

A couple problems w/ above:

  • Aggregate function names are hard-coded
  • Designated aggregate rule -- perhaps can be consolidated with the existing function call rule

In the partiql-ast:

// Aggregate Function Call
agg::{
function: identifier,
args: list::[expr],
setq: optional::set_quantifier,
},

Similar issue to above.

To allow for aggregate UDFs in the future, we should not distinguish between the aggregate and scalar functions till planning time. This will require modification of the AST to plan conversion code, which currently assumes the resolution occurs during parsing.

This task can be broken down into multiple components:

  1. removing hard-coded aggregate functions from AST + parser
  2. figuring out scalar vs aggregation resolution in the planner. As a temporary workaround, could hard-code the logic in the AST to plan code. A future PR could integrate this resolution w/ the SPI + connector metadata interfaces.
  3. (future) creating a UDF aggregation function -- might require further specification. E.g. name conflicts between scalar and aggregate functions.

Resolved by #1464.