diff --git a/go/store/prolly/tree/blob_builder.go b/go/store/prolly/tree/blob_builder.go index 06c0afbe6f..c47b1e705a 100644 --- a/go/store/prolly/tree/blob_builder.go +++ b/go/store/prolly/tree/blob_builder.go @@ -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 } diff --git a/integration-tests/bats/json-oldformat-repo/.dolt/config.json b/integration-tests/bats/json-oldformat-repo/.dolt/config.json new file mode 100755 index 0000000000..9e26dfeeb6 --- /dev/null +++ b/integration-tests/bats/json-oldformat-repo/.dolt/config.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/integration-tests/bats/json-oldformat-repo/.dolt/noms/LOCK b/integration-tests/bats/json-oldformat-repo/.dolt/noms/LOCK new file mode 100644 index 0000000000..e69de29bb2 diff --git a/integration-tests/bats/json-oldformat-repo/.dolt/noms/journal.idx b/integration-tests/bats/json-oldformat-repo/.dolt/noms/journal.idx new file mode 100644 index 0000000000..610950fd2f Binary files /dev/null and b/integration-tests/bats/json-oldformat-repo/.dolt/noms/journal.idx differ diff --git a/integration-tests/bats/json-oldformat-repo/.dolt/noms/manifest b/integration-tests/bats/json-oldformat-repo/.dolt/noms/manifest new file mode 100644 index 0000000000..b7498d866d --- /dev/null +++ b/integration-tests/bats/json-oldformat-repo/.dolt/noms/manifest @@ -0,0 +1 @@ +5:__DOLT__:9meojkibso7athar08m9btgeohtavtkh:k6bgrd1f6142qmf4dh6gucgmcp1djbm4:00000000000000000000000000000000:vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv:3826 \ No newline at end of file diff --git a/integration-tests/bats/json-oldformat-repo/.dolt/noms/vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv b/integration-tests/bats/json-oldformat-repo/.dolt/noms/vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv new file mode 100644 index 0000000000..c7157d4f7e Binary files /dev/null and b/integration-tests/bats/json-oldformat-repo/.dolt/noms/vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv differ diff --git a/integration-tests/bats/json-oldformat-repo/.dolt/repo_state.json b/integration-tests/bats/json-oldformat-repo/.dolt/repo_state.json new file mode 100755 index 0000000000..32f2d6197d --- /dev/null +++ b/integration-tests/bats/json-oldformat-repo/.dolt/repo_state.json @@ -0,0 +1,6 @@ +{ + "head": "refs/heads/main", + "remotes": {}, + "backups": {}, + "branches": {} +} \ No newline at end of file diff --git a/integration-tests/bats/json-oldformat-repo/.dolt/stats/.dolt/config.json b/integration-tests/bats/json-oldformat-repo/.dolt/stats/.dolt/config.json new file mode 100755 index 0000000000..9e26dfeeb6 --- /dev/null +++ b/integration-tests/bats/json-oldformat-repo/.dolt/stats/.dolt/config.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/integration-tests/bats/json-oldformat-repo/.dolt/stats/.dolt/noms/LOCK b/integration-tests/bats/json-oldformat-repo/.dolt/stats/.dolt/noms/LOCK new file mode 100644 index 0000000000..e69de29bb2 diff --git a/integration-tests/bats/json-oldformat-repo/.dolt/stats/.dolt/noms/journal.idx b/integration-tests/bats/json-oldformat-repo/.dolt/stats/.dolt/noms/journal.idx new file mode 100644 index 0000000000..21434375f0 Binary files /dev/null and b/integration-tests/bats/json-oldformat-repo/.dolt/stats/.dolt/noms/journal.idx differ diff --git a/integration-tests/bats/json-oldformat-repo/.dolt/stats/.dolt/noms/manifest b/integration-tests/bats/json-oldformat-repo/.dolt/stats/.dolt/noms/manifest new file mode 100644 index 0000000000..3bed411aeb --- /dev/null +++ b/integration-tests/bats/json-oldformat-repo/.dolt/stats/.dolt/noms/manifest @@ -0,0 +1 @@ +5:__DOLT__:0ced3kicdirbi5vrl72i5as7dtis5elq:1dd8gihhhhnmqc4s142f5pshrvgcndji:00000000000000000000000000000000:vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv:17 \ No newline at end of file diff --git a/integration-tests/bats/json-oldformat-repo/.dolt/stats/.dolt/noms/vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv b/integration-tests/bats/json-oldformat-repo/.dolt/stats/.dolt/noms/vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv new file mode 100644 index 0000000000..5fc069e390 Binary files /dev/null and b/integration-tests/bats/json-oldformat-repo/.dolt/stats/.dolt/noms/vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv differ diff --git a/integration-tests/bats/json-oldformat-repo/.dolt/stats/.dolt/repo_state.json b/integration-tests/bats/json-oldformat-repo/.dolt/stats/.dolt/repo_state.json new file mode 100755 index 0000000000..32f2d6197d --- /dev/null +++ b/integration-tests/bats/json-oldformat-repo/.dolt/stats/.dolt/repo_state.json @@ -0,0 +1,6 @@ +{ + "head": "refs/heads/main", + "remotes": {}, + "backups": {}, + "branches": {} +} \ No newline at end of file diff --git a/integration-tests/bats/json-oldformat.bats b/integration-tests/bats/json-oldformat.bats new file mode 100644 index 0000000000..3e2341fc95 --- /dev/null +++ b/integration-tests/bats/json-oldformat.bats @@ -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 +}