Commit Graph

2266 Commits

Author SHA1 Message Date
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
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
Glauber Costa
7a972318a8 Make query_pragma use enum instead of &str
Fixes #823
2025-01-30 14:06:17 -05:00
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
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
Ihor Andrianov
d66329343b add tests 2025-01-30 02:41:05 +02:00
Ihor Andrianov
5cf80d8cef cargo clippy 2025-01-30 02:40:35 +02:00
Ihor Andrianov
52eab0544a add Target discrete type to handle array and obj changes 2025-01-30 02:09:01 +02:00
김선우
0101946d67 Fix configuration file 2025-01-30 08:01:50 +09:00
김선우
0c2b774714 Add spare-checkout
- Related issue: https://github.com/actions/labeler/issues/814#issuecomment-2478374811
2025-01-30 08:01:44 +09:00
김선우
79da888c45 Fix labeler.yml 2025-01-30 07:38:58 +09:00
Ihor Andrianov
30d810bfe5 add utility function to get mut ref by path 2025-01-30 00:05:53 +02:00
Ihor Andrianov
305e86ec39 allow path parser accept numbers as keys 2025-01-29 22:39:35 +02:00
Ihor Andrianov
d57d9bef6f add function definition 2025-01-29 22:37:04 +02:00
Pekka Enberg
f086c1b32f Update COMPAT.md 2025-01-29 19:57:04 +02:00
Pekka Enberg
06edf33878 Merge 'json_patch() function implementation' from Ihor Andrianov
First review #820
The function follows RFC 7386 JSON Merge Patch semantics:
* If the patch is null, the target is replaced with null
* If the patch contains a scalar value, the target is replaced with that
value
* If both target and patch are objects, the patch is recursively applied
* null values in the patch result in property removal from the target

Closes #821
2025-01-29 19:54:12 +02:00
Pekka Enberg
db72756d2a Merge 'Changes to json serialization/deserialization' from Ihor Andrianov
Change JSON deserialization to enable json_patch implementation with
SQLite-compatible behavior:
* Preserves duplicate keys in JSON objects
* Applies patches only to the first occurrence of each key
* Trade-off: Changes key lookup from O(1) to O(n) to support duplicate
keys
* Have to be merged before json_patch() function

Closes #820
2025-01-29 19:53:41 +02:00
Pekka Enberg
ffb692b4a1 github: Configure a single Github actions token 2025-01-29 19:49:39 +02:00
krishvishal
f8c1828ddf Matched on i64::checked_abs and changed RuntimeError to IntegerOverflow 2025-01-29 22:34:19 +05:30
Pekka Enberg
4af6eb2f71 Merge 'Refactor Json serialization to accommodate formatters for pretty printing' from Pedro Muniz
Json serialization logic was pulled from serde_json. Google's json5
serialization code was not flexible enough to allow for pretty printing
json, so I believe that the formatter design is a good layer to abstract
this logic. This refactor will trivially enable the implementation of
json_pretty function from sqlite. My other PR for json_quote, #763,
depends a tiny bit on a helper utility from the previous serialization
implementation. If this PR is considered first, I will change the code
in my other PR to account for this.

Reviewed-by: Diego Reis (@diegoreis42)
Reviewed-by: Kacper Madej (@madejejej)

Closes #771
2025-01-29 19:03:14 +02:00
Ihor Andrianov
0048f77b45 add unit tests 2025-01-29 18:05:41 +02:00
Ihor Andrianov
4e7c4e7ced fixes to pass tests 2025-01-29 18:05:41 +02:00
Ihor Andrianov
166d0a7165 add more tests and fixed test for latest sqlite v 2025-01-29 18:05:41 +02:00
Ihor Andrianov
0714ab64af add tests for tricky edge cases 2025-01-29 18:05:40 +02:00
Ihor Andrianov
2407a29e90 refactored into patcher struct and made code more modular and readable 2025-01-29 18:05:40 +02:00
Ihor Andrianov
f164dbdb1e fix case where first patched value applied wins 2025-01-29 18:05:40 +02:00
Ihor Andrianov
8ba43bfc17 add tests for duplicate preservation and first-one-win behavior 2025-01-29 18:05:40 +02:00
Ihor Andrianov
6a605939e6 naming refine 2025-01-29 18:05:39 +02:00
Ihor Andrianov
3f7458faef add general tests 2025-01-29 18:05:39 +02:00
Ihor Andrianov
846a73188a add json_patch implementation 2025-01-29 18:05:39 +02:00
Ihor Andrianov
98be735f5a add json_patch to expr and vm 2025-01-29 18:05:39 +02:00
Ihor Andrianov
70396d7425 add function definition 2025-01-29 18:05:38 +02:00
Ihor Andrianov
5c55615896 add Removed enum type to discard removed fields on parsing stage 2025-01-29 17:59:48 +02:00
Ihor Andrianov
f97d085934 add deserialization patch to represent obj as ordered Vec and preserve duplicates 2025-01-29 17:59:48 +02:00
Pekka Enberg
489e3242c9 Merge 'Add github workflow labeler to automatically add labels ' from Kim Seon Woo
## Purpose of this PR
- Automatically add labels to PRs for easy classification
- We can add useful rules as needed
## Changes
- Add 2 files to configure labeler
- For now, changes under certain directory will add labels
## ETC
- workflow repo: https://github.com/marketplace/actions/labeler

Closes #817
2025-01-29 17:14:36 +02:00