-
Notifications
You must be signed in to change notification settings - Fork 616
Add support for postgres json operators ->
, ->>
, #>
, and #>>
#458
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
Conversation
Signed-off-by: password <rbalajis25@gmail.com>
Pull Request Test Coverage Report for Build 2187863098
💛 - Coveralls |
Signed-off-by: password <rbalajis25@gmail.com>
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.
According to
https://www.postgresql.org/docs/current/functions-json.html
It appears there are also #>
and #>>
operators. I wonder if you have thought about supporting them?
done 😃 |
Signed-off-by: poonai <rbalajis25@gmail.com>
->
m ->>
->
m ->>
->
, ->>
, #>
, and #>>
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.
Thanks @poonai -- I think this is quite close (the only thing I think that is required is the Display
for Token::LongArrow
)
src/ast/mod.rs
Outdated
JsonOperator::LongArrow => { | ||
write!(f, "->>") | ||
} | ||
JsonOperator::Arrow => { | ||
write!(f, "->") | ||
} |
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.
I don't think it matters, but it would be nice to keep the order of the variants consistent
JsonOperator::LongArrow => { | |
write!(f, "->>") | |
} | |
JsonOperator::Arrow => { | |
write!(f, "->") | |
} | |
JsonOperator::Arrow => { | |
write!(f, "->") | |
} | |
JsonOperator::LongArrow => { | |
write!(f, "->>") | |
} |
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.
done
src/ast/mod.rs
Outdated
@@ -192,6 +225,12 @@ pub enum Expr { | |||
Identifier(Ident), | |||
/// Multi-part identifier, e.g. `table_alias.column` or `schema.table.col` | |||
CompoundIdentifier(Vec<Ident>), | |||
/// JsonIdentifier eg: data->'tags' |
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.
/// JsonIdentifier eg: data->'tags' | |
/// JSON access (postgres) eg: data->'tags' |
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.
done
src/tokenizer.rs
Outdated
@@ -141,6 +141,14 @@ pub enum Token { | |||
PGCubeRoot, | |||
/// `?` or `$` , a prepared statement arg placeholder | |||
Placeholder(String), | |||
/// ->, used as a operator to extract json field in PostgreSQL | |||
Arrow, | |||
/// -->, used as a operator to extract json field as text in PostgreSQL |
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.
/// -->, used as a operator to extract json field as text in PostgreSQL | |
/// ->>, used as a operator to extract json field as text in PostgreSQL |
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.
done
src/tokenizer.rs
Outdated
@@ -197,6 +205,10 @@ impl fmt::Display for Token { | |||
Token::PGSquareRoot => f.write_str("|/"), | |||
Token::PGCubeRoot => f.write_str("||/"), | |||
Token::Placeholder(ref s) => write!(f, "{}", s), | |||
Token::Arrow => write!(f, "->"), | |||
Token::LongArrow => write!(f, "-->"), |
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.
Token::LongArrow => write!(f, "-->"), | |
Token::LongArrow => write!(f, "->>"), |
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.
I wonder why the tests didn't cover this? I think there is a function that verifies that a parsed sql statement is then displayed in the same way
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.
We are printing JsonOperator
not the Token
. so it escaped 😅
Signed-off-by: password <rbalajis25@gmail.com>
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.
Thanks @poonai !
arrow
are used to represent nested field of json.This PR adds support to parse identifier which are separated using
arrow
Signed-off-by: password rbalajis25@gmail.com