update as of

This commit is contained in:
jackfoxy 2023-12-16 16:13:39 -08:00
parent 9ca817d86a
commit 458c82399e
4 changed files with 239 additions and 149 deletions

View File

@ -10,7 +10,7 @@ Build the library.
Submit a command for parsing in the dojo. Submit a command for parsing in the dojo.
`(parse:parse(current-database 'db1') "FROM foo SELECT TOP 10 DISTINCT *")` `(parse:parse(current-database 'db1') "FROM foo SELECT TOP 10 *")`
Successful commands will return a typed list of commands parsed into their respective data structures. Successful commands will return a typed list of commands parsed into their respective data structures.

View File

@ -1274,7 +1274,7 @@
commands commands
== ==
!! !!
== ==
+$ urql-command +$ urql-command
$% $%
%alter-index %alter-index
@ -1888,14 +1888,26 @@
update-column-inner update-column-inner
== ==
++ parse-update ~+ ++ parse-update ~+
;~ plug ;~ pose
;~(pfix whitespace parse-qualified-object) ;~ plug
(cold %set ;~(plug whitespace (jester 'set'))) ;~(pfix whitespace parse-qualified-object)
(more com update-column) (cold %set ;~(plug whitespace (jester 'set')))
;~ pose (more com update-column)
;~(pfix ;~(plug whitespace (jester 'where')) parse-predicate) ;~ pose
(easy ~) ;~(pfix ;~(plug whitespace (jester 'where')) parse-predicate)
== (easy ~)
==
parse-as-of
==
;~ plug
;~(pfix whitespace parse-qualified-object)
(cold %set ;~(plug whitespace (jester 'set')))
(more com update-column)
;~ pose
;~(pfix ;~(plug whitespace (jester 'where')) parse-predicate)
(easy ~)
==
==
== ==
++ parse-with ~+ ++ parse-with ~+
;~ plug ;~ plug
@ -2517,6 +2529,43 @@
=/ columns-values=[(list @t) (list datum:ast)] (produce-column-sets +>-.a) =/ columns-values=[(list @t) (list datum:ast)] (produce-column-sets +>-.a)
?~ +>+.a ?~ +>+.a
(update:ast %update table -.columns-values +.columns-values ~ ~) (update:ast %update table -.columns-values +.columns-values ~ ~)
?: ?=([* %set * ~ %as-of %now] a)
(update:ast %update table -.columns-values +.columns-values ~ ~)
?: ?=([* %set * ~ %as-of [@ @]] a)
(update:ast %update table -.columns-values +.columns-values ~ [~ +>+>+>.a])
?: ?=([* %set * ~ %as-of *] a)
%: update:ast %update
table
-.columns-values
+.columns-values
~
[~ (as-of-offset:ast %as-of-offset +>+>+<.a +>+>+>-.a)]
==
?: ?=([* %set * * %as-of %now] a)
%: update:ast %update
table
-.columns-values
+.columns-values
`(produce-predicate (predicate-list +>+<.a))
~
==
?: ?=([* %set * * %as-of [@ @]] a)
%: update:ast %update
table
-.columns-values
+.columns-values
`(produce-predicate (predicate-list +>+<.a))
[~ +>+>+>.a]
==
?: ?=([* %set * * %as-of *] a)
%: update:ast %update
table
-.columns-values
+.columns-values
`(produce-predicate (predicate-list +>+<.a))
[~ (as-of-offset:ast %as-of-offset +>+>+<.a +>+>+>-.a)]
==
%: update:ast %update %: update:ast %update
table table
-.columns-values -.columns-values

View File

@ -24,181 +24,133 @@
[%cte name='bar' [%query [~ [%from object=[%table-set object=[%qualified-object ship=~ database='db1' namespace='dbo' name='bar'] alias=~] joins=~]] scalars=~ `[%eq [col1 ~ ~] [col2 ~ ~]] group-by=~ having=~ [%select top=~ bottom=~ columns=~[col2]] ~]] [%cte name='bar' [%query [~ [%from object=[%table-set object=[%qualified-object ship=~ database='db1' namespace='dbo' name='bar'] alias=~] joins=~]] scalars=~ `[%eq [col1 ~ ~] [col2 ~ ~]] group-by=~ having=~ [%select top=~ bottom=~ columns=~[col2]] ~]]
++ foo-table ++ foo-table
[%qualified-object ship=~ database='db1' namespace='dbo' name='foo'] [%qualified-object ship=~ database='db1' namespace='dbo' name='foo']
++ update-pred
[%and one-eq-1 [%eq [col2 ~ ~] [[value-type=%ud value=4] ~ ~]]]
++ one-eq-1
[%eq [literal-1 ~ ~] [literal-1 ~ ~]]
++ literal-1 [value-type=%ud value=1]
::@@@@@@@@@@@@@@@@@@@@@@@@@ ::@@@@@@@@@@@@@@@@@@@@@@@@@
:: ::
:: delete from foo;delete foo :: update one column, no predicate
++ test-delete-00 ++ test-update-00
=/ expected1 [%transform ctes=~ [[%delete table=foo-table ~ ~] ~ ~]]
=/ expected2 [%transform ctes=~ [[%delete table=foo-table ~ ~] ~ ~]]
%+ expect-eq %+ expect-eq
!> ~[expected1 expected2] !> ~[[%transform ctes=~ [[%update table=foo-table columns=~['col1'] values=~[[value-type=%t value='hello']] predicate=~ as-of=~] ~ ~]]]
!> (parse:parse(default-database 'db1') "delete from foo;delete foo") !> (parse:parse(default-database 'db1') "update foo set col1='hello'")
:: ::
:: delete from foo as of now;delete foo as of now :: update one column, no predicate as of now
++ test-delete-01 ++ test-update-01
=/ expected1 [%transform ctes=~ [[%delete table=foo-table ~ ~] ~ ~]]
=/ expected2 [%transform ctes=~ [[%delete table=foo-table ~ ~] ~ ~]]
%+ expect-eq %+ expect-eq
!> ~[expected1 expected2] !> ~[[%transform ctes=~ [[%update table=foo-table columns=~['col1'] values=~[[value-type=%t value='hello']] predicate=~ as-of=~] ~ ~]]]
!> (parse:parse(default-database 'db1') "delete from foo as of now;delete foo as of now") !> (parse:parse(default-database 'db1') "update foo set col1='hello' as of now")
:: ::
:: delete from foo as of ~2023.12.25..7.15.0..1ef5;delete foo as of ~2023.12.25..7.15.0..1ef5 :: update one column, no predicate as of ~2023.12.25..7.15.0..1ef5
++ test-delete-02 ++ test-update-02
=/ expected1 [%transform ctes=~ [[%delete table=foo-table ~ [~ ~2023.12.25..7.15.0..1ef5]] ~ ~]]
=/ expected2 [%transform ctes=~ [[%delete table=foo-table ~ [~ ~2023.12.25..7.15.0..1ef5]] ~ ~]]
%+ expect-eq %+ expect-eq
!> ~[expected1 expected2] !> ~[[%transform ctes=~ [[%update table=foo-table columns=~['col1'] values=~[[value-type=%t value='hello']] predicate=~ as-of=[~ ~2023.12.25..7.15.0..1ef5]] ~ ~]]]
!> (parse:parse(default-database 'db1') "delete from foo as of 2023.12.25..7.15.0..1ef5;delete foo as of ~2023.12.25..7.15.0..1ef5") !> (parse:parse(default-database 'db1') "update foo set col1='hello' as of ~2023.12.25..7.15.0..1ef5")
:: ::
:: delete from foo as of 5 seconds ago;delete foo as of 5 seconds ago :: update one column, no predicate as of 4 seconds ago
++ test-delete-03 ++ test-update-03
=/ expected1 [%transform ctes=~ [[%delete table=foo-table ~ [~ [%as-of-offset 5 %seconds]]] ~ ~]]
=/ expected2 [%transform ctes=~ [[%delete table=foo-table ~ [~ [%as-of-offset 4 %seconds]]] ~ ~]]
%+ expect-eq %+ expect-eq
!> ~[expected1 expected2] !> ~[[%transform ctes=~ [[%update table=foo-table columns=~['col1'] values=~[[value-type=%t value='hello']] predicate=~ as-of=[~ [%as-of-offset 4 %seconds]]] ~ ~]]]
!> (parse:parse(default-database 'db1') "delete from foo as of 5 seconds ago;delete foo as of 4 seconds ago") !> (parse:parse(default-database 'db1') "update foo set col1='hello' as of 4 seconds ago")
:: ::
:: delete with predicate as :: update two columns, no predicate
++ test-delete-04 ++ test-update-04
=/ expected [%transform ctes=~ [[%delete table=foo-table delete-pred ~] ~ ~]]
%+ expect-eq %+ expect-eq
!> ~[expected] !> ~[[%transform ctes=~ [[%update table=foo-table columns=~['col3' 'col1'] values=~[[value-type=%t value='hello'] col2] predicate=~ as-of=~] ~ ~]]]
!> (parse:parse(default-database 'db1') "delete from foo where foo=bar") !> (parse:parse(default-database 'db1') "update foo set col1=col2, col3 = 'hello'")
:: ::
:: delete with predicate of now :: update two columns, no predicate as of now
++ test-delete-05 ++ test-update-05
=/ expected [%transform ctes=~ [[%delete table=foo-table delete-pred ~] ~ ~]]
%+ expect-eq %+ expect-eq
!> ~[expected] !> ~[[%transform ctes=~ [[%update table=foo-table columns=~['col3' 'col1'] values=~[[value-type=%t value='hello'] col2] predicate=~ as-of=~] ~ ~]]]
!> (parse:parse(default-database 'db1') "delete from foo where foo=bar as of now") !> (parse:parse(default-database 'db1') "update foo set col1=col2, col3 = 'hello' as of now")
:: ::
:: delete with predicate of ~2023.12.25..7.15.0..1ef5 :: update two columns, no predicate as of ~2023.12.25..7.15.0..1ef5
++ test-delete-06 ++ test-update-06
=/ expected [%transform ctes=~ [[%delete table=foo-table delete-pred [~ ~2023.12.25..7.15.0..1ef5]] ~ ~]]
%+ expect-eq %+ expect-eq
!> ~[expected] !> ~[[%transform ctes=~ [[%update table=foo-table columns=~['col3' 'col1'] values=~[[value-type=%t value='hello'] col2] predicate=~ as-of=[~ ~2023.12.25..7.15.0..1ef5]] ~ ~]]]
!> (parse:parse(default-database 'db1') "delete from foo where foo=bar as of ~2023.12.25..7.15.0..1ef5") !> (parse:parse(default-database 'db1') "update foo set col1=col2, col3 = 'hello' as of ~2023.12.25..7.15.0..1ef5")
:: ::
:: delete with predicate of 5 seconds ago :: update two columns, no predicate as of 4 seconds ago
++ test-delete-07 ++ test-update-07
=/ expected [%transform ctes=~ [[%delete table=foo-table delete-pred [~ [%as-of-offset 5 %seconds]]] ~ ~]]
%+ expect-eq %+ expect-eq
!> ~[expected] !> ~[[%transform ctes=~ [[%update table=foo-table columns=~['col3' 'col1'] values=~[[value-type=%t value='hello'] col2] predicate=~ as-of=[~ [%as-of-offset 4 %seconds]]] ~ ~]]]
!> (parse:parse(default-database 'db1') "delete from foo where foo=bar as of 5 seconds ago") !> (parse:parse(default-database 'db1') "update foo set col1=col2, col3 = 'hello' as of 4 seconds ago")
:: ::
:: delete with one cte and predicate :: update two columns, with predicate
++ test-delete-08 ++ test-update-08
=/ expected [%transform ctes=~[cte-t1] [[%delete table=foo-table delete-pred ~] ~ ~]]
%+ expect-eq %+ expect-eq
!> ~[expected] !> ~[[%transform ctes=~ [[%update table=foo-table columns=~['col3' 'col1'] values=~[[value-type=%t value='hello'] col2] predicate=`update-pred as-of=~] ~ ~]]]
!> (parse:parse(default-database 'db1') "with (select *) as t1 delete from foo where foo=bar") !> (parse:parse(default-database 'db1') "update foo set col1=col2, col3 = 'hello' where 1 = 1 and col2 = 4")
:: ::
:: delete with one cte and predicate as of now :: update two columns, with predicate as of now
++ test-delete-09 ++ test-update-09
=/ expected [%transform ctes=~[cte-t1] [[%delete table=foo-table delete-pred ~] ~ ~]]
%+ expect-eq %+ expect-eq
!> ~[expected] !> ~[[%transform ctes=~ [[%update table=foo-table columns=~['col3' 'col1'] values=~[[value-type=%t value='hello'] col2] predicate=`update-pred as-of=~] ~ ~]]]
!> (parse:parse(default-database 'db1') "with (select *) as t1 delete from foo where foo=bar as of now") !> (parse:parse(default-database 'db1') "update foo set col1=col2, col3 = 'hello' where 1 = 1 and col2 = 4 as of now")
:: ::
:: delete with one cte and predicate as of ~2023.12.25..7.15.0..1ef5 :: update two columns, with predicate as of ~2023.12.25..7.15.0..1ef5
++ test-delete-10 ++ test-update-10
=/ expected [%transform ctes=~[cte-t1] [[%delete table=foo-table delete-pred [~ ~2023.12.25..7.15.0..1ef5]] ~ ~]]
%+ expect-eq %+ expect-eq
!> ~[expected] !> ~[[%transform ctes=~ [[%update table=foo-table columns=~['col3' 'col1'] values=~[[value-type=%t value='hello'] col2] predicate=`update-pred as-of=[~ ~2023.12.25..7.15.0..1ef5]] ~ ~]]]
!> (parse:parse(default-database 'db1') "with (select *) as t1 delete from foo where foo=bar as of ~2023.12.25..7.15.0..1ef5") !> (parse:parse(default-database 'db1') "update foo set col1=col2, col3 = 'hello' where 1 = 1 and col2 = 4 as of ~2023.12.25..7.15.0..1ef5")
:: ::
:: delete with one cte and predicate as of 5 seconds ago :: update two columns, with predicate as of 4 seconds ago
++ test-delete-11 ++ test-update-11
=/ expected [%transform ctes=~[cte-t1] [[%delete table=foo-table delete-pred [~ [%as-of-offset 5 %seconds]]] ~ ~]]
%+ expect-eq %+ expect-eq
!> ~[expected] !> ~[[%transform ctes=~ [[%update table=foo-table columns=~['col3' 'col1'] values=~[[value-type=%t value='hello'] col2] predicate=`update-pred as-of=[~ [%as-of-offset 4 %seconds]]] ~ ~]]]
!> (parse:parse(default-database 'db1') "with (select *) as t1 delete from foo where foo=bar as of 5 seconds ago") !> (parse:parse(default-database 'db1') "update foo set col1=col2, col3 = 'hello' where 1 = 1 and col2 = 4 as of 4 seconds ago")
:: ::
:: delete with two ctes and predicate :: update with one cte and predicate
++ test-delete-12 ++ test-update-12
=/ expected [%transform ctes=~[cte-t1 cte-foobar] [[%delete table=foo-table delete-pred ~] ~ ~]]
%+ expect-eq %+ expect-eq
!> ~[expected] !> ~[[%transform ctes=~[cte-t1] [[%update table=foo-table columns=~['col3' 'col1'] values=~[[value-type=%t value='hello'] col2] predicate=`update-pred as-of=~] ~ ~]]]
!> (parse:parse(default-database 'db1') "with (select *) as t1, (from foobar where col1=2 select col3, col4) as foobar delete from foo where foo=bar") !> (parse:parse(default-database 'db1') "with (select *) as t1 update foo set col1=col2, col3 = 'hello' where 1 = 1 and col2 = 4")
:: ::
:: delete with two ctes and predicate as of now :: update with one cte and predicate as of now
++ test-delete-13 ++ test-update-13
=/ expected [%transform ctes=~[cte-t1 cte-foobar] [[%delete table=foo-table delete-pred ~] ~ ~]]
%+ expect-eq %+ expect-eq
!> ~[expected] !> ~[[%transform ctes=~[cte-t1] [[%update table=foo-table columns=~['col3' 'col1'] values=~[[value-type=%t value='hello'] col2] predicate=`update-pred as-of=~] ~ ~]]]
!> (parse:parse(default-database 'db1') "with (select *) as t1, (from foobar where col1=2 select col3, col4) as foobar delete from foo where foo=bar as of now") !> (parse:parse(default-database 'db1') "with (select *) as t1 update foo set col1=col2, col3 = 'hello' where 1 = 1 and col2 = 4 as of now")
:: ::
:: delete with two ctes and predicate as of ~2023.12.25..7.15.0..1ef5 :: update with one cte and predicate as of ~2023.12.25..7.15.0..1ef5
++ test-delete-14 ++ test-update-14
=/ expected [%transform ctes=~[cte-t1 cte-foobar] [[%delete table=foo-table delete-pred [~ ~2023.12.25..7.15.0..1ef5]] ~ ~]]
%+ expect-eq %+ expect-eq
!> ~[expected] !> ~[[%transform ctes=~[cte-t1] [[%update table=foo-table columns=~['col3' 'col1'] values=~[[value-type=%t value='hello'] col2] predicate=`update-pred as-of=[~ ~2023.12.25..7.15.0..1ef5]] ~ ~]]]
!> (parse:parse(default-database 'db1') "with (select *) as t1, (from foobar where col1=2 select col3, col4) as foobar delete from foo where foo=bar as of ~2023.12.25..7.15.0..1ef5") !> (parse:parse(default-database 'db1') "with (select *) as t1 update foo set col1=col2, col3 = 'hello' where 1 = 1 and col2 = 4 as of ~2023.12.25..7.15.0..1ef5")
:: ::
:: delete with two ctes and predicate as of 5 seconds ago :: update with one cte and predicate as of 4 seconds ago
++ test-delete-15 ++ test-update-15
=/ expected [%transform ctes=~[cte-t1 cte-foobar] [[%delete table=foo-table delete-pred [~ [%as-of-offset 5 %seconds]]] ~ ~]]
%+ expect-eq %+ expect-eq
!> ~[expected] !> ~[[%transform ctes=~[cte-t1] [[%update table=foo-table columns=~['col3' 'col1'] values=~[[value-type=%t value='hello'] col2] predicate=`update-pred as-of=[~ [%as-of-offset 4 %seconds]]] ~ ~]]]
!> (parse:parse(default-database 'db1') "with (select *) as t1, (from foobar where col1=2 select col3, col4) as foobar delete from foo where foo=bar as of 5 seconds ago") !> (parse:parse(default-database 'db1') "with (select *) as t1 update foo set col1=col2, col3 = 'hello' where 1 = 1 and col2 = 4 as of 4 seconds ago")
:: ::
:: delete with three ctes and predicate :: update with three ctes and predicate
++ test-delete-16 ++ test-update-16
=/ expected [%transform ctes=~[cte-t1 cte-foobar cte-bar] [%delete table=foo-table delete-pred ~] ~ ~]
%+ expect-eq %+ expect-eq
!> ~[expected] !> ~[[%transform ctes=~[cte-t1 cte-foobar cte-bar] [[%update table=foo-table columns=~['col3' 'col1'] values=~[[value-type=%t value='hello'] col2] predicate=`update-pred as-of=~] ~ ~]]]
!> (parse:parse(default-database 'db1') "with (select *) as t1, (from foobar where col1=2 select col3, col4) as foobar, (from bar where col1=col2 select col2) as bar delete from foo where foo=bar") !> (parse:parse(default-database 'db1') "with (select *) as t1, (from foobar where col1=2 select col3, col4) as foobar, (from bar where col1=col2 select col2) as bar update foo set col1=col2, col3 = 'hello' where 1 = 1 and col2 = 4")
:: ::
:: delete with three ctes and predicate as of now :: update with three ctes and predicate as of now
++ test-delete-17 ++ test-update-17
=/ expected [%transform ctes=~[cte-t1 cte-foobar cte-bar] [%delete table=foo-table delete-pred ~] ~ ~]
%+ expect-eq %+ expect-eq
!> ~[expected] !> ~[[%transform ctes=~[cte-t1 cte-foobar cte-bar] [[%update table=foo-table columns=~['col3' 'col1'] values=~[[value-type=%t value='hello'] col2] predicate=`update-pred as-of=~] ~ ~]]]
!> (parse:parse(default-database 'db1') "with (select *) as t1, (from foobar where col1=2 select col3, col4) as foobar, (from bar where col1=col2 select col2) as bar delete from foo where foo=bar as of now") !> (parse:parse(default-database 'db1') "with (select *) as t1, (from foobar where col1=2 select col3, col4) as foobar, (from bar where col1=col2 select col2) as bar update foo set col1=col2, col3 = 'hello' where 1 = 1 and col2 = 4 as of now")
:: ::
:: delete with three ctes and predicate as of ~2023.12.25..7.15.0..1ef5 :: update with three ctes and predicate as of ~2023.12.25..7.15.0..1ef5
++ test-delete-18 ++ test-update-18
=/ expected [%transform ctes=~[cte-t1 cte-foobar cte-bar] [%delete table=foo-table delete-pred [~ ~2023.12.25..7.15.0..1ef5]] ~ ~]
%+ expect-eq %+ expect-eq
!> ~[expected] !> ~[[%transform ctes=~[cte-t1 cte-foobar cte-bar] [[%update table=foo-table columns=~['col3' 'col1'] values=~[[value-type=%t value='hello'] col2] predicate=`update-pred as-of=[~ ~2023.12.25..7.15.0..1ef5]] ~ ~]]]
!> (parse:parse(default-database 'db1') "with (select *) as t1, (from foobar where col1=2 select col3, col4) as foobar, (from bar where col1=col2 select col2) as bar delete from foo where foo=bar as of ~2023.12.25..7.15.0..1ef5") !> (parse:parse(default-database 'db1') "with (select *) as t1, (from foobar where col1=2 select col3, col4) as foobar, (from bar where col1=col2 select col2) as bar update foo set col1=col2, col3 = 'hello' where 1 = 1 and col2 = 4 as of ~2023.12.25..7.15.0..1ef5")
:: ::
:: delete with three ctes and predicate as of 5 seconds ago :: update with three ctes and predicate as of 4 seconds ago
++ test-delete-19 ++ test-update-19
=/ expected [%transform ctes=~[cte-t1 cte-foobar cte-bar] [%delete table=foo-table delete-pred [~ [%as-of-offset 5 %seconds]]] ~ ~]
%+ expect-eq %+ expect-eq
!> ~[expected] !> ~[[%transform ctes=~[cte-t1 cte-foobar cte-bar] [[%update table=foo-table columns=~['col3' 'col1'] values=~[[value-type=%t value='hello'] col2] predicate=`update-pred as-of=[~ [%as-of-offset 4 %seconds]]] ~ ~]]]
!> (parse:parse(default-database 'db1') "with (select *) as t1, (from foobar where col1=2 select col3, col4) as foobar, (from bar where col1=col2 select col2) as bar delete from foo where foo=bar as of 5 seconds ago") !> (parse:parse(default-database 'db1') "with (select *) as t1, (from foobar where col1=2 select col3, col4) as foobar, (from bar where col1=col2 select col2) as bar update foo set col1=col2, col3 = 'hello' where 1 = 1 and col2 = 4 as of 4 seconds ago")
::
:: delete cte with no predicate
++ test-delete-20
=/ expected [%transform ctes=~[cte-t1] [[%delete table=foo-table ~ ~] ~ ~]]
%+ expect-eq
!> ~[expected]
!> (parse:parse(default-database 'db1') "with (select *) as t1 delete from foo")
::
:: delete cte with no predicate as of now
++ test-delete-21
=/ expected [%transform ctes=~[cte-t1] [[%delete table=foo-table ~ ~] ~ ~]]
%+ expect-eq
!> ~[expected]
!> (parse:parse(default-database 'db1') "with (select *) as t1 delete from foo as of now")
::
:: delete cte with no predicate as of ~2023.12.25..7.15.0..1ef5
++ test-delete-22
=/ expected [%transform ctes=~[cte-t1] [[%delete table=foo-table ~ [~ ~2023.12.25..7.15.0..1ef5]] ~ ~]]
%+ expect-eq
!> ~[expected]
!> (parse:parse(default-database 'db1') "with (select *) as t1 delete from foo as of ~2023.12.25..7.15.0..1ef5")
::
:: delete cte with no predicate as of 5 seconds ago
++ test-delete-23
=/ expected [%transform ctes=~[cte-t1] [[%delete table=foo-table ~ [~ [%as-of-offset 5 %seconds]]] ~ ~]]
%+ expect-eq
!> ~[expected]
!> (parse:parse(default-database 'db1') "with (select *) as t1 delete from foo as of 5 seconds ago")
::@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ::@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

View File

@ -2928,36 +2928,125 @@
[%and one-eq-1 [%eq [col2 ~ ~] [[value-type=%ud value=4] ~ ~]]] [%and one-eq-1 [%eq [col2 ~ ~] [[value-type=%ud value=4] ~ ~]]]
:: ::
:: update one column, no predicate :: update one column, no predicate
++ test-update-01 ++ test-update-00
%+ expect-eq %+ expect-eq
!> ~[[%transform ctes=~ [[%update table=foo-table columns=~['col1'] values=~[[value-type=%t value='hello']] predicate=~ as-of=~] ~ ~]]] !> ~[[%transform ctes=~ [[%update table=foo-table columns=~['col1'] values=~[[value-type=%t value='hello']] predicate=~ as-of=~] ~ ~]]]
!> (parse:parse(default-database 'db1') "update foo set col1='hello'") !> (parse:parse(default-database 'db1') "update foo set col1='hello'")
:: ::
:: update two columns, no predicate :: update one column, no predicate as of now
++ test-update-01
%+ expect-eq
!> ~[[%transform ctes=~ [[%update table=foo-table columns=~['col1'] values=~[[value-type=%t value='hello']] predicate=~ as-of=~] ~ ~]]]
!> (parse:parse(default-database 'db1') "update foo set col1='hello' as of now")
::
:: update one column, no predicate as of ~2023.12.25..7.15.0..1ef5
++ test-update-02 ++ test-update-02
%+ expect-eq
!> ~[[%transform ctes=~ [[%update table=foo-table columns=~['col1'] values=~[[value-type=%t value='hello']] predicate=~ as-of=[~ ~2023.12.25..7.15.0..1ef5]] ~ ~]]]
!> (parse:parse(default-database 'db1') "update foo set col1='hello' as of ~2023.12.25..7.15.0..1ef5")
::
:: update one column, no predicate as of 4 seconds ago
++ test-update-03
%+ expect-eq
!> ~[[%transform ctes=~ [[%update table=foo-table columns=~['col1'] values=~[[value-type=%t value='hello']] predicate=~ as-of=[~ [%as-of-offset 4 %seconds]]] ~ ~]]]
!> (parse:parse(default-database 'db1') "update foo set col1='hello' as of 4 seconds ago")
::
:: update two columns, no predicate
++ test-update-04
%+ expect-eq %+ expect-eq
!> ~[[%transform ctes=~ [[%update table=foo-table columns=~['col3' 'col1'] values=~[[value-type=%t value='hello'] col2] predicate=~ as-of=~] ~ ~]]] !> ~[[%transform ctes=~ [[%update table=foo-table columns=~['col3' 'col1'] values=~[[value-type=%t value='hello'] col2] predicate=~ as-of=~] ~ ~]]]
!> (parse:parse(default-database 'db1') "update foo set col1=col2, col3 = 'hello'") !> (parse:parse(default-database 'db1') "update foo set col1=col2, col3 = 'hello'")
:: ::
:: update two columns, no predicate as of now
++ test-update-05
%+ expect-eq
!> ~[[%transform ctes=~ [[%update table=foo-table columns=~['col3' 'col1'] values=~[[value-type=%t value='hello'] col2] predicate=~ as-of=~] ~ ~]]]
!> (parse:parse(default-database 'db1') "update foo set col1=col2, col3 = 'hello' as of now")
::
:: update two columns, no predicate as of ~2023.12.25..7.15.0..1ef5
++ test-update-06
%+ expect-eq
!> ~[[%transform ctes=~ [[%update table=foo-table columns=~['col3' 'col1'] values=~[[value-type=%t value='hello'] col2] predicate=~ as-of=[~ ~2023.12.25..7.15.0..1ef5]] ~ ~]]]
!> (parse:parse(default-database 'db1') "update foo set col1=col2, col3 = 'hello' as of ~2023.12.25..7.15.0..1ef5")
::
:: update two columns, no predicate as of 4 seconds ago
++ test-update-07
%+ expect-eq
!> ~[[%transform ctes=~ [[%update table=foo-table columns=~['col3' 'col1'] values=~[[value-type=%t value='hello'] col2] predicate=~ as-of=[~ [%as-of-offset 4 %seconds]]] ~ ~]]]
!> (parse:parse(default-database 'db1') "update foo set col1=col2, col3 = 'hello' as of 4 seconds ago")
::
:: update two columns, with predicate :: update two columns, with predicate
++ test-update-03 ++ test-update-08
%+ expect-eq %+ expect-eq
!> ~[[%transform ctes=~ [[%update table=foo-table columns=~['col3' 'col1'] values=~[[value-type=%t value='hello'] col2] predicate=`update-pred as-of=~] ~ ~]]] !> ~[[%transform ctes=~ [[%update table=foo-table columns=~['col3' 'col1'] values=~[[value-type=%t value='hello'] col2] predicate=`update-pred as-of=~] ~ ~]]]
!> (parse:parse(default-database 'db1') "update foo set col1=col2, col3 = 'hello' where 1 = 1 and col2 = 4") !> (parse:parse(default-database 'db1') "update foo set col1=col2, col3 = 'hello' where 1 = 1 and col2 = 4")
::
:: update two columns, with predicate as of now
++ test-update-09
%+ expect-eq
!> ~[[%transform ctes=~ [[%update table=foo-table columns=~['col3' 'col1'] values=~[[value-type=%t value='hello'] col2] predicate=`update-pred as-of=~] ~ ~]]]
!> (parse:parse(default-database 'db1') "update foo set col1=col2, col3 = 'hello' where 1 = 1 and col2 = 4 as of now")
::
:: update two columns, with predicate as of ~2023.12.25..7.15.0..1ef5
++ test-update-10
%+ expect-eq
!> ~[[%transform ctes=~ [[%update table=foo-table columns=~['col3' 'col1'] values=~[[value-type=%t value='hello'] col2] predicate=`update-pred as-of=[~ ~2023.12.25..7.15.0..1ef5]] ~ ~]]]
!> (parse:parse(default-database 'db1') "update foo set col1=col2, col3 = 'hello' where 1 = 1 and col2 = 4 as of ~2023.12.25..7.15.0..1ef5")
::
:: update two columns, with predicate as of 4 seconds ago
++ test-update-11
%+ expect-eq
!> ~[[%transform ctes=~ [[%update table=foo-table columns=~['col3' 'col1'] values=~[[value-type=%t value='hello'] col2] predicate=`update-pred as-of=[~ [%as-of-offset 4 %seconds]]] ~ ~]]]
!> (parse:parse(default-database 'db1') "update foo set col1=col2, col3 = 'hello' where 1 = 1 and col2 = 4 as of 4 seconds ago")
:: ::
:: update with one cte and predicate :: update with one cte and predicate
++ test-update-04 ++ test-update-12
%+ expect-eq %+ expect-eq
!> ~[[%transform ctes=~[cte-t1] [[%update table=foo-table columns=~['col3' 'col1'] values=~[[value-type=%t value='hello'] col2] predicate=`update-pred as-of=~] ~ ~]]] !> ~[[%transform ctes=~[cte-t1] [[%update table=foo-table columns=~['col3' 'col1'] values=~[[value-type=%t value='hello'] col2] predicate=`update-pred as-of=~] ~ ~]]]
!> (parse:parse(default-database 'db1') "with (select *) as t1 update foo set col1=col2, col3 = 'hello' where 1 = 1 and col2 = 4") !> (parse:parse(default-database 'db1') "with (select *) as t1 update foo set col1=col2, col3 = 'hello' where 1 = 1 and col2 = 4")
:: ::
:: update with one cte and predicate as of now
++ test-update-13
%+ expect-eq
!> ~[[%transform ctes=~[cte-t1] [[%update table=foo-table columns=~['col3' 'col1'] values=~[[value-type=%t value='hello'] col2] predicate=`update-pred as-of=~] ~ ~]]]
!> (parse:parse(default-database 'db1') "with (select *) as t1 update foo set col1=col2, col3 = 'hello' where 1 = 1 and col2 = 4 as of now")
::
:: update with one cte and predicate as of ~2023.12.25..7.15.0..1ef5
++ test-update-14
%+ expect-eq
!> ~[[%transform ctes=~[cte-t1] [[%update table=foo-table columns=~['col3' 'col1'] values=~[[value-type=%t value='hello'] col2] predicate=`update-pred as-of=[~ ~2023.12.25..7.15.0..1ef5]] ~ ~]]]
!> (parse:parse(default-database 'db1') "with (select *) as t1 update foo set col1=col2, col3 = 'hello' where 1 = 1 and col2 = 4 as of ~2023.12.25..7.15.0..1ef5")
::
:: update with one cte and predicate as of 4 seconds ago
++ test-update-15
%+ expect-eq
!> ~[[%transform ctes=~[cte-t1] [[%update table=foo-table columns=~['col3' 'col1'] values=~[[value-type=%t value='hello'] col2] predicate=`update-pred as-of=[~ [%as-of-offset 4 %seconds]]] ~ ~]]]
!> (parse:parse(default-database 'db1') "with (select *) as t1 update foo set col1=col2, col3 = 'hello' where 1 = 1 and col2 = 4 as of 4 seconds ago")
::
:: update with three ctes and predicate :: update with three ctes and predicate
++ test-update-05 ++ test-update-16
%+ expect-eq %+ expect-eq
!> ~[[%transform ctes=~[cte-t1 cte-foobar cte-bar] [[%update table=foo-table columns=~['col3' 'col1'] values=~[[value-type=%t value='hello'] col2] predicate=`update-pred as-of=~] ~ ~]]] !> ~[[%transform ctes=~[cte-t1 cte-foobar cte-bar] [[%update table=foo-table columns=~['col3' 'col1'] values=~[[value-type=%t value='hello'] col2] predicate=`update-pred as-of=~] ~ ~]]]
!> (parse:parse(default-database 'db1') "with (select *) as t1, (from foobar where col1=2 select col3, col4) as foobar, (from bar where col1=col2 select col2) as bar update foo set col1=col2, col3 = 'hello' where 1 = 1 and col2 = 4") !> (parse:parse(default-database 'db1') "with (select *) as t1, (from foobar where col1=2 select col3, col4) as foobar, (from bar where col1=col2 select col2) as bar update foo set col1=col2, col3 = 'hello' where 1 = 1 and col2 = 4")
:: ::
:: update with three ctes and predicate as of now
++ test-update-17
%+ expect-eq
!> ~[[%transform ctes=~[cte-t1 cte-foobar cte-bar] [[%update table=foo-table columns=~['col3' 'col1'] values=~[[value-type=%t value='hello'] col2] predicate=`update-pred as-of=~] ~ ~]]]
!> (parse:parse(default-database 'db1') "with (select *) as t1, (from foobar where col1=2 select col3, col4) as foobar, (from bar where col1=col2 select col2) as bar update foo set col1=col2, col3 = 'hello' where 1 = 1 and col2 = 4 as of now")
::
:: update with three ctes and predicate as of ~2023.12.25..7.15.0..1ef5
++ test-update-18
%+ expect-eq
!> ~[[%transform ctes=~[cte-t1 cte-foobar cte-bar] [[%update table=foo-table columns=~['col3' 'col1'] values=~[[value-type=%t value='hello'] col2] predicate=`update-pred as-of=[~ ~2023.12.25..7.15.0..1ef5]] ~ ~]]]
!> (parse:parse(default-database 'db1') "with (select *) as t1, (from foobar where col1=2 select col3, col4) as foobar, (from bar where col1=col2 select col2) as bar update foo set col1=col2, col3 = 'hello' where 1 = 1 and col2 = 4 as of ~2023.12.25..7.15.0..1ef5")
::
:: update with three ctes and predicate as of 4 seconds ago
++ test-update-19
%+ expect-eq
!> ~[[%transform ctes=~[cte-t1 cte-foobar cte-bar] [[%update table=foo-table columns=~['col3' 'col1'] values=~[[value-type=%t value='hello'] col2] predicate=`update-pred as-of=[~ [%as-of-offset 4 %seconds]]] ~ ~]]]
!> (parse:parse(default-database 'db1') "with (select *) as t1, (from foobar where col1=2 select col3, col4) as foobar, (from bar where col1=col2 select col2) as bar update foo set col1=col2, col3 = 'hello' where 1 = 1 and col2 = 4 as of 4 seconds ago")
::
:: fail update cte with no predicate :: fail update cte with no predicate
::++ test-fail-update-06 ::++ test-fail-update-06
:: %- expect-fail :: %- expect-fail