Commit Graph

2300 Commits

Author SHA1 Message Date
pedrocarlo
a4251e0448 add dynamic linking in extensions/time/Cargo.toml 2025-02-01 20:14:23 -03:00
pedrocarlo
26f24f93ad cargo clippy 2025-02-01 16:28:40 -03:00
pedrocarlo
9acba9c140 added tests 2025-02-01 16:13:37 -03:00
pedrocarlo
7b801f38de cleanup up error messages 2025-01-31 23:37:26 -03:00
pedrocarlo
309591044b Merge branch 'main' into feature/time-ext 2025-01-31 22:54:14 -03:00
pedrocarlo
e1733ca31e all functions implemented 2025-01-31 22:44:00 -03:00
pedrocarlo
65b43614e3 checkpoint: implemented function up to time_trunc 2025-01-31 21:18:06 -03:00
Pekka Enberg
98579ab2e4 Merge 'Implement Noop bytecode' from Pedro Muniz
This PR implements Noop. I really don't know what else to say. This
bytecode according to sqlite does: _Do nothing. Continue downward to the
next opcode._ I advanced the program counter to account for continuing
to the next instruction.

Closes #795
2025-01-31 18:49:54 +02:00
Pekka Enberg
44e5402464 Merge branch 'main' into feature/noop 2025-01-31 18:49:39 +02:00
Pekka Enberg
d8a9c57d3a Merge 'Fix table with single column PRIMARY KEY to not create extra btree' from Krishna Vishal
The error is due to comparing the PRIMARY KEY's name to INTEGER when in
it was all in lowercase. This was causing `needs_auto_index` to be set
to `true`.
After the fix:
```
/limbo /tmp/sc2-limbo.db
Limbo v0.0.13
Enter ".help" for usage hints.
limbo> CREATE TABLE temp (t1 integer, primary key (t1));

hexdump -s 28 -n 4 /tmp/sc2-limbo.db
000001c 0000 0200 -- matches SQLite
0000020
```
Closes https://github.com/tursodatabase/limbo/issues/824

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

Closes #830
2025-01-31 18:33:28 +02:00
Pekka Enberg
c05b81fdbd Merge 'Pragma list' from Glauber Costa
Closes #841
2025-01-31 18:32:21 +02:00
Glauber Costa
a7cc367c1f implement pragma pragma_list
List all available pragmas (Except pragma_list)
2025-01-31 06:44:56 -05:00
Glauber Costa
62efbde661 use strum package to simplify PragmaName enum management
The pragma list will only grow. The strum crate can be used to:
* automatically convert to string from enum
* automatically convert to enum from string
* implement an iterator over all elements of the enum
2025-01-31 06:44:56 -05:00
Pekka Enberg
e96b649a1a Merge 'github: Use only Python 3.13 for pull request runs' from Pekka Enberg
...speeds up PR cycle time by not running on all the possible Python
configurations all the time.

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

Closes #840
2025-01-31 11:41:26 +02:00
Pekka Enberg
3398252ca0 github: Use only Python 3.13 for pull request runs
...speeds up PR cycle time by not running on all the possible Python
configurations all the time.
2025-01-31 11:31:04 +02:00
Pekka Enberg
7f0274e48f Merge 'Table info' from Glauber Costa
This implements the table_info pragma, allowing us to fetch information
about columns present in a table.

Closes #837
2025-01-31 08:46:27 +02:00
Pekka Enberg
053a1acef1 Merge 'Refactor cursor to support multiple state machines' from Alex Miller
This is mostly refactoring Cursor.write_info to instead be an enum,
where one of the options is a WriteInfo.  This permits one to add other
state machines to Cursor, and I added the state needed for Count as an
example, but all the testing for count's implementation depends on
ANALYZE #656 working end-to-end (to some degree) so that one can write a
SQL test for it.
But this code seems conflict-prone, so it seems better to get it in
sooner than later.
I also finally understood what the point of RefCell is from fighting
with rust on this, so that was nice.

Closes #836
2025-01-31 08:45:01 +02:00
Pekka Enberg
a94cd03dfb Merge 'Performance test side by side comparison with rusqlite' from Levy A.
More convenient side by side comparison with sqlite.  Got this idea from
[criterion's documentation](https://bheisler.github.io/criterion.rs/book
/user_guide/comparing_functions.html). Some examples:
<img width="1010" alt="image" src="https://github.com/user-
attachments/assets/1cb400f6-f6a5-44af-a429-8e09a42dcd0d" />
<img width="1002" alt="image" src="https://github.com/user-
attachments/assets/ef35dfa6-6474-4fec-9b78-d81b274f2ca1" />

Closes #839
2025-01-31 08:44:07 +02:00
Pekka Enberg
de45ca82e4 github: Switch labeler to use GH_TOKEN
GITHUB_TOKEN is restricted to read-only by organization rules.
2025-01-31 08:42:24 +02:00
Levy A.
5acd7a5ea8 side by side comparison with sqlite 2025-01-31 03:11:07 -03:00
krishvishal
8b2393fcef Check for if a column is in descending order to add an automatic primary key index. 2025-01-31 08:25:54 +05:30
Glauber Costa
016b815b59 implement pragma table_info
Both () and = variants covered. It is important to make sure that
the transaction is a read transaction, so we cannot hide all that logic
inside update_pragma, and have to make our decision before that.
2025-01-30 20:00:20 -05:00
Glauber Costa
249a8cf8d2 keep type information as a string in column metadata
SQLite holds on to it deeply, for example:

sqlite> create table a(a int);
sqlite> create table b(b integer);
sqlite> create table c(c glauber);

sqlite> pragma table_info=a;
0|a|INT|0||0
sqlite> pragma table_info=b;
0|b|INTEGER|0||0
sqlite> pragma table_info=c;
0|c|glauber|0||0

So we'll keep it as well so we can produce the same responses.
2025-01-30 19:53:36 -05:00
Glauber Costa
f1df43633a change type Display implementation to not show null
This is the behavior that things like pragma table_info seem to
expect.
2025-01-30 19:53:36 -05:00
Alex Miller
9ac52b66d9 Refactor cursor to support multiple state machines 2025-01-30 14:08:44 -08:00
Glauber Costa
69d3fbc797 keep track of notnull constraint on column creation 2025-01-30 17:04:12 -05:00
Glauber Costa
42f93e9bea add default type to Column definition 2025-01-30 16:45:57 -05:00
Pekka Enberg
d25ccf0e06 Merge 'bindings/go Support blob types in query arguments, free non-gc allocations' from Preston Thorpe
This PR fixes/adds support for the Blob type and adds the appropriate
tests.
Types created on the Go side will be cleaned up rather quickly if
nothing is referencing them, so this approach uses `runtime.Pinner` to
pin the bytes in memory so the pointers will be valid when Rust uses
`from_raw_parts` and then owns a new vec. They are then cleaned up after
the FFI call with `pinner.Unpin`.

Closes #822
2025-01-30 21:12:22 +02:00
Pekka Enberg
c7c3461daa Merge 'add compat statement about CreateBTree opcode' from Glauber Costa
It is partially supported - only on the existing database.

Closes #833
2025-01-30 21:11:41 +02:00
Pekka Enberg
d558f6aca8 Merge 'Make query_pragma use enum instead of &str' from Glauber Costa
Fixes #823

Closes #834
2025-01-30 21:11:18 +02:00
Glauber Costa
7a972318a8 Make query_pragma use enum instead of &str
Fixes #823
2025-01-30 14:06:17 -05:00
Glauber Costa
598f793581 add compat statement about CreateBTree opcode
It is partially supported - only on the existing database.
2025-01-30 12:52:04 -05:00
krishvishal
6f32344efb Make comparison of type_name case insensitive by converting to uppercase 2025-01-30 17:05:14 +05:30
Pekka Enberg
3a4cb34606 Merge 'Fix memory leaks, make extension types more efficient' from Preston Thorpe
I was baffled previously, because any time that `free` was called on a
type from an extension, it would hang even when I knew it wasn't in use
any longer, and hadn't been double free'd.
After #737 was merged, I tried it again and noticed that it would no
longer hang... but only for extensions that were staticly linked.
Then I realized that we are using a global allocator, that likely wasn't
getting used in the shared library that is built separately that won't
inherit from our global allocator in core, causing some symbol mismatch
and the subsequent hanging on calls to `free`.
This PR adds the global allocator to extensions behind a feature flag in
the macro that will prevent it from being used in `wasm` and staticly
linked environments where it would conflict with limbos normal global
allocator. This allows us to properly free the memory from returning
extension functions over FFI.
This PR also changes the Extension type to a union field so we can store
int + float values inline without boxing them.
any additional tips or thoughts anyone else has on improving this would
be appreciated 👍

Closes #803
2025-01-30 13:31:17 +02:00
Pekka Enberg
c779537f2f Merge 'Strftime compatibility solved' from Pedro Muniz
This PR closes #787. Chrono offers to format the string from an iterator
of Format Items. I created a custom iterator that only allows formatters
specified by sqlite. This approach however does not address the
inefficient way that julianday is calculated. Also, with this
implementation we avoid having to maintain a separate vendored package
for strftime that may become incompatible with Chrono in the future.

Closes #792
2025-01-30 13:30:11 +02:00
Pekka Enberg
e66648beb8 Merge 'Add support for offset in select queries' from Ben Li
#739
Started adding support for `LIMIT...OFFSET...`
- New `OffsetLimit` opcode
- `OFFSET` is now supported for:
    - `SELECT...LIMIT...OFFSET`
    - `SELECT...GROUP BY...LIMIT...OFFSET`
    - `SELECT...ORDER BY...LIMIT...OFFSET`
    - Subqueries for `SELECT` statements
**In progress/todo**
- [x] Testing
- [x] Handle negative offset value
- **(will make in separate PR)** Add support for
`DELETE...LIMIT...OFFSET`
- **(will make in separate PR)** Use `limit + offset` sum register from
`OffsetLimit` to constrain number of records inserted into sorter

Closes #779
2025-01-30 13:29:49 +02:00
Pekka Enberg
5614a7751c Merge 'implement isnull / not null for filter expressions' from Glauber Costa
Allow us to write queries like:
        SELECT name, type, sql FROM sqlite_schema where sql isnull
and
        SELECT name, type, sql FROM sqlite_schema where sql not null

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

Closes #829
2025-01-30 13:28:53 +02:00
Pekka Enberg
a2ac3132c4 Merge 'Fix SELECT ABS(-9223372036854775808) causes limbo to panic. ' from Krishna Vishal
Now we return `RuntimeError`.  Matches SQLite behavior.
SQLite:
```sql
sqlite> SELECT ABS(-9223372036854775808);
Runtime error: integer overflow
```
Limbo after this fix:
```sql
limbo> SELECT ABS(-9223372036854775808);
Runtime error: integer overflow
```
Closes https://github.com/tursodatabase/limbo/issues/815

Closes #818
2025-01-30 13:25:39 +02:00
Pekka Enberg
4673ac969e Merge 'Fix SELECT -9223372036854775808 result differs from SQLite' from Krishna Vishal
Closes #812
`-9223372036854775808` is `MIN_INT64`. So when we extract out the minus
and try to parse the remainder it becomes greater than MAX_INT64
(9223372036854775807) and will trigger overflow, which converts the
literal into `Real`. So we have to handle it as a special case.

Reviewed-by: Kim Seon Woo (@seonWKim)

Closes #814
2025-01-30 13:25:27 +02:00
Pekka Enberg
4a0701794c Merge 'json_remove() function implementation' from Ihor Andrianov
Uses already implemented json path parser so shares limitations with
json_extract()

Closes #828
2025-01-30 13:24:59 +02:00
Pekka Enberg
c4bab1297d Merge 'Fix labeler.yml ' from Kim Seon Woo
## Changes
- labeler@v4 -> labeler@v5
- GH_TOKEN -> GITHUB_TOKEN
- add sparse checkout action(to properly read `.github/labeler.yml`)
- fix `.github/labeler.yml` which is where the configurations go
## Reference
- Tests in my forked repository
![image](https://github.com/user-
attachments/assets/49ed8e96-7bc9-419b-beca-e838c86fb2d7)
![image](https://github.com/user-
attachments/assets/cab87024-933c-4eb6-a025-c2f8faf0af2f)

Closes #825
2025-01-30 13:24:15 +02:00
krishvishal
cab0625017 Fixes limbo creating an extra btree, when table has single column PRIMARy KEY.
The error is due to comparing the PRIMARY KEY's name to INTEGER when in it was all in lowercase.
2025-01-30 15:04:50 +05:30
pedrocarlo
643ad147c0 checkpoint: implemented time_now, time_fmt_iso, time_date 2025-01-30 01:26:47 -03:00
Ihor Andrianov
8a01b842a5 fix function import 2025-01-30 04:05:05 +02:00
Glauber Costa
effde1cc04 implement isnull / not null for filter expressions
Allow us to write queries like:

	SELECT name, type, sql FROM sqlite_schema where sql isnull

and

	SELECT name, type, sql FROM sqlite_schema where sql not null
2025-01-29 20:58:04 -05:00
Ihor Andrianov
d968b314ed fix bug for 1 arg 2025-01-30 03:44:33 +02:00
Ihor Andrianov
c500c16eca fix COMPAT.md message 2025-01-30 03:32:39 +02:00
Ihor Andrianov
7455d9718a update COMPAT.md 2025-01-30 03:28:55 +02:00
Ihor Andrianov
ee52192cd8 add unit tests 2025-01-30 03:13:58 +02:00
Ihor Andrianov
ccf51cae80 moved is_json_valid above tests 2025-01-30 02:47:11 +02:00