jussisaurio
3ab7f7a0b8
Merge 'Use custom expr equality check in translation and planning' from Preston Thorpe
...
Idk how I missed these during the initial PR 👍
Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com >
Closes #541
2024-12-23 22:58:03 +02:00
PThorpe92
fbf42458b8
Use custom expr equality check in translation and planner
2024-12-22 21:46:31 -05:00
PThorpe92
c06c4115f1
Adapt OwnedValues in uuid ext to new LimboText
2024-12-21 09:17:53 -05:00
PThorpe92
2fcae80902
Create ext directory for outside funcs, add uuid to ext dir
2024-12-21 09:16:04 -05:00
PThorpe92
f96f289609
Remove unnecessary nanos arg from uuid7, add insn const
2024-12-21 09:13:48 -05:00
PThorpe92
c1561ecbb0
Tests for uuid funcitons, add compat docs
2024-12-21 09:13:48 -05:00
PThorpe92
fcab0ae299
Add uuid support for v4 and v7
2024-12-21 09:13:46 -05:00
Kacper Madej
cdb24d3de1
Handle issues with nested arguments
2024-12-20 11:32:57 +01:00
Kacper Madej
19ae42dfa3
Implement json_array
2024-12-20 11:15:48 +01:00
Lauri Virtanen
e69ee80fac
Support log(X) and log(B,X) math functions
2024-12-17 00:14:25 +02:00
Lauri Virtanen
89d0289444
Support pi() function
2024-12-17 00:14:25 +02:00
Lauri Virtanen
5e426a7624
Support binary math functions
2024-12-16 22:29:05 +02:00
Lauri Virtanen
f69fdc1645
Support unary math functions
2024-12-16 19:31:20 +02:00
Lauri Virtanen
9720f63a55
Add types for mathematical functions
2024-12-16 19:31:20 +02:00
jussisaurio
961e57df94
Fix returning rowid instead of PK when PK is not a rowid alias
2024-12-14 15:51:08 +02:00
Pekka Enberg
2b85d2a600
Merge 'Add implementation and tests for replace scalar function' from Alperen Keleş
...
Adds `replace` scalar function.
Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com >
Closes #446
2024-12-13 11:02:08 +02:00
JeanArhancet
8bf6572e9e
feat: support unary positive
2024-12-13 02:07:34 +01:00
alpaylan
5742c51c5c
improve error messages on replace function call
2024-12-12 14:14:04 -05:00
Alperen Keleş
841a4fe2f8
Merge branch 'tursodatabase:main' into main
2024-12-12 13:13:41 -05:00
Pekka Enberg
5796b418b9
Merge 'Add support for soundex() function' from flaneur
...
add [soundex](https://www.sqlite.org/lang_corefunc.html#soundex ) scalar
function.
it seems that sqlite did not enable `soundex()` function by default
unless build it with `SQLITE_SOUNDEX`, while the sqlite in the ci
workflow did not enable it. this pr skipped the test over `soundex()`
temporarily in the `scalar-function.test` file.
Closes #453
2024-12-12 18:10:46 +02:00
Pekka Enberg
91764b85e6
Merge 'Add bitwise vdbe ops' from Preston Thorpe
...
Love the project, been following your blog posts for quite a while now.
I asked on Discord prior to submitting this, just because I didn't see a
specific issue for this feature... but if this PR is out of scope for
contributors, feel free to close it as I just had a good time hacking on
it.
This PR adds support for `BitAnd`, `BitOr`, and `BitNot` operators in
the vdbe, as well as unary expressions applied to aggregate functions;
which was needed in order to have `BitNot` support the same tests that
the other operators had.
*Also added unary negation of function calls, because since unary ops
were added, I figured adding support for the other existing unary
operator might be in scope, but lmk if not.
Let me know if there is any more tests or documentation to add/improve.
Closes #445
2024-12-12 17:35:12 +02:00
Li Yazhou
03288e5170
add impl about scalar function soundex with test
2024-12-12 21:48:05 +08:00
Alex Miller
c4d4569dc9
Merge remote-tracking branch 'upstream/main' into expr-iif
2024-12-11 20:13:54 -08:00
alpaylan
da28ed51ca
add implementation and tests for replace scalar function
2024-12-11 16:23:13 -05:00
PThorpe92
16595f39f5
Add support for unary op negation of aggregates
2024-12-11 15:38:21 -05:00
PThorpe92
d5391dc716
Add vdbe bitwise operators: and, or, not
2024-12-11 11:06:22 -05:00
jussisaurio
eb9374aebf
Merge 'Add support for CASE expressions.' from Alex Miller
...
There's two forms of case:
CASE (WHEN [bool expr] THEN [value])+ (ELSE [value])? END
which checks a series of boolean conditions, and:
CASE expr (WHEN [expr] THEN [value})+ (ELSE [value])? END
Which checks a series of equality conditions.
This implements support for both. Note that the ELSE is optional, and
will be equivalent to `ELSE null` if not specified.
sqlite3 gives the implementation as:
```
sqlite> explain select case a WHEN a THEN b WHEN c THEN d ELSE 0 END from casetest;
addr opcode p1 p2 p3 p4 p5 comment
---- ------------- ---- ---- ---- ------------- -- -------------
0 Init 0 16 0 0 Start at 16
1 OpenRead 0 3 0 4 0 root=3 iDb=0; casetest
2 Rewind 0 15 0 0
3 Column 0 0 2 0 r[2]= cursor 0 column 0
4 Column 0 0 3 0 r[3]= cursor 0 column 0
5 Ne 3 8 2 BINARY-8 83 if r[2]!=r[3] goto 8
6 Column 0 1 1 0 r[1]= cursor 0 column 1
7 Goto 0 13 0 0
8 Column 0 2 3 0 r[3]= cursor 0 column 2
9 Ne 3 12 2 BINARY-8 83 if r[2]!=r[3] goto 12
10 Column 0 3 1 0 r[1]= cursor 0 column 3
11 Goto 0 13 0 0
12 Integer 0 1 0 0 r[1]=0
13 ResultRow 1 1 0 0 output=r[1]
14 Next 0 3 0 1
15 Halt 0 0 0 0
16 Transaction 0 0 2 0 1 usesStmtJournal=0
17 Goto 0 1 0 0
```
and after this patch, limbo gives:
```
addr opcode p1 p2 p3 p4 p5 comment
---- ----------------- ---- ---- ---- ------------- -- -------
0 Init 0 19 0 0 Start at 19
1 OpenReadAsync 0 4 0 0 table=casetest, root=4
2 OpenReadAwait 0 0 0 0
3 RewindAsync 0 0 0 0
4 RewindAwait 0 18 0 0 Rewind table casetest
5 Column 0 0 2 0 r[2]=casetest.a
6 Column 0 0 3 0 r[3]=casetest.a
7 Ne 2 3 10 0 if r[2]!=r[3] goto 10
8 Column 0 1 1 0 r[1]=casetest.b
9 Goto 0 15 0 0
10 Column 0 2 3 0 r[3]=casetest.c
11 Ne 2 3 14 0 if r[2]!=r[3] goto 14
12 Column 0 3 1 0 r[1]=casetest.d
13 Goto 0 15 0 0
14 Integer 0 1 0 0 r[1]=0
15 ResultRow 1 1 0 0 output=r[1]
16 NextAsync 0 0 0 0
17 NextAwait 0 5 0 0
18 Halt 0 0 0 0
19 Transaction 0 0 0 0
20 Goto 0 1 0 0
```
And then as there's nowhere to annotate this new support in COMPAT.md, I
added a corresponding heading for SELECT expressions and what is/isn't
supported.
Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com >
Closes #425
2024-12-11 17:05:41 +02:00
Pekka Enberg
04f196113a
Merge 'Add last_insert_rowid() function' from Krishna Vishal
...
- Changed `Cursor` trait to be able to get access to `root_page`
- SQLite only updates last_insert_rowid for non-schema inserts. So we
check if the `InsertAwait` is not for `root_page` before updating
rowid
In SQLite it looks like this:
```
sqlite> EXPLAIN SELECT last_insert_rowid();
addr opcode p1 p2 p3 p4 p5 comment
---- ------------- ---- ---- ---- ------------- -- -------------
0 Init 0 4 0 0
1 Function 0 0 1 last_insert_rowid(0) 0
2 ResultRow 1 1 0 0
3 Halt 0 0 0 0
4 Goto 0 1 0 0
```
In limbo it will look like this:
```
limbo> EXPLAIN SELECT last_insert_rowid();
addr opcode p1 p2 p3 p4 p5 comment
---- ----------------- ---- ---- ---- ------------- -- -------
0 Init 0 4 0 0 Start at 4
1 Function 0 2 1 last_insert_rowid 0 r[1]=func()
2 ResultRow 1 1 0 0 output=r[1]
3 Halt 0 0 0 0
4 Transaction 0 0 0 0
5 Goto 0 1 0 0
```
Closes #427
2024-12-11 10:44:34 +02:00
Alex Miller
88c862ce4d
Comments, resolve label better, make tests more fun
2024-12-10 19:59:54 -08:00
Alex Miller
e85df1c895
resolve labels to current offset. make test clearer.
2024-12-10 19:36:54 -08:00
Kacper Kołodziej
d4bff2c93e
add octet_length scalar function
2024-12-10 22:56:38 +01:00
krishvishal
134b5576ad
Ran cargo fmt
2024-12-09 22:55:54 +05:30
krishvishal
1e23af7d24
Added last_insert_rowid() function.
...
Need to fix its behavior. Problem is probably with `Cursor` implementation.
2024-12-09 17:41:28 +05:30
Alex Miller
f7bb7f8dee
Fix typo and improve comment
2024-12-08 14:20:23 -08:00
Alex Miller
c2e3957d73
I misunderstood what a constant instruction was
2024-12-08 14:12:45 -08:00
Alex Miller
eb00226cfe
Add support for CASE expressions.
...
There's two forms of case:
CASE (WHEN [bool expr] THEN [value])+ (ELSE [value])? END
which checks a series of boolean conditions, and:
CASE expr (WHEN [expr] THEN [value})+ (ELSE [value])? END
Which checks a series of equality conditions.
This implements support for both. Note that the ELSE is optional, and
will be equivalent to `ELSE null` if not specified.
sqlite3 gives the implementation as:
sqlite> explain select case a WHEN a THEN b WHEN c THEN d ELSE 0 END from casetest;
addr opcode p1 p2 p3 p4 p5 comment
---- ------------- ---- ---- ---- ------------- -- -------------
0 Init 0 16 0 0 Start at 16
1 OpenRead 0 3 0 4 0 root=3 iDb=0; casetest
2 Rewind 0 15 0 0
3 Column 0 0 2 0 r[2]= cursor 0 column 0
4 Column 0 0 3 0 r[3]= cursor 0 column 0
5 Ne 3 8 2 BINARY-8 83 if r[2]!=r[3] goto 8
6 Column 0 1 1 0 r[1]= cursor 0 column 1
7 Goto 0 13 0 0
8 Column 0 2 3 0 r[3]= cursor 0 column 2
9 Ne 3 12 2 BINARY-8 83 if r[2]!=r[3] goto 12
10 Column 0 3 1 0 r[1]= cursor 0 column 3
11 Goto 0 13 0 0
12 Integer 0 1 0 0 r[1]=0
13 ResultRow 1 1 0 0 output=r[1]
14 Next 0 3 0 1
15 Halt 0 0 0 0
16 Transaction 0 0 2 0 1 usesStmtJournal=0
17 Goto 0 1 0 0
and after this patch, limbo gives:
addr opcode p1 p2 p3 p4 p5 comment
---- ----------------- ---- ---- ---- ------------- -- -------
0 Init 0 18 0 0 Start at 18
1 OpenReadAsync 0 4 0 0 table=casetest, root=4
2 OpenReadAwait 0 0 0 0
3 RewindAsync 0 0 0 0
4 RewindAwait 0 17 0 0 Rewind table casetest
5 Column 0 0 2 0 r[2]=casetest.a
6 Column 0 0 3 0 r[3]=casetest.a
7 Ne 2 3 10 0 if r[2]!=r[3] goto 10
8 Column 0 1 1 0 r[1]=casetest.b
9 Goto 0 14 0 0
10 Column 0 2 3 0 r[3]=casetest.c
11 Ne 2 3 14 0 if r[2]!=r[3] goto 14
12 Column 0 3 1 0 r[1]=casetest.d
13 Goto 0 14 0 0
14 ResultRow 1 1 0 0 output=r[1]
15 NextAsync 0 0 0 0
16 NextAwait 0 5 0 0
17 Halt 0 0 0 0
18 Transaction 0 0 0 0
19 Integer 0 1 0 0 r[1]=0
20 Goto 0 1 0 0
And then as there's nowhere to annotate this new support in COMPAT.md, I
added a corresponding heading for SELECT expressions and what is/isn't
supported.
2024-12-08 14:09:03 -08:00
Alex Miller
27ef95e0ab
LLM recommended a better way to write args matching
2024-12-07 21:15:04 -08:00
Alex Miller
183ea8e362
Implement support for iif().
...
In sqlite, iif() looks like:
sqlite> create table iiftest(a int, b int, c int);
sqlite> explain select iif(a,b,c) from iiftest;
addr opcode p1 p2 p3 p4 p5 comment
---- ------------- ---- ---- ---- ------------- -- -------------
0 Init 0 11 0 0 Start at 11
1 OpenRead 0 2 0 3 0 root=2 iDb=0; iiftest
2 Rewind 0 10 0 0
3 Column 0 0 2 0 r[2]= cursor 0 column 0
4 IfNot 2 7 1 0
5 Column 0 1 1 0 r[1]= cursor 0 column 1
6 Goto 0 8 0 0
7 Column 0 2 1 0 r[1]= cursor 0 column 2
8 ResultRow 1 1 0 0 output=r[1]
9 Next 0 3 0 1
10 Halt 0 0 0 0
11 Transaction 0 0 1 0 1 usesStmtJournal=0
12 Goto 0 1 0 0
And with this change, in limbo it looks like:
addr opcode p1 p2 p3 p4 p5 comment
---- ----------------- ---- ---- ---- ------------- -- -------
0 Init 0 14 0 0 Start at 14
1 OpenReadAsync 0 2 0 0 table=iiftest, root=2
2 OpenReadAwait 0 0 0 0
3 RewindAsync 0 0 0 0
4 RewindAwait 0 13 0 0 Rewind table iiftest
5 Column 0 0 2 0 r[2]=iiftest.a
6 IfNot 2 9 1 0 if !r[2] goto 9
7 Column 0 1 1 0 r[1]=iiftest.b
8 Goto 0 10 0 0
9 Column 0 2 1 0 r[1]=iiftest.c
10 ResultRow 1 1 0 0 output=r[1]
11 NextAsync 0 0 0 0
12 NextAwait 0 5 0 0
13 Halt 0 0 0 0
14 Transaction 0 0 0 0
15 Goto 0 1 0 0
2024-12-07 21:04:03 -08:00
jussisaurio
3f80e41e7a
support HAVING
2024-11-30 10:05:13 +02:00
jussisaurio
885b6ecd76
Remove 'cursor_hint': it is never needed
2024-11-26 17:31:51 +02:00
jussisaurio
008be10cfd
Add TODO about expression equality comparisons
2024-11-26 17:31:51 +02:00
jussisaurio
9a557516b8
Fixes for expressions with aggregate arguments + limit 0
2024-11-26 17:31:51 +02:00
jussisaurio
cc902ed25d
GROUP BY and ORDER BY mostly work
2024-11-26 17:31:51 +02:00
jussisaurio
3f9e60633f
select refactor: order by and basic agg kinda work
2024-11-26 17:31:51 +02:00
jussisaurio
d0466e1cae
introduce Column member of ast::Expr and bind idents to columns
2024-11-26 17:31:51 +02:00
Lauri Virtanen
cafbf5499f
Support divide operator in expressions
2024-11-24 22:10:07 +02:00
jussisaurio
b86501f12e
Merge 'implement CAST(col as type)' from Jussi Saurio
...
Closes #398
Reviewed-by: Pere Diaz Bou <pere-altea@hotmail.com >
Closes #404
2024-11-18 20:53:58 +02:00
Pekka Enberg
5efc218e6e
Merge 'support subtract in translate_expr() (not in condition expressions yet)' from Jussi Saurio
...
closes #402
Closes #403
2024-11-18 09:28:23 +02:00
jussisaurio
62761d2b34
uppercase only once
2024-11-17 22:22:03 +02:00
jussisaurio
ddd0cc041c
implement CAST(col as type)
2024-11-17 22:12:22 +02:00