Commit Graph

1977 Commits

Author SHA1 Message Date
Pekka Enberg
e2efdf724e Merge 'Fix panics on invalid aggregate function arguments' from Krishna Vishal
This pull request fixes panics when there's an aggregate function call
with too few or too many arguments.

Closes #726
2025-01-19 08:51:55 +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
31856315fe Fix merge conflicts 2025-01-19 04:45:14 +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
Krishna Vishal
776aecbce0 1. All aggregate functions now validate their args and return Parse error for wrong number of args.
2. Unknown functions now return `no such function: unknown_function`
2025-01-19 03:00:18 +05:30
Krishna Vishal
ed5c8ddcf0 Remove unused import 2025-01-19 01:02:46 +05:30
Krishna Vishal
4c1f4d71d6 Refactor code 2025-01-19 01:02:41 +05:30
Krishna Vishal
bff3af6326 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 01:02:37 +05:30
Pekka Enberg
4a41736f89 Merge 'Implement IsNot operator' from Vrishabh
This PR adds support for IsNot Operator which was not working as shown
below.
```
❯ ./target/debug/limbo
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 1 is not 0;
thread 'main' panicked at core\translate\expr.rs:626:40:
not yet implemented: IsNot
stack backtrace:
```

Closes #731
2025-01-18 19:39:57 +02:00
psvri
b966351e1f Implement IsNot operator 2025-01-18 22:49:09 +05:30
Pekka Enberg
315d225a85 Merge 'Implement Is operator' from Vrishabh
This PR adds support for `Is` Operator which was not working as shown
below. I have also added compare.test for all compare operations on
which we can expand upon.
```
❯ .\target\debug\limbo.exe
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 1 is 2;
thread 'main' panicked at core\translate\expr.rs:613:40:
not yet implemented: Is
```

Closes #729
2025-01-18 19:05:39 +02:00
psvri
5a13f0790f Implement is operator 2025-01-18 15:57:26 +05:30
psvri
bfadd30f54 Add compare tests 2025-01-18 15:51:31 +05:30
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