mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-09-27 07:59:11 +00:00
Fixed the bug that the access parsing is wrong when multiple query conditions contain arrays or map. (#433)
This commit is contained in:
parent
6b55e51101
commit
497a3b0e1b
2 changed files with 71 additions and 21 deletions
|
@ -1285,7 +1285,7 @@ impl<'a> Parser<'a> {
|
||||||
Token::Mul | Token::Div | Token::Mod | Token::StringConcat => Ok(40),
|
Token::Mul | Token::Div | Token::Mod | Token::StringConcat => Ok(40),
|
||||||
Token::DoubleColon => Ok(50),
|
Token::DoubleColon => Ok(50),
|
||||||
Token::ExclamationMark => Ok(50),
|
Token::ExclamationMark => Ok(50),
|
||||||
Token::LBracket => Ok(10),
|
Token::LBracket => Ok(50),
|
||||||
_ => Ok(0),
|
_ => Ok(0),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,17 +18,23 @@ mod test_utils;
|
||||||
|
|
||||||
use test_utils::*;
|
use test_utils::*;
|
||||||
|
|
||||||
use sqlparser::ast::Expr::{Identifier, MapAccess};
|
use sqlparser::ast::Expr::{BinaryOp, Identifier, MapAccess};
|
||||||
|
use sqlparser::ast::Ident;
|
||||||
|
use sqlparser::ast::SelectItem::UnnamedExpr;
|
||||||
|
use sqlparser::ast::TableFactor::Table;
|
||||||
use sqlparser::ast::*;
|
use sqlparser::ast::*;
|
||||||
|
|
||||||
use sqlparser::dialect::ClickHouseDialect;
|
use sqlparser::dialect::ClickHouseDialect;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_map_access_expr() {
|
fn parse_map_access_expr() {
|
||||||
let sql = r#"SELECT string_values[indexOf(string_names, 'endpoint')] FROM foos"#;
|
let sql = r#"SELECT string_values[indexOf(string_names, 'endpoint')] FROM foos WHERE id = 'test' AND string_value[indexOf(string_name, 'app')] <> 'foo'"#;
|
||||||
let select = clickhouse().verified_only_select(sql);
|
let select = clickhouse().verified_only_select(sql);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
&MapAccess {
|
Select {
|
||||||
|
distinct: false,
|
||||||
|
top: None,
|
||||||
|
projection: vec![UnnamedExpr(MapAccess {
|
||||||
column: Box::new(Identifier(Ident {
|
column: Box::new(Identifier(Ident {
|
||||||
value: "string_values".to_string(),
|
value: "string_values".to_string(),
|
||||||
quote_style: None,
|
quote_style: None,
|
||||||
|
@ -46,8 +52,52 @@ fn parse_map_access_expr() {
|
||||||
over: None,
|
over: None,
|
||||||
distinct: false,
|
distinct: false,
|
||||||
})],
|
})],
|
||||||
|
})],
|
||||||
|
from: vec![TableWithJoins {
|
||||||
|
relation: Table {
|
||||||
|
name: ObjectName(vec![Ident::new("foos")]),
|
||||||
|
alias: None,
|
||||||
|
args: vec![],
|
||||||
|
with_hints: vec![],
|
||||||
},
|
},
|
||||||
expr_from_projection(only(&select.projection)),
|
joins: vec![]
|
||||||
|
}],
|
||||||
|
lateral_views: vec![],
|
||||||
|
selection: Some(BinaryOp {
|
||||||
|
left: Box::new(BinaryOp {
|
||||||
|
left: Box::new(Identifier(Ident::new("id"))),
|
||||||
|
op: BinaryOperator::Eq,
|
||||||
|
right: Box::new(Expr::Value(Value::SingleQuotedString("test".to_string())))
|
||||||
|
}),
|
||||||
|
op: BinaryOperator::And,
|
||||||
|
right: Box::new(BinaryOp {
|
||||||
|
left: Box::new(MapAccess {
|
||||||
|
column: Box::new(Identifier(Ident::new("string_value"))),
|
||||||
|
keys: vec![Expr::Function(Function {
|
||||||
|
name: ObjectName(vec![Ident::new("indexOf")]),
|
||||||
|
args: vec![
|
||||||
|
FunctionArg::Unnamed(FunctionArgExpr::Expr(Expr::Identifier(
|
||||||
|
Ident::new("string_name")
|
||||||
|
))),
|
||||||
|
FunctionArg::Unnamed(FunctionArgExpr::Expr(Expr::Value(
|
||||||
|
Value::SingleQuotedString("app".to_string())
|
||||||
|
))),
|
||||||
|
],
|
||||||
|
over: None,
|
||||||
|
distinct: false
|
||||||
|
})]
|
||||||
|
}),
|
||||||
|
op: BinaryOperator::NotEq,
|
||||||
|
right: Box::new(Expr::Value(Value::SingleQuotedString("foo".to_string())))
|
||||||
|
})
|
||||||
|
}),
|
||||||
|
group_by: vec![],
|
||||||
|
cluster_by: vec![],
|
||||||
|
distribute_by: vec![],
|
||||||
|
sort_by: vec![],
|
||||||
|
having: None
|
||||||
|
},
|
||||||
|
select
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue