You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think adding JSON to file format (e.g. variant or something, if needed) and adding JSON to the table format (JSON indexes) and adding JSON to the compute engine (JSON functions) can all be tackled independently.
The file format and compute engine changes are probably more well understood.
The table format changes are a little less understood to me. There is maybe an easy path for some kind of read-only JSON column where a write means rewriting the entire JSON value. Making a full schema-less table will be quite different.
Is a user going to want to change a JSON value for a row (e.g. an update)? Will they want to add a new JSON column (to an existing JSON object)?
I assume if we are training a vector index on a vector field and that field isn't a vector type on some row (JSON does not enforce homogenous types) or if the vector has different dimensions then we just skip the field?
What should we use to determine the dimension of the JSON vector field? Should it be the first value we encounter?
One good option is to join the effort in DataFusion to support the Parquet Variant data type. (It's just called Parquet Variant because that's where the standard was defined, not because it's tied to parquet.)
Similar to how we can add geospatial support by just including a few plugins (see demo from #4482), we could probably add variant support with a few plugins.
I think the variant approach works well for shredding support. Our ultimate goal is to support variants in Lance. However, we can begin by adding JSON support through the introduction of jsonb first. We have a mature jsonb crate and it has nearly everthing we need so far.
Our current JSON index is defined as follows. I think we can also support full-text indexes for JSON column. As the number of fields/paths in JSON can be very large, it is impractical to create an index for each field. Full-text indexing allows querying all fields of json data in one index, making it more practical and useful.
/// A JSON index that indexes a field in a JSON column
///
/// The underlying index can be any other type of scalar index
#[derive(Debug)]
pub struct JsonIndex {
target_index: Arc<dyn ScalarIndex>,
path: String,
}
To implement this, we just need to create a new tokenizer (may be call it JsonTokenizer).
For JSON data, parse it into (json_path, value_type, value) tokens.
For FST queries, such as MatchQuery("my_path.my_segment:233"), convert it into tokens like (my_path.my_segment, String, 233) and (my_path.my_segment, u64, 233), and perform an Operator::Or query.
Motivation: Lance JSON inverted indexing needs to preserve array-of-object structure instead of treating each row as one token stream. Tantivy documents the flaw of a bag-of-terms JSON array index: a query like cart.product_type:sneakers AND cart.attributes.color:red can match even when sneakers and red live in different objects in the same array.
By porting the idea of Apache Pinot Json Index which I worked on previously, this PR addresses that class of false positive with FlattenedSubDocs: each JSON row is flattened into sub-docs, related path constraints can be evaluated inside the same flattened array element, and matches are then mapped back to the original Lance row id.
The PR also keeps existing JSON indexes readable, preserves positional/wildcard differences like foo[0].bar[0],str,y vs foo[0].bar[*],str,y, and adds disable_cross_array_unnest=false by default with a Pinot-style opt-in to avoid Cartesian sub-doc growth when users accept reduced accuracy for cross-array query constraints.
@westonpace@wojiaodoubao@jackye1995 Could you take an early review of the PR proposal to see if there are any major concerns? I've included detailed examples throughout to make it easier for reviewers to understand the proposed solution.
Activity
westonpace commentedon Aug 20, 2025
I think adding JSON to file format (e.g. variant or something, if needed) and adding JSON to the table format (JSON indexes) and adding JSON to the compute engine (JSON functions) can all be tackled independently.
The file format and compute engine changes are probably more well understood.
The table format changes are a little less understood to me. There is maybe an easy path for some kind of read-only JSON column where a write means rewriting the entire JSON value. Making a full schema-less table will be quite different.
Is a user going to want to change a JSON value for a row (e.g. an update)? Will they want to add a new JSON column (to an existing JSON object)?
westonpace commentedon Aug 20, 2025
I assume if we are training a vector index on a vector field and that field isn't a vector type on some row (JSON does not enforce homogenous types) or if the vector has different dimensions then we just skip the field?
What should we use to determine the dimension of the JSON vector field? Should it be the first value we encounter?
wjones127 commentedon Aug 20, 2025
One good option is to join the effort in DataFusion to support the Parquet Variant data type. (It's just called Parquet Variant because that's where the standard was defined, not because it's tied to parquet.)
Similar to how we can add geospatial support by just including a few plugins (see demo from #4482), we could probably add variant support with a few plugins.
Relevant packages:
wjones127 commentedon Aug 20, 2025
If we want something more immediate, there is:
https://github.com/datafusion-contrib/datafusion-functions-json
Xuanwo commentedon Aug 22, 2025
I think the variant approach works well for shredding support. Our ultimate goal is to support variants in Lance. However, we can begin by adding JSON support through the introduction of jsonb first. We have a mature
jsonbcrate and it has nearly everthing we need so far.My current plan:
jsonjsonbbinary as a logic typeLargeBinaryin lanceThe first MVP will allow users to:
feat: add JSONB read/write support (#4566)
feat: add UDFs for json (#4577)
wojiaodoubao commentedon Sep 5, 2025
Our current JSON index is defined as follows. I think we can also support full-text indexes for JSON column. As the number of fields/paths in JSON can be very large, it is impractical to create an index for each field. Full-text indexing allows querying all fields of json data in one index, making it more practical and useful.
The key to building full-text indexing for JSON is how to tokenize it. We can refer to Tantivy's JSON Indexing Design.
For example, given the following JSON:
The tokens generated would be:
To implement this, we just need to create a new tokenizer (may be call it JsonTokenizer).
(json_path, value_type, value)tokens.MatchQuery("my_path.my_segment:233"), convert it into tokens like(my_path.my_segment, String, 233)and(my_path.my_segment, u64, 233), and perform an Operator::Or query.cc @jackye1995 @Xuanwo
westonpace commentedon Sep 16, 2025
Yes, a full text JSON index like the one in tantivy would be very cool.
feat: add UDFs for json (lance-format#4577)
wirybeaver commentedon Jun 21, 2026
Opened draft PR #7377 for this.
Motivation: Lance JSON inverted indexing needs to preserve array-of-object structure instead of treating each row as one token stream. Tantivy documents the flaw of a bag-of-terms JSON array index: a query like
cart.product_type:sneakers AND cart.attributes.color:redcan match even whensneakersandredlive in different objects in the same array.By porting the idea of Apache Pinot Json Index which I worked on previously, this PR addresses that class of false positive with
FlattenedSubDocs: each JSON row is flattened into sub-docs, related path constraints can be evaluated inside the same flattened array element, and matches are then mapped back to the original Lance row id.The PR also keeps existing JSON indexes readable, preserves positional/wildcard differences like
foo[0].bar[0],str,yvsfoo[0].bar[*],str,y, and addsdisable_cross_array_unnest=falseby default with a Pinot-style opt-in to avoid Cartesian sub-doc growth when users accept reduced accuracy for cross-array query constraints.@westonpace @wojiaodoubao @jackye1995 Could you take an early review of the PR proposal to see if there are any major concerns? I've included detailed examples throughout to make it easier for reviewers to understand the proposed solution.
wirybeaver commentedon Jun 24, 2026
@eddyxu @Xuanwo Could you take a look when you are available for this JSON Indexing improvement proposal? #7377