hashroute3 opened a new pull request, #20414:
URL: https://github.com/apache/pinot/pull/20414

   Part of #20413. Label: `feature`.
   
   `STDDEV` and `VARIANCE` are the standard SQL names for the sample standard 
deviation and variance; PostgreSQL, Trino and Calcite all define them that way. 
Neither query engine recognized them: the multi-stage engine failed with `No 
match found for function signature STDDEV`, and the single-stage engine with 
`Unsupported function: stddev`. Tools that generate standard SQL, such as BI 
tools, sqlglot and text-to-SQL agents, hit this even though Pinot has the 
functions as `STDDEV_SAMP` and `VAR_SAMP`.
   
   ## Changes
   
   - **Multi-stage:** `STDDEV` and `VARIANCE` are registered in 
`PinotOperatorTable` as aliases of Calcite's `STDDEV_SAMP` and `VAR_SAMP`, the 
same way `LOG` is an alias of `LN`.
   - **Single-stage:** `CalciteSqlParser` rewrites them to `stddevsamp` and 
`varsamp` when the query is compiled on the broker. The alias map is 
`AggregationFunctionType#fromStandardSqlAlias`.
   
   ## Compatibility
   
   The single-stage rewrite happens on the broker, so servers only ever receive 
the existing names. That keeps a new broker compatible with servers that 
haven't been upgraded yet. Neither name was valid before, so no existing query 
changes meaning.
   
   ## Tests
   
   - `CalciteSqlParserTest#testStandardSqlAggregateAliasesAreRewritten`: the 
aliases compile to `stddevsamp` and `varsamp` in either case.
   - `StatisticalQueriesTest#testStandardSqlAliasesMatchSampleFunctions`: 
single-stage results match `STDDEV_SAMP` and `VAR_SAMP`.
   - `StatisticAggregates.json`: a multi-stage query using `STDDEV` and 
`VARIANCE`, checked against H2's `STDDEV_SAMP` and `VAR_SAMP`.
   
   Each new test fails without the corresponding change. 
`CalciteSqlParserTest`, `StatisticalQueriesTest`, `QueryCompilationTest` and 
`ResourceBasedQueriesTest` pass with it. `spotless:apply`, `license:format`, 
`checkstyle:check` and `license:check` pass on the affected modules.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to