Commit Graph

10673 Commits

Author SHA1 Message Date
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
PThorpe92
bcd3ae2bd7 Add documentation to core/ext and relevant macros 2025-01-18 16:04:28 -05:00
alpaylan
e476b9f697 implement watch mode
- add `--watch` flag
- start saving seeds in persistent storage
- make a separate version of execution functions that use `vector of interaction` instead of `InteractionPlan`
2025-01-18 23:54:03 +03:00
PThorpe92
9c47379927 Fix deref null ptr in Debug impl on external types 2025-01-18 15:23:33 -05:00
PThorpe92
956320b7d0 Fix scalar API in extensions, add some error handling 2025-01-18 15:19:35 -05:00
Elijah Morgan
74ddc42df0 Add back integration tests
Fix package.json for better imports vs web/nodejs
Fix examples and integration tests
2025-01-18 15:01:16 -05:00
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
psvri
e16b3491c4 Fix null compares giving incorrect results 2025-01-19 00:44:38 +05:30
psvri
554244209d Add Null comparision tests 2025-01-19 00:39:10 +05:30
Jorge López
e5faa3273a syntactic changes: remove unused self dependency to appease to our Clippy overlord... 2025-01-18 19:36:32 +01:00
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
f7001b974a syntactic changes: weird issue with a previous commit. More unwrap() -> ? 2025-01-18 19:20:12 +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
683125fefb syntactic changes: factor duplicated code into helper function that can be reused 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
07970468bd syntactic changes: remove unneeded parentheses 2025-01-18 18:45:05 +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
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
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
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
Jorge Hermo
b79bc8f8b6 trigger CI 2025-01-18 09:39:22 +01: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