treat Percentile as an error if we can't use PQL Percentile

If we can't successfully generate a PQL Percentile call, error
out rather than implementing an actual Percentile function in SQL.
This can be revisited if anyone needs it.
This commit is contained in:
Seebs 2023-03-29 14:51:15 -05:00 committed by seebs
parent c658e771b0
commit 6383a96ac5
3 changed files with 12 additions and 4 deletions

View file

@ -2899,7 +2899,7 @@ func (p *ExecutionPlanner) compileCallExpr(expr *parser.Call) (_ types.PlanExpre
return agg, nil
case "PERCENTILE":
agg := newPercentilePlanExpression(args[0], args[1], expr.ResultDataType)
agg := newPercentilePlanExpression(expr.Name.NamePos, args[0], args[1], expr.ResultDataType)
return agg, nil
case "CORR":

View file

@ -881,6 +881,7 @@ func (n *maxPlanExpression) WithChildren(children ...types.PlanExpression) (type
// percentilePlanExpression handles PERCENTILE()
type percentilePlanExpression struct {
pos parser.Pos
arg types.PlanExpression
nthArg types.PlanExpression
returnDataType parser.ExprDataType
@ -888,8 +889,9 @@ type percentilePlanExpression struct {
var _ types.Aggregable = (*percentilePlanExpression)(nil)
func newPercentilePlanExpression(arg types.PlanExpression, nthArg types.PlanExpression, returnDataType parser.ExprDataType) *percentilePlanExpression {
func newPercentilePlanExpression(pos parser.Pos, arg types.PlanExpression, nthArg types.PlanExpression, returnDataType parser.ExprDataType) *percentilePlanExpression {
return &percentilePlanExpression{
pos: pos,
arg: arg,
nthArg: nthArg,
returnDataType: returnDataType,
@ -905,7 +907,7 @@ func (n *percentilePlanExpression) Evaluate(currentRow []interface{}) (interface
}
func (n *percentilePlanExpression) NewBuffer() (types.AggregationBuffer, error) {
return NewAggCountBuffer(n), nil
return nil, sql3.NewErrUnsupported(n.pos.Line, n.pos.Column, true, "Percentile call that can't be pushed down to PQL")
}
func (n *percentilePlanExpression) FirstChildExpr() types.PlanExpression {
@ -941,7 +943,7 @@ func (n *percentilePlanExpression) WithChildren(children ...types.PlanExpression
if len(children) != 2 {
return nil, sql3.NewErrInternalf("unexpected number of children '%d'", len(children))
}
return newPercentilePlanExpression(children[0], children[1], n.returnDataType), nil
return newPercentilePlanExpression(n.pos, children[0], children[1], n.returnDataType), nil
}
// aggregator for CORR()

View file

@ -494,6 +494,12 @@ var percentileTests = TableTest{
),
ExpErr: "integer, decimal or timestamp expression expected",
},
{
SQLs: sqls(
"SELECT percentile(i1, 50) AS avg_rows FROM percentile_test WHERE s1 != 'a'",
),
ExpErr: "Percentile call that can't be pushed down to PQL is not supported",
},
{
SQLs: sqls(
"SELECT percentile(i1, 50) AS p_rows FROM percentile_test",