Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: json data type for non object values #1236

Merged
merged 3 commits into from
Nov 14, 2024

Conversation

surbhigarg92
Copy link
Contributor

@surbhigarg92 surbhigarg92 commented Nov 13, 2024

JSON supports various types of values. At a high level: Objects, Arrays, and various kinds of Scalars. A Spanner column of type JSON can support any of these:

spanner> create table t_json (i int64, j json) primary key (i);
spanner> insert into t_json (i,j) values (1,JSON '[1,2,3]');
spanner> insert into t_json (i,j) values (2,JSON '"foo"');
spanner> insert into t_json (i,j) values (3,JSON '{"a": "b"}');
spanner> select * from t_json;
+---+-----------+
| i | j |
+---+-----------+
| 1 | [1,2,3] |
| 2 | "foo" |
| 3 | {"a":"b"} |
+---+-----------+
Spanner's Python Client assumes that all JSON values are Objects. If you read back a value that is not an Object, you will get an error that looks like:

ValueError: dictionary update sequence element #0 has length 3; 2 is required
The root cause of this issue is this line here: https://github.com/googleapis/python-spanner/blob/main/google/cloud/spanner_v1/data_types.py#L47

        super(JsonObject, self).__init__(*args, **kwargs)

@surbhigarg92 surbhigarg92 requested review from a team as code owners November 13, 2024 08:16
@product-auto-label product-auto-label bot added the size: m Pull request size is medium. label Nov 13, 2024
@product-auto-label product-auto-label bot added the api: spanner Issues related to the googleapis/python-spanner API. label Nov 13, 2024
@surbhigarg92 surbhigarg92 assigned harshachinta and unassigned larkee Nov 13, 2024
google/cloud/spanner_v1/data_types.py Outdated Show resolved Hide resolved
@surbhigarg92 surbhigarg92 enabled auto-merge (squash) November 14, 2024 08:52
@surbhigarg92 surbhigarg92 merged commit 0007be3 into googleapis:main Nov 14, 2024
10 of 12 checks passed
yeesian added a commit to yeesian/langchain-google-spanner-python that referenced this pull request Nov 14, 2024
The bump in lowerbound for google-cloud-spanner is to capture the fix in googleapis/python-spanner#1236.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the googleapis/python-spanner API. size: m Pull request size is medium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants