Commit Graph

104 Commits

Author SHA1 Message Date
Pekka Enberg
0abb917604 Limbo 0.0.13 2025-01-19 13:30:56 +02:00
Jussi Saurio
af039ffa6e Merge 'Initial support for aggregate functions in extensions' from Preston Thorpe
#708
This PR adds basic support for the following API for defining
Aggregates, and changes the existing API for scalars.
```rust
register_extension! {
    scalars: { Double },
    aggregates: { MedianState },
}

#[derive(ScalarDerive)]
struct Double;

impl Scalar for Double {
    fn name(&self) -> &'static str {
        "double"
    }
    fn call(&self, args: &[Value]) -> Value {
        if let Some(arg) = args.first() {
            match arg.value_type() {
                ValueType::Float => {
                    let val = arg.to_float().unwrap();
                    Value::from_float(val * 2.0)
                }
                ValueType::Integer => {
                    let val = arg.to_integer().unwrap();
                    Value::from_integer(val * 2)
                }
                _ => {
                    println!("arg: {:?}", arg);
                    Value::null()
                }
            }
        } else {
            Value::null()
        }
    }
}

#[derive(AggregateDerive)]
struct MedianState;

impl AggFunc for MedianState {
    type State = Vec<f64>;

    fn name(&self) -> &'static str {
        "median"
    }
    fn args(&self) -> i32 { 1 }

    fn step(state: &mut Self::State, args: &[Value]) {
        if let Some(val) = args.first().and_then(Value::to_float) {
            state.push(val);
        }
    }

    fn finalize(state: Self::State) -> Value {
        if state.is_empty() {
            return Value::null();
        }
        let mut sorted = state;
        sorted.sort_by(|a, b| a.partial_cmp(b).unwrap());
        let len = sorted.len();
        if len % 2 == 1 {
            Value::from_float(sorted[len / 2])
        } else {
            let mid1 = sorted[len / 2 - 1];
            let mid2 = sorted[len / 2];
            Value::from_float((mid1 + mid2) / 2.0)
        }
    }
}

```
I know it's a bit more verbose than the previous version, but I think in
the long run this will be more robust, and it matches the aggregate API
of implementing a trait on a struct that you derive the relevant trait
on.
Also this allows for better registration of functions, I think passing
in the struct identifiers just feels much better than the `"func_name"
=> function_ptr`

Closes #721
2025-01-18 11:07:06 +02:00
PThorpe92
fc82461eff Complete percentile extension, enable col+delimeter args 2025-01-17 21:15:09 -05:00
김선우
eaa8743c36 Nit 2025-01-18 09:16:09 +09:00
김선우
fcadc2f825 Add connect function for creating connections from limbo db 2025-01-18 09:09:36 +09:00
PThorpe92
5dfc3b8787 Create simple extension for testing aggregate functions, add tests 2025-01-17 14:30:12 -05:00
psvri
e43271f53b Implement regexp extension 2025-01-16 23:15:59 +05:30
Pekka Enberg
e8420a3cb7 Update Cargo.lock 2025-01-16 14:42:07 +02:00
Pekka Enberg
93903555aa Rename limbo_extension crate to limbo_ext 2025-01-16 14:40:52 +02:00
PThorpe92
343ccb3f72 Replace declare_scalar_functions in extension API with proc macro 2025-01-14 11:49:57 -05:00
PThorpe92
9c208dc866 Add tests for first extension 2025-01-14 07:27:35 -05:00
PThorpe92
c565fba195 Adjust types in extension API 2025-01-14 07:20:49 -05:00
PThorpe92
3412a3d4c2 Rough design for extension api/draft extension 2025-01-14 07:20:48 -05:00
PThorpe92
0a10d893d9 Sketch out runtime extension loading 2025-01-14 07:18:07 -05:00
Jorge López
a16282ea62 core: remove nix as a dependency 2025-01-14 11:06:13 +01:00
Pekka Enberg
b6ae8990e3 Limbo 0.0.12 2025-01-14 11:39:17 +02:00
Pekka Enberg
d223c72d03 Revert "core: Previous commits didn't actually remove nix as dependency, so do that here"
This reverts commit cca3846f95, we need to
bring it back unfortunately.
2025-01-14 10:25:11 +02:00
Pekka Enberg
945a91dee5 Merge 'core: Consolidate libc implementations' from Jorge López Tello
This shaves off `nix` as a dependency in core, which was only being used
in the io_uring backend for the `fcntl` advisory record locking. Since a
previous PR made `rustix` a dep not only for Mac but for any Unix, and
`rustix` also has `fcntl`, `nix` becomes redundant.
Furthermore, it reduces `libc` usage across core. The only remaining
uses are:
```rust
io_uring::opcode::Readv::new(fd, iovec as *const iovec as *const libc::iovec, 1)
io_uring::opcode::Writev::new(fd, iovec as *const iovec as *const libc::iovec, 1)
```
These two are a little ugly, but sadly the `io_uring` crate requires
both opcodes to take a `libc::iovec` while it doesn't export the type.
See tokio-rs/io-uring#259 for a request to use `std::io::IoSlice` or to
export the type directly.
Apart from those two, there are no other usages of libc, so if those are
resolved, we could also drop the dependency on libc.

Closes #668
2025-01-14 10:07:20 +02:00
Pekka Enberg
af020c27d6 Initial take on Rust bindings
This implements libSQL compatible Rust API on top of Limbo's core. The
purpose of this is to allow libraries and apps that build on libSQL to
use Limbo.
2025-01-14 09:16:46 +02:00
Jorge López
cca3846f95 core: Previous commits didn't actually remove nix as dependency, so do that here 2025-01-13 21:15:36 +01: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
Samyak S Sarnayak
c09a0bcbf3 Nicer parse errors using miette
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 CLI.

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.

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)
```

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
   ╰────

```
2025-01-05 17:56:59 +05:30
김선우
370e1ca5c2 Add support Java bindings
This add support for Java bindings in the bindings/java directory.
2025-01-05 10:28:05 +02:00
psvri
1f21cf6a71 Feat: Import csv support 2025-01-03 15:20:22 +05:30
Elijah Morgan
058ca89561 feat add basic opfs support and tests 2025-01-01 10:31:26 -05:00
Pekka Enberg
c4b0eb398c Limbo 0.0.11 2024-12-31 10:43:24 +02:00
Jussi Saurio
8c9bd0deb9 chore: commit cargo lock changes from #553 2024-12-29 08:58:26 +02:00
Pekka Enberg
37e1f35df8 Fix Cargo.toml in macros crate 2024-12-25 11:54:16 +02:00
Pekka Enberg
ffd1c725ee Merge 'Simulator improvements' from Alperen Keleş
This PR makes two small incremental updates:
1- It adds a Clap CLI for simulator configuration, using the same Clap
version as the Limbo cli crate
2- It creates a new submodule called `simulator`, moving simulator
related structs from the large main file into their own files.
I am open to suggestions on the submodule name instead of `simulator` as
it's kind of weird to have `simulator/simulator` in the file tree.

Closes #540
2024-12-25 09:41:17 +02:00
alpaylan
9f08b621ec add clap CLI for configuring the simulator 2024-12-22 17:06:46 -05:00
PThorpe92
fcab0ae299 Add uuid support for v4 and v7 2024-12-21 09:13:46 -05:00
vignesh-j-shetty
a43a1d204c renamed macro crate 2024-12-21 13:19:04 +05:30
vignesh-j-shetty
1e72fee343 Implemented proc_macro_derive extract description from rust docs and generate get_description function 2024-12-21 12:23:04 +05:30
Diego Reis
3a0e56bca5 Implement basic sqlite3_get_table() API 2024-12-19 23:13:51 -03:00
Pekka Enberg
69e3dd28f7 Limbo 0.0.10 2024-12-18 20:45:55 +02:00
Pekka Enberg
636b78d4ff Merge 'Minimal cargo-c support' from Luca Barbato
Fixes #437

Closes #458
2024-12-15 09:30:12 +02:00
Luca Barbato
eacbba2c07 Minimal cargo-c support 2024-12-14 15:19:50 +01:00
Pere Diaz Bou
1a663a6ed7 cargo stuff rm 2024-12-13 13:09:13 +01:00
Pekka Enberg
3023d228c7 Limbo 0.0.9 2024-12-12 18:49:05 +02:00
Pekka Enberg
617f95c7b6 Update clap to 4.5
The Github dependabot complains about anstream, which comes through `clap`:

https://github.com/tursodatabase/limbo/security/dependabot/8
2024-12-11 14:39:27 +02:00
Pekka Enberg
ab07c77036 Upgrade pprof to 0.14
Github's dependabot complains that the current version has an unsoudness
issue so let's bump to a newer version:

https://github.com/tursodatabase/limbo/security/dependabot/10
2024-12-11 11:21:09 +02:00
Pekka Enberg
e1b2d043be Limbo 0.0.8 2024-11-20 19:16:11 +02:00
Pekka Enberg
81b68b7047 Limbo 0.0.7 2024-11-20 18:15:36 +02:00
Pekka Enberg
fc07445e0a Merge 'sim: improve simulator' from Pere Diaz Bou
Newly improved simulator with CREATE TABLE, INSERT, SELECT, connection
management, etc...
This new simulator is finding a bunch of bugs with write path so after
this PR I will start fixing those.

Closes #405
2024-11-20 08:59:13 +02:00
Pekka Enberg
0fb1e59c9a Limbo 0.0.6 2024-11-18 19:16:15 +02:00
Pekka Enberg
a83e62f6f4 Limbo 0.0.5 2024-11-18 14:57:00 +02:00
Pere Diaz Bou
44e22c50cf sim: improve simulator 2024-11-18 13:40:37 +01:00
jussisaurio
3cc9d9d79f vendor sqlite3-parser (lemon-rs) 2024-11-16 20:08:59 +02:00
Pekka Enberg
9473668196 core: Bump jsonb dependency
The `fast-float` library has soundness issues, which why `jsonb`
switched to `fast-float2`:

https://github.com/databendlabs/jsonb/issues/68
2024-11-16 18:58:13 +02:00
Pekka Enberg
17c7e8d346 sqlite3: Disable env_logger default features
Let's keep the dependencies as light-weight as possible.
2024-11-16 09:47:12 +02:00