Harin
ab3a15e489
Code refactor
2025-01-21 10:02:19 +05:30
Harin
da53cc3821
Added Concat Opcode
2025-01-21 00:29:23 +05:30
Pekka Enberg
c27427d644
Merge 'translate_condition_expr(): fix cases where 1. we jump on false and 2. either operand is NULL' from Jussi Saurio
...
Change explanation is in the code comment for `Insn::Eq`:
```
/// Jump if either of the operands is null. Used for "jump when false" logic.
/// Eg. "SELECT * FROM users WHERE id = NULL" becomes:
/// <JUMP TO NEXT ROW IF id != NULL>
/// Without the jump_if_null flag it would not jump because the logical comparison "id != NULL" is never true.
/// This flag indicates that if either is null we should still jump.
jump_if_null: bool,
```
Closes #754
Excerpt from SQLite bytecode documentation for e.g. `Lt`:
> If the SQLITE_JUMPIFNULL bit of P5 is set and either reg(P1) or
reg(P3) is NULL then the take the jump. If the SQLITE_JUMPIFNULL bit is
clear then fall through if either operand is NULL.
I didn't want to start putting these flags into a bitmask so I just
added a separate boolean. Probably for sqlite `EXPLAIN` compatibility we
should, IF we want to be exactly compatible (which we aren't anyway atm)
Closes #755
2025-01-20 19:40:08 +02:00
Jussi Saurio
2cd9118be6
Fix jump_if_true to be a bool literal in places where it was used as a register number
2025-01-20 17:13:34 +02:00
Jussi Saurio
f88a4d6ac6
Add jump_if_null to cmp insns to account for either operand being NULL
2025-01-20 16:54:39 +02:00
Krishna Vishal
04fd5a40d6
Finalize the parser in the case of Error while running queries. This resets the parser stack and prevents triggering the assertion and thereby panic.
...
Closes https://github.com/tursodatabase/limbo/issues/742
2025-01-20 16:10:35 +05:30
Pekka Enberg
9369f06699
Merge 'Initial support for wal_checkpoint pragma' from Sonny
...
Wire pragma wal_checkpoint to checkpoint infra
- add basic support for parsing and instruction emitting `pragma
wal_checkpoint;`
- checkpoint opcode for instruction
- checkpoint execution in `virtual machine`
- cli test
Part of #696 .
Before
```
limbo> pragma wal_checkpoint;
× Parse error: Not a valid pragma name
```
After
```
Enter ".help" for usage hints.
limbo> pragma wal_checkpoint;
0|0|0
```
```
Closes #694
2025-01-20 09:57:58 +02:00
Pekka Enberg
bda1e4e6ab
Merge 'Add support for json_object function' from Jorge Hermo
...
Relates to #127 . This PR is still in draft and I have a few left things
to do (tests, improve implementation), just opening it so anyone can
track this work meanwhile.
Closes #664
2025-01-20 09:36:56 +02:00
Pekka Enberg
a338a19130
Merge 'Make clippy happy' from Sonny
...
Closes #751
2025-01-20 09:18:19 +02:00
Pekka Enberg
c25d9a1824
Merge 'Implement Not' from Vrishabh
...
This PR adds support for Not operator and Opcode.
Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com >
Closes #748
2025-01-20 09:17:45 +02:00
sonhmai
75f0cf9e20
chore: make clippy happy
2025-01-20 13:29:23 +07:00
ben594
6c4ee1e905
Update changes on delete
...
Remove unwrap
2025-01-19 20:51:16 -05:00
ben594
28ce68091f
Modified changes and total_changes scalarfuncs to be more like sqlite
...
Fmt and clippy
Remove print
2025-01-19 20:51:13 -05:00
sonhmai
e45a807f0e
core: allocate 2 registers for checkpoint opcode execution
2025-01-20 08:34:13 +07:00
sonhmai
cb631dafdc
feat: wire checkpoint to bytecode execution
2025-01-20 08:34:13 +07:00
sonhmai
66d6291f32
add scaffolding for supporting wal checkpoint
2025-01-20 08:34:13 +07:00
psvri
e616bd5361
Implement Not
2025-01-20 00:21:23 +05:30
Pekka Enberg
f5e5428d45
Merge 'Syntactic improvements' from Jorge López Tello
...
This is a purely syntactic PR. It doesn't change behavior, just rewrites
some loops and removes unneeded parts, like lifetime annotations and
references. Mainly because the Clippy and IDE warnings get annoying.
Don't worry about the number of commits, I just separated based on type
of change.
Closes #732
2025-01-19 12:17:28 +02:00
Pekka Enberg
5851d6643a
Revert "core: Move re-exports at top of lib.rs"
...
This reverts commit c8a979eb4b . It
conflicts with a cleanup PR I am about to merge.
2025-01-19 12:17:06 +02:00
Pekka Enberg
c8a979eb4b
core: Move re-exports at top of lib.rs
...
Clean up the code a bit by moving re-exports at the top of lib.rs to
make them more visible to the reader.
2025-01-19 11:34:59 +02:00
Pekka Enberg
0561ff1545
Merge 'Fix scalar API in extensions, add documentation and error handling' from Preston Thorpe
...
Closes #728
Changes the API to one macro/annotation on the relevant function
```rust
#[scalar(name = "uuid4_str", alias = "gen_random_uuid")]
fn uuid4_str(_args: &[Value]) -> Value {
let uuid = uuid::Uuid::new_v4().to_string();
Value::from_text(uuid)
}
register_extension! {
scalars: { uuid4_str, uuid4 }
}
```
The only downside of this, is that for functions that use their
arguments, because this is not a trait, there is not really a way of
enforcing the function signature like there is with the other way.
Documentation has been added for this in the `scalar` macro, so
hopefully will not be an issue.
Also this PR cleans up the Aggregate API by changing the `args` and
`name` functions to constant associated types, as well as adds some
error handling and documentation.
```rust
impl AggFunc for Median {
type State = Vec<f64>;
const NAME: &'static str = "median";
const ARGS: i32 = 1;
fn step(state: &mut Self::State, args: &[Value]) {
if let Some(val) = args.first().and_then(Value::to_float) {
state.push(val);
}
}
//.. etc
```
Closes #735
2025-01-19 09:53:31 +02:00
Pekka Enberg
3e28541b53
Merge 'Fix null compare operations not giving null' from Vrishabh
...
In limbo when we do any compare operations like `Eq, gt, lt, gte, lte`
with nulls , we were actually giving the result as true where as sqlite3
gives null. This is because if we had a null, we were incorrectly going
to conditional branch and not increment program by 1. Also the sqlite
generates `ZeroOrNull` op in these cases
(https://github.com/sqlite/sqlite/blob/version-3.45.3/src/expr.c#L4644 )
but we were generating a Integer instruction. The below outputs can give
a clearer picture.
This PR aims to fix this.
sqlite3 output
```
SQLite version 3.48.0
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> select 8 = null;
sqlite> select 8 > null;
sqlite> explain select 8 > null;
addr opcode p1 p2 p3 p4 p5 comment
---- ------------- ---- ---- ---- ------------- -- -------------
0 Init 0 6 0 0
1 Integer 1 1 0 0
2 Gt 3 4 2 64
3 ZeroOrNull 2 1 3 0
4 ResultRow 1 1 0 0
5 Halt 0 0 0 0
6 Integer 8 2 0 0
7 Null 0 3 0 0
8 Goto 0 1 0 0
sqlite> explain select 8 = null;
addr opcode p1 p2 p3 p4 p5 comment
---- ------------- ---- ---- ---- ------------- -- -------------
0 Init 0 6 0 0
1 Integer 1 1 0 0
2 Eq 3 4 2 64
3 ZeroOrNull 2 1 3 0
4 ResultRow 1 1 0 0
5 Halt 0 0 0 0
6 Integer 8 2 0 0
7 Null 0 3 0 0
8 Goto 0 1 0 0
```
Limbo Output
```
Limbo v0.0.12
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database
limbo> select 8 = null;
1
limbo> select 8 > null;
1
limbo> explain select 8 > null;
addr opcode p1 p2 p3 p4 p5 comment
---- ----------------- ---- ---- ---- ------------- -- -------
0 Init 0 8 0 0 Start at 8
1 Integer 8 2 0 0 r[2]=8
2 Null 0 3 0 0 r[3]=NULL
3 Integer 1 1 0 0 r[1]=1
4 Gt 2 3 6 0 if r[2]>r[3] goto 6
5 Integer 0 1 0 0 r[1]=0
6 ResultRow 1 1 0 0 output=r[1]
7 Halt 0 0 0 0
8 Transaction 0 0 0 0
9 Goto 0 1 0 0
limbo> explain select 8 = null;
addr opcode p1 p2 p3 p4 p5 comment
---- ----------------- ---- ---- ---- ------------- -- -------
0 Init 0 8 0 0 Start at 8
1 Integer 8 2 0 0 r[2]=8
2 Null 0 3 0 0 r[3]=NULL
3 Integer 1 1 0 0 r[1]=1
4 Eq 2 3 6 0 if r[2]==r[3] goto 6
5 Integer 0 1 0 0 r[1]=0
6 ResultRow 1 1 0 0 output=r[1]
7 Halt 0 0 0 0
8 Transaction 0 0 0 0
9 Goto 0 1 0 0
limbo>
```
Limbo Output with this PR
```
Limbo v0.0.12
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database
limbo> select 8 = null;
limbo> select 8 > null;
limbo> explain select 8 > null;
addr opcode p1 p2 p3 p4 p5 comment
---- ----------------- ---- ---- ---- ------------- -- -------
0 Init 0 8 0 0 Start at 8
1 Integer 8 2 0 0 r[2]=8
2 Null 0 3 0 0 r[3]=NULL
3 Integer 1 1 0 0 r[1]=1
4 Gt 2 3 6 0 if r[2]>r[3] goto 6
5 ZeroOrNull 2 1 3 0 ((r[2]=NULL)|(r[3]=NULL)) ? r[1]=NULL : r[1]=0
6 ResultRow 1 1 0 0 output=r[1]
7 Halt 0 0 0 0
8 Transaction 0 0 0 0
9 Goto 0 1 0 0
limbo> explain select 8 = null;
addr opcode p1 p2 p3 p4 p5 comment
---- ----------------- ---- ---- ---- ------------- -- -------
0 Init 0 8 0 0 Start at 8
1 Integer 8 2 0 0 r[2]=8
2 Null 0 3 0 0 r[3]=NULL
3 Integer 1 1 0 0 r[1]=1
4 Eq 2 3 6 0 if r[2]==r[3] goto 6
5 ZeroOrNull 2 1 3 0 ((r[2]=NULL)|(r[3]=NULL)) ? r[1]=NULL : r[1]=0
6 ResultRow 1 1 0 0 output=r[1]
7 Halt 0 0 0 0
8 Transaction 0 0 0 0
9 Goto 0 1 0 0
```
Closes #733
2025-01-19 09:09:12 +02:00
Pekka Enberg
cdcc98540a
cargo fmt
2025-01-19 08:52:01 +02:00
Krishna Vishal
5cf78b7d54
chore: clippy remove unused imports
2025-01-19 07:18:31 +05:30
Krishna Vishal
acad562c07
Remove unnecessary Result
2025-01-19 06:50:00 +05:30
Krishna Vishal
870a2ea802
clean up
2025-01-19 06:40:40 +05:30
Krishna Vishal
fa0503f0ce
1. Changes to extension.py
...
2. chore: cargo fmt
2025-01-19 04:58:05 +05:30
Krishna Vishal
6173aeeb3b
1. Fix merge conflicts
...
2. change tests for extensions to return error instead of null (Preston)
2025-01-19 04:39:25 +05:30
Krishna Vishal
ca097b1972
Remove unused import
2025-01-19 04:35:21 +05:30
Krishna Vishal
027803aabf
Refactor code
2025-01-19 04:35:21 +05:30
Krishna Vishal
68553904c7
Converted the unconditional unwrap to a match which handles the case when the function is COUNT and args are None and replaces the args. Solves https://github.com/tursodatabase/limbo/issues/725
2025-01-19 04:35:21 +05:30
PThorpe92
956320b7d0
Fix scalar API in extensions, add some error handling
2025-01-18 15:19:35 -05:00
psvri
e16b3491c4
Fix null compares giving incorrect results
2025-01-19 00:44:38 +05:30
Jorge López
9b8baa7895
syntactic changes: adds default impl to Parameters based on new(), fixes Clippy warn https://rust-lang.github.io/rust-clippy/master/index.html#new_without_default
2025-01-18 19:21:50 +01:00
Jorge López
50852f36f8
syntactic changes: semantics, call is_empty instead of manually checking the size
2025-01-18 19:20:12 +01:00
Jorge López
3da813b260
syntactic changes: use if let .. else instead of checking for is_none() and calling unwrap()
2025-01-18 19:20:12 +01:00
Jorge López
9c1d890d59
syntactic changes: 2 typos I missed earlier
2025-01-18 19:20:11 +01:00
Jorge López
3da7d8cb79
syntactic changes: Markdown semantics
2025-01-18 19:20:11 +01:00
Jorge López
0d6e6a0aa4
syntactic changes: use Result::unwrap_or() instead of manual match
2025-01-18 19:20:11 +01:00
Jorge López
00c503dcf5
syntactic changes: lift return out of ifs
2025-01-18 19:20:11 +01:00
Jorge López
90a14a7bc7
syntactic changes: replace explicit while let Some in iterator with for..in loop (see https://rust-lang.github.io/rust-clippy/master/index.html#while_let_on_iterator )
2025-01-18 19:20:11 +01:00
Jorge López
bbe3cded38
syntactic changes: use f64::INFINITY instead of deprecated std::f64::INFINITY
2025-01-18 19:20:11 +01:00
Jorge López
cfff4dd21c
syntactic changes: fix typos in comments
2025-01-18 19:20:11 +01:00
Jorge López
e4ab2fb273
syntactic changes: rewrite loop with while
2025-01-18 19:19:49 +01:00
Jorge López
218a2e6dda
syntactic changes: remove unneeded mut, lifetimes,references that get instantaneously dereferenced and casts
2025-01-18 18:43:47 +01:00
Jorge López
2cc8cb9ad8
syntactic changes: use assert_eq!() instead of assert!() for equality comparisons
2025-01-18 18:37:50 +01:00
Jorge López
f160206cdd
syntactic changes: replace unwrap() with ? in functions that return Result<...>
2025-01-18 18:33:43 +01:00
Jorge López
86a4714711
syntactic changes: remove unneeded paths when the type is already imported
2025-01-18 18:29:12 +01:00
psvri
b966351e1f
Implement IsNot operator
2025-01-18 22:49:09 +05:30
psvri
5a13f0790f
Implement is operator
2025-01-18 15:57:26 +05:30