Commit Graph

1735 Commits

Author SHA1 Message Date
Kacper Madej
7efa87ff31 Merge branch 'main' into right-arrow-json 2025-01-10 19:25:56 +07:00
Pekka Enberg
3bc86a3cfc Merge 'Add CI for java testing' from Kim Seon Woo
## Purpose of the PR
- Add CI for java testing
## Reference
https://github.com/tursodatabase/limbo/issues/615

Closes #643
2025-01-10 13:05:05 +02:00
김선우
071d9513ab Add CI for java testing 2025-01-10 19:13:52 +09:00
Pekka Enberg
d31ccf2933 Merge 'core/optimizer: do expression rewriting on all expressions' from Jussi Saurio
Fixes #640 , unblocks some tests in #636

Closes #641
2025-01-10 11:23:51 +02:00
Pekka Enberg
93e4b8d917 Merge 'bindings/java: Enhance exception handling logic' from Kim Seon Woo
### Purpose of this PR
- Enhance exception handling logic
  - When exceptions has to be thrown from Rust to Java, let's just
return the error message directly.
  - Removes JNI call to get error message using
`Java_org_github_tursodatabase_core_LimboDB_getErrorMessageUtf8`
- Add `throwJavaException` to assure that the exception throwing logic
works corretly

Closes #642
2025-01-10 11:22:08 +02:00
김선우
90258a44b4 Add throwJavaException 2025-01-10 17:47:27 +09:00
Jussi Saurio
1bcdf99eab core/optimizer: do expression rewriting on all expressions 2025-01-10 10:04:07 +02:00
Kacper Madej
1a46988a73 Fix hardcoded numbers in macros 2025-01-10 14:50:38 +07:00
Kacper Madej
1a85601261 Update docs 2025-01-10 13:41:47 +07:00
Kacper Madej
a2e1ef2439 Use newest SQLite on Github Actions 2025-01-10 13:31:38 +07:00
김선우
3e26e7ebc5 Remove newSQLException and add throwLimboException in the LimboDB.java 2025-01-10 14:58:35 +09:00
Kacper Madej
536fbe9d9e Fix imports 2025-01-10 12:24:08 +07:00
Kacper Madej
91d4ac3ac0 Fix expression chaining 2025-01-10 12:14:57 +07:00
Kacper Madej
0f4e5ad26d Implement simplified json path 2025-01-10 11:50:43 +07:00
Kacper Madej
743a8b2d94 Merge branch 'main' into right-arrow-json 2025-01-10 11:28:13 +07:00
Pekka Enberg
5c38cc88a9 Merge 'Implement open function in Java bindings' from Kim Seon Woo
## Purpose of this PR
- Implement open function
- Add basic structure for the following
  - exception handling
  - testing using gradle
## Changes
- Java
  - Remove unnecessary example code(Connection.java, Cursor.java,
Limbo.java)
  - Implement `open`
  - Add exception handling logic
  - Add junit test
- Rust
  - Add limbo_db.rs which implements native functions defined in
`Limbo.java`
  - Remove unnecessary example code in lib.rs
## TODOS
- Implement core features for AbstractDB.java and LimboDB.java (I'm
currently referencing sqlite-java, but there are some minor differences
as we use rust instead of C)
## Reference
- https://github.com/tursodatabase/limbo/issues/615

Closes #632
2025-01-09 18:05:42 +02:00
Pekka Enberg
317acb842b Merge 'Implement json_type' from Kacper Madej
Closes #631
2025-01-09 14:25:32 +02:00
Pekka Enberg
2bf7e31b64 Merge 'distinguish balance and balance_non_root' from Pere Diaz Bou
`balance_non_root` should be as close as possible to `balance_non_root`
in SQLite. This commits extract `balance_non_root` from `balance` and
renames `balance_leaf` to `balance` as it enables future work on a
complete `balance_non_root` procedure.

Closes #634
2025-01-09 14:24:46 +02:00
Kacper Madej
f4e331231b More tests 2025-01-09 17:22:19 +07:00
Kacper Madej
74e19e2148 Optimization 2025-01-09 17:16:58 +07:00
Jussi Saurio
10fd8bb234 Merge 'Support nested parenthesized conditional expressions in translator' from Preston Thorpe
This PR fixes queries like:
```sql
    SELECT count(*) FROM users WHERE ((age > 25 OR age < 18) AND (city = 'Boston' OR state = 'MA'));
```
Previously we would return `7516` rows instead of `146`, due to
disregarding the final `AND` from within the nested `OR` conditions,
unconditionally short circuiting when a TRUE is found in an OR
expression without any surrounding relevant context.
or:
```sql
    SELECT * FROM users WHERE (((age > 18 AND city = 'New Mario') OR age = 92) AND city = 'Lake Paul');
```
Previously we would incorrectly return the top row:
```
9984|Leah|Russell|..|..|6733 Weber Crossing|New Mario|SC|57707|78
9989|Timothy|Harrison|..|..|782 Wright Harbors|Lake Paul|ID|52330|92
```
Added localized jump targets for OR expressions within AND blocks to
prevent premature short-circuiting and `parent operator` to condition
metadata to trigger them.
If parent operator should instead be another function param on
`translate_conditional_expr`, instead of a field in condition_metadata,
let me know and I can change it.
EDIT: sorry I realize I should have included the other cleanup changes
in a different PR. I will fix this after work

Reviewed-by: Jussi Saurio <kacperoza@gmail.com>

Closes #633
2025-01-09 11:58:45 +02:00
Kacper Madej
dd533414ef Implement -> and ->> operators for json 2025-01-09 15:38:32 +07:00
Kacper Madej
eebf9bfaac Implement json_type 2025-01-09 11:29:17 +07:00
PThorpe92
97d0fc68b2 Add macro and helper to clean up expression translations 2025-01-08 19:29:56 -05:00
PThorpe92
183797898b Add tests for nested conditional expressions 2025-01-08 17:19:37 -05:00
PThorpe92
fa0e7d5729 Support nested parenthesized conditional exprs in translator 2025-01-08 17:16:17 -05:00
Pere Diaz Bou
6802bb7e6a distinguish balance and balance_non_root
`balance_non_root` should be as close as possible to `balance_non_root`
in SQLite. This commits extract `balance_non_root` from `balance` and
renames `balance_leaf` to `balance` as it enables future work on a
complete `balance_non_root` procedure.
2025-01-08 19:05:49 +01:00
김선우
b3762b3e92 Fix clippy 2025-01-08 23:01:24 +09:00
김선우
9e0e3dc81a Update rust side logic to open database 2025-01-08 22:51:33 +09:00
김선우
29e434754b Enhance LimboDB.java open logic 2025-01-08 22:50:48 +09:00
김선우
281ba8d552 Remove unused java files 2025-01-08 19:41:31 +09:00
Pekka Enberg
0ef4def900 Merge 'Optimizer bugfixes' from Jussi Saurio
Closes #629
- Fix bug with column being considered rowid alias based on
'primary_key' (non INTEGER pks are not rowid aliases)
- fix logic bug in check_index_scan() that swapped lhs/rhs but not the
comparison op
- Rename eliminate_between to rewrite_exprs and add true/false->1/0 case
there

Closes #630
2025-01-08 09:59:49 +02:00
Jussi Saurio
b062a5f528 Fix bug with column being considered rowid alias based on 'primary_key' 2025-01-08 08:20:13 +02:00
Jussi Saurio
925bd62cbc fix logic bug in check_index_scan() that swapped lhs/rhs but not the comparison op 2025-01-08 08:20:13 +02:00
Jussi Saurio
4a58898863 Rename eliminate_between to rewrite_exprs and add true/false->1/0 case there 2025-01-08 08:20:13 +02:00
Pekka Enberg
bc1fd20892 Merge 'Fix precision issue in datetime tests' from Preston Thorpe
This PR fixes the issue with tests running on slow systems such as
github actions, where a couple `datetime` tests would be off by very
small margins and fail (e.g. #626)
![image](https://github.com/user-
attachments/assets/57d5a7bf-5acc-41f6-839b-034cab771dce)

Closes #627
2025-01-07 20:36:35 +02:00
Pekka Enberg
3a853ada57 Merge 'Rename IO backends to support Linux platforms without io_uring' from Jorge López Tello
As was suggested in #502 I have renamed the IO backends from `darwin` to
`unix` and from `linux` to `io_uring`. The `unix` backend is now
available to Linux platforms without io_uring.

On the topic of letting platforms disable io_uring support, the primary
example is Google, which posted this
[blog](https://security.googleblog.com/2023/06/learnings-from-kctf-
vrps-42-linux.html) in 2023 about disabling io_uring by default in most
of their servers/platforms, including Android (prime candidate user for
a SQLite rewrite).

Closes #628
2025-01-07 20:33:36 +02:00
PThorpe92
345107ce21 Fix precision issue in datetime tests 2025-01-07 09:57:19 -05:00
Jorge López
511c0b495d Rename LinuxIOError to UringIOError to match the IO backend renames 2025-01-07 15:19:31 +01:00
Jorge López
e5a12bdf01 Rename linux backend to io_uring and darwin to unix. Add new feature flag to IO backend selection 2025-01-07 15:19:29 +01:00
Jorge López
737533e35f Prepare Cargo.toml for upcoming rewrite from macos->unix and linux->io_uring. Make io_uring an optional dependency that is only enabled with a new default feature io-uring. 2025-01-07 15:17:24 +01:00
Pekka Enberg
fbb5ddd8f1 Merge 'Simplify working with labels' from Jussi Saurio
TLDR: no need to call either of:
---
program.emit_insn_with_label_dependency() -> just call
program.emit_insn()
program.defer_label_resolution() -> just call program.resolve_label()
---
Changes:
- make BranchOffset an explicit enum (Label, Offset, Placeholder)
- remove program.emit_insn_with_label_dependency() - label dependency is
automatically detected
- for label to offset mapping, use a hashmap from label(negative i32) to
offset (positive u32)
- resolve all labels in program.build()
- remove program.defer_label_resolution() - all labels are resolved in
build()

Closes #625
2025-01-07 13:11:19 +02:00
Jussi Saurio
731ff1480f Simplify working with labels
TLDR: no need to call either of:

program.emit_insn_with_label_dependency() -> just call program.emit_insn()
program.defer_label_resolution() -> just call program.resolve_label()

Changes:

- make BranchOffset an explicit enum (Label, Offset, Placeholder)
- remove program.emit_insn_with_label_dependency() - label dependency is automatically detected
- for label to offset mapping, use a hashmap from label(negative i32) to offset (positive u32)
- resolve all labels in program.build()
- remove program.defer_label_resolution() - all labels are resolved in build()
2025-01-07 12:53:10 +02:00
Pekka Enberg
a369329988 Merge 'Add OPFS support to Wasm bindings' from Elijah Morgan
Lots of cleanup still left to do. Draft PR for adding support for OPFS
for WASM build (add support for limbo in browser).
Overall explanation of the architecture: this follows the sqlite wasm
architecture for OPFS.
main <> (limbo-worker.js) limbo (VFS - opfs.js) <> opfs-sync-proxy
The main thread loads limbo-worker.js which bootstraps the opfs.js and
opfs-sync-proxy.js and then launches the limbo-wasm.js.
At that point it can be used with worker.postmessage and
worker.onmessage interactions from the main thread.
The VFS provided by opfs.js provides a sync API by offloading async
operations to opfs-sync-proxy.js. This is done through SharedArrayBuffer
and Atomic.wait() to make the actual async operations appear synchronous
for limbo.
resolves #531

Closes #594
2025-01-07 10:36:18 +02:00
Elijah Morgan
c8232b019a commonize test code 2025-01-06 20:57:02 -05:00
Elijah Morgan
b9c94ba53c have tests run on different ports
cleanup tests cruft from trying to fix that issue
2025-01-06 20:42:37 -05:00
Elijah Morgan
ad9d372e9c cleanup
remove happy-dom
try to fix some issues with tests
add wasm-pack as devDependency
update versions
2025-01-06 19:22:20 -05:00
Pekka Enberg
3bfc4ce820 sqlite3-parser: Use trace-level logging for syntax errors
Spamming the error logs for syntax errors is not nice for a library...
2025-01-05 21:12:01 +02:00
Pekka Enberg
2cd3c47691 Merge 'Nicer parse errors using miette' from Samyak Sarnayak
I noticed that the parse errors were a bit hard to read - only the
nearest token and the line/col offsets were printed.
I made a first attempt at improving the errors using
[miette](https://github.com/zkat/miette).
- Added derive for `miette::Diagnostic` to both the parser's error type
and LimboError.
- Added miette dependency to both sqlite3_parser and core. The `fancy`
feature is only enabled for the CLI. So the overhead on the libraries
(core, parser) should be minimal.
Some future improvements that can be made further:
- Add spans to AST nodes so that errors can better point to the correct
token. See upstream issue: https://github.com/gwenn/lemon-rs/issues/33
- Construct more errors with offset information. I noticed that most
parser errors are constructed with `None` as the offset.
- The messages are a bit redundant (example "syntax error at (1, 6)").
This can improved.
Comparisons.
Before:
```
❯ cargo run --package limbo --bin limbo database.db --output-mode pretty
...
limbo> selet * from a;
[2025-01-05T11:22:55Z ERROR sqlite3Parser] near "Token([115, 101, 108, 101, 116])": syntax error
Parse error: near "selet": syntax error at (1, 6)
```
<img width="969" alt="image" src="https://github.com/user-
attachments/assets/82651a77-f5ac-4eee-b208-88c6ea7fc9b7" />
After:
```
❯ cargo run --package limbo --bin limbo database.db --output-mode pretty
...
limbo> selet * from a;
[2025-01-05T12:25:52Z ERROR sqlite3Parser] near "Token([115, 101, 108, 101, 116])": syntax error

  × near "selet": syntax error at (1, 6)
   ╭────
 1 │ selet * from a
   ·     ▲
   ·     ╰── syntax error
   ╰────

```
<img width="980" alt="image" src="https://github.com/user-
attachments/assets/747a90e5-5085-41f9-b0fe-25864179ca35" />

Closes #618
2025-01-05 21:09:52 +02:00
Pekka Enberg
ec9031dcf8 Improve JavaScript benchmarks 2025-01-05 20:43:55 +02:00