From e24d8ef837303e675bc7c29b8a41f3cc81d6b96e Mon Sep 17 00:00:00 2001 From: Alan Cai Date: Tue, 11 Apr 2023 12:38:47 -0700 Subject: [PATCH] Change top-level aggregate function tests to use `COLL_` (#76) --- .../static-analysis/query/sql-aggregate.ion | 111 ++++ .../primitives/coll-aggregate-function.ion | 360 +++++++++++ .../select/sql-aggregate.ion} | 583 ++++-------------- .../primitives/aggregate-function-call.ion | 127 ---- .../primitives/coll-aggregate-function.ion | 127 ++++ .../primitives/aggregate-function-call.ion | 159 ----- .../coll-aggregate-function-call.ion | 159 +++++ .../syntax/query/select/sql-aggregate.ion | 206 +++++++ 8 files changed, 1074 insertions(+), 758 deletions(-) create mode 100644 partiql-tests-data-extended/fail/static-analysis/query/sql-aggregate.ion create mode 100644 partiql-tests-data/eval/primitives/coll-aggregate-function.ion rename partiql-tests-data/eval/{primitives/aggregate-function-call.ion => query/select/sql-aggregate.ion} (67%) delete mode 100644 partiql-tests-data/fail/static-analysis/primitives/aggregate-function-call.ion create mode 100644 partiql-tests-data/fail/static-analysis/primitives/coll-aggregate-function.ion delete mode 100644 partiql-tests-data/success/syntax/primitives/aggregate-function-call.ion create mode 100644 partiql-tests-data/success/syntax/primitives/coll-aggregate-function-call.ion create mode 100644 partiql-tests-data/success/syntax/query/select/sql-aggregate.ion diff --git a/partiql-tests-data-extended/fail/static-analysis/query/sql-aggregate.ion b/partiql-tests-data-extended/fail/static-analysis/query/sql-aggregate.ion new file mode 100644 index 0000000..c497ebf --- /dev/null +++ b/partiql-tests-data-extended/fail/static-analysis/query/sql-aggregate.ion @@ -0,0 +1,111 @@ +// Pending resolution of https://github.com/partiql/partiql-spec/issues/51#issuecomment-1498352752. +// The following tests use SQL aggregation functions in contexts where a `COLL_` aggregation function is expected +// (e.g. as a top-level query) + +spec_51::[ + { + name:"top level AVG disallowed", + statement:"AVG([1, 2, 3, 3])", + assert: { + result: StaticAnalysisFail + }, + }, + { + name:"top level AVG ALL disallowed", + statement:"AVG(ALL [1, 2, 3, 3])", + assert: { + result: StaticAnalysisFail + }, + }, + { + name:"top level AVG DISTINCT disallowed", + statement:"AVG(DISTINCT [1, 2, 3, 3])", + assert: { + result: StaticAnalysisFail + }, + }, + { + name:"top level COUNT disallowed", + statement:"COUNT([1, 2, 3, 3])", + assert: { + result: StaticAnalysisFail + }, + }, + { + name:"top level COUNT ALL disallowed", + statement:"COUNT(ALL [1, 2, 3, 3])", + assert: { + result: StaticAnalysisFail + }, + }, + { + name:"top level COUNT DISTINCT disallowed", + statement:"COUNT(DISTINCT [1, 2, 3, 3])", + assert: { + result: StaticAnalysisFail + }, + }, + { + name:"top level MAX disallowed", + statement:"MAX([1, 2, 3, 3])", + assert: { + result: StaticAnalysisFail + }, + }, + { + name:"top level MAX ALL disallowed", + statement:"MAX(ALL [1, 2, 3, 3])", + assert: { + result: StaticAnalysisFail + }, + }, + { + name:"top level MAX DISTINCT disallowed", + statement:"MAX(DISTINCT [1, 2, 3, 3])", + assert: { + result: StaticAnalysisFail + }, + }, + { + name:"top level MIN disallowed", + statement:"MIN([1, 2, 3, 3])", + assert: { + result: StaticAnalysisFail + }, + }, + { + name:"top level MIN ALL disallowed", + statement:"MIN(ALL [1, 2, 3, 3])", + assert: { + result: StaticAnalysisFail + }, + }, + { + name:"top level MIN DISTINCT disallowed", + statement:"MIN(DISTINCT [1, 2, 3, 3])", + assert: { + result: StaticAnalysisFail + }, + }, + { + name:"top level SUM disallowed", + statement:"SUM([1, 2, 3, 3])", + assert: { + result: StaticAnalysisFail + }, + }, + { + name:"top level SUM ALL disallowed", + statement:"SUM(ALL [1, 2, 3, 3])", + assert: { + result: StaticAnalysisFail + }, + }, + { + name:"top level SUM DISTINCT disallowed", + statement:"SUM(DISTINCT [1, 2, 3, 3])", + assert: { + result: StaticAnalysisFail + }, + }, +] \ No newline at end of file diff --git a/partiql-tests-data/eval/primitives/coll-aggregate-function.ion b/partiql-tests-data/eval/primitives/coll-aggregate-function.ion new file mode 100644 index 0000000..ce70f05 --- /dev/null +++ b/partiql-tests-data/eval/primitives/coll-aggregate-function.ion @@ -0,0 +1,360 @@ +envs::{ + data:[ + 1, + 1, + 1, + 2 + ], + numbers:[ + 1, + 2.0, + 3e0, + 4, + 5. + ], +} + +coll_max::[ + { + name:"max top level{agg:'COLL_MAX(data)',result:(success 2)}", + statement:"COLL_MAX(data)", + assert:{ + result:EvaluationSuccess, + evalMode:[ + EvalModeCoerce, + EvalModeError + ], + output:2 + } + }, + { + name:"coll_max top level{agg:'COLL_MAX(ALL data)',result:(success 2)}", + statement:"COLL_MAX(ALL data)", + assert:{ + result:EvaluationSuccess, + evalMode:[ + EvalModeCoerce, + EvalModeError + ], + output:2 + } + }, + { + name:"coll_max top level{agg:'COLL_MAX(DISTINCT data)',result:(success 2)}", + statement:"COLL_MAX(DISTINCT data)", + assert:{ + result:EvaluationSuccess, + evalMode:[ + EvalModeCoerce, + EvalModeError + ], + output:2 + } + }, + { + name:"topLevelCollMax", + statement:"COLL_MAX(numbers)", + assert:{ + evalMode:[EvalModeCoerce, EvalModeError], + result:EvaluationSuccess, + output:5. + } + }, + { + name:"topLevelDistinctCollMax", + statement:"COLL_MAX(DISTINCT numbers)", + assert:{ + evalMode:[EvalModeCoerce, EvalModeError], + result:EvaluationSuccess, + output:5. + } + }, + { + name:"topLevelAllCollMax", + statement:"COLL_MAX(ALL numbers)", + assert:{ + evalMode:[EvalModeCoerce, EvalModeError], + result:EvaluationSuccess, + output:5. + } + }, +] + +coll_avg::[ + { + name:"coll_avg top level{agg:'COLL_AVG(data)',result:(success 1.25)}", + statement:"COLL_AVG(data)", + assert:{ + result:EvaluationSuccess, + evalMode:[ + EvalModeCoerce, + EvalModeError + ], + output:1.25 + } + }, + { + name:"coll_avg top level{agg:'COLL_AVG(ALL data)',result:(success 1.25)}", + statement:"COLL_AVG(ALL data)", + assert:{ + result:EvaluationSuccess, + evalMode:[ + EvalModeCoerce, + EvalModeError + ], + output:1.25 + } + }, + { + name:"coll_avg top level{agg:'COLL_AVG(DISTINCT data)',result:(success 1.5)}", + statement:"COLL_AVG(DISTINCT data)", + assert:{ + result:EvaluationSuccess, + evalMode:[ + EvalModeCoerce, + EvalModeError + ], + output:1.5 + } + }, + { + name:"topLevelCollAvg", + statement:"COLL_AVG(numbers)", + assert:{ + evalMode:[EvalModeCoerce, EvalModeError], + result:EvaluationSuccess, + output:3.0 + } + }, + { + name:"topLevelDistinctCollAvg", + statement:"COLL_AVG(DISTINCT [1,1,1,1,1,3])", + assert:{ + evalMode:[EvalModeCoerce, EvalModeError], + result:EvaluationSuccess, + output:2. + } + }, + { + name:"topLevelCollAvgOnlyInt", + statement:"COLL_AVG([2,2,2,4])", + assert:{ + evalMode:[EvalModeCoerce, EvalModeError], + result:EvaluationSuccess, + output:2.5 + } + }, +] + +coll_count::[ + { + name:"coll_count top level{agg:'COLL_COUNT(data)',result:(success 4)}", + statement:"COLL_COUNT(data)", + assert:{ + result:EvaluationSuccess, + evalMode:[ + EvalModeCoerce, + EvalModeError + ], + output:4 + } + }, + { + name:"coll_count top level{agg:'COLL_COUNT(ALL data)',result:(success 4)}", + statement:"COLL_COUNT(ALL data)", + assert:{ + result:EvaluationSuccess, + evalMode:[ + EvalModeCoerce, + EvalModeError + ], + output:4 + } + }, + { + name:"coll_count top level{agg:'COLL_COUNT(DISTINCT data)',result:(success 2)}", + statement:"COLL_COUNT(DISTINCT data)", + assert:{ + result:EvaluationSuccess, + evalMode:[ + EvalModeCoerce, + EvalModeError + ], + output:2 + } + }, + { + name:"topLevelCollCountDistinct", + statement:"COLL_COUNT(DISTINCT [1,1,1,1,2])", + assert:{ + evalMode:[EvalModeCoerce, EvalModeError], + result:EvaluationSuccess, + output:2 + } + }, + { + name:"topLevelCollCount", + statement:"COLL_COUNT(numbers)", + assert:{ + evalMode:[EvalModeCoerce, EvalModeError], + result:EvaluationSuccess, + output:5 + } + }, + { + name:"topLevelAllCollCount", + statement:"COLL_COUNT(ALL numbers)", + assert:{ + evalMode:[EvalModeCoerce, EvalModeError], + result:EvaluationSuccess, + output:5 + } + }, +] + +coll_sum::[ + { + name:"coll_sum top level{agg:'COLL_SUM(data)',result:(success 5)}", + statement:"COLL_SUM(data)", + assert:{ + result:EvaluationSuccess, + evalMode:[ + EvalModeCoerce, + EvalModeError + ], + output:5 + } + }, + { + name:"coll_sum top level{agg:'COLL_SUM(ALL data)',result:(success 5)}", + statement:"COLL_SUM(ALL data)", + assert:{ + result:EvaluationSuccess, + evalMode:[ + EvalModeCoerce, + EvalModeError + ], + output:5 + } + }, + { + name:"coll_sum top level{agg:'COLL_SUM(DISTINCT data)',result:(success 3)}", + statement:"COLL_SUM(DISTINCT data)", + assert:{ + result:EvaluationSuccess, + evalMode:[ + EvalModeCoerce, + EvalModeError + ], + output:3 + } + }, + { + name:"topLevelCollSum", + statement:"COLL_SUM(numbers)", + assert:{ + evalMode:[EvalModeCoerce, EvalModeError], + result:EvaluationSuccess, + output:15.0 + } + }, + { + name:"topLevelAllCollSum", + statement:"COLL_SUM(ALL numbers)", + assert:{ + evalMode:[EvalModeCoerce, EvalModeError], + result:EvaluationSuccess, + output:15.0 + } + }, + { + name:"topLevelDistinctCollSum", + statement:"COLL_SUM(DISTINCT [1,1,1,1,1,1,1,2])", + assert:{ + evalMode:[EvalModeCoerce, EvalModeError], + result:EvaluationSuccess, + output:3 + } + }, +] + +coll_min::[ + { + name:"coll_min top level{agg:'COLL_MIN(data)',result:(success 1)}", + statement:"COLL_MIN(data)", + assert:{ + result:EvaluationSuccess, + evalMode:[ + EvalModeCoerce, + EvalModeError + ], + output:1 + } + }, + { + name:"coll_min top level{agg:'COLL_MIN(ALL data)',result:(success 1)}", + statement:"COLL_MIN(ALL data)", + assert:{ + result:EvaluationSuccess, + evalMode:[ + EvalModeCoerce, + EvalModeError + ], + output:1 + } + }, + { + name:"coll_min top level{agg:'COLL_MIN(DISTINCT data)',result:(success 1)}", + statement:"COLL_MIN(DISTINCT data)", + assert:{ + result:EvaluationSuccess, + evalMode:[ + EvalModeCoerce, + EvalModeError + ], + output:1 + } + }, + { + name:"topLevelCollMin", + statement:"COLL_MIN(numbers)", + assert:{ + evalMode:[EvalModeCoerce, EvalModeError], + result:EvaluationSuccess, + output:1 + } + }, + { + name:"topLevelDistinctCollMin", + statement:"COLL_MIN(DISTINCT numbers)", + assert:{ + evalMode:[EvalModeCoerce, EvalModeError], + result:EvaluationSuccess, + output:1 + } + }, + { + name:"topLevelAllCollMin", + statement:"COLL_MIN(ALL numbers)", + assert:{ + evalMode:[EvalModeCoerce, EvalModeError], + result:EvaluationSuccess, + output:1 + } + }, +] + +coll_agg_in_select::[ + { + name:"selectValueCollAggregate", + statement:"SELECT VALUE COLL_COUNT(v) + COLL_SUM(v) FROM <> AS v", + assert:{ + evalMode:[EvalModeCoerce, EvalModeError], + result:EvaluationSuccess, + output:$bag::[ + 20.0, + 20.0 + ] + } + }, +] diff --git a/partiql-tests-data/eval/primitives/aggregate-function-call.ion b/partiql-tests-data/eval/query/select/sql-aggregate.ion similarity index 67% rename from partiql-tests-data/eval/primitives/aggregate-function-call.ion rename to partiql-tests-data/eval/query/select/sql-aggregate.ion index a0b0ee1..ece0dd5 100644 --- a/partiql-tests-data/eval/primitives/aggregate-function-call.ion +++ b/partiql-tests-data/eval/query/select/sql-aggregate.ion @@ -1,4 +1,10 @@ envs::{ + data:[ + 1, + 1, + 1, + 2 + ], numbers:[ 1, 2.0, @@ -8,311 +14,7 @@ envs::{ ], } -aggregates::[ - { - name:"topLevelCountDistinct", - statement:"COUNT(DISTINCT [1,1,1,1,2])", - assert:{ - evalMode:[EvalModeCoerce, EvalModeError], - result:EvaluationSuccess, - output:2 - } - }, - { - name:"topLevelCount", - statement:"COUNT(numbers)", - assert:{ - evalMode:[EvalModeCoerce, EvalModeError], - result:EvaluationSuccess, - output:5 - } - }, - { - name:"topLevelAllCount", - statement:"COUNT(ALL numbers)", - assert:{ - evalMode:[EvalModeCoerce, EvalModeError], - result:EvaluationSuccess, - output:5 - } - }, - { - name:"topLevelSum", - statement:"SUM(numbers)", - assert:{ - evalMode:[EvalModeCoerce, EvalModeError], - result:EvaluationSuccess, - output:15.0 - } - }, - { - name:"topLevelAllSum", - statement:"SUM(ALL numbers)", - assert:{ - evalMode:[EvalModeCoerce, EvalModeError], - result:EvaluationSuccess, - output:15.0 - } - }, - { - name:"topLevelDistinctSum", - statement:"SUM(DISTINCT [1,1,1,1,1,1,1,2])", - assert:{ - evalMode:[EvalModeCoerce, EvalModeError], - result:EvaluationSuccess, - output:3 - } - }, - { - name:"topLevelMin", - statement:"MIN(numbers)", - assert:{ - evalMode:[EvalModeCoerce, EvalModeError], - result:EvaluationSuccess, - output:1 - } - }, - { - name:"topLevelDistinctMin", - statement:"MIN(DISTINCT numbers)", - assert:{ - evalMode:[EvalModeCoerce, EvalModeError], - result:EvaluationSuccess, - output:1 - } - }, - { - name:"topLevelAllMin", - statement:"MIN(ALL numbers)", - assert:{ - evalMode:[EvalModeCoerce, EvalModeError], - result:EvaluationSuccess, - output:1 - } - }, - { - name:"topLevelMax", - statement:"MAX(numbers)", - assert:{ - evalMode:[EvalModeCoerce, EvalModeError], - result:EvaluationSuccess, - output:5. - } - }, - { - name:"topLevelDistinctMax", - statement:"MAX(DISTINCT numbers)", - assert:{ - evalMode:[EvalModeCoerce, EvalModeError], - result:EvaluationSuccess, - output:5. - } - }, - { - name:"topLevelAllMax", - statement:"MAX(ALL numbers)", - assert:{ - evalMode:[EvalModeCoerce, EvalModeError], - result:EvaluationSuccess, - output:5. - } - }, - { - name:"topLevelAvg", - statement:"AVG(numbers)", - assert:{ - evalMode:[EvalModeCoerce, EvalModeError], - result:EvaluationSuccess, - output:3.0 - } - }, - { - name:"topLevelDistinctAvg", - statement:"AVG(DISTINCT [1,1,1,1,1,3])", - assert:{ - evalMode:[EvalModeCoerce, EvalModeError], - result:EvaluationSuccess, - output:2. - } - }, - { - name:"topLevelAvgOnlyInt", - statement:"AVG([2,2,2,4])", - assert:{ - evalMode:[EvalModeCoerce, EvalModeError], - result:EvaluationSuccess, - output:2.5 - } - }, - { - name:"selectValueAggregate", - statement:"SELECT VALUE COUNT(v) + SUM(v) FROM <> AS v", - assert:{ - evalMode:[EvalModeCoerce, EvalModeError], - result:EvaluationSuccess, - output:$bag::[ - 20.0, - 20.0 - ] - } - }, - { - name:"selectListCountStar", - statement:"SELECT COUNT(*) AS c FROM <> AS v", - assert:{ - evalMode:[EvalModeCoerce, EvalModeError], - result:EvaluationSuccess, - output:$bag::[ - { - c:2 - } - ] - } - }, - { - name:"selectListCountVariable", - statement:"SELECT COUNT(v) AS c FROM <> AS v", - assert:{ - evalMode:[EvalModeCoerce, EvalModeError], - result:EvaluationSuccess, - output:$bag::[ - { - c:2 - } - ] - } - }, - { - name:"selectListMultipleAggregates", - statement:"SELECT COUNT(*) AS c, AVG(v * 2) + SUM(v + v) AS result FROM numbers AS v", - assert:{ - evalMode:[EvalModeCoerce, EvalModeError], - result:EvaluationSuccess, - output:$bag::[ - { - c:5, - result:36.0 - } - ] - } - }, - { - name:"selectListMultipleAggregatesNestedQuery", - statement:"SELECT VALUE (SELECT MAX(v2 * v2) + MIN(v2 * 2) * v1 AS result FROM numbers AS v2) FROM numbers AS v1", - assert:{ - evalMode:[EvalModeCoerce, EvalModeError], - result:EvaluationSuccess, - output:$bag::[ - $bag::[ - { - result:27. - } - ], - $bag::[ - { - result:29.0 - } - ], - $bag::[ - { - result:31. - } - ], - $bag::[ - { - result:33. - } - ], - $bag::[ - { - result:35. - } - ] - ] - } - }, - { - name:"aggregateInSubqueryOfSelect", - statement:"SELECT foo.cnt FROM (SELECT COUNT(*) AS cnt FROM [1, 2, 3]) AS foo", - assert:{ - evalMode:[EvalModeCoerce, EvalModeError], - result:EvaluationSuccess, - output:$bag::[ - { - cnt:3 - } - ] - } - }, - { - name:"aggregateInSubqueryOfSelectValue", - statement:"SELECT VALUE foo.cnt FROM (SELECT COUNT(*) AS cnt FROM [1, 2, 3]) AS foo", - assert:{ - evalMode:[EvalModeCoerce, EvalModeError], - result:EvaluationSuccess, - output:$bag::[ - 3 - ] - } - }, - { - name:"aggregateWithAliasingInSubqueryOfSelectValue", - statement:"SELECT VALUE foo.cnt FROM (SELECT COUNT(baz.bar) AS cnt FROM << { 'bar': 1 }, { 'bar': 2 } >> AS baz) AS foo", - assert:{ - evalMode:[EvalModeCoerce, EvalModeError], - result:EvaluationSuccess, - output:$bag::[ - 2 - ] - } - } -] - -max::[ - envs::{ - data:[ - 1, - 1, - 1, - 2 - ] - }, - { - name:"max top level{agg:'MAX(data)',result:(success 2)}", - statement:"MAX(data)", - assert:{ - result:EvaluationSuccess, - evalMode:[ - EvalModeCoerce, - EvalModeError - ], - output:2 - } - }, - { - name:"max top level{agg:'MAX(ALL data)',result:(success 2)}", - statement:"MAX(ALL data)", - assert:{ - result:EvaluationSuccess, - evalMode:[ - EvalModeCoerce, - EvalModeError - ], - output:2 - } - }, - { - name:"max top level{agg:'MAX(DISTINCT data)',result:(success 2)}", - statement:"MAX(DISTINCT data)", - assert:{ - result:EvaluationSuccess, - evalMode:[ - EvalModeCoerce, - EvalModeError - ], - output:2 - } - }, +sql_max::[ { name:"max select{agg:'MAX(d)',result:2}", statement:"SELECT MAX(d) AS a FROM data d", @@ -426,51 +128,7 @@ max::[ } ] -avg::[ - envs::{ - data:[ - 1, - 1, - 1, - 2 - ] - }, - { - name:"avg top level{agg:'AVG(data)',result:(success 1.25)}", - statement:"AVG(data)", - assert:{ - result:EvaluationSuccess, - evalMode:[ - EvalModeCoerce, - EvalModeError - ], - output:1.25 - } - }, - { - name:"avg top level{agg:'AVG(ALL data)',result:(success 1.25)}", - statement:"AVG(ALL data)", - assert:{ - result:EvaluationSuccess, - evalMode:[ - EvalModeCoerce, - EvalModeError - ], - output:1.25 - } - }, - { - name:"avg top level{agg:'AVG(DISTINCT data)',result:(success 1.5)}", - statement:"AVG(DISTINCT data)", - assert:{ - result:EvaluationSuccess, - evalMode:[ - EvalModeCoerce, - EvalModeError - ], - output:1.5 - } - }, +sql_avg::[ { name:"avg select{agg:'AVG(d)',result:1.25}", statement:"SELECT AVG(d) AS a FROM data d", @@ -584,51 +242,7 @@ avg::[ } ] -count::[ - envs::{ - data:[ - 1, - 1, - 1, - 2 - ] - }, - { - name:"count top level{agg:'COUNT(data)',result:(success 4)}", - statement:"COUNT(data)", - assert:{ - result:EvaluationSuccess, - evalMode:[ - EvalModeCoerce, - EvalModeError - ], - output:4 - } - }, - { - name:"count top level{agg:'COUNT(ALL data)',result:(success 4)}", - statement:"COUNT(ALL data)", - assert:{ - result:EvaluationSuccess, - evalMode:[ - EvalModeCoerce, - EvalModeError - ], - output:4 - } - }, - { - name:"count top level{agg:'COUNT(DISTINCT data)',result:(success 2)}", - statement:"COUNT(DISTINCT data)", - assert:{ - result:EvaluationSuccess, - evalMode:[ - EvalModeCoerce, - EvalModeError - ], - output:2 - } - }, +sql_count::[ { name:"count select{agg:'COUNT(d)',result:4}", statement:"SELECT COUNT(d) AS a FROM data d", @@ -739,54 +353,71 @@ count::[ } ] } - } -] - -sum::[ - envs::{ - data:[ - 1, - 1, - 1, - 2 - ] }, { - name:"sum top level{agg:'SUM(data)',result:(success 5)}", - statement:"SUM(data)", + name:"selectListCountStar", + statement:"SELECT COUNT(*) AS c FROM <> AS v", assert:{ + evalMode:[EvalModeCoerce, EvalModeError], result:EvaluationSuccess, - evalMode:[ - EvalModeCoerce, - EvalModeError - ], - output:5 + output:$bag::[ + { + c:2 + } + ] } }, { - name:"sum top level{agg:'SUM(ALL data)',result:(success 5)}", - statement:"SUM(ALL data)", + name:"selectListCountVariable", + statement:"SELECT COUNT(v) AS c FROM <> AS v", assert:{ + evalMode:[EvalModeCoerce, EvalModeError], result:EvaluationSuccess, - evalMode:[ - EvalModeCoerce, - EvalModeError - ], - output:5 + output:$bag::[ + { + c:2 + } + ] } }, { - name:"sum top level{agg:'SUM(DISTINCT data)',result:(success 3)}", - statement:"SUM(DISTINCT data)", + name:"aggregateInSubqueryOfSelect", + statement:"SELECT foo.cnt FROM (SELECT COUNT(*) AS cnt FROM [1, 2, 3]) AS foo", assert:{ + evalMode:[EvalModeCoerce, EvalModeError], result:EvaluationSuccess, - evalMode:[ - EvalModeCoerce, - EvalModeError - ], - output:3 + output:$bag::[ + { + cnt:3 + } + ] + } + }, + { + name:"aggregateInSubqueryOfSelectValue", + statement:"SELECT VALUE foo.cnt FROM (SELECT COUNT(*) AS cnt FROM [1, 2, 3]) AS foo", + assert:{ + evalMode:[EvalModeCoerce, EvalModeError], + result:EvaluationSuccess, + output:$bag::[ + 3 + ] } }, + { + name:"aggregateWithAliasingInSubqueryOfSelectValue", + statement:"SELECT VALUE foo.cnt FROM (SELECT COUNT(baz.bar) AS cnt FROM << { 'bar': 1 }, { 'bar': 2 } >> AS baz) AS foo", + assert:{ + evalMode:[EvalModeCoerce, EvalModeError], + result:EvaluationSuccess, + output:$bag::[ + 2 + ] + } + } +] + +sql_sum::[ { name:"sum select{agg:'SUM(d)',result:5}", statement:"SELECT SUM(d) AS a FROM data d", @@ -900,51 +531,7 @@ sum::[ } ] -min::[ - envs::{ - data:[ - 1, - 1, - 1, - 2 - ] - }, - { - name:"min top level{agg:'MIN(data)',result:(success 1)}", - statement:"MIN(data)", - assert:{ - result:EvaluationSuccess, - evalMode:[ - EvalModeCoerce, - EvalModeError - ], - output:1 - } - }, - { - name:"min top level{agg:'MIN(ALL data)',result:(success 1)}", - statement:"MIN(ALL data)", - assert:{ - result:EvaluationSuccess, - evalMode:[ - EvalModeCoerce, - EvalModeError - ], - output:1 - } - }, - { - name:"min top level{agg:'MIN(DISTINCT data)',result:(success 1)}", - statement:"MIN(DISTINCT data)", - assert:{ - result:EvaluationSuccess, - evalMode:[ - EvalModeCoerce, - EvalModeError - ], - output:1 - } - }, +sql_min::[ { name:"min select{agg:'MIN(d)',result:1}", statement:"SELECT MIN(d) AS a FROM data d", @@ -1057,3 +644,55 @@ min::[ } } ] + +multiple_sql_aggregates::[ + { + name:"selectListMultipleAggregates", + statement:"SELECT COUNT(*) AS c, AVG(v * 2) + SUM(v + v) AS result FROM numbers AS v", + assert:{ + evalMode:[EvalModeCoerce, EvalModeError], + result:EvaluationSuccess, + output:$bag::[ + { + c:5, + result:36.0 + } + ] + } + }, + { + name:"selectListMultipleAggregatesNestedQuery", + statement:"SELECT VALUE (SELECT MAX(v2 * v2) + MIN(v2 * 2) * v1 AS result FROM numbers AS v2) FROM numbers AS v1", + assert:{ + evalMode:[EvalModeCoerce, EvalModeError], + result:EvaluationSuccess, + output:$bag::[ + $bag::[ + { + result:27. + } + ], + $bag::[ + { + result:29.0 + } + ], + $bag::[ + { + result:31. + } + ], + $bag::[ + { + result:33. + } + ], + $bag::[ + { + result:35. + } + ] + ] + } + }, +] diff --git a/partiql-tests-data/fail/static-analysis/primitives/aggregate-function-call.ion b/partiql-tests-data/fail/static-analysis/primitives/aggregate-function-call.ion deleted file mode 100644 index 8600b85..0000000 --- a/partiql-tests-data/fail/static-analysis/primitives/aggregate-function-call.ion +++ /dev/null @@ -1,127 +0,0 @@ -{ - name: "AVG no args", - statement: "AVG()", - assert: { - result: StaticAnalysisFail - }, -} - -{ - name: "AVG too many args", - statement: "AVG(a, b)", - assert: { - result: StaticAnalysisFail - }, -} - -{ - name: "AVG with star", - statement: "AVG(*)", - assert: { - result: StaticAnalysisFail - }, -} - -{ - name: "MAX no args", - statement: "MAX()", - assert: { - result: StaticAnalysisFail - }, -} - -{ - name: "MAX too many args", - statement: "MAX(a, b)", - assert: { - result: StaticAnalysisFail - }, -} - -{ - name: "MAX with star", - statement: "MAX(*)", - assert: { - result: StaticAnalysisFail - }, -} - -{ - name: "MIN no args", - statement: "MIN()", - assert: { - result: StaticAnalysisFail - }, -} - -{ - name: "MIN too many args", - statement: "MIN(a, b)", - assert: { - result: StaticAnalysisFail - }, -} - -{ - name: "MIN with star", - statement: "MIN(*)", - assert: { - result: StaticAnalysisFail - }, -} - -{ - name: "SUM no args", - statement: "SUM()", - assert: { - result: StaticAnalysisFail - }, -} - -{ - name: "SUM too many args", - statement: "SUM(a, b)", - assert: { - result: StaticAnalysisFail - }, -} - -{ - name: "SUM with star", - statement: "SUM(*)", - assert: { - result: StaticAnalysisFail - }, -} - -{ - name: "COUNT no args", - statement: "COUNT()", - assert: { - result: StaticAnalysisFail - }, -} - -{ - name: "COUNT too many args", - statement: "COUNT(a, b)", - assert: { - result: StaticAnalysisFail - }, -} - -{ - name: "COUNT DISTINCT star", - statement: "COUNT(DISTINCT *)", - assert: { - result: StaticAnalysisFail - }, -} - -{ - name: "COUNT ALL star", - statement: "COUNT(ALL *)", - assert: { - result: StaticAnalysisFail - }, -} diff --git a/partiql-tests-data/fail/static-analysis/primitives/coll-aggregate-function.ion b/partiql-tests-data/fail/static-analysis/primitives/coll-aggregate-function.ion new file mode 100644 index 0000000..612bc28 --- /dev/null +++ b/partiql-tests-data/fail/static-analysis/primitives/coll-aggregate-function.ion @@ -0,0 +1,127 @@ +{ + name: "COLL_AVG no args", + statement: "COLL_AVG()", + assert: { + result: StaticAnalysisFail + }, +} + +{ + name: "COLL_AVG too many args", + statement: "COLL_AVG(a, b)", + assert: { + result: StaticAnalysisFail + }, +} + +{ + name: "COLL_AVG with star", + statement: "COLL_AVG(*)", + assert: { + result: StaticAnalysisFail + }, +} + +{ + name: "COLL_MAX no args", + statement: "COLL_MAX()", + assert: { + result: StaticAnalysisFail + }, +} + +{ + name: "COLL_MAX too many args", + statement: "COLL_MAX(a, b)", + assert: { + result: StaticAnalysisFail + }, +} + +{ + name: "COLL_MAX with star", + statement: "COLL_MAX(*)", + assert: { + result: StaticAnalysisFail + }, +} + +{ + name: "COLL_MIN no args", + statement: "COLL_MIN()", + assert: { + result: StaticAnalysisFail + }, +} + +{ + name: "COLL_MIN too many args", + statement: "COLL_MIN(a, b)", + assert: { + result: StaticAnalysisFail + }, +} + +{ + name: "COLL_MIN with star", + statement: "COLL_MIN(*)", + assert: { + result: StaticAnalysisFail + }, +} + +{ + name: "COLL_SUM no args", + statement: "COLL_SUM()", + assert: { + result: StaticAnalysisFail + }, +} + +{ + name: "COLL_SUM too many args", + statement: "COLL_SUM(a, b)", + assert: { + result: StaticAnalysisFail + }, +} + +{ + name: "COLL_SUM with star", + statement: "COLL_SUM(*)", + assert: { + result: StaticAnalysisFail + }, +} + +{ + name: "COLL_COUNT no args", + statement: "COLL_COUNT()", + assert: { + result: StaticAnalysisFail + }, +} + +{ + name: "COLL_COUNT too many args", + statement: "COLL_COUNT(a, b)", + assert: { + result: StaticAnalysisFail + }, +} + +{ + name: "COLL_COUNT DISTINCT star", + statement: "COLL_COUNT(DISTINCT *)", + assert: { + result: StaticAnalysisFail + }, +} + +{ + name: "COLL_COUNT ALL star", + statement: "COLL_COUNT(ALL *)", + assert: { + result: StaticAnalysisFail + }, +} diff --git a/partiql-tests-data/success/syntax/primitives/aggregate-function-call.ion b/partiql-tests-data/success/syntax/primitives/aggregate-function-call.ion deleted file mode 100644 index 1fb84f4..0000000 --- a/partiql-tests-data/success/syntax/primitives/aggregate-function-call.ion +++ /dev/null @@ -1,159 +0,0 @@ -{ - name: "SUM aggregate function call", - statement: "SUM(a)", - assert: [ - { - result: SyntaxSuccess - }, - ] -} - -{ - name: "SUM DISTINCT aggregate function call", - statement: "SUM(DISTINCT a)", - assert: [ - { - result: SyntaxSuccess - }, - ] -} - -{ - name: "SUM ALL aggregate function call", - statement: "SUM(ALL a)", - assert: [ - { - result: SyntaxSuccess - }, - ] -} - -{ - name: "COUNT aggregate function call", - statement: "COUNT(a)", - assert: [ - { - result: SyntaxSuccess - }, - ] -} - -{ - name: "COUNT star aggregate function call", - statement: "COUNT(*)", - assert: [ - { - result: SyntaxSuccess - }, - ] -} - -{ - name: "COUNT ALL aggregate function call", - statement: "COUNT(ALL a)", - assert: [ - { - result: SyntaxSuccess - }, - ] -} - -{ - name: "COUNT DISTINCT aggregate function call", - statement: "COUNT(DISTINCT a)", - assert: [ - { - result: SyntaxSuccess - }, - ] -} - -{ - name: "AVG aggregate function call", - statement: "AVG(a)", - assert: [ - { - result: SyntaxSuccess - }, - ] -} - -{ - name: "AVG DISTINCT aggregate function call", - statement: "AVG(DISTINCT a)", - assert: [ - { - result: SyntaxSuccess - }, - ] -} - -{ - name: "AVG ALL aggregate function call", - statement: "AVG(ALL a)", - assert: [ - { - result: SyntaxSuccess - }, - ] -} - -{ - name: "MAX DISTINCT aggregate function call", - statement: "MAX(a)", - assert: [ - { - result: SyntaxSuccess - }, - ] -} - -{ - name: "MAX DISTINCT aggregate function call", - statement: "MAX(DISTINCT a)", - assert: [ - { - result: SyntaxSuccess - }, - ] -} - -{ - name: "MAX ALL aggregate function call", - statement: "MAX(ALL a)", - assert: [ - { - result: SyntaxSuccess - }, - ] -} - -{ - name: "MIN DISTINCT aggregate function call", - statement: "MIN(a)", - assert: [ - { - result: SyntaxSuccess - }, - ] -} - -{ - name: "MIN DISTINCT aggregate function call", - statement: "MIN(DISTINCT a)", - assert: [ - { - result: SyntaxSuccess - }, - ] -} - -{ - name: "MIN ALL aggregate function call", - statement: "MIN(ALL a)", - assert: [ - { - result: SyntaxSuccess - }, - ] -} diff --git a/partiql-tests-data/success/syntax/primitives/coll-aggregate-function-call.ion b/partiql-tests-data/success/syntax/primitives/coll-aggregate-function-call.ion new file mode 100644 index 0000000..a4f56bc --- /dev/null +++ b/partiql-tests-data/success/syntax/primitives/coll-aggregate-function-call.ion @@ -0,0 +1,159 @@ +{ + name: "COLL_SUM aggregate function call", + statement: "COLL_SUM(a)", + assert: [ + { + result: SyntaxSuccess + }, + ] +} + +{ + name: "COLL_SUM DISTINCT aggregate function call", + statement: "COLL_SUM(DISTINCT a)", + assert: [ + { + result: SyntaxSuccess + }, + ] +} + +{ + name: "COLL_SUM ALL aggregate function call", + statement: "COLL_SUM(ALL a)", + assert: [ + { + result: SyntaxSuccess + }, + ] +} + +{ + name: "COLL_COUNT aggregate function call", + statement: "COLL_COUNT(a)", + assert: [ + { + result: SyntaxSuccess + }, + ] +} + +{ + name: "COLL_COUNT star aggregate function call", + statement: "COLL_COUNT(*)", + assert: [ + { + result: SyntaxSuccess + }, + ] +} + +{ + name: "COLL_COUNT ALL aggregate function call", + statement: "COLL_COUNT(ALL a)", + assert: [ + { + result: SyntaxSuccess + }, + ] +} + +{ + name: "COLL_COUNT DISTINCT aggregate function call", + statement: "COLL_COUNT(DISTINCT a)", + assert: [ + { + result: SyntaxSuccess + }, + ] +} + +{ + name: "COLL_AVG aggregate function call", + statement: "COLL_AVG(a)", + assert: [ + { + result: SyntaxSuccess + }, + ] +} + +{ + name: "COLL_AVG DISTINCT aggregate function call", + statement: "COLL_AVG(DISTINCT a)", + assert: [ + { + result: SyntaxSuccess + }, + ] +} + +{ + name: "COLL_AVG ALL aggregate function call", + statement: "COLL_AVG(ALL a)", + assert: [ + { + result: SyntaxSuccess + }, + ] +} + +{ + name: "COLL_MAX DISTINCT aggregate function call", + statement: "COLL_MAX(a)", + assert: [ + { + result: SyntaxSuccess + }, + ] +} + +{ + name: "COLL_MAX DISTINCT aggregate function call", + statement: "COLL_MAX(DISTINCT a)", + assert: [ + { + result: SyntaxSuccess + }, + ] +} + +{ + name: "COLL_MAX ALL aggregate function call", + statement: "COLL_MAX(ALL a)", + assert: [ + { + result: SyntaxSuccess + }, + ] +} + +{ + name: "COLL_MIN DISTINCT aggregate function call", + statement: "COLL_MIN(a)", + assert: [ + { + result: SyntaxSuccess + }, + ] +} + +{ + name: "COLL_MIN DISTINCT aggregate function call", + statement: "COLL_MIN(DISTINCT a)", + assert: [ + { + result: SyntaxSuccess + }, + ] +} + +{ + name: "COLL_MIN ALL aggregate function call", + statement: "COLL_MIN(ALL a)", + assert: [ + { + result: SyntaxSuccess + }, + ] +} diff --git a/partiql-tests-data/success/syntax/query/select/sql-aggregate.ion b/partiql-tests-data/success/syntax/query/select/sql-aggregate.ion new file mode 100644 index 0000000..09bbfa7 --- /dev/null +++ b/partiql-tests-data/success/syntax/query/select/sql-aggregate.ion @@ -0,0 +1,206 @@ +sql_sum::[ + { + name: "SQL SUM aggregate function call", + statement: "SELECT SUM(a) FROM t", + assert: [ + { + result: SyntaxSuccess + }, + ] + }, + { + name: "SQL SUM DISTINCT aggregate function call", + statement: "SELECT SUM(DISTINCT a) FROM t", + assert: [ + { + result: SyntaxSuccess + }, + ] + }, + { + name: "SQL SUM ALL aggregate function call", + statement: "SELECT SUM(ALL a) FROM t", + assert: [ + { + result: SyntaxSuccess + }, + ] + }, +] + +sql_count::[ + { + name: "SQL COUNT aggregate function call", + statement: "SELECT COUNT(a) FROM t", + assert: [ + { + result: SyntaxSuccess + }, + ] + }, + { + name: "SQL COUNT DISTINCT aggregate function call", + statement: "SELECT COUNT(DISTINCT a) FROM t", + assert: [ + { + result: SyntaxSuccess + }, + ] + }, + { + name: "SQL COUNT ALL aggregate function call", + statement: "SELECT COUNT(ALL a) FROM t", + assert: [ + { + result: SyntaxSuccess + }, + ] + }, + { + name: "SQL COUNT 1 aggregate function call", + statement: "SELECT COUNT(1) FROM t", + assert: [ + { + result: SyntaxSuccess + }, + ] + }, + { + name: "SQL COUNT * aggregate function call", + statement: "SELECT COUNT(*) FROM t", + assert: [ + { + result: SyntaxSuccess + }, + ] + }, +] + +sql_max::[ + { + name: "SQL MAX aggregate function call", + statement: "SELECT MAX(a) FROM t", + assert: [ + { + result: SyntaxSuccess + }, + ] + }, + { + name: "SQL MAX DISTINCT aggregate function call", + statement: "SELECT MAX(DISTINCT a) FROM t", + assert: [ + { + result: SyntaxSuccess + }, + ] + }, + { + name: "SQL MAX ALL aggregate function call", + statement: "SELECT MAX(ALL a) FROM t", + assert: [ + { + result: SyntaxSuccess + }, + ] + }, +] + +sql_min::[ + { + name: "SQL MIN aggregate function call", + statement: "SELECT MIN(a) FROM t", + assert: [ + { + result: SyntaxSuccess + }, + ] + }, + { + name: "SQL MIN DISTINCT aggregate function call", + statement: "SELECT MIN(DISTINCT a) FROM t", + assert: [ + { + result: SyntaxSuccess + }, + ] + }, + { + name: "SQL MIN ALL aggregate function call", + statement: "SELECT MIN(ALL a) FROM t", + assert: [ + { + result: SyntaxSuccess + }, + ] + }, +] + +sql_avg::[ + { + name: "SQL AVG aggregate function call", + statement: "SELECT AVG(a) FROM t", + assert: [ + { + result: SyntaxSuccess + }, + ] + }, + { + name: "SQL AVG DISTINCT aggregate function call", + statement: "SELECT AVG(DISTINCT a) FROM t", + assert: [ + { + result: SyntaxSuccess + }, + ] + }, + { + name: "SQL AVG ALL aggregate function call", + statement: "SELECT AVG(ALL a) FROM t", + assert: [ + { + result: SyntaxSuccess + }, + ] + }, +] + +sql_aggregates::[ + { + name: "multiple SQL aggregates", + statement: "SELECT AVG(a), COUNT(b), MAX(c), MIN(d), SUM(e) FROM t", + assert: [ + { + result: SyntaxSuccess + }, + ] + }, + { + name: "SQL aggregate in SELECT VALUE", + statement: "SELECT VALUE AVG(a) FROM t", + assert: [ + { + result: SyntaxSuccess + }, + ] + }, + { + name: "SQL aggregate in HAVING", + statement: "SELECT a FROM t GROUP BY a HAVING SUM(a) > 0", + assert: [ + { + result: SyntaxSuccess + }, + ] + }, + { + name: "SQL aggregate in ORDER BY", + statement: "SELECT a FROM t GROUP BY a ORDER BY SUM(a)", + assert: [ + { + result: SyntaxSuccess + }, + ] + }, +]