Commit Graph

1962 Commits

Author SHA1 Message Date
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
Jussi Saurio
a48c9033e2 Merge pull request #724 from PThorpe92/extdocs
Add documentation for extensions/core
2025-01-18 11:08:35 +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
Pekka Enberg
7f372d5498 Merge 'bindings/java: Implement minimal execute method ' from Kim Seon Woo
## Purpose of this PR
- Minimal implementation of `execute`
## Changes
### Java side
- Implement `execute`
- Along the way, rename classes and methods which have the same meanings
  - `fileName` -> `filePath`
  - unify file names for rust code to java code e.g.
`limbo_connection.rs` will match `LimboConnection.java`
### Rust side
- Replace `pointer to struct` and `struct to pointer` functions close
together
- Rename rust files to match java files
## Note
- Implementation differs from that of `sqlite-java`. It's because we can
easily add JNI code and thereby implementing bindings is less restriced.
## References
https://github.com/tursodatabase/limbo/issues/615

Closes #723
2025-01-18 09:05:37 +02:00
Pekka Enberg
51e90ba5dd Merge 'Fix SQL comment handling Limbo shell' from Clyde
This PR improves comment handling in Limbo to precisely match SQLite's
behavior:
Fixes some edge cases involving #711
Inline comments mess up queries --
![image](https://github.com/user-
attachments/assets/10a90c39-a9b7-49e4-a018-1489914a5b64)
Query in the left terminal is current limbo state, upper right is limbo
in the state of this PR
and lower right is sqlite behavior.
![image](https://github.com/user-
attachments/assets/2f1b369a-0495-415e-a091-5b6972488f50)
Added support for inline comments using "--" syntax
Comments are now properly stripped before query execution
Maintains correct query execution when comments appear mid-query
Preserves multiline query functionality with comments
Ensures consistent behavior between pasted and typed queries
Testing:
Added test cases for single-line comments
Added test cases for inline comments
Added test cases for multiline queries with comments
Verified behavior matches SQLite CLI
![image](https://github.com/user-
attachments/assets/225772e9-03c4-472d-8a17-0f46e35c34ba)

Reviewed-by: Preston Thorpe (@PThorpe92)

Closes #722
2025-01-18 08:45:57 +02:00
PThorpe92
b57308003e Handle freeing memory in finalize, remove unused free fn 2025-01-17 21:54:25 -05:00
PThorpe92
fc82461eff Complete percentile extension, enable col+delimeter args 2025-01-17 21:15:09 -05:00
PThorpe92
dc16ed1ef6 Add documentation for extensions/core 2025-01-17 20:43:10 -05:00
김선우
ab23e20732 Revert java image. Disable some failing test for now. 2025-01-18 09:52:42 +09:00
김선우
6542fefd83 Change java image 2025-01-18 09:49:02 +09:00
김선우
aa88dd5d1a Print out yest results while build 2025-01-18 09:42:48 +09:00
김선우
eaa8743c36 Nit 2025-01-18 09:16:09 +09:00
김선우
39245f35cc Add TODOs 2025-01-18 09:09:36 +09:00
김선우
5b9a158db1 Remove unused methods 2025-01-18 09:09:36 +09:00
김선우
a3a31e787c Initial pass on step function 2025-01-18 09:09:36 +09:00
김선우
5fc5f650cd Extract set_err_msg_and_throw_exception to utils.rs 2025-01-18 09:09:36 +09:00
김선우
7028d963ba Remove unused methods for now 2025-01-18 09:09:36 +09:00
김선우
f6ec2252cf Group "pointer to struct" and "struct to pointer" functions 2025-01-18 09:09:36 +09:00
김선우
9765eaba52 Implement prepare 2025-01-18 09:09:36 +09:00
김선우
b77bf879f7 Implement prepare on java side 2025-01-18 09:09:36 +09:00
김선우
3e2e998060 Rename fileName to filePath for clarity 2025-01-18 09:09:36 +09:00
김선우
0819963b2f Implement rust side connect and prepare function 2025-01-18 09:09:36 +09:00
김선우
7e78ec448b Clean up error code related classes 2025-01-18 09:09:36 +09:00
김선우
fcadc2f825 Add connect function for creating connections from limbo db 2025-01-18 09:09:36 +09:00
김선우
3409a82513 Add LimboDBFactory to support multiple LimboDB in single process 2025-01-18 09:09:36 +09:00
김선우
0a071d26f7 Add logback dependency for logging 2025-01-18 09:09:36 +09:00
김선우
a6f389125c Implement minimal JDBC4Statement#exec(String sql) 2025-01-18 09:09:36 +09:00
김선우
8a1ffbbb65 Add JDBC4ResultSet 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
PThorpe92
44374b9e69 Clean up scalar trait remove unnecessary args method 2025-01-17 14:13:57 -05:00
PThorpe92
a1b1c01e9a Alter existing extensions to match new API 2025-01-17 14:13:57 -05:00
PThorpe92
0c737d88f7 Support aggregate functions in Extensions 2025-01-17 14:13:57 -05:00
PThorpe92
9b7b794e07 Begin sketching out aggregates api 2025-01-17 14:13:42 -05:00
CK-7vn
57274fa40b Correct CLI comment handling to mimic sqlite behavior 2025-01-17 13:59:34 -05:00
Pekka Enberg
20837d217b Update COMPAT.md 2025-01-17 19:50:43 +02:00
Pekka Enberg
02d410eb79 Merge 'Add regexp extension' from Vrishabh
Implements some of the regexp functions as an extension from
[sqlean](https://github.com/nalgeon/sqlean/blob/main/docs/regexp.md)

Reviewed-by: Preston Thorpe (@PThorpe92)

Closes #717
2025-01-17 19:49:22 +02:00
Pekka Enberg
67b4b24580 Merge 'Reduce liblimbo_sqlite3.a size' from Pekka Enberg
This reduces `liblimbo_sqlite3.a` size from 37M to 15M.
Refs #714

Closes #715
2025-01-17 13:42:23 +02:00
Pekka Enberg
21c5fe2909 cargo: Switch to "line-tables-only" debug symbols
...reduces size of `liblimbo_sqlite3.a` to 15 MB.

Suggested by @psvri
2025-01-17 11:52:17 +02:00
Pekka Enberg
4943217045 cargo: Disable LTO..
..to reduce `liblimbo_sqlite3.a` size from 37M to 20M. As it turns out,
LLVM emits its bitcode into static libraries when LTO is enabled to be
"more aggressive" in optimizations

Refs #714
2025-01-17 11:52:17 +02:00
Pekka Enberg
b2cbc3e0eb Merge 'github: Switch to upload-artifact v4' from Pekka Enberg
The current version is getting deprecated:
https://github.blog/news-insights/product-news/get-started-with-v4-of-
github-actions-artifacts/

Closes #716
2025-01-17 11:52:00 +02:00
Pekka Enberg
f550ee5f11 github: Switch to upload-artifact v4
The current version is getting deprecated:

https://github.blog/news-insights/product-news/get-started-with-v4-of-github-actions-artifacts/
2025-01-17 11:44:34 +02:00
Pekka Enberg
718ba17c0a Merge 'Fix cli comments parsing' from Diego Reis
#711
I followed the patterns that sqlite has, so everything after `--` is
treated as a comment. A bunch of spaces and a `--` is treated as a
comment also.

Closes #718
2025-01-17 07:40:29 +02:00
Diego Reis
285eeccb84 Fix cli comments parsing 2025-01-16 20:20:36 -03:00
psvri
e43271f53b Implement regexp extension 2025-01-16 23:15:59 +05:30
psvri
3e9f3ae652 Fix all args not being passed to external functions 2025-01-16 23:15:01 +05:30
Pekka Enberg
20ea8fb941 Make Clippy happy 2025-01-16 15:57:08 +02:00
Pekka Enberg
41b8228744 Merge 'Enable all features and targets in clippy for CI' from Jorge Hermo
I think we should run clippy in CI with all the features and targets
enabled.
This would help to get more clippy coverage as with the current CI
command, some code paths were not covered by clippy. For example, `test`
modules were not covered by it as we need at least the `--tests` flag
(or `--all-targets`)

Reviewed-by: Pere Diaz Bou <pere-altea@homail.com>

Closes #707
2025-01-16 15:10:11 +02:00