You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "gaoqiangz (via GitHub)" <gi...@apache.org> on 2024/11/06 09:19:12 UTC
[PR] Add support for MSSQL's `XQuery` methods [datafusion-sqlparser-rs]
gaoqiangz opened a new pull request, #1500:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/1500
Supports `XQuery` methods:
```sql
SELECT STUFF((SELECT ',' + name FROM sys.objects FOR XML PATH(''), TYPE).value('.', 'NVARCHAR(MAX)'), 1, 1, '') AS T
SELECT CAST(column AS XML).value('.', 'NVARCHAR(MAX)') AS T
```
See <https://learn.microsoft.com/en-us/sql/t-sql/xml/xml-data-type-methods?view=sql-server-ver16>.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add support for MSSQL's `XQuery` methods [datafusion-sqlparser-rs]
Posted by "gaoqiangz (via GitHub)" <gi...@apache.org>.
gaoqiangz commented on code in PR #1500:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/1500#discussion_r1835275253
##########
src/ast/mod.rs:
##########
@@ -5593,6 +5609,21 @@ impl fmt::Display for FunctionArgumentClause {
}
}
+/// A method call
+#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
+#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
+#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
+pub struct Method {
+ pub expr: Box<Expr>,
+ pub method: Function,
+}
Review Comment:
good advice!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add support for MSSQL's `XQuery` methods [datafusion-sqlparser-rs]
Posted by "iffyio (via GitHub)" <gi...@apache.org>.
iffyio commented on code in PR #1500:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/1500#discussion_r1834691705
##########
src/parser/mod.rs:
##########
@@ -3532,9 +3580,9 @@ impl<'a> Parser<'a> {
}
/// Run a parser method `f`, reverting back to the current position if unsuccessful.
- pub fn maybe_parse<T, F>(&mut self, mut f: F) -> Result<Option<T>, ParserError>
+ pub fn maybe_parse<T, F>(&mut self, f: F) -> Result<Option<T>, ParserError>
where
- F: FnMut(&mut Parser) -> Result<T, ParserError>,
+ F: FnOnce(&mut Parser) -> Result<T, ParserError>,
Review Comment:
Oh was it something that required this change from fnmut to fnonce?
##########
src/ast/mod.rs:
##########
@@ -808,6 +808,21 @@ pub enum Expr {
},
/// Scalar function call e.g. `LEFT(foo, 5)`
Function(Function),
+ /// Arbitrary expr method call
+ ///
+ /// Syntax:
+ ///
+ /// `<arbitrary-expr>.<arbitrary-expr>.<arbitrary-expr>...`
+ ///
+ /// > `arbitrary-expr` can be any expression including a function call.
Review Comment:
Ah if i understand correctly I think this comment might not be accurate. My understanding is that first expression is indeed an arbitrary expression but subsequent expressions must be function calls?
##########
src/ast/mod.rs:
##########
@@ -5593,6 +5609,21 @@ impl fmt::Display for FunctionArgumentClause {
}
}
+/// A method call
+#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
+#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
+#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
+pub struct Method {
+ pub expr: Box<Expr>,
+ pub method: Function,
+}
Review Comment:
representation wise I'm thinking we could use something like
```rust
struct Method {
pub prefix: Box<Expr>,
pub suffix: Vec<Function>
}
```
Actually I'm not super sure naming wise of the properties, maybe we can come up with something better. But the main point/change I'm thinking would be the overall representation. Instead of using a nested datastructure for this, that doesn't seem required, the syntax is just a chain of expression so we can just use list to store that chain - and it maps nicely to how the parsing is done since its clear that the first part can be any expr, while subsequent components must be functions. wdyt?
##########
src/ast/mod.rs:
##########
@@ -808,6 +808,21 @@ pub enum Expr {
},
/// Scalar function call e.g. `LEFT(foo, 5)`
Function(Function),
+ /// Arbitrary expr method call
+ ///
+ /// Syntax:
+ ///
+ /// `<arbitrary-expr>.<arbitrary-expr>.<arbitrary-expr>...`
+ ///
+ /// > `arbitrary-expr` can be any expression including a function call.
+ ///
+ /// Example:
+ ///
+ /// ```sql
+ /// SELECT (SELECT ',' + name FROM sys.objects FOR XML PATH(''), TYPE).value('.','NVARCHAR(MAX)')
+ /// SELECT CONVERT(XML,'<Book>abc</Book>').value('.','NVARCHAR(MAX)').value('.','NVARCHAR(MAX)')
+ /// ```
+ Method(Method),
Review Comment:
Should we maybe call this MethodInvocation vs Method? thinking the latter might suggest similar to Function that we're looking to represent a method body
##########
src/parser/mod.rs:
##########
@@ -1258,23 +1258,27 @@ impl<'a> Parser<'a> {
}
};
self.expect_token(&Token::RParen)?;
- if !self.consume_token(&Token::Period) {
+ if let Some(expr) = self.try_parse_method(&expr)? {
Ok(expr)
} else {
- let tok = self.next_token();
- let key = match tok.token {
- Token::Word(word) => word.to_ident(),
- _ => {
- return parser_err!(
- format!("Expected identifier, found: {tok}"),
- tok.location
- )
- }
- };
- Ok(Expr::CompositeAccess {
- expr: Box::new(expr),
- key,
- })
+ if !self.consume_token(&Token::Period) {
+ Ok(expr)
+ } else {
Review Comment:
I think the else block can be unnested one level to be?
```rust
else if !self.consume_token(...) {
Ok(expr)
} else {
let tok = ...
}
```
##########
src/ast/mod.rs:
##########
@@ -808,6 +808,21 @@ pub enum Expr {
},
/// Scalar function call e.g. `LEFT(foo, 5)`
Function(Function),
+ /// Arbitrary expr method call
+ ///
+ /// Syntax:
+ ///
+ /// `<arbitrary-expr>.<arbitrary-expr>.<arbitrary-expr>...`
+ ///
+ /// > `arbitrary-expr` can be any expression including a function call.
+ ///
+ /// Example:
+ ///
+ /// ```sql
+ /// SELECT (SELECT ',' + name FROM sys.objects FOR XML PATH(''), TYPE).value('.','NVARCHAR(MAX)')
+ /// SELECT CONVERT(XML,'<Book>abc</Book>').value('.','NVARCHAR(MAX)').value('.','NVARCHAR(MAX)')
Review Comment:
I saw this doc that seems to describe the feature and could be useful to include here (for a lack of syntax spec from mssql)?
https://learn.microsoft.com/en-us/sql/relational-databases/server-management-objects-smo/create-program/calling-methods?view=sql-server-ver16
##########
src/parser/mod.rs:
##########
@@ -1345,6 +1354,45 @@ impl<'a> Parser<'a> {
})
}
+ fn try_parse_method(&mut self, expr: &Expr) -> Result<Option<Expr>, ParserError> {
Review Comment:
instead of passing a reference we can use owned values, such that here we return the same expression if we didn't parse anything. That would avoid cloning the expression. I think with that and the linear representation of the method expression, the parsing logic could be slightly simpler (since it won't need to mutate anything, given that the maybe_parse section would only deal with the suffix)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add support for MSSQL's `XQuery` methods [datafusion-sqlparser-rs]
Posted by "gaoqiangz (via GitHub)" <gi...@apache.org>.
gaoqiangz commented on PR #1500:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/1500#issuecomment-2461690779
I redesigned `CompositeFunction`, please take a look.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add support for MSSQL's `XQuery` methods [datafusion-sqlparser-rs]
Posted by "gaoqiangz (via GitHub)" <gi...@apache.org>.
gaoqiangz commented on PR #1500:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/1500#issuecomment-2466777884
@iffyio CI was fixed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add support for MSSQL's `XQuery` methods [datafusion-sqlparser-rs]
Posted by "yoavcloud (via GitHub)" <gi...@apache.org>.
yoavcloud commented on PR #1500:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/1500#issuecomment-2486684910
@gaoqiangz I've been working on a similar addition, it's great to see you beat me to it :-) One thing I added in my (unpublished) work is data-type specific methods. For example:
`SELECT geography::STGeomFromText('POLYGON((-122.358 47.653, -122.348 47.649, -122.348 47.658, -122.358 47.658, -122.358 47.653))', 4326).STAsText() FROM customers`
How would you support the `geography` data type here? In my code I added it as a `namespace` field. I'm trying to avoid expanding ObjectName. Do you think that can work in your code too?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add support for MSSQL's `XQuery` methods [datafusion-sqlparser-rs]
Posted by "iffyio (via GitHub)" <gi...@apache.org>.
iffyio commented on PR #1500:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/1500#issuecomment-2466266070
@gaoqiangz could you take a look at the doc building failure when you get the chance?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add support for MSSQL's `XQuery` methods [datafusion-sqlparser-rs]
Posted by "gaoqiangz (via GitHub)" <gi...@apache.org>.
gaoqiangz commented on code in PR #1500:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/1500#discussion_r1832131298
##########
src/parser/mod.rs:
##########
@@ -1269,6 +1269,50 @@ impl<'a> Parser<'a> {
_ => self.expected("an expression", next_token),
}?;
+ if dialect_of!(self is MsSqlDialect) {
+ // Convert `CompositeAccess` to `CompositeFunction` (MSSQL doesn't support `CompositeAccess` syntax)
+ // ```sql
+ // SELECT (SELECT ',' + name FROM sys.objects FOR XML PATH(''), TYPE).value('.','NVARCHAR(MAX)')
Review Comment:
`CompositeFunction` is similar to `CompositeAccess` but supports method call syntax, that supports method calls on subquery results (must be `XML` data type in MSSQL).
Maybe it would be better to make `CompositeFunction` a generic feature?
```rs
/// CompositeFunction
/// Syntax: `<arbitrary-expr>.<arbitrary-expr>.<arbitrary-expr>...`, `arbitrary-expr` can be any expr including a function call.
/// Example:
/// ```sql
/// SELECT (SELECT ',' + name FROM sys.objects FOR XML PATH(''), TYPE).value('.','NVARCHAR(MAX)')
/// SELECT CONVERT(XML,'<Book>abc</Book>').value('.','NVARCHAR(MAX)').value('.','NVARCHAR(MAX)')
/// ```
CompositeFunction {
expr: Box<Expr>,
name: Ident,
args: Vec<Expr>,
},
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add support for MSSQL's `XQuery` methods [datafusion-sqlparser-rs]
Posted by "gaoqiangz (via GitHub)" <gi...@apache.org>.
gaoqiangz commented on code in PR #1500:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/1500#discussion_r1832131298
##########
src/parser/mod.rs:
##########
@@ -1269,6 +1269,50 @@ impl<'a> Parser<'a> {
_ => self.expected("an expression", next_token),
}?;
+ if dialect_of!(self is MsSqlDialect) {
+ // Convert `CompositeAccess` to `CompositeFunction` (MSSQL doesn't support `CompositeAccess` syntax)
+ // ```sql
+ // SELECT (SELECT ',' + name FROM sys.objects FOR XML PATH(''), TYPE).value('.','NVARCHAR(MAX)')
Review Comment:
`CompositeFunction` is similar to `CompositeAccess` but supports method call syntax, that supports method calls on subquery results (must be `XML` data type in MSSQL).
Maybe it would be better to make `CompositeFunction` a generic feature?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add support for MSSQL's `XQuery` methods [datafusion-sqlparser-rs]
Posted by "lovasoa (via GitHub)" <gi...@apache.org>.
lovasoa commented on code in PR #1500:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/1500#discussion_r1832982378
##########
tests/sqlparser_common.rs:
##########
@@ -11387,6 +11387,372 @@ fn test_try_convert() {
dialects.verified_expr("TRY_CONVERT('foo', VARCHAR(MAX))");
}
+#[test]
+fn parse_composite_function() {
+ let sql = all_dialects().verified_only_select("SELECT STUFF((SELECT ',' + name FROM sys.objects FOR XML PATH(''), TYPE).value('.', 'NVARCHAR(MAX)'), 1, 1, '') AS T");
+ assert_eq!(
+ vec![SelectItem::ExprWithAlias {
+ expr: Expr::Function(Function {
+ name: ObjectName(vec![Ident {
+ value: "STUFF".into(),
+ quote_style: None
+ }]),
+ parameters: FunctionArguments::None,
+ args: FunctionArguments::List(FunctionArgumentList {
+ duplicate_treatment: None,
+ args: vec![
+ FunctionArg::Unnamed(FunctionArgExpr::Expr(Expr::CompositeFunction(
+ CompositeFunction {
+ left: Expr::Subquery(
+ Query {
+ with: None,
+ body: SetExpr::Select(
+ Select {
+ distinct: None,
+ top: None,
+ top_before_distinct: false,
+ projection: vec![SelectItem::UnnamedExpr(
+ Expr::BinaryOp {
+ left: Expr::Value(
+ Value::SingleQuotedString(",".into())
+ )
+ .into(),
+ op: BinaryOperator::Plus,
+ right: Expr::Identifier(Ident {
+ value: "name".into(),
+ quote_style: None
+ })
+ .into()
+ }
+ )],
+ into: None,
+ from: vec![TableWithJoins {
+ relation: TableFactor::Table {
+ name: ObjectName(vec![
+ Ident {
+ value: "sys".into(),
+ quote_style: None,
+ },
+ Ident {
+ value: "objects".into(),
+ quote_style: None,
+ }
+ ]),
+ alias: None,
+ args: None,
+ with_hints: vec![],
+ version: None,
+ with_ordinality: false,
+ partitions: vec![]
+ },
+ joins: vec![]
+ }],
+ lateral_views: vec![],
+ prewhere: None,
+ selection: None,
+ group_by: GroupByExpr::Expressions(vec![], vec![]),
+ cluster_by: vec![],
+ distribute_by: vec![],
+ sort_by: vec![],
+ having: None,
+ named_window: vec![],
+ qualify: None,
+ window_before_qualify: false,
+ value_table_mode: None,
+ connect_by: None,
+ }
+ .into()
+ )
+ .into(),
+ order_by: None,
+ limit: None,
+ limit_by: vec![],
+ offset: None,
+ fetch: None,
+ locks: vec![],
+ for_clause: Some(ForClause::Xml {
+ for_xml: ForXml::Path(Some("".into())),
+ elements: false,
+ binary_base64: false,
+ root: None,
+ r#type: true
+ }),
+ settings: None,
+ format_clause: None,
+ }
+ .into()
+ )
+ .into(),
+ right: Function {
+ name: ObjectName(vec![Ident {
+ value: "value".into(),
+ quote_style: None
+ }]),
+ parameters: FunctionArguments::None,
+ args: FunctionArguments::List(FunctionArgumentList {
+ duplicate_treatment: None,
+ args: vec![
+ FunctionArg::Unnamed(FunctionArgExpr::Expr(
+ Expr::Value(Value::SingleQuotedString(".".into()))
+ )),
+ FunctionArg::Unnamed(FunctionArgExpr::Expr(
+ Expr::Value(Value::SingleQuotedString(
+ "NVARCHAR(MAX)".into()
+ ))
+ ))
+ ],
+ clauses: vec![]
+ }),
+ filter: None,
+ null_treatment: None,
+ over: None,
+ within_group: vec![]
+ }
+ }
+ ))),
+ FunctionArg::Unnamed(FunctionArgExpr::Expr(Expr::Value(number("1")))),
+ FunctionArg::Unnamed(FunctionArgExpr::Expr(Expr::Value(number("1")))),
+ FunctionArg::Unnamed(FunctionArgExpr::Expr(Expr::Value(
+ Value::SingleQuotedString("".into())
+ )))
+ ],
+ clauses: vec![]
+ }),
+ filter: None,
+ null_treatment: None,
+ over: None,
+ within_group: vec![]
+ })
+ .into(),
+ alias: Ident {
+ value: "T".into(),
+ quote_style: None
+ }
+ }],
+ sql.projection
+ );
+ let sql = all_dialects()
+ .verified_only_select("SELECT CAST(column AS XML).value('.', 'NVARCHAR(MAX)') AS T");
+ assert_eq!(
+ vec![SelectItem::ExprWithAlias {
+ expr: Expr::CompositeFunction(CompositeFunction {
+ left: Expr::Cast {
+ kind: CastKind::Cast,
+ expr: Expr::Identifier(Ident {
+ value: "column".into(),
+ quote_style: None
+ })
+ .into(),
+ data_type: DataType::Custom(
+ ObjectName(vec![Ident {
+ value: "XML".into(),
+ quote_style: None
+ }]),
+ vec![]
+ ),
+ format: None
+ }
+ .into(),
+ right: Function {
+ name: ObjectName(vec![Ident {
+ value: "value".into(),
+ quote_style: None
+ }]),
+ parameters: FunctionArguments::None,
+ args: FunctionArguments::List(FunctionArgumentList {
+ duplicate_treatment: None,
+ args: vec![
+ FunctionArg::Unnamed(FunctionArgExpr::Expr(Expr::Value(
+ Value::SingleQuotedString(".".into())
+ ))),
+ FunctionArg::Unnamed(FunctionArgExpr::Expr(Expr::Value(
+ Value::SingleQuotedString("NVARCHAR(MAX)".into())
+ )))
+ ],
+ clauses: vec![]
+ }),
+ filter: None,
+ null_treatment: None,
+ over: None,
+ within_group: vec![]
+ }
+ })
+ .into(),
+ alias: Ident {
+ value: "T".into(),
+ quote_style: None
+ }
+ }],
+ sql.projection
+ );
+ let dialects =
+ all_dialects_where(|d| d.supports_try_convert() && d.convert_type_before_value());
+ let sql = dialects.verified_only_select("SELECT CONVERT(XML, '<Book>abc</Book>').value('.', 'NVARCHAR(MAX)').value('.', 'NVARCHAR(MAX)') AS T");
+ assert_eq!(
+ vec![SelectItem::ExprWithAlias {
+ expr: Expr::CompositeFunction(CompositeFunction {
+ left: Expr::CompositeFunction(CompositeFunction {
+ left: Expr::Convert {
+ expr: Expr::Value(Value::SingleQuotedString("<Book>abc</Book>".into()))
+ .into(),
+ is_try: false,
+ data_type: Some(DataType::Custom(
+ ObjectName(vec![Ident {
+ value: "XML".into(),
+ quote_style: None
+ }]),
+ vec![]
+ )),
+ charset: None,
+ target_before_value: true,
+ styles: vec![]
+ }
+ .into(),
+ right: Function {
+ name: ObjectName(vec![Ident {
+ value: "value".into(),
+ quote_style: None
+ }]),
+ parameters: FunctionArguments::None,
+ args: FunctionArguments::List(FunctionArgumentList {
+ duplicate_treatment: None,
+ args: vec![
+ FunctionArg::Unnamed(FunctionArgExpr::Expr(Expr::Value(
+ Value::SingleQuotedString(".".into())
+ ))),
+ FunctionArg::Unnamed(FunctionArgExpr::Expr(Expr::Value(
+ Value::SingleQuotedString("NVARCHAR(MAX)".into())
+ )))
+ ],
+ clauses: vec![]
+ }),
+ filter: None,
+ null_treatment: None,
+ over: None,
+ within_group: vec![]
+ }
+ })
+ .into(),
+ right: Function {
+ name: ObjectName(vec![Ident {
+ value: "value".into(),
+ quote_style: None
+ }]),
+ parameters: FunctionArguments::None,
+ args: FunctionArguments::List(FunctionArgumentList {
+ duplicate_treatment: None,
+ args: vec![
+ FunctionArg::Unnamed(FunctionArgExpr::Expr(Expr::Value(
+ Value::SingleQuotedString(".".into())
+ ))),
+ FunctionArg::Unnamed(FunctionArgExpr::Expr(Expr::Value(
+ Value::SingleQuotedString("NVARCHAR(MAX)".into())
+ )))
+ ],
+ clauses: vec![]
+ }),
+ filter: None,
+ null_treatment: None,
+ over: None,
+ within_group: vec![]
+ }
+ }),
+ alias: Ident {
+ value: "T".into(),
+ quote_style: None
+ }
+ }],
+ sql.projection
+ );
Review Comment:
I find these tests hard to follow. And they will need to be updated even when the ast changes in places completely unrelated to Expr::CompositeFunction.
Maybe you could just test the new syntax introduced here with small precise asserts that test just a single thing ? Like:
```rs
assert!eq!(verified_expr("convert(XML, '<x/>').query('x')", some_small_ast);
```
If you want to ensure some more complex queries always parse, you could add some verified_only_select, without adding an assert on the result.
This should make the tests easier to understand, this pr easier to review, and reduce the burden of maintaining these tests in the future.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add support for MSSQL's `XQuery` methods [datafusion-sqlparser-rs]
Posted by "gaoqiangz (via GitHub)" <gi...@apache.org>.
gaoqiangz commented on PR #1500:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/1500#issuecomment-2466063532
The code has been rewritten for the new `Method` definition, seems more reasonable:
```rs
pub struct Method {
pub expr: Box<Expr>,
// always non-empty
pub method_chain: Vec<Function>,
}
```
Any other comments?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add support for MSSQL's `XQuery` methods [datafusion-sqlparser-rs]
Posted by "lovasoa (via GitHub)" <gi...@apache.org>.
lovasoa commented on code in PR #1500:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/1500#discussion_r1832990576
##########
src/ast/mod.rs:
##########
@@ -808,6 +808,21 @@ pub enum Expr {
},
/// Scalar function call e.g. `LEFT(foo, 5)`
Function(Function),
+ /// CompositeFunction (function chain)
+ ///
+ /// Syntax:
+ ///
+ /// `<arbitrary-expr>.<arbitrary-expr>.<arbitrary-expr>...`
+ ///
+ /// > `arbitrary-expr` can be any expression including a function call.
+ ///
+ /// Example:
+ ///
+ /// ```sql
+ /// SELECT (SELECT ',' + name FROM sys.objects FOR XML PATH(''), TYPE).value('.','NVARCHAR(MAX)')
+ /// SELECT CONVERT(XML,'<Book>abc</Book>').value('.','NVARCHAR(MAX)')
+ /// ```
+ CompositeFunction(CompositeFunction),
Review Comment:
Maybe we can find a better name ? Something like `MethodCall { expr, method }` instead of `CompositeFunction { left, right }`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add support for MSSQL's `XQuery` methods [datafusion-sqlparser-rs]
Posted by "iffyio (via GitHub)" <gi...@apache.org>.
iffyio commented on code in PR #1500:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/1500#discussion_r1834864224
##########
src/ast/mod.rs:
##########
@@ -808,6 +808,21 @@ pub enum Expr {
},
/// Scalar function call e.g. `LEFT(foo, 5)`
Function(Function),
+ /// Arbitrary expr method call
+ ///
+ /// Syntax:
+ ///
+ /// `<arbitrary-expr>.<arbitrary-expr>.<arbitrary-expr>...`
+ ///
+ /// > `arbitrary-expr` can be any expression including a function call.
+ ///
+ /// Example:
+ ///
+ /// ```sql
+ /// SELECT (SELECT ',' + name FROM sys.objects FOR XML PATH(''), TYPE).value('.','NVARCHAR(MAX)')
+ /// SELECT CONVERT(XML,'<Book>abc</Book>').value('.','NVARCHAR(MAX)').value('.','NVARCHAR(MAX)')
+ /// ```
+ Method(Method),
Review Comment:
Actually I think never mind this comment, realised this is indeed similar to Function as a function call, not sure why I was thinking of a different Function body
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add support for MSSQL's `XQuery` methods [datafusion-sqlparser-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #1500:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/1500#issuecomment-2477356423
🚀
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add support for MSSQL's `XQuery` methods [datafusion-sqlparser-rs]
Posted by "gaoqiangz (via GitHub)" <gi...@apache.org>.
gaoqiangz commented on PR #1500:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/1500#issuecomment-2464386606
I added `supports_methods` to the `Dialect` trait and `try_parse_method` to the `Parser`, this might be better suited for different scenarios and doesn't break existing behavior.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add support for MSSQL's `XQuery` methods [datafusion-sqlparser-rs]
Posted by "iffyio (via GitHub)" <gi...@apache.org>.
iffyio commented on code in PR #1500:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/1500#discussion_r1835312544
##########
src/parser/mod.rs:
##########
@@ -1345,6 +1355,38 @@ impl<'a> Parser<'a> {
})
}
+ /// Parses method call expression
+ ///
+ /// Returns `Result<{parsed method-call-expr},{orig_expr}>`
+ fn try_parse_method(&mut self, orig_expr: Expr) -> Result<Result<Expr, Expr>, ParserError> {
+ if !self.dialect.supports_methods() {
+ return Ok(Err(orig_expr));
+ }
+ let method_chain = self.maybe_parse(|p| {
Review Comment:
I think we can simplify the return type a bit if we do something like
```rust
let method_chain = self.maybe_parse(|p| {
let mut method_chain = Vec::new();
loop {
// ...
method_chain.push(func);
}
if method_chain.is_empty() {
p.expected("function")
} else {
Ok(method_chain)
}
})?;
if let Some(method_chain) {
Ok(Expr::Method{Method { expr, method_chain }})
} else {
Ok(expr)
}
```
that would remove the nested result type `Result<Result<Expr, Expr>>` -> `Result<Expr>` as usual
##########
src/ast/mod.rs:
##########
@@ -808,6 +808,21 @@ pub enum Expr {
},
/// Scalar function call e.g. `LEFT(foo, 5)`
Function(Function),
+ /// Arbitrary expr method call
+ ///
+ /// Syntax:
+ ///
+ /// `<arbitrary-expr>.<arbitrary-expr>.<arbitrary-expr>...`
+ ///
+ /// > `arbitrary-expr` can be any expression including a function call.
+ ///
+ /// Example:
+ ///
+ /// ```sql
+ /// SELECT (SELECT ',' + name FROM sys.objects FOR XML PATH(''), TYPE).value('.','NVARCHAR(MAX)')
+ /// SELECT CONVERT(XML,'<Book>abc</Book>').value('.','NVARCHAR(MAX)').value('.','NVARCHAR(MAX)')
Review Comment:
Ah my bad, wrong link I was supposed to paste this one
https://learn.microsoft.com/en-us/sql/t-sql/xml/xml-data-type-methods?view=sql-server-ver16
in that it mentions explicitly the methods functionality, even though the doc is specific to xml
##########
src/parser/mod.rs:
##########
@@ -1258,23 +1258,28 @@ impl<'a> Parser<'a> {
}
};
self.expect_token(&Token::RParen)?;
- if !self.consume_token(&Token::Period) {
- Ok(expr)
- } else {
- let tok = self.next_token();
- let key = match tok.token {
- Token::Word(word) => word.to_ident(),
- _ => {
- return parser_err!(
- format!("Expected identifier, found: {tok}"),
- tok.location
- )
+ match self.try_parse_method(expr)? {
Review Comment:
left a suggestion to avoid the nested result, thinking with that it should be possible to return the expr as is and then here we avoid the need to match: e.g.
```rust
let expr = self.try_parse_method(expr)?;
if !self.consume_token(...) {
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add support for MSSQL's `XQuery` methods [datafusion-sqlparser-rs]
Posted by "gaoqiangz (via GitHub)" <gi...@apache.org>.
gaoqiangz commented on code in PR #1500:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/1500#discussion_r1835282237
##########
src/parser/mod.rs:
##########
@@ -3532,9 +3580,9 @@ impl<'a> Parser<'a> {
}
/// Run a parser method `f`, reverting back to the current position if unsuccessful.
- pub fn maybe_parse<T, F>(&mut self, mut f: F) -> Result<Option<T>, ParserError>
+ pub fn maybe_parse<T, F>(&mut self, f: F) -> Result<Option<T>, ParserError>
where
- F: FnMut(&mut Parser) -> Result<T, ParserError>,
+ F: FnOnce(&mut Parser) -> Result<T, ParserError>,
Review Comment:
This change is no longer needed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add support for MSSQL's `XQuery` methods [datafusion-sqlparser-rs]
Posted by "gaoqiangz (via GitHub)" <gi...@apache.org>.
gaoqiangz commented on code in PR #1500:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/1500#discussion_r1832134100
##########
src/ast/mod.rs:
##########
@@ -560,6 +560,13 @@ pub enum Expr {
expr: Box<Expr>,
key: Ident,
},
+ /// CompositeFunction (mssql) e.g. SELECT (SELECT ',' + name FROM sys.objects FOR XML PATH(''), TYPE).value('.','NVARCHAR(MAX)')
+ /// <https://learn.microsoft.com/en-us/sql/t-sql/xml/xml-data-type-methods?view=sql-server-ver16>
Review Comment:
There is no special syntax definition, just ordinary method calling syntax.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add support for MSSQL's `XQuery` methods [datafusion-sqlparser-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #1500:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/1500
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add support for MSSQL's `XQuery` methods [datafusion-sqlparser-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #1500:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/1500#issuecomment-2477357000
Thanks again @gaoqiangz and @lovasoa and @iffyio
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add support for MSSQL's `XQuery` methods [datafusion-sqlparser-rs]
Posted by "iffyio (via GitHub)" <gi...@apache.org>.
iffyio commented on code in PR #1500:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/1500#discussion_r1833051964
##########
src/parser/mod.rs:
##########
@@ -1271,10 +1271,22 @@ impl<'a> Parser<'a> {
)
}
};
- Ok(Expr::CompositeAccess {
- expr: Box::new(expr),
- key,
- })
+ if self.consume_token(&Token::LParen) {
+ self.prev_token();
+ let func = match self.parse_function(ObjectName(vec![key]))? {
+ Expr::Function(func) => func,
+ _ => unreachable!(),
Review Comment:
Oh I think this panic won't be desirable here in any case given we don't have an invariant and `self.parse_function` could be in its own right to return something other than `Expr::Function` in a different situation.
Also given the nature of the syntax that we don't have any special keyword to match on, feels a bit uneasy that we could end up parsing sql incorrectly in other dialects in ambiguous cases.
could we do similar to e.g. [try_parse_lambda](https://github.com/apache/datafusion-sqlparser-rs/blob/main/src/parser/mod.rs#L1332-L1346) where this is both specific to mssql dialect, as well as potentially relying on `self.maybe_parse` to bail out if the lookahead isn't what we expect?
##########
src/parser/mod.rs:
##########
@@ -1288,6 +1300,35 @@ impl<'a> Parser<'a> {
_ => self.expected("an expression", next_token),
}?;
+ // Composite function chain
+ while matches!(
+ expr,
+ Expr::Function(_)
+ | Expr::CompositeFunction { .. }
+ | Expr::Cast { .. }
+ | Expr::Convert { .. }
Review Comment:
hmm some of the entries seem a bit arbitary (like cast, convert)? I wonder if instead of having this block as a special case, piggy-backing on my other comment to do similar to the lambda parsing, we could probably have the chain continuation logic in the same helper function that gets called once here (as in the function knows to parse not just a single function but also continuation/suffix if present of the full expression)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add support for MSSQL's `XQuery` methods [datafusion-sqlparser-rs]
Posted by "gaoqiangz (via GitHub)" <gi...@apache.org>.
gaoqiangz commented on code in PR #1500:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/1500#discussion_r1832131298
##########
src/parser/mod.rs:
##########
@@ -1269,6 +1269,50 @@ impl<'a> Parser<'a> {
_ => self.expected("an expression", next_token),
}?;
+ if dialect_of!(self is MsSqlDialect) {
+ // Convert `CompositeAccess` to `CompositeFunction` (MSSQL doesn't support `CompositeAccess` syntax)
+ // ```sql
+ // SELECT (SELECT ',' + name FROM sys.objects FOR XML PATH(''), TYPE).value('.','NVARCHAR(MAX)')
Review Comment:
`CompositeFunction` is similar to `CompositeAccess` but supports method call syntax, that supports method calls on subquery results (must be `XML` data type in MSSQL).
Maybe it would be better to make `CompositeFunction` a generic feature?
```rs
/// CompositeFunction
/// Syntax: `<arbitrary-expr>.<arbitrary-expr>.<arbitrary-expr>...`, `arbitrary-expr` can be any expr including a function call.
/// Example:
/// ```sql
/// SELECT (SELECT ',' + name FROM sys.objects FOR XML PATH(''), TYPE).value('.','NVARCHAR(MAX)')
/// SELECT CONVERT(XML,'<Book>abc</Book>').value('.','NVARCHAR(MAX)')
/// ```
CompositeFunction {
expr: Box<Expr>,
name: Ident,
args: Vec<Expr>,
},
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add support for MSSQL's `XQuery` methods [datafusion-sqlparser-rs]
Posted by "iffyio (via GitHub)" <gi...@apache.org>.
iffyio commented on code in PR #1500:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/1500#discussion_r1831422229
##########
src/parser/mod.rs:
##########
@@ -1269,6 +1269,50 @@ impl<'a> Parser<'a> {
_ => self.expected("an expression", next_token),
}?;
+ if dialect_of!(self is MsSqlDialect) {
+ // Convert `CompositeAccess` to `CompositeFunction` (MSSQL doesn't support `CompositeAccess` syntax)
+ // ```sql
+ // SELECT (SELECT ',' + name FROM sys.objects FOR XML PATH(''), TYPE).value('.','NVARCHAR(MAX)')
Review Comment:
is it possible to represent this syntax as the existing `Expr::JsonAccess`? I'm assuming that isn't the case since otherwise the the feature will be already be supported. If not its not super clear to me what exactly is the composite access we're introducing with this PR - My assumption is that its adding support for syntax like `<arbitrary-expr>.<arbitrary-expr>.<arbitrary-expr>...` and so on where `arbitrary-expr` can be any expr including a function call. Like in the example `SELECT CONVERT(XML,'<Book>abc</Book>').value('.','NVARCHAR(MAX)')`
##########
src/ast/mod.rs:
##########
@@ -560,6 +560,13 @@ pub enum Expr {
expr: Box<Expr>,
key: Ident,
},
+ /// CompositeFunction (mssql) e.g. SELECT (SELECT ',' + name FROM sys.objects FOR XML PATH(''), TYPE).value('.','NVARCHAR(MAX)')
+ /// <https://learn.microsoft.com/en-us/sql/t-sql/xml/xml-data-type-methods?view=sql-server-ver16>
Review Comment:
```suggestion
/// CompositeFunction [mssql]
/// Example:
/// ```sql
/// SELECT (SELECT ',' + name FROM sys.objects FOR XML PATH(''), TYPE).value('.','NVARCHAR(MAX)')
/// ```
/// [mssql]: https://learn.microsoft.com/en-us/sql/t-sql/xml/xml-data-type-methods?view=sql-server-ver16
```
Something similar regarding doc formatting I'm thinking.
Also double checking: is the link correct, the doc on the link describes the xml data type and its not super obvious to me if/how it relates to the composite function feature
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add support for MSSQL's `XQuery` methods [datafusion-sqlparser-rs]
Posted by "gaoqiangz (via GitHub)" <gi...@apache.org>.
gaoqiangz commented on code in PR #1500:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/1500#discussion_r1835285111
##########
src/ast/mod.rs:
##########
@@ -808,6 +808,21 @@ pub enum Expr {
},
/// Scalar function call e.g. `LEFT(foo, 5)`
Function(Function),
+ /// Arbitrary expr method call
+ ///
+ /// Syntax:
+ ///
+ /// `<arbitrary-expr>.<arbitrary-expr>.<arbitrary-expr>...`
+ ///
+ /// > `arbitrary-expr` can be any expression including a function call.
+ ///
+ /// Example:
+ ///
+ /// ```sql
+ /// SELECT (SELECT ',' + name FROM sys.objects FOR XML PATH(''), TYPE).value('.','NVARCHAR(MAX)')
+ /// SELECT CONVERT(XML,'<Book>abc</Book>').value('.','NVARCHAR(MAX)').value('.','NVARCHAR(MAX)')
Review Comment:
This document is not about T-SQL.
Indeed, no exact syntax definition was found, another related documents like this:
https://learn.microsoft.com/en-us/sql/xquery/xquery-language-reference-sql-server?view=sql-server-ver16&redirectedfrom=MSDN
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add support for MSSQL's `XQuery` methods [datafusion-sqlparser-rs]
Posted by "gaoqiangz (via GitHub)" <gi...@apache.org>.
gaoqiangz commented on code in PR #1500:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/1500#discussion_r1835322261
##########
src/ast/mod.rs:
##########
@@ -808,6 +808,21 @@ pub enum Expr {
},
/// Scalar function call e.g. `LEFT(foo, 5)`
Function(Function),
+ /// Arbitrary expr method call
+ ///
+ /// Syntax:
+ ///
+ /// `<arbitrary-expr>.<arbitrary-expr>.<arbitrary-expr>...`
+ ///
+ /// > `arbitrary-expr` can be any expression including a function call.
+ ///
+ /// Example:
+ ///
+ /// ```sql
+ /// SELECT (SELECT ',' + name FROM sys.objects FOR XML PATH(''), TYPE).value('.','NVARCHAR(MAX)')
+ /// SELECT CONVERT(XML,'<Book>abc</Book>').value('.','NVARCHAR(MAX)').value('.','NVARCHAR(MAX)')
Review Comment:
This link is what I mentioned in the topic. I'll add it to the comments.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add support for MSSQL's `XQuery` methods [datafusion-sqlparser-rs]
Posted by "iffyio (via GitHub)" <gi...@apache.org>.
iffyio commented on code in PR #1500:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/1500#discussion_r1835436155
##########
src/ast/mod.rs:
##########
@@ -808,6 +808,21 @@ pub enum Expr {
},
/// Scalar function call e.g. `LEFT(foo, 5)`
Function(Function),
+ /// Arbitrary expr method call
+ ///
+ /// Syntax:
+ ///
+ /// `<arbitrary-expr>.<arbitrary-expr>.<arbitrary-expr>...`
+ ///
+ /// > `arbitrary-expr` can be any expression including a function call.
+ ///
+ /// Example:
+ ///
+ /// ```sql
+ /// SELECT (SELECT ',' + name FROM sys.objects FOR XML PATH(''), TYPE).value('.','NVARCHAR(MAX)')
+ /// SELECT CONVERT(XML,'<Book>abc</Book>').value('.','NVARCHAR(MAX)').value('.','NVARCHAR(MAX)')
Review Comment:
Ah indeed it was :+1:
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org