mirror of
https://github.com/dolthub/dolt.git
synced 2026-03-03 01:19:09 -06:00
Detect reading from non-indexed JSON documents and store it in a LazyJSONDocument instead of an IndexedJSONDocument.
This commit is contained in:
@@ -304,6 +304,10 @@ func (b *JSONDoc) ToIndexedJSONDocument(ctx context.Context) (sql.JSONWrapper, e
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if root.level > 0 && root.keys.IsEmpty() {
|
||||
// We're reading a non-indexed multi-chunk document written by an older version of Dolt.
|
||||
return b.ToLazyJSONDocument(ctx)
|
||||
}
|
||||
return NewIndexedJsonDocument(ctx, root, b.ns), nil
|
||||
}
|
||||
|
||||
|
||||
1
integration-tests/bats/json-oldformat-repo/.dolt/config.json
Executable file
1
integration-tests/bats/json-oldformat-repo/.dolt/config.json
Executable file
@@ -0,0 +1 @@
|
||||
{}
|
||||
Binary file not shown.
@@ -0,0 +1 @@
|
||||
5:__DOLT__:9meojkibso7athar08m9btgeohtavtkh:k6bgrd1f6142qmf4dh6gucgmcp1djbm4:00000000000000000000000000000000:vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv:3826
|
||||
Binary file not shown.
6
integration-tests/bats/json-oldformat-repo/.dolt/repo_state.json
Executable file
6
integration-tests/bats/json-oldformat-repo/.dolt/repo_state.json
Executable file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"head": "refs/heads/main",
|
||||
"remotes": {},
|
||||
"backups": {},
|
||||
"branches": {}
|
||||
}
|
||||
1
integration-tests/bats/json-oldformat-repo/.dolt/stats/.dolt/config.json
Executable file
1
integration-tests/bats/json-oldformat-repo/.dolt/stats/.dolt/config.json
Executable file
@@ -0,0 +1 @@
|
||||
{}
|
||||
Binary file not shown.
@@ -0,0 +1 @@
|
||||
5:__DOLT__:0ced3kicdirbi5vrl72i5as7dtis5elq:1dd8gihhhhnmqc4s142f5pshrvgcndji:00000000000000000000000000000000:vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv:17
|
||||
Binary file not shown.
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"head": "refs/heads/main",
|
||||
"remotes": {},
|
||||
"backups": {},
|
||||
"branches": {}
|
||||
}
|
||||
29
integration-tests/bats/json-oldformat.bats
Normal file
29
integration-tests/bats/json-oldformat.bats
Normal file
@@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env bats
|
||||
load $BATS_TEST_DIRNAME/helper/common.bash
|
||||
|
||||
# This BATS test attempts to read JSON documents that were written prior to v1.40
|
||||
|
||||
# This function was used to create the dolt repo used for this test. It is not run during testing.
|
||||
create_repo() {
|
||||
dolt init
|
||||
dolt sql -q "CREATE TABLE jsonTable(pk int primary key, j json);"
|
||||
dolt sql -q 'INSERT INTO jsonTable( with recursive cte (pk, j) as ( select 0, JSON_OBJECT("K", "V") union all select pk+1, JSON_INSERT(j, CONCAT("$.k", pk), j) from cte where pk < 20 ) select * from cte );'
|
||||
dolt add .
|
||||
dolt commit -m "create json table"
|
||||
}
|
||||
|
||||
setup() {
|
||||
cp -r $BATS_TEST_DIRNAME/json-oldformat-repo/ $BATS_TMPDIR/dolt-repo-$$
|
||||
cd $BATS_TMPDIR/dolt-repo-$$
|
||||
}
|
||||
|
||||
@test "json-oldformat: verify queries" {
|
||||
run dolt sql -q "SELECT pk, JSON_EXTRACT(j, '$.k10.k5.k3.k2') FROM jsonTable WHERE pk = 12;"
|
||||
[[ "$output" =~ '{"K": "V", "k0": {"K": "V"}, "k1": {"K": "V", "k0": {"K": "V"}}}' ]] || false
|
||||
|
||||
run dolt sql -q "SELECT pk, JSON_VALUE(j, '$.k8.k6.k4.k1') FROM jsonTable WHERE pk = 12;"
|
||||
[[ "$output" =~ '{"K": "V", "k0": {"K": "V"}}' ]] || false
|
||||
|
||||
run dolt sql -q "SELECT pk, JSON_EXTRACT(JSON_INSERT(j, '$.k9.k6.k1.TESTKEY', 'TESTVALUE'), '$.k9.k6.k1') FROM jsonTable WHERE pk = 12;"
|
||||
[[ "$output" =~ '{"K": "V", "k0": {"K": "V"}, "TESTKEY": "TESTVALUE"}' ]] || false
|
||||
}
|
||||
Reference in New Issue
Block a user