-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[Variant] Enahcne bracket access for VariantPath #9479
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -170,9 +170,10 @@ pub(crate) fn fits_precision<const N: u32>(n: impl Into<i64>) -> bool { | |
| /// - `"foo"` -> single field `foo` | ||
| /// - `"foo.bar"` -> nested fields `foo`, `bar` | ||
| /// - `"[1]"` -> array index 1 | ||
| /// - `"['1']"` or `"["1"]"`-> field `1` | ||
| /// - `"foo[1].bar"` -> field `foo`, index 1, field `bar` | ||
| /// - `"[a.b]"` -> field `a.b` (dot is literal inside bracket) | ||
| /// - `"[a\\]b]"` -> field `a]b` (escaped `]` | ||
| /// - `"['a.b']"` -> field `a.b` (dot is literal inside bracket) | ||
| /// - `"['a\]b']"` -> field `a]b` (escaped `]` | ||
| /// - etc. | ||
| /// | ||
| /// # Errors | ||
|
|
@@ -267,9 +268,23 @@ fn parse_in_bracket(s: &str, i: usize) -> Result<(VariantPathElement<'_>, usize) | |
| } | ||
| }; | ||
|
|
||
| let element = match unescaped.parse() { | ||
| Ok(idx) => VariantPathElement::index(idx), | ||
| Err(_) => VariantPathElement::field(unescaped), | ||
| let element = if let Some(inner) = unescaped | ||
| .strip_prefix('\'') | ||
| .and_then(|s| s.strip_suffix('\'')) | ||
| .or_else(|| { | ||
| unescaped | ||
| .strip_prefix('"') | ||
| .and_then(|s| s.strip_suffix('"')) | ||
| }) { | ||
| // Quoted field name, e.g., ['field'] or ['123'] or ["123"] | ||
| VariantPathElement::field(inner.to_string()) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What are the string-escape rules here? Can the user embed a single quote as
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update: Here's the relevant grammar from JSONpath spec: AI web search overview suggests the actual handling of delimiters and escapes tends to be vendor-specific (e.g. many database engines double up the delimiter as an escape)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah! This function already handles |
||
| } else { | ||
| let Ok(idx) = unescaped.parse() else { | ||
| return Err(ArrowError::ParseError(format!( | ||
| "Invalid token in bracket request: `{unescaped}`. Expected a quoted string or a number(e.g., `['field']` or `[123]`)" | ||
| ))); | ||
| }; | ||
| VariantPathElement::index(idx) | ||
| }; | ||
|
|
||
| Ok((element, end + 1)) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JSONpath allows either
'or"as the string delimiter. Do we want to support both? Or take the intersection between SQL and JSONpath and only support single quotes?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Followed the examples on databricks web previously, this is a valid json syntax, not don't add much more complexity, added
"now.