mirror of
https://github.com/jackfoxy/urQL.git
synced 2024-09-11 11:55:33 +03:00
all select tests pass
This commit is contained in:
parent
3e0ddcf274
commit
892a3f2047
@ -114,3 +114,4 @@ Keywords are uppercase. This is not a requirement, but is strongly suggested for
|
||||
1. stored procedures
|
||||
2. https://github.com/sigilante/l10n localization of date/time
|
||||
3. triggers
|
||||
4. SELECT single column named top, bottom, or distinct is problematic
|
||||
|
@ -106,10 +106,6 @@
|
||||
::
|
||||
(stag %p fed:ag)
|
||||
==
|
||||
::++ select-rule :: does not build
|
||||
:: |* text=tape
|
||||
:: ^- rule
|
||||
:: ;~(pfix (jest 'select') (funk "select" (easy text)))
|
||||
++ jester :: match a cord, case agnostic, thanks ~tinnus-napbus
|
||||
|= daf=@t
|
||||
|= tub=nail
|
||||
@ -384,7 +380,7 @@
|
||||
==
|
||||
++ cook-aggregate
|
||||
|= parsed=*
|
||||
(aggregate:ast %aggregate -.parsed +.parsed)
|
||||
[%selected-aggregate -.parsed +.parsed]
|
||||
++ parse-aggregate ;~ pose
|
||||
(cook cook-aggregate ;~(pfix whitespace ;~(plug ;~(sfix parse-alias pal) ;~(sfix get-datum par))))
|
||||
(cook cook-aggregate ;~(plug ;~(sfix parse-alias pal) ;~(sfix get-datum par)))
|
||||
@ -965,12 +961,11 @@
|
||||
;~(plug (jester 'top') whitespace dem whitespace (jester 'bottom'))
|
||||
==
|
||||
==
|
||||
++ parse-aggregate-column ~+ (stag %selected-aggregate parse-aggregate)
|
||||
++ parse-alias-all (stag %all-columns ;~(sfix parse-alias ;~(plug dot tar)))
|
||||
++ parse-object-all (stag %all-columns ;~(sfix parse-qualified-object ;~(plug dot tar)))
|
||||
++ parse-selection ~+ ;~ pose
|
||||
;~(plug ;~(sfix parse-aggregate-column whitespace) (cold %as (jester 'as')) ;~(pfix whitespace alias))
|
||||
parse-aggregate-column
|
||||
;~(plug ;~(sfix parse-aggregate whitespace) (cold %as (jester 'as')) ;~(pfix whitespace alias))
|
||||
parse-aggregate
|
||||
parse-alias-all
|
||||
parse-object-all
|
||||
;~(plug ;~(sfix ;~(pose parse-qualified-column parse-value-literal) whitespace) (cold %as (jester 'as')) ;~(pfix whitespace alias))
|
||||
@ -1098,38 +1093,59 @@
|
||||
=/ bottom=(unit @ud) ~
|
||||
=/ distinct=? %.n
|
||||
=/ columns=(list selected-column:ast) ~
|
||||
~| "produce-select a: {<a>}"
|
||||
?: ?=([%top @ %bottom @ %distinct %all ~] a)
|
||||
?> ?=(selected-column:ast %all)
|
||||
(select:ast %select `+<.a `+>+<.a ~ %.y ~[(selected-column:ast %all)])
|
||||
?: ?=([%top @ %bottom @ %all ~] a)
|
||||
?> ?=(selected-column:ast %all)
|
||||
(select:ast %select `+<.a `+>+<.a ~ %.n ~[(selected-column:ast %all)])
|
||||
?: ?=([%top @ %distinct %all ~] a)
|
||||
?> ?=(selected-column:ast %all)
|
||||
(select:ast %select `+<.a ~ %.y ~[(selected-column:ast %all)])
|
||||
?: ?=([%top @ %all ~] a)
|
||||
?> ?=(selected-column:ast %all)
|
||||
(select:ast %select `+<.a ~ %.n ~[(selected-column:ast %all)])
|
||||
?: ?=([%bottom @ %distinct %all ~] a)
|
||||
?> ?=(selected-column:ast %all)
|
||||
(select:ast %select ~ `+<.a %.y ~[(selected-column:ast %all)])
|
||||
?: ?=([%bottom @ %all ~] a)
|
||||
?> ?=(selected-column:ast %all)
|
||||
(select:ast %select ~ `+<.a %.n ~[(selected-column:ast %all)])
|
||||
?: ?=([%distinct %all ~] a)
|
||||
?> ?=(selected-column:ast %all)
|
||||
(select:ast %select ~ ~ %.y ~[(selected-column:ast %all)])
|
||||
?: ?=([%all ~] a)
|
||||
?> ?=(selected-column:ast %all)
|
||||
(select:ast %select ~ ~ %.n ~[(selected-column:ast %all)])
|
||||
:: |-
|
||||
:: ?~ a (select:ast %select top bottom distinct columns)
|
||||
:: ?: ?&(=(-.a %top) ?=(@ud +<.a)) $(a +>.a, top `+<.a)
|
||||
:: ?: ?&(=(-.a %bottom) ?=(@ud +<.a)) $(a +>.a, bottom `+<.a)
|
||||
:: ?: =(-.a %distinct) $(a +.a, distinct %.y)
|
||||
:: ?: =(-.a %all) $(a ~, columns ~[(selected-column:ast %all)])
|
||||
~|("cannot parse select {<a>}" !!)
|
||||
|-
|
||||
~| "cannot parse select -.a: {<-.a>}"
|
||||
?~ a
|
||||
?~ columns ~|('no columns selected' !!)
|
||||
(select:ast %select top bottom distinct (flop columns))
|
||||
?@ -.a
|
||||
?+ -.a ~|('some other select atom' !!)
|
||||
%top ?> ?=(@ud +<.a) $(top `+<.a, a +>.a)
|
||||
%bottom ?> ?=(@ud +<.a) $(bottom `+<.a, a +>.a)
|
||||
%distinct $(distinct %.y, a +.a)
|
||||
%all
|
||||
%= $
|
||||
columns [(qualified-object:ast %qualified-object ~ 'ALL' 'ALL' 'ALL') columns]
|
||||
a +.a
|
||||
==
|
||||
==
|
||||
?: ?=([[%selected-aggregate @ %qualified-column [%qualified-object @ @ @ @] @ @] %as @] -.a)
|
||||
%= $
|
||||
columns [(selected-aggregate:ast %selected-aggregate -<+<.a (qualified-column:ast %qualified-column -<+>+<.a -<+>+>-.a -<+>+>+.a) `->+.a) columns]
|
||||
a +.a
|
||||
==
|
||||
?: ?=([%selected-aggregate @ %qualified-column [%qualified-object @ @ @ @] @ @] -.a)
|
||||
%= $
|
||||
columns [(selected-aggregate:ast %selected-aggregate ->-.a (qualified-column:ast %qualified-column ->+>-.a ->+>+<.a ->+>+>.a) ~) columns]
|
||||
a +.a
|
||||
==
|
||||
?: ?=([%all-columns %qualified-object @ @ @ @] -.a)
|
||||
%= $
|
||||
columns [(qualified-column:ast %qualified-column (qualified-object:ast %qualified-object ->+<.a ->+>-.a ->+>+<.a ->+>+>.a) 'ALL' ~) columns]
|
||||
a +.a
|
||||
==
|
||||
?: ?=([@ @] -.a)
|
||||
?: =(%all-columns -<.a)
|
||||
%= $
|
||||
columns [(qualified-column:ast %qualified-column (qualified-object:ast %qualified-object ~ 'UNKNOWN' 'COLUMN-OR-CTE' ->.a) 'ALL' ~) columns]
|
||||
a +.a
|
||||
==
|
||||
?> ?=(value-literal:ast -.a)
|
||||
%= $
|
||||
columns [(selected-value:ast %selected-value -.a ~) columns]
|
||||
a +.a
|
||||
==
|
||||
?: ?=([qualified-column:ast %as @] -.a)
|
||||
%= $
|
||||
columns [(qualified-column:ast %qualified-column (qualified-object:ast %qualified-object -<+<+<.a -<+<+>-.a -<+<+>+<.a -<+<+>+>.a) -<+>-.a `->+.a) columns]
|
||||
a +.a
|
||||
==
|
||||
?: ?=([[@tas @] %as @] -.a)
|
||||
%= $
|
||||
columns [(selected-value:ast %selected-value -<.a `->+.a) columns]
|
||||
a +.a
|
||||
==
|
||||
?> ?=(qualified-column:ast -.a) $(columns [-.a columns], a +.a)
|
||||
++ build-simple-query
|
||||
|= a=[from=(unit from:ast) scalars=(list scalar-function:ast) predicate=(unit predicate:ast) select=select:ast group-by=(unit group-by:ast) having=(unit having:ast) order-by=(unit order-by:ast)]
|
||||
^- simple-query:ast
|
||||
@ -1250,9 +1266,14 @@
|
||||
:: parse-order-by
|
||||
end-or-next-command
|
||||
==
|
||||
++ parse-query9 ;~ plug
|
||||
parse-select
|
||||
end-or-next-command
|
||||
==
|
||||
++ parse-query ;~ pose
|
||||
parse-query1
|
||||
parse-query2
|
||||
parse-query9
|
||||
==
|
||||
++ parse-revoke ;~ plug
|
||||
:: permission
|
||||
@ -1290,8 +1311,7 @@
|
||||
(cold %grant ;~(plug whitespace (jester 'grant')))
|
||||
(cold %insert ;~(plug whitespace (jester 'insert') whitespace (jester 'into')))
|
||||
(cold %query ;~(plug whitespace (jester 'from')))
|
||||
::(cold %query ;~(plug whitespace (jester 'select')))
|
||||
::(cold %query ;~(plug whitespace select-rule))
|
||||
(cold %query ;~(plug whitespace ;~(pfix (jester 'select') (funk "select" (easy ' ')))))
|
||||
(cold %revoke ;~(plug whitespace (jester 'revoke')))
|
||||
(cold %truncate-table ;~(plug whitespace (jester 'truncate') whitespace (jester 'table')))
|
||||
==
|
||||
|
@ -48,12 +48,10 @@
|
||||
namespace=@t
|
||||
name=@t
|
||||
==
|
||||
+$ cte-name @t
|
||||
+$ column-qualifier $%(qualified-object cte-name)
|
||||
+$ qualified-column
|
||||
$:
|
||||
%qualified-column
|
||||
qualifier=column-qualifier
|
||||
qualifier=qualified-object
|
||||
column=@t
|
||||
alias=(unit @t)
|
||||
==
|
||||
@ -124,68 +122,13 @@
|
||||
::
|
||||
:: query
|
||||
::
|
||||
+$ selected-scalar
|
||||
+$ simple-query
|
||||
$:
|
||||
%selected-scalar
|
||||
scalar=scalar-function
|
||||
alias=(unit @t)
|
||||
%simple-query
|
||||
(unit priori)
|
||||
select
|
||||
(unit posteriori)
|
||||
==
|
||||
+$ selected-object
|
||||
$%
|
||||
%all-columns
|
||||
query-object
|
||||
==
|
||||
+$ query-object
|
||||
$:
|
||||
%query-object
|
||||
object=qualified-object
|
||||
alias=(unit @t)
|
||||
==
|
||||
+$ joined-object
|
||||
$:
|
||||
%joined-object
|
||||
join=join-type
|
||||
object=query-object
|
||||
predicate=(unit predicate)
|
||||
==
|
||||
+$ from
|
||||
$:
|
||||
%from
|
||||
object=query-object
|
||||
joins=(list joined-object)
|
||||
==
|
||||
+$ aggregate-source $%(qualified-column selected-scalar)
|
||||
+$ aggregate
|
||||
$:
|
||||
%aggregate
|
||||
function=@t
|
||||
source=aggregate-source ::* :: should be aggregate-source
|
||||
==
|
||||
+$ selected-aggregate
|
||||
$:
|
||||
%selected-aggregate
|
||||
aggregate=aggregate
|
||||
alias=(unit @t)
|
||||
==
|
||||
+$ selected-column ?(%all qualified-column selected-object) :: selected-aggregate) :: scalar-function or selected-scalar fish-loop
|
||||
+$ select
|
||||
$:
|
||||
%select
|
||||
top=(unit @ud)
|
||||
bottom=(unit @ud)
|
||||
distinct=?
|
||||
columns=(list selected-column)
|
||||
==
|
||||
+$ grouping-column ?(qualified-column @ud)
|
||||
+$ ordering-column
|
||||
$:
|
||||
%ordering-column
|
||||
grouping-column
|
||||
is-ascending=?
|
||||
==
|
||||
+$ group-by (list grouping-column)
|
||||
+$ having predicate
|
||||
+$ order-by (list ordering-column)
|
||||
+$ priori
|
||||
$:
|
||||
%priori
|
||||
@ -200,13 +143,71 @@
|
||||
(unit having)
|
||||
(unit order-by)
|
||||
==
|
||||
+$ simple-query
|
||||
+$ from
|
||||
$:
|
||||
%simple-query
|
||||
(unit priori)
|
||||
select
|
||||
(unit posteriori)
|
||||
%from
|
||||
object=query-object
|
||||
joins=(list joined-object)
|
||||
==
|
||||
+$ query-object
|
||||
$:
|
||||
%query-object
|
||||
object=qualified-object
|
||||
alias=(unit @t)
|
||||
==
|
||||
+$ joined-object
|
||||
$:
|
||||
%joined-object
|
||||
join=join-type
|
||||
object=query-object
|
||||
predicate=(unit predicate)
|
||||
==
|
||||
+$ select
|
||||
$:
|
||||
%select
|
||||
top=(unit @ud)
|
||||
bottom=(unit @ud)
|
||||
distinct=?
|
||||
columns=(list selected-column)
|
||||
==
|
||||
+$ selected-column
|
||||
$%(qualified-column qualified-object selected-aggregate selected-value) :: ) :: scalar-function or selected-scalar fish-loop
|
||||
+$ selected-aggregate
|
||||
$:
|
||||
%selected-aggregate
|
||||
aggregate=@t
|
||||
column=aggregate-source
|
||||
alias=(unit @t)
|
||||
==
|
||||
+$ selected-scalar
|
||||
$:
|
||||
%selected-scalar
|
||||
scalar=scalar-function
|
||||
alias=(unit @t)
|
||||
==
|
||||
+$ selected-value
|
||||
$:
|
||||
%selected-value
|
||||
value=value-literal
|
||||
alias=(unit @t)
|
||||
==
|
||||
+$ aggregate-source $%(qualified-column selected-scalar)
|
||||
::+$ aggregate
|
||||
:: $:
|
||||
:: %aggregate
|
||||
:: function=@t
|
||||
:: source=aggregate-source
|
||||
:: ==
|
||||
+$ grouping-column ?(qualified-column @ud)
|
||||
+$ ordering-column
|
||||
$:
|
||||
%ordering-column
|
||||
grouping-column
|
||||
is-ascending=?
|
||||
==
|
||||
+$ group-by (list grouping-column)
|
||||
+$ having predicate
|
||||
+$ order-by (list ordering-column)
|
||||
+$ cte-query
|
||||
$:
|
||||
%cte
|
||||
|
131
urql/tests/lib/parse-sans.hoon
Normal file
131
urql/tests/lib/parse-sans.hoon
Normal file
@ -0,0 +1,131 @@
|
||||
/- ast
|
||||
/+ parse, *test
|
||||
::
|
||||
:: we frequently break the rules of unit and regression tests here
|
||||
:: by testing more than one thing per result, otherwise there would
|
||||
:: just be too many tests
|
||||
::
|
||||
:: each arm tests one urql command
|
||||
::
|
||||
:: common things to test
|
||||
:: 1) basic command works producing AST object
|
||||
:: 2) multiple ASTs
|
||||
:: 3) all keywords are case ambivalent
|
||||
:: 4) all names follow rules for faces
|
||||
:: 5) all qualifier combinations work
|
||||
::
|
||||
:: -test /=urql=/tests/lib/parse/hoon ~
|
||||
|%
|
||||
::
|
||||
|
||||
:: predicate
|
||||
::
|
||||
:: re-used components
|
||||
++ all-columns [%qualified-object ship=~ database='ALL' namespace='ALL' name='ALL']
|
||||
++ foo
|
||||
[[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN-OR-CTE' 'foo'] 'foo' ~] ~ ~]
|
||||
++ t1-foo
|
||||
[[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN' 'T1'] 'foo' ~] ~ ~]
|
||||
|
||||
++ foo2 [[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN-OR-CTE' 'foo2'] 'foo2' ~] ~ ~]
|
||||
++ t1-foo2 [[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN' 'T1'] 'foo2' ~] ~ ~]
|
||||
++ foo3 [[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN-OR-CTE' 'foo3'] 'foo3' ~] ~ ~]
|
||||
++ t1-foo3 [[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN' 'T1'] 'foo3' ~] ~ ~]
|
||||
++ foo4 [[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN-OR-CTE' 'foo4'] 'foo4' ~] ~ ~]
|
||||
++ foo5 [[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN-OR-CTE' 'foo5'] 'foo5' ~] ~ ~]
|
||||
++ foo6 [[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN-OR-CTE' 'foo6'] 'foo6' ~] ~ ~]
|
||||
++ foo7 [[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN-OR-CTE' 'foo7'] 'foo7' ~] ~ ~]
|
||||
++ bar
|
||||
[[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN-OR-CTE' 'bar'] 'bar' ~] ~ ~]
|
||||
++ t2-bar
|
||||
[[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN' 'T2'] 'bar' ~] ~ ~]
|
||||
|
||||
++ foobar [[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN-OR-CTE' 'foobar'] 'foobar' ~] ~ ~]
|
||||
|
||||
++ a1-adoption-email [[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN' 'A1'] 'adoption-email' ~] ~ ~]
|
||||
++ a2-adoption-email [[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN' 'A2'] 'adoption-email' ~] ~ ~]
|
||||
|
||||
++ a1-adoption-date [[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN' 'A1'] 'adoption-date' ~] ~ ~]
|
||||
++ a2-adoption-date [[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN' 'A2'] 'adoption-date' ~] ~ ~]
|
||||
|
||||
++ a1-name [[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN' 'A1'] 'name' ~] ~ ~]
|
||||
++ a2-name [[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN' 'A2'] 'name' ~] ~ ~]
|
||||
++ a1-species [[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN' 'A1'] 'species' ~] ~ ~]
|
||||
++ a2-species [[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN' 'A2'] 'species' ~] ~ ~]
|
||||
|
||||
++ value-literal-list [[%value-literal-list %ud '3;2;1'] ~ ~]
|
||||
++ aggregate-count-foo [%aggregate %count %qualified-column [%qualified-object 0 'UNKNOWN' 'COLUMN-OR-CTE' %foo] %foo 0]
|
||||
++ literal-10 [[%ud 10] 0 0]
|
||||
::
|
||||
:: re-used simple predicates
|
||||
++ foobar-gte-foo [%gte foobar foo]
|
||||
++ foobar-lte-bar [%lte foobar bar]
|
||||
++ foo-eq-1 [%eq foo [[%ud 1] ~ ~]]
|
||||
++ t1-foo-gt-foo2 [%gt t1-foo foo2]
|
||||
++ t2-bar-in-list [%in t2-bar value-literal-list]
|
||||
++ t1-foo2-eq-zod [%eq t1-foo2 [[%p 0] ~ ~]]
|
||||
++ t1-foo3-lt-any-list [%lt t1-foo3 [%any value-literal-list ~]]
|
||||
::
|
||||
:: re-used predicates with conjunctions
|
||||
++ and-fb-gte-f--fb-lte-b [%and foobar-gte-foo foobar-lte-bar]
|
||||
++ and-fb-gte-f--t1f2-eq-z [%and foobar-gte-foo t1-foo2-eq-zod]
|
||||
++ and-f-eq-1--t1f3-lt-any [%and foo-eq-1 t1-foo3-lt-any-list]
|
||||
++ and-and [%and and-fb-gte-f--fb-lte-b t1-foo2-eq-zod]
|
||||
++ and-and-or [%or and-and t2-bar-in-list]
|
||||
++ and-and-or-and [%or and-and and-fb-gte-f--t1f2-eq-z]
|
||||
++ and-and-or-and-or-and [%or and-and-or-and and-f-eq-1--t1f3-lt-any]
|
||||
::
|
||||
:: predicates with conjunctions and nesting
|
||||
++ and-fb-gt-f--fb-lt-b [%and [%gt foobar foo] [%lt foobar bar]]
|
||||
++ and-t1f-gt-f2--t2b-in-l [%and t1-foo-gt-foo2 t2-bar-in-list]
|
||||
++ or2 [%and [%and t1-foo3-lt-any-list t1-foo2-eq-zod] foo-eq-1]
|
||||
++ or3 [%and [%eq foo3 foo4] [%eq foo5 foo6]]
|
||||
++ big-or [%or [%or [%or and-t1f-gt-f2--t2b-in-l or2] or3] [%eq foo4 foo5]]
|
||||
++ big-and [%and and-fb-gt-f--fb-lt-b big-or]
|
||||
++ a-a-l-a-o-l-a-a-r-o-r-a-l-o-r-a
|
||||
[%and big-and [%eq foo6 foo7]]
|
||||
++ first-or [%or [%gt foobar foo] [%lt foobar bar]]
|
||||
++ last-or [%or t1-foo3-lt-any-list [%and t1-foo2-eq-zod foo-eq-1]]
|
||||
++ first-and [%and first-or t1-foo-gt-foo2]
|
||||
++ second-and [%and first-and t2-bar-in-list]
|
||||
++ king-and [%and [second-and] last-or]
|
||||
|
||||
::
|
||||
:: scalar
|
||||
::
|
||||
++ column-foo [%qualified-column qualifier=[%qualified-object ship=~ database='UNKNOWN' namespace='COLUMN-OR-CTE' name='foo'] column='foo' alias=~]
|
||||
++ column-foo2 [%qualified-column qualifier=[%qualified-object ship=~ database='UNKNOWN' namespace='COLUMN-OR-CTE' name='foo2'] column='foo2' alias=~]
|
||||
++ column-foo3 [%qualified-column qualifier=[%qualified-object ship=~ database='UNKNOWN' namespace='COLUMN-OR-CTE' name='foo3'] column='foo3' alias=~]
|
||||
++ column-bar [%qualified-column qualifier=[%qualified-object ship=~ database='UNKNOWN' namespace='COLUMN-OR-CTE' name='bar'] column='bar' alias=~]
|
||||
++ literal-zod [value-type=%p value=0]
|
||||
++ literal-1 [value-type=%ud value=1]
|
||||
++ naked-coalesce ~[%coalesce column-bar literal-zod literal-1 column-foo]
|
||||
++ simple-coalesce [[%scalar %foobar] naked-coalesce]
|
||||
++ simple-if-naked [%if [%eq [literal-1 0 0] literal-1 0 0] %then column-foo %else column-bar %endif]
|
||||
++ simple-if [[%scalar %foobar] simple-if-naked]
|
||||
++ case-predicate [%when [%eq [literal-1 0 0] literal-1 0 0] %then column-foo]
|
||||
++ case-datum [%when column-foo2 %then column-foo]
|
||||
++ case-coalesce [%when column-foo3 %then naked-coalesce]
|
||||
++ case-1 [[%scalar %foobar] [%case column-foo3 ~[case-predicate] %else column-bar %end]]
|
||||
++ case-2 [[%scalar %foobar] [%case column-foo3 ~[case-datum] %else column-bar %end]]
|
||||
++ case-3 [[%scalar %foobar] [%case column-foo3 ~[case-datum case-predicate] %else column-bar %end]]
|
||||
++ case-4 [[%scalar %foobar] [%case column-foo3 ~[case-datum case-predicate] %else simple-if-naked %end]]
|
||||
++ case-5 [[%scalar %foobar] [%case column-foo3 ~[case-datum case-predicate case-coalesce] %else simple-if-naked %end]]
|
||||
++ case-aggregate [[%scalar %foobar] [%case [%qualified-column [%qualified-object 0 'UNKNOWN' 'COLUMN-OR-CTE' %foo3] %foo3 0] [[%when [%qualified-column [%qualified-object 0 'UNKNOWN' 'COLUMN-OR-CTE' %foo2] %foo2 0] %then %aggregate %count %qualified-column [%qualified-object 0 'UNKNOWN' 'COLUMN-OR-CTE' %foo] %foo 0] 0] %else [%aggregate %count %qualified-column [%qualified-object 0 'UNKNOWN' 'COLUMN-OR-CTE' %foo] %foo 0] %end]]
|
||||
|
||||
::
|
||||
:: select
|
||||
::
|
||||
++ mixed-all
|
||||
~[[%qualified-column qualifier=[%qualified-object ship=~ database='db' namespace='dbo' name='t1'] column='ALL' alias=~] [%qualified-column qualifier=[%qualified-object ship=~ database='UNKNOWN' namespace='COLUMN-OR-CTE' name='foo'] column='foo' alias=[~ 'foobar']] [%qualified-column qualifier=[%qualified-object ship=~ database='UNKNOWN' namespace='COLUMN-OR-CTE' name='bar'] column='bar' alias=~] [%qualified-object ship=~ database='ALL' namespace='ALL' name='ALL'] [%qualified-column qualifier=[%qualified-object ship=~ database='UNKNOWN' namespace='COLUMN-OR-CTE' name='T2'] column='ALL' alias=~]]
|
||||
++ aggregates
|
||||
~[[%qualified-column qualifier=[%qualified-object ship=~ database='UNKNOWN' namespace='COLUMN-OR-CTE' name='foo'] column='foo' alias=~] [%selected-aggregate aggregate='COUNT' column=[%qualified-column qualifier=[%qualified-object ship=~ database='UNKNOWN' namespace='COLUMN-OR-CTE' name='foo'] column='foo' alias=~] alias=[~ 'CountFoo']] [%selected-aggregate aggregate='cOUNT' column=[%qualified-column qualifier=[%qualified-object ship=~ database='UNKNOWN' namespace='COLUMN-OR-CTE' name='bar'] column='bar' alias=~] alias=~] [%selected-aggregate aggregate='sum' column=[%qualified-column qualifier=[%qualified-object ship=~ database='UNKNOWN' namespace='COLUMN-OR-CTE' name='bar'] column='bar' alias=~] alias=~] [%selected-aggregate aggregate='sum' column=[%qualified-column qualifier=[%qualified-object ship=~ database='UNKNOWN' namespace='COLUMN-OR-CTE' name='foobar'] column='foobar' alias=~] alias=[~ 'foobar']]]
|
||||
|
||||
++ test-select-23
|
||||
=/ select "select foo , COUNT(foo) as CountFoo, cOUNT( bar) ,sum(bar ) , sum( foobar ) as foobar "
|
||||
:::: =/ my-columns
|
||||
%+ expect-eq
|
||||
:::: !> [%select [aggregates]]
|
||||
!> ~[[%simple-query ~ [%select top=[~ 10] bottom=[~ 10] distinct=%.y columns=aggregates] ~]]
|
||||
!> (parse:parse(current-database 'db1') select)
|
||||
--
|
File diff suppressed because it is too large
Load Diff
@ -1,466 +0,0 @@
|
||||
/- ast
|
||||
/+ parse, *test
|
||||
|%
|
||||
:: predicate
|
||||
::
|
||||
:: re-used components
|
||||
++ foo
|
||||
[[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN-OR-CTE' 'foo'] 'foo' ~] ~ ~]
|
||||
++ t1-foo
|
||||
[[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN' 'T1'] 'foo' ~] ~ ~]
|
||||
|
||||
++ foo2 [[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN-OR-CTE' 'foo2'] 'foo2' ~] ~ ~]
|
||||
++ t1-foo2 [[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN' 'T1'] 'foo2' ~] ~ ~]
|
||||
++ foo3 [[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN-OR-CTE' 'foo3'] 'foo3' ~] ~ ~]
|
||||
++ t1-foo3 [[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN' 'T1'] 'foo3' ~] ~ ~]
|
||||
++ foo4 [[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN-OR-CTE' 'foo4'] 'foo4' ~] ~ ~]
|
||||
++ foo5 [[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN-OR-CTE' 'foo5'] 'foo5' ~] ~ ~]
|
||||
++ foo6 [[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN-OR-CTE' 'foo6'] 'foo6' ~] ~ ~]
|
||||
++ foo7 [[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN-OR-CTE' 'foo7'] 'foo7' ~] ~ ~]
|
||||
++ bar
|
||||
[[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN-OR-CTE' 'bar'] 'bar' ~] ~ ~]
|
||||
++ t2-bar
|
||||
[[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN' 'T2'] 'bar' ~] ~ ~]
|
||||
|
||||
++ foobar [[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN-OR-CTE' 'foobar'] 'foobar' ~] ~ ~]
|
||||
|
||||
++ a1-adoption-email [[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN' 'A1'] 'adoption-email' ~] ~ ~]
|
||||
++ a2-adoption-email [[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN' 'A2'] 'adoption-email' ~] ~ ~]
|
||||
|
||||
++ a1-adoption-date [[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN' 'A1'] 'adoption-date' ~] ~ ~]
|
||||
++ a2-adoption-date [[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN' 'A2'] 'adoption-date' ~] ~ ~]
|
||||
|
||||
++ a1-name [[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN' 'A1'] 'name' ~] ~ ~]
|
||||
++ a2-name [[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN' 'A2'] 'name' ~] ~ ~]
|
||||
++ a1-species [[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN' 'A1'] 'species' ~] ~ ~]
|
||||
++ a2-species [[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN' 'A2'] 'species' ~] ~ ~]
|
||||
|
||||
++ value-literal-list [[%value-literal-list %ud '3;2;1'] ~ ~]
|
||||
++ aggregate-count-foo [%aggregate %count %qualified-column [%qualified-object 0 'UNKNOWN' 'COLUMN-OR-CTE' %foo] %foo 0]
|
||||
++ literal-10 [[%ud 10] 0 0]
|
||||
::
|
||||
:: re-used simple predicates
|
||||
++ foobar-gte-foo [%gte foobar foo]
|
||||
++ foobar-lte-bar [%lte foobar bar]
|
||||
++ foo-eq-1 [%eq foo [[%ud 1] ~ ~]]
|
||||
++ t1-foo-gt-foo2 [%gt t1-foo foo2]
|
||||
++ t2-bar-in-list [%in t2-bar value-literal-list]
|
||||
++ t1-foo2-eq-zod [%eq t1-foo2 [[%p 0] ~ ~]]
|
||||
++ t1-foo3-lt-any-list [%lt t1-foo3 [%any value-literal-list ~]]
|
||||
::
|
||||
:: re-used predicates with conjunctions
|
||||
++ and-fb-gte-f--fb-lte-b [%and foobar-gte-foo foobar-lte-bar]
|
||||
++ and-fb-gte-f--t1f2-eq-z [%and foobar-gte-foo t1-foo2-eq-zod]
|
||||
++ and-f-eq-1--t1f3-lt-any [%and foo-eq-1 t1-foo3-lt-any-list]
|
||||
++ and-and [%and and-fb-gte-f--fb-lte-b t1-foo2-eq-zod]
|
||||
++ and-and-or [%or and-and t2-bar-in-list]
|
||||
++ and-and-or-and [%or and-and and-fb-gte-f--t1f2-eq-z]
|
||||
++ and-and-or-and-or-and [%or and-and-or-and and-f-eq-1--t1f3-lt-any]
|
||||
::
|
||||
:: predicates with conjunctions and nesting
|
||||
++ and-fb-gt-f--fb-lt-b [%and [%gt foobar foo] [%lt foobar bar]]
|
||||
++ and-t1f-gt-f2--t2b-in-l [%and t1-foo-gt-foo2 t2-bar-in-list]
|
||||
++ or2 [%and [%and t1-foo3-lt-any-list t1-foo2-eq-zod] foo-eq-1]
|
||||
++ or3 [%and [%eq foo3 foo4] [%eq foo5 foo6]]
|
||||
++ big-or [%or [%or [%or and-t1f-gt-f2--t2b-in-l or2] or3] [%eq foo4 foo5]]
|
||||
++ big-and [%and and-fb-gt-f--fb-lt-b big-or]
|
||||
++ a-a-l-a-o-l-a-a-r-o-r-a-l-o-r-a
|
||||
[%and big-and [%eq foo6 foo7]]
|
||||
++ first-or [%or [%gt foobar foo] [%lt foobar bar]]
|
||||
++ last-or [%or t1-foo3-lt-any-list [%and t1-foo2-eq-zod foo-eq-1]]
|
||||
++ first-and [%and first-or t1-foo-gt-foo2]
|
||||
++ second-and [%and first-and t2-bar-in-list]
|
||||
++ king-and [%and [second-and] last-or]
|
||||
::
|
||||
:: test binary operators, varying spacing
|
||||
++ test-predicate-01
|
||||
=/ query "FROM adoptions AS T1 JOIN adoptions AS T2 ON T1.foo = T2.bar SELECT *"
|
||||
=/ pred=(tree predicate-component:ast) [%eq t1-foo t2-bar]
|
||||
=/ expected=simple-query:ast [%simple-query [~ [%priori [~ [%from object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T1']] joins=~[[%joined-object join=%join object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T2']] predicate=`pred]]]] ~ ~]] [%select top=~ bottom=~ distinct=%.n columns=~[%all]] ~]
|
||||
%+ expect-eq
|
||||
!> ~[expected]
|
||||
!> (parse:parse(current-database 'db1') query)
|
||||
++ test-predicate-02
|
||||
=/ query "FROM adoptions AS T1 JOIN adoptions AS T2 ON foo<>bar SELECT *"
|
||||
=/ pred=(tree predicate-component:ast) [%neq foo bar]
|
||||
=/ expected=simple-query:ast [%simple-query [~ [%priori [~ [%from object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T1']] joins=~[[%joined-object join=%join object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T2']] predicate=`pred]]]] ~ ~]] [%select top=~ bottom=~ distinct=%.n columns=~[%all]] ~]
|
||||
%+ expect-eq
|
||||
!> ~[expected]
|
||||
!> (parse:parse(current-database 'db1') query)
|
||||
++ test-predicate-03
|
||||
=/ query "FROM adoptions AS T1 JOIN adoptions AS T2 ON foo!= bar SELECT *"
|
||||
=/ pred=(tree predicate-component:ast) [%neq foo bar]
|
||||
=/ expected=simple-query:ast [%simple-query [~ [%priori [~ [%from object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T1']] joins=~[[%joined-object join=%join object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T2']] predicate=`pred]]]] ~ ~]] [%select top=~ bottom=~ distinct=%.n columns=~[%all]] ~]
|
||||
%+ expect-eq
|
||||
!> ~[expected]
|
||||
!> (parse:parse(current-database 'db1') query)
|
||||
++ test-predicate-04
|
||||
=/ query "FROM adoptions AS T1 JOIN adoptions AS T2 ON foo >bar SELECT *"
|
||||
=/ pred=(tree predicate-component:ast) [%gt foo bar]
|
||||
=/ expected=simple-query:ast [%simple-query [~ [%priori [~ [%from object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T1']] joins=~[[%joined-object join=%join object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T2']] predicate=`pred]]]] ~ ~]] [%select top=~ bottom=~ distinct=%.n columns=~[%all]] ~]
|
||||
%+ expect-eq
|
||||
!> ~[expected]
|
||||
!> (parse:parse(current-database 'db1') query)
|
||||
++ test-predicate-05
|
||||
=/ query "FROM adoptions AS T1 JOIN adoptions AS T2 ON foo <bar SELECT *"
|
||||
=/ pred=(tree predicate-component:ast) [%lt foo bar]
|
||||
=/ expected=simple-query:ast [%simple-query [~ [%priori [~ [%from object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T1']] joins=~[[%joined-object join=%join object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T2']] predicate=`pred]]]] ~ ~]] [%select top=~ bottom=~ distinct=%.n columns=~[%all]] ~]
|
||||
%+ expect-eq
|
||||
!> ~[expected]
|
||||
!> (parse:parse(current-database 'db1') query)
|
||||
++ test-predicate-06
|
||||
=/ query "FROM adoptions AS T1 JOIN adoptions AS T2 ON foo>= bar SELECT *"
|
||||
=/ pred=(tree predicate-component:ast) [%gte foo bar]
|
||||
=/ expected=simple-query:ast [%simple-query [~ [%priori [~ [%from object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T1']] joins=~[[%joined-object join=%join object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T2']] predicate=`pred]]]] ~ ~]] [%select top=~ bottom=~ distinct=%.n columns=~[%all]] ~]
|
||||
%+ expect-eq
|
||||
!> ~[expected]
|
||||
!> (parse:parse(current-database 'db1') query)
|
||||
++ test-predicate-07
|
||||
=/ query "FROM adoptions AS T1 JOIN adoptions AS T2 ON foo!< bar SELECT *"
|
||||
=/ pred=(tree predicate-component:ast) [%gte foo bar]
|
||||
=/ expected=simple-query:ast [%simple-query [~ [%priori [~ [%from object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T1']] joins=~[[%joined-object join=%join object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T2']] predicate=`pred]]]] ~ ~]] [%select top=~ bottom=~ distinct=%.n columns=~[%all]] ~]
|
||||
%+ expect-eq
|
||||
!> ~[expected]
|
||||
!> (parse:parse(current-database 'db1') query)
|
||||
++ test-predicate-08
|
||||
=/ query "FROM adoptions AS T1 JOIN adoptions AS T2 ON foo <= bar SELECT *"
|
||||
=/ pred=(tree predicate-component:ast) [%lte foo bar]
|
||||
=/ expected=simple-query:ast [%simple-query [~ [%priori [~ [%from object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T1']] joins=~[[%joined-object join=%join object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T2']] predicate=`pred]]]] ~ ~]] [%select top=~ bottom=~ distinct=%.n columns=~[%all]] ~]
|
||||
%+ expect-eq
|
||||
!> ~[expected]
|
||||
!> (parse:parse(current-database 'db1') query)
|
||||
++ test-predicate-09
|
||||
=/ query "FROM adoptions AS T1 JOIN adoptions AS T2 ON foo !> bar SELECT *"
|
||||
=/ pred=(tree predicate-component:ast) [%lte foo bar]
|
||||
=/ expected=simple-query:ast [%simple-query [~ [%priori [~ [%from object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T1']] joins=~[[%joined-object join=%join object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T2']] predicate=`pred]]]] ~ ~]] [%select top=~ bottom=~ distinct=%.n columns=~[%all]] ~]
|
||||
%+ expect-eq
|
||||
!> ~[expected]
|
||||
!> (parse:parse(current-database 'db1') query)
|
||||
::
|
||||
:: remaining simple predicates, varying spacing and keywork casing
|
||||
++ test-predicate-10
|
||||
=/ query "FROM adoptions AS T1 JOIN adoptions AS T2 ON T1.foo = T2.bar ".
|
||||
" WHERE foobar Not Between foo And bar ".
|
||||
" SELECT *"
|
||||
=/ joinpred=(tree predicate-component:ast) [%eq t1-foo t2-bar]
|
||||
=/ pred=(tree predicate-component:ast) [%not [%between foobar-gte-foo foobar-lte-bar] ~]
|
||||
=/ expected=simple-query:ast
|
||||
[%simple-query [~ [%priori [~ [%from object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T1']] joins=~[[%joined-object join=%join object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T2']] predicate=`joinpred]]]] ~ `pred]] [%select top=~ bottom=~ distinct=%.n columns=~[%all]] ~]
|
||||
%+ expect-eq
|
||||
!> ~[expected]
|
||||
!> (parse:parse(current-database 'db1') query)
|
||||
++ test-predicate-11
|
||||
=/ query "FROM adoptions AS T1 JOIN adoptions AS T2 ON T1.foo = T2.bar ".
|
||||
" WHERE foobar Not Between foo bar ".
|
||||
" SELECT *"
|
||||
=/ joinpred=(tree predicate-component:ast) [%eq t1-foo t2-bar]
|
||||
=/ pred=(tree predicate-component:ast) [%not [%between foobar-gte-foo foobar-lte-bar] ~]
|
||||
=/ expected=simple-query:ast
|
||||
[%simple-query [~ [%priori [~ [%from object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T1']] joins=~[[%joined-object join=%join object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T2']] predicate=`joinpred]]]] ~ `pred]] [%select top=~ bottom=~ distinct=%.n columns=~[%all]] ~]
|
||||
%+ expect-eq
|
||||
!> ~[expected]
|
||||
!> (parse:parse(current-database 'db1') query)
|
||||
++ test-predicate-12
|
||||
=/ query "FROM adoptions AS T1 JOIN adoptions AS T2 ON T1.foo = T2.bar ".
|
||||
" WHERE foobar Between foo And bar ".
|
||||
" SELECT *"
|
||||
=/ joinpred=(tree predicate-component:ast) [%eq t1-foo t2-bar]
|
||||
=/ pred=(tree predicate-component:ast) [%between foobar-gte-foo foobar-lte-bar]
|
||||
=/ expected=simple-query:ast
|
||||
[%simple-query [~ [%priori [~ [%from object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T1']] joins=~[[%joined-object join=%join object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T2']] predicate=`joinpred]]]] ~ `pred]] [%select top=~ bottom=~ distinct=%.n columns=~[%all]] ~]
|
||||
%+ expect-eq
|
||||
!> ~[expected]
|
||||
!> (parse:parse(current-database 'db1') query)
|
||||
++ test-predicate-13
|
||||
=/ query "FROM adoptions AS T1 JOIN adoptions AS T2 ON T1.foo = T2.bar ".
|
||||
" WHERE foobar between foo And bar ".
|
||||
" SELECT *"
|
||||
=/ joinpred=(tree predicate-component:ast) [%eq t1-foo t2-bar]
|
||||
=/ pred=(tree predicate-component:ast) [%between foobar-gte-foo foobar-lte-bar]
|
||||
=/ expected=simple-query:ast
|
||||
[%simple-query [~ [%priori [~ [%from object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T1']] joins=~[[%joined-object join=%join object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T2']] predicate=`joinpred]]]] ~ `pred]] [%select top=~ bottom=~ distinct=%.n columns=~[%all]] ~]
|
||||
%+ expect-eq
|
||||
!> ~[expected]
|
||||
!> (parse:parse(current-database 'db1') query)
|
||||
++ test-predicate-14
|
||||
=/ query "FROM adoptions AS T1 JOIN adoptions AS T2 ON T1.foo = T2.bar ".
|
||||
" WHERE T1.foo>=aLl bar ".
|
||||
" SELECT *"
|
||||
=/ joinpred=(tree predicate-component:ast) [%eq t1-foo t2-bar]
|
||||
=/ pred=(tree predicate-component:ast) [%gte t1-foo [%all bar ~]]
|
||||
=/ expected=simple-query:ast
|
||||
[%simple-query [~ [%priori [~ [%from object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T1']] joins=~[[%joined-object join=%join object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T2']] predicate=`joinpred]]]] ~ `pred]] [%select top=~ bottom=~ distinct=%.n columns=~[%all]] ~]
|
||||
%+ expect-eq
|
||||
!> ~[expected]
|
||||
!> (parse:parse(current-database 'db1') query)
|
||||
++ test-predicate-15
|
||||
=/ query "FROM adoptions AS T1 JOIN adoptions AS T2 ON T1.foo = T2.bar ".
|
||||
" WHERE T1.foo nOt In bar ".
|
||||
" SELECT *"
|
||||
=/ joinpred=(tree predicate-component:ast) [%eq t1-foo t2-bar]
|
||||
=/ pred=(tree predicate-component:ast) [%not [%in t1-foo bar] ~]
|
||||
=/ expected=simple-query:ast
|
||||
[%simple-query [~ [%priori [~ [%from object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T1']] joins=~[[%joined-object join=%join object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T2']] predicate=`joinpred]]]] ~ `pred]] [%select top=~ bottom=~ distinct=%.n columns=~[%all]] ~]
|
||||
%+ expect-eq
|
||||
!> ~[expected]
|
||||
!> (parse:parse(current-database 'db1') query)
|
||||
++ test-predicate-16
|
||||
=/ query "FROM adoptions AS T1 JOIN adoptions AS T2 ON T1.foo = T2.bar ".
|
||||
" WHERE T1.foo not in (1,2,3) ".
|
||||
" SELECT *"
|
||||
=/ joinpred=(tree predicate-component:ast) [%eq t1-foo t2-bar]
|
||||
=/ pred=(tree predicate-component:ast) [%not [%in t1-foo value-literal-list] ~]
|
||||
=/ expected=simple-query:ast
|
||||
[%simple-query [~ [%priori [~ [%from object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T1']] joins=~[[%joined-object join=%join object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T2']] predicate=`joinpred]]]] ~ `pred]] [%select top=~ bottom=~ distinct=%.n columns=~[%all]] ~]
|
||||
%+ expect-eq
|
||||
!> ~[expected]
|
||||
!> (parse:parse(current-database 'db1') query)
|
||||
++ test-predicate-17
|
||||
=/ query "FROM adoptions AS T1 JOIN adoptions AS T2 ON T1.foo = T2.bar ".
|
||||
" WHERE T1.foo in bar ".
|
||||
" SELECT *"
|
||||
=/ joinpred=(tree predicate-component:ast) [%eq t1-foo t2-bar]
|
||||
=/ pred=(tree predicate-component:ast) [%in t1-foo bar]
|
||||
=/ expected=simple-query:ast
|
||||
[%simple-query [~ [%priori [~ [%from object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T1']] joins=~[[%joined-object join=%join object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T2']] predicate=`joinpred]]]] ~ `pred]] [%select top=~ bottom=~ distinct=%.n columns=~[%all]] ~]
|
||||
%+ expect-eq
|
||||
!> ~[expected]
|
||||
!> (parse:parse(current-database 'db1') query)
|
||||
++ test-predicate-18
|
||||
=/ query "FROM adoptions AS T1 JOIN adoptions AS T2 ON T1.foo = T2.bar ".
|
||||
" WHERE T1.foo in (1,2,3) ".
|
||||
" SELECT *"
|
||||
=/ joinpred=(tree predicate-component:ast) [%eq t1-foo t2-bar]
|
||||
=/ pred=(tree predicate-component:ast) [%in t1-foo value-literal-list]
|
||||
=/ expected=simple-query:ast
|
||||
[%simple-query [~ [%priori [~ [%from object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T1']] joins=~[[%joined-object join=%join object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T2']] predicate=`joinpred]]]] ~ `pred]] [%select top=~ bottom=~ distinct=%.n columns=~[%all]] ~]
|
||||
%+ expect-eq
|
||||
!> ~[expected]
|
||||
!> (parse:parse(current-database 'db1') query)
|
||||
++ test-predicate-19
|
||||
=/ query "FROM adoptions AS T1 JOIN adoptions AS T2 ON T1.foo = T2.bar ".
|
||||
" WHERE NOT EXISTS T1.foo ".
|
||||
" SELECT *"
|
||||
=/ joinpred=(tree predicate-component:ast) [%eq t1-foo t2-bar]
|
||||
=/ pred=(tree predicate-component:ast) [%not [%exists t1-foo ~] ~]
|
||||
=/ expected=simple-query:ast
|
||||
[%simple-query [~ [%priori [~ [%from object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T1']] joins=~[[%joined-object join=%join object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T2']] predicate=`joinpred]]]] ~ `pred]] [%select top=~ bottom=~ distinct=%.n columns=~[%all]] ~]
|
||||
%+ expect-eq
|
||||
!> ~[expected]
|
||||
!> (parse:parse(current-database 'db1') query)
|
||||
++ test-predicate-20
|
||||
=/ query "FROM adoptions AS T1 JOIN adoptions AS T2 ON T1.foo = T2.bar ".
|
||||
" WHERE NOT exists foo ".
|
||||
" SELECT *"
|
||||
=/ joinpred=(tree predicate-component:ast) [%eq t1-foo t2-bar]
|
||||
=/ pred=(tree predicate-component:ast) [%not [%exists foo ~] ~]
|
||||
=/ expected=simple-query:ast
|
||||
[%simple-query [~ [%priori [~ [%from object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T1']] joins=~[[%joined-object join=%join object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T2']] predicate=`joinpred]]]] ~ `pred]] [%select top=~ bottom=~ distinct=%.n columns=~[%all]] ~]
|
||||
%+ expect-eq
|
||||
!> ~[expected]
|
||||
!> (parse:parse(current-database 'db1') query)
|
||||
++ test-predicate-21
|
||||
=/ query "FROM adoptions AS T1 JOIN adoptions AS T2 ON T1.foo = T2.bar ".
|
||||
" WHERE EXISTS T1.foo ".
|
||||
" SELECT *"
|
||||
=/ joinpred=(tree predicate-component:ast) [%eq t1-foo t2-bar]
|
||||
=/ pred=(tree predicate-component:ast) [%exists t1-foo ~]
|
||||
=/ expected=simple-query:ast
|
||||
[%simple-query [~ [%priori [~ [%from object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T1']] joins=~[[%joined-object join=%join object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T2']] predicate=`joinpred]]]] ~ `pred]] [%select top=~ bottom=~ distinct=%.n columns=~[%all]] ~]
|
||||
%+ expect-eq
|
||||
!> ~[expected]
|
||||
!> (parse:parse(current-database 'db1') query)
|
||||
++ test-predicate-22
|
||||
=/ query "FROM adoptions AS T1 JOIN adoptions AS T2 ON T1.foo = T2.bar ".
|
||||
" WHERE EXISTS foo ".
|
||||
" SELECT *"
|
||||
=/ joinpred=(tree predicate-component:ast) [%eq t1-foo t2-bar]
|
||||
=/ pred=(tree predicate-component:ast) [%exists foo ~]
|
||||
=/ expected=simple-query:ast
|
||||
[%simple-query [~ [%priori [~ [%from object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T1']] joins=~[[%joined-object join=%join object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T2']] predicate=`joinpred]]]] ~ `pred]] [%select top=~ bottom=~ distinct=%.n columns=~[%all]] ~]
|
||||
%+ expect-eq
|
||||
!> ~[expected]
|
||||
!> (parse:parse(current-database 'db1') query)
|
||||
::
|
||||
:: test conjunctions, varying spacing and keyword casing
|
||||
++ test-predicate-23
|
||||
=/ query "FROM adoptions AS T1 JOIN adoptions AS T2 ON T1.foo = T2.bar ".
|
||||
" WHERE foobar >=foo And foobar<=bar ".
|
||||
" SELECT *"
|
||||
=/ joinpred=(tree predicate-component:ast) [%eq t1-foo t2-bar]
|
||||
=/ pred=(tree predicate-component:ast) and-fb-gte-f--fb-lte-b
|
||||
=/ expected=simple-query:ast
|
||||
[%simple-query [~ [%priori [~ [%from object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T1']] joins=~[[%joined-object join=%join object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T2']] predicate=`joinpred]]]] ~ `pred]] [%select top=~ bottom=~ distinct=%.n columns=~[%all]] ~]
|
||||
%+ expect-eq
|
||||
!> ~[expected]
|
||||
!> (parse:parse(current-database 'db1') query)
|
||||
|
||||
:: expected/actual match
|
||||
::++ test-predicate-24
|
||||
:: =/ query "FROM adoptions AS T1 JOIN adoptions AS T2 ON T1.foo = T2.bar ".
|
||||
:: " WHERE foobar >=foo And foobar<=bar ".
|
||||
:: " and T1.foo2 = ~zod ".
|
||||
:: " SELECT *"
|
||||
:: =/ joinpred=(tree predicate-component:ast) [%eq t1-foo t2-bar]
|
||||
:: =/ pred=(tree predicate-component:ast) and-and
|
||||
:: =/ expected=simple-query:ast
|
||||
:: [%simple-query [~ [%priori [~ [%from object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T1']] joins=~[[%joined-object join=%join object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T2']] predicate=`joinpred]]]] ~ `pred]] [%select top=~ bottom=~ distinct=%.n columns=~[%all]] ~]
|
||||
:: %+ expect-eq
|
||||
:: !> ~[expected]
|
||||
:: !> (parse:parse(current-database 'db1') query)
|
||||
|
||||
:: expected/actual match
|
||||
::++ test-predicate-25
|
||||
:: =/ query "FROM adoptions AS T1 JOIN adoptions AS T2 ON T1.foo = T2.bar ".
|
||||
:: " WHERE foobar >=foo And foobar<=bar ".
|
||||
:: " and T1.foo2 = ~zod ".
|
||||
:: " or T2.bar in (1,2,3)".
|
||||
:: " SELECT *"
|
||||
:: =/ joinpred=(tree predicate-component:ast) [%eq t1-foo t2-bar]
|
||||
:: =/ pred=(tree predicate-component:ast) and-and-or
|
||||
:: =/ expected=simple-query:ast
|
||||
:: [%simple-query [~ [%priori [~ [%from object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T1']] joins=~[[%joined-object join=%join object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T2']] predicate=`joinpred]]]] ~ `pred]] [%select top=~ bottom=~ distinct=%.n columns=~[%all]] ~]
|
||||
:: %+ expect-eq
|
||||
:: !> ~[expected]
|
||||
:: !> (parse:parse(current-database 'db1') query)
|
||||
|
||||
:: expected/actual match
|
||||
::++ test-predicate-26
|
||||
:: =/ query "FROM adoptions AS T1 JOIN adoptions AS T2 ON T1.foo = T2.bar ".
|
||||
:: " WHERE foobar >=foo And foobar<=bar ".
|
||||
:: " and T1.foo2 = ~zod ".
|
||||
:: " or ".
|
||||
:: " foobar>=foo ".
|
||||
:: " AND T1.foo2=~zod ".
|
||||
:: " SELECT *"
|
||||
:: =/ joinpred=(tree predicate-component:ast) [%eq t1-foo t2-bar]
|
||||
:: =/ pred=(tree predicate-component:ast) and-and-or-and
|
||||
:: =/ expected=simple-query:ast
|
||||
:: [%simple-query [~ [%priori [~ [%from object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T1']] joins=~[[%joined-object join=%join object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T2']] predicate=`joinpred]]]] ~ `pred]] [%select top=~ bottom=~ distinct=%.n columns=~[%all]] ~]
|
||||
:: %+ expect-eq
|
||||
:: !> ~[expected]
|
||||
:: !> (parse:parse(current-database 'db1') query)
|
||||
|
||||
:: expected/actual match
|
||||
::++ test-predicate-27
|
||||
:: =/ query "FROM adoptions AS T1 JOIN adoptions AS T2 ON T1.foo = T2.bar ".
|
||||
:: " WHERE foobar >=foo And foobar<=bar ".
|
||||
:: " and T1.foo2 = ~zod ".
|
||||
:: " or ".
|
||||
:: " foobar>=foo ".
|
||||
:: " AND T1.foo2=~zod ".
|
||||
:: " OR ".
|
||||
:: " foo = 1 ".
|
||||
:: " AND T1.foo3 < any (1,2,3) ".
|
||||
:: " SELECT *"
|
||||
:: =/ joinpred=(tree predicate-component:ast) [%eq t1-foo t2-bar]
|
||||
:: =/ pred=(tree predicate-component:ast) and-and-or-and-or-and
|
||||
:: =/ expected=simple-query:ast
|
||||
:: [%simple-query [~ [%priori [~ [%from object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T1']] joins=~[[%joined-object join=%join object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T2']] predicate=`joinpred]]]] ~ `pred]] [%select top=~ bottom=~ distinct=%.n columns=~[%all]] ~]
|
||||
:: %+ expect-eq
|
||||
:: !> ~[expected]
|
||||
:: !> (parse:parse(current-database 'db1') query)
|
||||
|
||||
::
|
||||
:: simple nesting
|
||||
:: expected/actual match
|
||||
::++ test-predicate-28
|
||||
:: =/ query "FROM adoptions AS T1 JOIN adoptions AS T2 ON T1.foo = T2.bar ".
|
||||
:: " WHERE (foobar > foo OR foobar < bar) ".
|
||||
:: " AND T1.foo>foo2 ".
|
||||
:: " AND T2.bar IN (1,2,3) ".
|
||||
:: " AND (T1.foo3< any (1,2,3) OR T1.foo2=~zod AND foo=1 ) ".
|
||||
:: " SELECT *"
|
||||
:: =/ joinpred=(tree predicate-component:ast) [%eq t1-foo t2-bar]
|
||||
:: =/ pred=(tree predicate-component:ast) king-and
|
||||
:: =/ expected=simple-query:ast
|
||||
:: [%simple-query [~ [%priori [~ [%from object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T1']] joins=~[[%joined-object join=%join object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T2']] predicate=`joinpred]]]] ~ `pred]] [%select top=~ bottom=~ distinct=%.n columns=~[%all]] ~]
|
||||
:: %+ expect-eq
|
||||
:: !> ~[expected]
|
||||
:: !> (parse:parse(current-database 'db1') query)
|
||||
|
||||
::
|
||||
:: nesting
|
||||
:: expected/actual match
|
||||
::++ test-predicate-29
|
||||
:: =/ query "FROM adoptions AS T1 JOIN adoptions AS T2 ON T1.foo = T2.bar ".
|
||||
:: " WHERE foobar > foo AND foobar < bar ".
|
||||
:: " AND ( T1.foo>foo2 AND T2.bar IN (1,2,3) ".
|
||||
:: " OR (T1.foo3< any (1,2,3) AND T1.foo2=~zod AND foo=1 ) ".
|
||||
:: " OR (foo3=foo4 AND foo5=foo6) ".
|
||||
:: " OR foo4=foo5 ".
|
||||
:: " ) ".
|
||||
:: " AND foo6=foo7".
|
||||
:: " SELECT *"
|
||||
:: =/ joinpred=(tree predicate-component:ast) [%eq t1-foo t2-bar]
|
||||
:: =/ pred=(tree predicate-component:ast) a-a-l-a-o-l-a-a-r-o-r-a-l-o-r-a
|
||||
:: =/ expected=simple-query:ast
|
||||
:: [%simple-query [~ [%priori [~ [%from object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T1']] joins=~[[%joined-object join=%join object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T2']] predicate=`joinpred]]]] ~ `pred]] [%select top=~ bottom=~ distinct=%.n columns=~[%all]] ~]
|
||||
:: %+ expect-eq
|
||||
:: !> ~[expected]
|
||||
:: !> (parse:parse(current-database 'db1') query)
|
||||
|
||||
|
||||
::
|
||||
:: simple nesting, superfluous () around entire predicate
|
||||
:: expected/actual match
|
||||
::++ test-predicate-30
|
||||
:: =/ query "FROM adoptions AS T1 JOIN adoptions AS T2 ON T1.foo = T2.bar ".
|
||||
:: " WHERE ((foobar > foo OR foobar < bar) ".
|
||||
:: " AND T1.foo>foo2 ".
|
||||
:: " AND T2.bar IN (1,2,3) ".
|
||||
:: " AND (T1.foo3< any (1,2,3) OR T1.foo2=~zod AND foo=1 )) ".
|
||||
:: " SELECT *"
|
||||
:: =/ joinpred=(tree predicate-component:ast) [%eq t1-foo t2-bar]
|
||||
:: =/ pred=(tree predicate-component:ast) king-and
|
||||
:: =/ expected=simple-query:ast
|
||||
:: [%simple-query [~ [%priori [~ [%from object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T1']] joins=~[[%joined-object join=%join object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T2']] predicate=`joinpred]]]] ~ `pred]] [%select top=~ bottom=~ distinct=%.n columns=~[%all]] ~]
|
||||
:: %+ expect-eq
|
||||
:: !> ~[expected]
|
||||
:: !> (parse:parse(current-database 'db1') query)
|
||||
|
||||
::
|
||||
:: aggregate inequality
|
||||
::++ test-predicate-31
|
||||
:: =/ predicate " count( foo ) > 10 "
|
||||
:: %+ expect-eq
|
||||
:: !> [%gt [aggregate-count-foo 0 0] literal-10]
|
||||
:: !> (wonk (parse-predicate:parse [[1 1] predicate]))
|
||||
::
|
||||
:: aggregate inequality, no whitespace
|
||||
::++ test-predicate-32
|
||||
:: =/ predicate "count(foo) > 10"
|
||||
:: %+ expect-eq
|
||||
:: !> [%gt [aggregate-count-foo 0 0] literal-10]
|
||||
:: !> (wonk (parse-predicate:parse [[1 1] predicate]))
|
||||
::
|
||||
:: aggregate equality
|
||||
::++ test-predicate-33
|
||||
:: =/ predicate "bar = count(foo)"
|
||||
:: %+ expect-eq
|
||||
:: !> [%eq bar [aggregate-count-foo 0 0]]
|
||||
:: !> (wonk (parse-predicate:parse [[1 1] predicate]))
|
||||
::
|
||||
:: complext predicate, bug test
|
||||
:: expected/actual match
|
||||
::++ test-predicate-34
|
||||
:: =/ query "FROM adoptions AS T1 JOIN adoptions AS T2 ON T1.foo = T2.bar ".
|
||||
:: " WHERE A1.adoption-email = A2.adoption-email ".
|
||||
:: " AND A1.adoption-date = A2.adoption-date ".
|
||||
:: " AND foo = bar ".
|
||||
:: " AND ((A1.name = A2.name AND A1.species > A2.species) ".
|
||||
:: " OR ".
|
||||
:: " (A1.name > A2.name AND A1.species = A2.species) ".
|
||||
:: " OR ".
|
||||
:: " (A1.name > A2.name AND A1.species > A2.species) ".
|
||||
:: " ) ".
|
||||
:: " SELECT *"
|
||||
:: =/ joinpred=(tree predicate-component:ast) [%eq t1-foo t2-bar]
|
||||
:: =/ pred=(tree predicate-component:ast)
|
||||
:: [%and [%and [%and [%eq a1-adoption-email a2-adoption-email] [%eq a1-adoption-date a2-adoption-date]] [%eq foo bar]] [%or [%or [%and [%eq a1-name a2-name] [%gt a1-species a2-species]] [%and [%gt a1-name a2-name] [%eq a1-species a2-species]]] [%and [%gt a1-name a2-name] [%gt a1-species a2-species]]]]
|
||||
:: =/ expected=simple-query:ast
|
||||
:: [%simple-query [~ [%priori [~ [%from object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T1']] joins=~[[%joined-object join=%join object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T2']] predicate=`joinpred]]]] ~ `pred]] [%select top=~ bottom=~ distinct=%.n columns=~[%all]] ~]
|
||||
:: %+ expect-eq
|
||||
:: !> ~[expected]
|
||||
:: !> (parse:parse(current-database 'db1') query)
|
||||
--
|
File diff suppressed because it is too large
Load Diff
@ -1,338 +0,0 @@
|
||||
/+ parse, *test
|
||||
|%
|
||||
::
|
||||
:: select
|
||||
::
|
||||
++ simple-columns ~[[%qualified-column qualifier=[%qualified-object ship=~ database='UNKNOWN' namespace='COLUMN-OR-CTE' name='x1'] column='x1' alias=~] [%qualified-column qualifier=[%qualified-object ship=~ database='db' namespace='ns' name='table'] column='col1' alias=~] [%qualified-column qualifier=[%qualified-object ship=~ database='UNKNOWN' namespace='COLUMN' name='table-alias'] column='name' alias=~] [%qualified-column qualifier=[%qualified-object ship=~ database='db' namespace='dbo' name='table'] column='col2' alias=~] [%qualified-column qualifier=[%qualified-object ship=~ database='UNKNOWN' namespace='COLUMN' name='T1'] column='foo' alias=~] [%ud 1] [%p 0] [%t 'cord']]
|
||||
++ aliased-columns-1 ~[[[%qualified-column qualifier=[%qualified-object ship=~ database='UNKNOWN' namespace='COLUMN-OR-CTE' name='x1'] column='x1' alias=~] %as %foo] [[%qualified-column qualifier=[%qualified-object ship=~ database='db' namespace='ns' name='table'] column='col1' alias=~] %as %foo2] [[%qualified-column qualifier=[%qualified-object ship=~ database='UNKNOWN' namespace='COLUMN' name='table-alias'] column='name' alias=~] %as %bar] [[%qualified-column qualifier=[%qualified-object ship=~ database='db' namespace='dbo' name='table'] column='col2' alias=~] %as %bar2] [[%ud 1] %as %foobar] [[%p 0] %as 'F1'] [[%t 'cord'] %as 'BAR3']]
|
||||
++ mixed-all ~[[%all-columns %qualified-object ship=~ database='db' namespace='dbo' name='t1'] [[%qualified-column qualifier=[%qualified-object ship=~ database='UNKNOWN' namespace='COLUMN-OR-CTE' name='foo'] column='foo' alias=~] %as 125.762.588.864.358] [%qualified-column qualifier=[%qualified-object ship=~ database='UNKNOWN' namespace='COLUMN-OR-CTE' name='bar'] column='bar' alias=~] %all [%all-columns 'T2']]
|
||||
++ aggregates ~[[%qualified-column qualifier=[%qualified-object ship=~ database='UNKNOWN' namespace='COLUMN-OR-CTE' name='foo'] column='foo' alias=~] [[%selected-aggregate 'COUNT' [%qualified-column qualifier=[%qualified-object ship=~ database='UNKNOWN' namespace='COLUMN-OR-CTE' name='foo'] column='foo' alias=~]] %as 'CountFoo'] [%selected-aggregate 'cOUNT' [%qualified-column qualifier=[%qualified-object ship=~ database='UNKNOWN' namespace='COLUMN-OR-CTE' name='bar'] column='bar' alias=~]] [%selected-aggregate 'sum' [%qualified-column qualifier=[%qualified-object ship=~ database='UNKNOWN' namespace='COLUMN-OR-CTE' name='bar'] column='bar' alias=~]] [[%selected-aggregate 'sum' [%qualified-column qualifier=[%qualified-object ship=~ database='UNKNOWN' namespace='COLUMN-OR-CTE' name='foobar'] column='foobar' alias=~]] %as 'foobar']]
|
||||
::
|
||||
:: star select top, bottom, distinct, trailing whitespace
|
||||
++ test-select-01
|
||||
=/ select "select top 10 bottom 10 distinct * "
|
||||
%+ expect-eq
|
||||
!> [%select %top 10 %bottom 10 %distinct [%all ~]]
|
||||
!> (wonk (parse-select:parse [[1 1] select]))
|
||||
::
|
||||
:: star select top, bottom, distinct
|
||||
++ test-select-02
|
||||
=/ select "select top 10 bottom 10 distinct *"
|
||||
%+ expect-eq
|
||||
!> [%select %top 10 %bottom 10 %distinct [%all ~]]
|
||||
!> (wonk (parse-select:parse [[1 1] select]))
|
||||
::
|
||||
:: star select top bottom
|
||||
++ test-select-03
|
||||
=/ select "select top 10 bottom 10 *"
|
||||
%+ expect-eq
|
||||
!> [%select %top 10 %bottom 10 [%all ~]]
|
||||
!> (wonk (parse-select:parse [[1 1] select]))
|
||||
::
|
||||
:: star select top, distinct, trailing whitespace
|
||||
++ test-select-04
|
||||
=/ select "select top 10 distinct * "
|
||||
%+ expect-eq
|
||||
!> [%select %top 10 %distinct [%all ~]]
|
||||
!> (wonk (parse-select:parse [[1 1] select]))
|
||||
::
|
||||
:: star select top, distinct
|
||||
++ test-select-05
|
||||
=/ select "select top 10 distinct *"
|
||||
%+ expect-eq
|
||||
!> [%select %top 10 %distinct [%all ~]]
|
||||
!> (wonk (parse-select:parse [[1 1] select]))
|
||||
::
|
||||
:: star select top, trailing whitespace
|
||||
++ test-select-06
|
||||
=/ select "select top 10 * "
|
||||
%+ expect-eq
|
||||
!> [%select %top 10 [%all ~]]
|
||||
!> (wonk (parse-select:parse [[1 1] select]))
|
||||
::
|
||||
:: star select top
|
||||
++ test-select-07
|
||||
=/ select "select top 10 *"
|
||||
%+ expect-eq
|
||||
!> [%select %top 10 [%all ~]]
|
||||
!> (wonk (parse-select:parse [[1 1] select]))
|
||||
::
|
||||
:: star select, trailing whitespace
|
||||
++ test-select-08
|
||||
=/ select "select * "
|
||||
%+ expect-eq
|
||||
!> [%select [%all ~]]
|
||||
!> (wonk (parse-select:parse [[1 1] select]))
|
||||
::
|
||||
:: star select
|
||||
++ test-select-09
|
||||
=/ select "select *"
|
||||
%+ expect-eq
|
||||
!> [%select [%all ~]]
|
||||
!> (wonk (parse-select:parse [[1 1] select]))
|
||||
::
|
||||
:: star select bottom, distinct, trailing whitespace
|
||||
++ test-select-10
|
||||
=/ select "select bottom 10 distinct * "
|
||||
%+ expect-eq
|
||||
!> [%select %bottom 10 %distinct [%all ~]]
|
||||
!> (wonk (parse-select:parse [[1 1] select]))
|
||||
::
|
||||
:: star select bottom, distinct
|
||||
++ test-select-11
|
||||
=/ select "select bottom 10 distinct *"
|
||||
%+ expect-eq
|
||||
!> [%select %bottom 10 %distinct [%all ~]]
|
||||
!> (wonk (parse-select:parse [[1 1] select]))
|
||||
::
|
||||
:: star select bottom, trailing whitespace
|
||||
++ test-select-12
|
||||
=/ select "select bottom 10 * "
|
||||
%+ expect-eq
|
||||
!> [%select %bottom 10 [%all ~]]
|
||||
!> (wonk (parse-select:parse [[1 1] select]))
|
||||
::
|
||||
:: star select bottom
|
||||
++ test-select-13
|
||||
=/ select "select bottom 10 *"
|
||||
%+ expect-eq
|
||||
!> [%select %bottom 10 [%all ~]]
|
||||
!> (wonk (parse-select:parse [[1 1] select]))
|
||||
::
|
||||
:: star select distinct, trailing whitespace
|
||||
++ test-select-14
|
||||
=/ select "select distinct * "
|
||||
%+ expect-eq
|
||||
!> [%select %distinct [%all ~]]
|
||||
!> (wonk (parse-select:parse [[1 1] select]))
|
||||
::
|
||||
:: star select distinct
|
||||
++ test-select-15
|
||||
=/ select "select distinct *"
|
||||
%+ expect-eq
|
||||
!> [%select %distinct [%all ~]]
|
||||
!> (wonk (parse-select:parse [[1 1] select]))
|
||||
::
|
||||
:: fail top, bottom, distinct, no column selection, trailing whitespace
|
||||
++ test-fail-select-16
|
||||
=/ select "select top 10 bottom 10 distinct "
|
||||
%- expect-fail
|
||||
|. (wonk (parse-select:parse [[1 1] select]))
|
||||
::
|
||||
:: fail top, bottom, distinct, no bottom parameter, trailing whitespace
|
||||
++ test-fail-select-17
|
||||
=/ select "select top 10 bottom distinct * "
|
||||
%- expect-fail
|
||||
|. (wonk (parse-select:parse [[1 1] select]))
|
||||
::
|
||||
:: fail top, bottom, distinct, no bottom parameter
|
||||
++ test-fail-select-18
|
||||
=/ select "select top 10 bottom distinct *"
|
||||
%- expect-fail
|
||||
|. (wonk (parse-select:parse [[1 1] select]))
|
||||
::
|
||||
:: fail top, bottom, distinct, no top parameter, trailing whitespace
|
||||
++ test-fail-select-19
|
||||
=/ select "select top bottom 10 distinct * "
|
||||
%- expect-fail
|
||||
|. (wonk (parse-select:parse [[1 1] select]))
|
||||
::
|
||||
:: fail top, bottom, distinct, no top parameter
|
||||
++ test-fail-select-20
|
||||
=/ select "select top bottom 10 distinct *"
|
||||
%- expect-fail
|
||||
|. (wonk (parse-select:parse [[1 1] select]))
|
||||
::
|
||||
:: fail top, bottom, no column selection, trailing whitespace
|
||||
++ test-fail-select-21
|
||||
=/ select "select top 10 bottom 10 "
|
||||
%- expect-fail
|
||||
|. (wonk (parse-select:parse [[1 1] select]))
|
||||
::
|
||||
:: fail top, bottom, no bottom parameter, trailing whitespace
|
||||
++ test-fail-select-22
|
||||
=/ select "select top 10 bottom * "
|
||||
%- expect-fail
|
||||
|. (wonk (parse-select:parse [[1 1] select]))
|
||||
::
|
||||
:: fail top, bottom, no bottom parameter
|
||||
++ test-fail-select-23
|
||||
=/ select "select top 10 bottom *"
|
||||
%- expect-fail
|
||||
|. (wonk (parse-select:parse [[1 1] select]))
|
||||
::
|
||||
:: fail top, no column selection, trailing whitespace
|
||||
++ test-fail-select-24
|
||||
=/ select "select top 10 "
|
||||
%- expect-fail
|
||||
|. (wonk (parse-select:parse [[1 1] select]))
|
||||
::
|
||||
:: fail top, distinct, no column selection, trailing whitespace
|
||||
++ test-fail-select-25
|
||||
=/ select "select top 10 distinct "
|
||||
%- expect-fail
|
||||
|. (wonk (parse-select:parse [[1 1] select]))
|
||||
::
|
||||
:: fail top, distinct, no top parameter, trailing whitespace
|
||||
++ test-fail-select-26
|
||||
=/ select "select top distinct * "
|
||||
%- expect-fail
|
||||
|. (wonk (parse-select:parse [[1 1] select]))
|
||||
::
|
||||
:: fail top, distinct, no top parameter
|
||||
++ test-fail-select-27
|
||||
=/ select "select top distinct *"
|
||||
%- expect-fail
|
||||
|. (wonk (parse-select:parse [[1 1] select]))
|
||||
::
|
||||
:: fail no column selection, trailing whitespace
|
||||
++ test-fail-select-28
|
||||
=/ select "select "
|
||||
%- expect-fail
|
||||
|. (wonk (parse-select:parse [[1 1] select]))
|
||||
::
|
||||
:: fail bottom, distinct, no column selection, trailing whitespace
|
||||
++ test-fail-select-29
|
||||
=/ select "select bottom 10 distinct "
|
||||
%- expect-fail
|
||||
|. (wonk (parse-select:parse [[1 1] select]))
|
||||
::
|
||||
:: fail bottom, distinct, no bottom parameter, trailing whitespace
|
||||
++ test-fail-select-30
|
||||
=/ select "select bottom distinct * "
|
||||
%- expect-fail
|
||||
|. (wonk (parse-select:parse [[1 1] select]))
|
||||
::
|
||||
:: fail bottom, distinct, no bottom parameter
|
||||
++ test-fail-select-31
|
||||
=/ select "select bottom distinct *"
|
||||
%- expect-fail
|
||||
|. (wonk (parse-select:parse [[1 1] select]))
|
||||
::
|
||||
:: fail bottom, no column selection, trailing whitespace
|
||||
++ test-fail-select-32
|
||||
=/ select "select bottom 10 "
|
||||
%- expect-fail
|
||||
|. (wonk (parse-select:parse [[1 1] select]))
|
||||
::
|
||||
:: fail distinct, no column selection, trailing whitespace
|
||||
++ test-fail-select-33
|
||||
=/ select "select distinct "
|
||||
%- expect-fail
|
||||
|. (wonk (parse-select:parse [[1 1] select]))
|
||||
::
|
||||
:: select top, bottom, distinct, simple columns
|
||||
++ test-select-34
|
||||
=/ select "select top 10 bottom 10 distinct ".
|
||||
" x1, db.ns.table.col1, table-alias.name, db..table.col2, T1.foo, 1, ~zod, 'cord'"
|
||||
%+ expect-eq
|
||||
!> [%select %top 10 %bottom 10 %distinct [simple-columns]]
|
||||
!> (wonk (parse-select:parse [[1 1] select]))
|
||||
::
|
||||
:: select top, bottom, distinct, simple columns, trailing space, no internal space
|
||||
++ test-select-35
|
||||
=/ select "select top 10 bottom 10 distinct x1,db.ns.table.col1,table-alias.name,db..table.col2,T1.foo,1,~zod,'cord' "
|
||||
%+ expect-eq
|
||||
!> [%select %top 10 %bottom 10 %distinct [simple-columns]]
|
||||
!> (wonk (parse-select:parse [[1 1] select]))
|
||||
::
|
||||
:: aliased format 1 columns
|
||||
++ test-select-36
|
||||
=/ select "select x1 as foo , db.ns.table.col1 as foo2 , table-alias.name as bar , db..table.col2 as bar2 , 1 as foobar , ~zod as F1 , 'cord' as BAR3 "
|
||||
%+ expect-eq
|
||||
!> [%select [aliased-columns-1]]
|
||||
!> (wonk (parse-select:parse [[1 1] select]))
|
||||
::
|
||||
:: aliased format 1 columns, no whitespace
|
||||
++ test-select-37
|
||||
=/ select "select x1 as foo,db.ns.table.col1 as foo2,table-alias.name as bar,db..table.col2 as bar2,1 as foobar,~zod as F1,'cord' as BAR3"
|
||||
%+ expect-eq
|
||||
!> [%select [aliased-columns-1]]
|
||||
!> (wonk (parse-select:parse [[1 1] select]))
|
||||
::
|
||||
:: mixed all, object all, object alias all, column, aliased column
|
||||
++ test-select-38
|
||||
=/ select "select db..t1.* , foo as foobar , bar , * , T2.* "
|
||||
%+ expect-eq
|
||||
!> [%select [mixed-all]]
|
||||
!> (wonk (parse-select:parse [[1 1] select]))
|
||||
::
|
||||
:: mixed all, object all, object alias all, column, aliased column, no whitespace
|
||||
++ test-select-39
|
||||
=/ select "select db..t1.*,foo as foobar,bar,*,T2.*"
|
||||
%+ expect-eq
|
||||
!> [%select [mixed-all]]
|
||||
!> (wonk (parse-select:parse [[1 1] select]))
|
||||
::
|
||||
:: mixed aggregates
|
||||
++ test-select-40
|
||||
=/ select "select foo , COUNT(foo) as CountFoo, cOUNT( bar) ,sum(bar ) , sum( foobar ) as foobar "
|
||||
%+ expect-eq
|
||||
!> [%select [aggregates]]
|
||||
!> (wonk (parse-select:parse [[1 1] select]))
|
||||
::
|
||||
:: mixed aggregates, no whitespace
|
||||
++ test-select-41
|
||||
=/ select "select foo,COUNT(foo) as CountFoo,cOUNT( bar),sum(bar ),sum( foobar ) as foobar"
|
||||
%+ expect-eq
|
||||
!> [%select [aggregates]]
|
||||
!> (wonk (parse-select:parse [[1 1] select]))
|
||||
--
|
||||
|
||||
:: for later inclusion in full query
|
||||
|
||||
::
|
||||
:: fail top, bottom, distinct, no column selection
|
||||
::++ test-fail-select-
|
||||
:: =/ select "select top 10 bottom 10 distinct"
|
||||
:: %- expect-fail
|
||||
:: |. (wonk (parse-select:parse [[1 1] select]))
|
||||
|
||||
::
|
||||
:: fail top, bottom, no column selection
|
||||
::++ test-fail-select-
|
||||
:: =/ select "select top 10 bottom 10"
|
||||
:: %- expect-fail
|
||||
:: |. (wonk (parse-select:parse [[1 1] select]))
|
||||
|
||||
::
|
||||
:: fail top, no column selection
|
||||
::++ test-fail-select-
|
||||
:: =/ select "select top 10"
|
||||
:: %- expect-fail
|
||||
:: |. (wonk (parse-select:parse [[1 1] select]))
|
||||
|
||||
::
|
||||
:: fail top, distinct, no column selection
|
||||
::++ test-fail-select-
|
||||
:: =/ select "select top 10 distinct"
|
||||
:: %- expect-fail
|
||||
:: |. (wonk (parse-select:parse [[1 1] select]))
|
||||
|
||||
::
|
||||
:: fail no column selection
|
||||
::++ test-fail-select-
|
||||
:: =/ select "select"
|
||||
:: %- expect-fail
|
||||
:: |. (wonk (parse-select:parse [[1 1] select]))
|
||||
|
||||
::
|
||||
:: fail bottom, distinct, no column selection
|
||||
::++ test-fail-select-
|
||||
:: =/ select "select bottom 10 distinct"
|
||||
:: %- expect-fail
|
||||
:: |. (wonk (parse-select:parse [[1 1] select]))
|
||||
|
||||
::
|
||||
:: fail bottom, no column selection
|
||||
::++ test-fail-select-
|
||||
:: =/ select "select bottom 10"
|
||||
:: %- expect-fail
|
||||
:: |. (wonk (parse-select:parse [[1 1] select]))
|
||||
|
||||
::
|
||||
:: fail distinct, no column selection
|
||||
::++ test-fail-select-
|
||||
:: =/ select "select distinct"
|
||||
:: %- expect-fail
|
||||
:: |. (wonk (parse-select:parse [[1 1] select]))
|
Loading…
Reference in New Issue
Block a user