Repository navigation
feat: add JSONB read/write support - #4566
Conversation
Signed-off-by: Xuanwo <[email protected]>
Signed-off-by: Xuanwo <[email protected]>
This comment was marked as resolved.
This comment was marked as resolved.
Signed-off-by: Xuanwo <[email protected]>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #4566 +/- ##
==========================================
- Coverage 80.98% 80.89% -0.10%
==========================================
Files 312 314 +2
Lines 114696 115072 +376
Branches 114696 115072 +376
==========================================
+ Hits 92886 93083 +197
- Misses 18539 18703 +164
- Partials 3271 3286 +15
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Signed-off-by: Xuanwo <[email protected]>
Signed-off-by: Xuanwo <[email protected]>
Signed-off-by: Xuanwo <[email protected]>
Signed-off-by: Xuanwo <[email protected]>
Signed-off-by: Xuanwo <[email protected]>
Signed-off-by: Xuanwo <[email protected]>
Signed-off-by: Xuanwo <[email protected]>
Signed-off-by: Xuanwo <[email protected]>
westonpace
left a comment
There was a problem hiding this comment.
I have some suggestions but overall I think this is a good starting point for moving forward on JSON.
Some of the test cases in test_json.py seem a little extraneous.
Also, someday, I'd love to get rid of logical type from the lance table format and just use Arrow there too but definitely we should save that for a future PR 😆
| # Write the dataset with version 2.2 (required for JSON support) | ||
| lance.write_dataset(table, dataset_path, data_storage_version="2.2") |
There was a problem hiding this comment.
I don't think we actually need 2.2 if we're doing everything at the table level (originally I thought you were adding JSONB to file level)
| } | ||
| } | ||
|
|
||
| impl TryFrom<&LargeStringArray> for JsonArray { |
There was a problem hiding this comment.
Hmm, supporting both string and large string is ok, but not sure it is vital at the moment if it becomes an inconvenience.
| "binary" => Some(Binary), | ||
| "large_string" => Some(LargeUtf8), | ||
| "large_binary" => Some(LargeBinary), | ||
| "json" => Some(LargeBinary), |
There was a problem hiding this comment.
Does this mean JSON is always large binary?
There was a problem hiding this comment.
Yes for now. I'm open to provide Binary support for small json. Maybe it's worth a seperate issue?
| let schema_has_json = manifest.schema.fields_pre_order().any(|field| { | ||
| let arrow_field = ArrowField::from(field); | ||
| lance_arrow::json::has_json_fields(&arrow_field) | ||
| }); | ||
|
|
||
| if schema_has_json { | ||
| let storage_version = manifest.data_storage_format.lance_file_version()?; | ||
| if storage_version < lance_file::version::LanceFileVersion::V2_2 { | ||
| return Err(Error::NotSupported { | ||
| source: format!( | ||
| "Cannot read dataset with JSON fields from file format version {}. \ | ||
| JSON fields require Lance file format version 2.2 or later.", | ||
| storage_version | ||
| ) | ||
| .into(), | ||
| location: location!(), | ||
| }); | ||
| } | ||
| } |
There was a problem hiding this comment.
Can we remove this check for now since we aren't modifying file format? Maybe once this feature stabilzes we can put it back (if we add variant type to file format) or handle it with a table feature flag.
There was a problem hiding this comment.
I'm hesitant about this because the binary format for jsonb is not quite stable and is still evolving. My current plan is to change into pg compatible jsonb format in the future.
There was a problem hiding this comment.
Tracked at #4575, I'm open to create a new PR to get it removed. And for now, I will merge this PR first.
| let schema_has_json = data_schema.fields_pre_order().any(|field| { | ||
| let arrow_field = ArrowField::from(field); | ||
| lance_arrow::json::has_json_fields(&arrow_field) | ||
| }); | ||
|
|
||
| if schema_has_json && context.storage_version < LanceFileVersion::V2_2 { | ||
| return Err(Error::NotSupported { | ||
| source: format!( | ||
| "JSON fields require Lance file format version 2.2 or later. \ | ||
| Current version: {}. Please specify data_storage_version='2.2' in WriteParams", | ||
| context.storage_version | ||
| ) | ||
| .into(), | ||
| location: location!(), | ||
| }); | ||
| } | ||
|
|
There was a problem hiding this comment.
Same as above, let's remove this check for now
Signed-off-by: Xuanwo <[email protected]>
Signed-off-by: Xuanwo <[email protected]>
Signed-off-by: Xuanwo <[email protected]>
Signed-off-by: Xuanwo <[email protected]>
Signed-off-by: Xuanwo <[email protected]>
Part of #4516
This PR will add basic JSONB read/write support so users can use them like an extension arrow type like
blobandbfloat16.This PR was primarily authored with Claude Code using Opus 4.1 and then hand-reviewed by me. I AM responsible for every change made in this PR. I aimed to keep it aligned with our goals, though I may have missed minor issues. Please flag anything that feels off, I'll fix it quickly.