mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-09-26 23:49:10 +00:00
Fix table alias parsing regression in 0.31.0 by backing out redshift column definition list (#827)
* Fix table alias parsing regression
* Revert "Support redshift's columns definition list for system information functions (#769)"
This reverts commit c35dcc93a7
.
This commit is contained in:
parent
d69b875367
commit
7f4c9132d7
14 changed files with 37 additions and 194 deletions
|
@ -4150,35 +4150,6 @@ impl fmt::Display for SearchModifier {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A result table definition i.e. `cols(view_schema name, view_name name, col_name name, col_type varchar, col_num int)`
|
|
||||||
/// used for redshift functions: pg_get_late_binding_view_cols, pg_get_cols, pg_get_grantee_by_iam_role,pg_get_iam_role_by_user
|
|
||||||
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
|
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
||||||
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
|
|
||||||
pub struct TableAliasDefinition {
|
|
||||||
pub name: Ident,
|
|
||||||
pub args: Vec<IdentPair>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Display for TableAliasDefinition {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
write!(f, "{}({})", self.name, display_comma_separated(&self.args))?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
|
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
||||||
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
|
|
||||||
pub struct IdentPair(pub Ident, pub Ident);
|
|
||||||
|
|
||||||
impl fmt::Display for IdentPair {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
write!(f, "{} {}", self.0, self.1)?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
|
@ -631,9 +631,6 @@ pub enum TableFactor {
|
||||||
/// vector of arguments, in the case of a table-valued function call,
|
/// vector of arguments, in the case of a table-valued function call,
|
||||||
/// whereas it's `None` in the case of a regular table name.
|
/// whereas it's `None` in the case of a regular table name.
|
||||||
args: Option<Vec<FunctionArg>>,
|
args: Option<Vec<FunctionArg>>,
|
||||||
/// A table alias definition i.e. `cols(view_schema name, view_name name, col_name name, col_type varchar, col_num int)`
|
|
||||||
/// used for redshift functions: pg_get_late_binding_view_cols, pg_get_cols, pg_get_grantee_by_iam_role,pg_get_iam_role_by_user)
|
|
||||||
columns_definition: Option<TableAliasDefinition>,
|
|
||||||
/// MSSQL-specific `WITH (...)` hints such as NOLOCK.
|
/// MSSQL-specific `WITH (...)` hints such as NOLOCK.
|
||||||
with_hints: Vec<Expr>,
|
with_hints: Vec<Expr>,
|
||||||
},
|
},
|
||||||
|
@ -682,7 +679,6 @@ impl fmt::Display for TableFactor {
|
||||||
name,
|
name,
|
||||||
alias,
|
alias,
|
||||||
args,
|
args,
|
||||||
columns_definition,
|
|
||||||
with_hints,
|
with_hints,
|
||||||
} => {
|
} => {
|
||||||
write!(f, "{name}")?;
|
write!(f, "{name}")?;
|
||||||
|
@ -692,9 +688,6 @@ impl fmt::Display for TableFactor {
|
||||||
if let Some(alias) = alias {
|
if let Some(alias) = alias {
|
||||||
write!(f, " AS {alias}")?;
|
write!(f, " AS {alias}")?;
|
||||||
}
|
}
|
||||||
if let Some(columns_definition) = columns_definition {
|
|
||||||
write!(f, " {columns_definition}")?;
|
|
||||||
}
|
|
||||||
if !with_hints.is_empty() {
|
if !with_hints.is_empty() {
|
||||||
write!(f, " WITH ({})", display_comma_separated(with_hints))?;
|
write!(f, " WITH ({})", display_comma_separated(with_hints))?;
|
||||||
}
|
}
|
||||||
|
|
|
@ -671,7 +671,6 @@ pub const RESERVED_FOR_TABLE_ALIAS: &[Keyword] = &[
|
||||||
Keyword::OUTER,
|
Keyword::OUTER,
|
||||||
Keyword::SET,
|
Keyword::SET,
|
||||||
Keyword::QUALIFY,
|
Keyword::QUALIFY,
|
||||||
Keyword::AS,
|
|
||||||
];
|
];
|
||||||
|
|
||||||
/// Can't be used as a column alias, so that `SELECT <expr> alias`
|
/// Can't be used as a column alias, so that `SELECT <expr> alias`
|
||||||
|
@ -701,5 +700,4 @@ pub const RESERVED_FOR_COLUMN_ALIAS: &[Keyword] = &[
|
||||||
// Reserved only as a column alias in the `SELECT` clause
|
// Reserved only as a column alias in the `SELECT` clause
|
||||||
Keyword::FROM,
|
Keyword::FROM,
|
||||||
Keyword::INTO,
|
Keyword::INTO,
|
||||||
Keyword::AS,
|
|
||||||
];
|
];
|
||||||
|
|
|
@ -5731,7 +5731,6 @@ impl<'a> Parser<'a> {
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
let columns_definition = self.parse_redshift_columns_definition_list()?;
|
|
||||||
let alias = self.parse_optional_table_alias(keywords::RESERVED_FOR_TABLE_ALIAS)?;
|
let alias = self.parse_optional_table_alias(keywords::RESERVED_FOR_TABLE_ALIAS)?;
|
||||||
// MSSQL-specific table hints:
|
// MSSQL-specific table hints:
|
||||||
let mut with_hints = vec![];
|
let mut with_hints = vec![];
|
||||||
|
@ -5748,56 +5747,11 @@ impl<'a> Parser<'a> {
|
||||||
name,
|
name,
|
||||||
alias,
|
alias,
|
||||||
args,
|
args,
|
||||||
columns_definition,
|
|
||||||
with_hints,
|
with_hints,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_redshift_columns_definition_list(
|
|
||||||
&mut self,
|
|
||||||
) -> Result<Option<TableAliasDefinition>, ParserError> {
|
|
||||||
if !dialect_of!(self is RedshiftSqlDialect | GenericDialect) {
|
|
||||||
return Ok(None);
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(col_definition_list_name) = self.parse_optional_columns_definition_list_alias()
|
|
||||||
{
|
|
||||||
if self.consume_token(&Token::LParen) {
|
|
||||||
let names = self.parse_comma_separated(Parser::parse_ident_pair)?;
|
|
||||||
self.expect_token(&Token::RParen)?;
|
|
||||||
Ok(Some(TableAliasDefinition {
|
|
||||||
name: col_definition_list_name,
|
|
||||||
args: names,
|
|
||||||
}))
|
|
||||||
} else {
|
|
||||||
self.prev_token();
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn parse_optional_columns_definition_list_alias(&mut self) -> Option<Ident> {
|
|
||||||
match self.next_token().token {
|
|
||||||
Token::Word(w) if !keywords::RESERVED_FOR_TABLE_ALIAS.contains(&w.keyword) => {
|
|
||||||
Some(w.to_ident())
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
self.prev_token();
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn parse_ident_pair(&mut self) -> Result<IdentPair, ParserError> {
|
|
||||||
Ok(IdentPair(
|
|
||||||
self.parse_identifier()?,
|
|
||||||
self.parse_identifier()?,
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn parse_derived_table_factor(
|
pub fn parse_derived_table_factor(
|
||||||
&mut self,
|
&mut self,
|
||||||
lateral: IsLateral,
|
lateral: IsLateral,
|
||||||
|
|
|
@ -185,7 +185,6 @@ pub fn table(name: impl Into<String>) -> TableFactor {
|
||||||
name: ObjectName(vec![Ident::new(name.into())]),
|
name: ObjectName(vec![Ident::new(name.into())]),
|
||||||
alias: None,
|
alias: None,
|
||||||
args: None,
|
args: None,
|
||||||
columns_definition: None,
|
|
||||||
with_hints: vec![],
|
with_hints: vec![],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,7 +99,6 @@ fn parse_table_identifiers() {
|
||||||
name: ObjectName(expected),
|
name: ObjectName(expected),
|
||||||
alias: None,
|
alias: None,
|
||||||
args: None,
|
args: None,
|
||||||
columns_definition: None,
|
|
||||||
with_hints: vec![],
|
with_hints: vec![],
|
||||||
},
|
},
|
||||||
joins: vec![]
|
joins: vec![]
|
||||||
|
|
|
@ -60,7 +60,6 @@ fn parse_map_access_expr() {
|
||||||
name: ObjectName(vec![Ident::new("foos")]),
|
name: ObjectName(vec![Ident::new("foos")]),
|
||||||
alias: None,
|
alias: None,
|
||||||
args: None,
|
args: None,
|
||||||
columns_definition: None,
|
|
||||||
with_hints: vec![],
|
with_hints: vec![],
|
||||||
},
|
},
|
||||||
joins: vec![]
|
joins: vec![]
|
||||||
|
@ -165,13 +164,11 @@ fn parse_delimited_identifiers() {
|
||||||
name,
|
name,
|
||||||
alias,
|
alias,
|
||||||
args,
|
args,
|
||||||
columns_definition,
|
|
||||||
with_hints,
|
with_hints,
|
||||||
} => {
|
} => {
|
||||||
assert_eq!(vec![Ident::with_quote('"', "a table")], name.0);
|
assert_eq!(vec![Ident::with_quote('"', "a table")], name.0);
|
||||||
assert_eq!(Ident::with_quote('"', "alias"), alias.unwrap().name);
|
assert_eq!(Ident::with_quote('"', "alias"), alias.unwrap().name);
|
||||||
assert!(args.is_none());
|
assert!(args.is_none());
|
||||||
assert!(columns_definition.is_none());
|
|
||||||
assert!(with_hints.is_empty());
|
assert!(with_hints.is_empty());
|
||||||
}
|
}
|
||||||
_ => panic!("Expecting TableFactor::Table"),
|
_ => panic!("Expecting TableFactor::Table"),
|
||||||
|
|
|
@ -210,7 +210,6 @@ fn parse_update_set_from() {
|
||||||
name: ObjectName(vec![Ident::new("t1")]),
|
name: ObjectName(vec![Ident::new("t1")]),
|
||||||
alias: None,
|
alias: None,
|
||||||
args: None,
|
args: None,
|
||||||
columns_definition: None,
|
|
||||||
with_hints: vec![],
|
with_hints: vec![],
|
||||||
},
|
},
|
||||||
joins: vec![],
|
joins: vec![],
|
||||||
|
@ -237,7 +236,6 @@ fn parse_update_set_from() {
|
||||||
name: ObjectName(vec![Ident::new("t1")]),
|
name: ObjectName(vec![Ident::new("t1")]),
|
||||||
alias: None,
|
alias: None,
|
||||||
args: None,
|
args: None,
|
||||||
columns_definition: None,
|
|
||||||
with_hints: vec![],
|
with_hints: vec![],
|
||||||
},
|
},
|
||||||
joins: vec![],
|
joins: vec![],
|
||||||
|
@ -300,7 +298,6 @@ fn parse_update_with_table_alias() {
|
||||||
columns: vec![],
|
columns: vec![],
|
||||||
}),
|
}),
|
||||||
args: None,
|
args: None,
|
||||||
columns_definition: None,
|
|
||||||
with_hints: vec![],
|
with_hints: vec![],
|
||||||
},
|
},
|
||||||
joins: vec![],
|
joins: vec![],
|
||||||
|
@ -333,6 +330,43 @@ fn parse_update_with_table_alias() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_select_with_table_alias_as() {
|
||||||
|
// AS is optional
|
||||||
|
one_statement_parses_to(
|
||||||
|
"SELECT a, b, c FROM lineitem l (A, B, C)",
|
||||||
|
"SELECT a, b, c FROM lineitem AS l (A, B, C)",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_select_with_table_alias() {
|
||||||
|
let select = verified_only_select("SELECT a, b, c FROM lineitem AS l (A, B, C)");
|
||||||
|
assert_eq!(
|
||||||
|
select.projection,
|
||||||
|
vec![
|
||||||
|
SelectItem::UnnamedExpr(Expr::Identifier(Ident::new("a")),),
|
||||||
|
SelectItem::UnnamedExpr(Expr::Identifier(Ident::new("b")),),
|
||||||
|
SelectItem::UnnamedExpr(Expr::Identifier(Ident::new("c")),),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
select.from,
|
||||||
|
vec![TableWithJoins {
|
||||||
|
relation: TableFactor::Table {
|
||||||
|
name: ObjectName(vec![Ident::new("lineitem")]),
|
||||||
|
alias: Some(TableAlias {
|
||||||
|
name: Ident::new("l"),
|
||||||
|
columns: vec![Ident::new("A"), Ident::new("B"), Ident::new("C"),],
|
||||||
|
}),
|
||||||
|
args: None,
|
||||||
|
with_hints: vec![],
|
||||||
|
},
|
||||||
|
joins: vec![],
|
||||||
|
}]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_invalid_table_name() {
|
fn parse_invalid_table_name() {
|
||||||
let ast = all_dialects()
|
let ast = all_dialects()
|
||||||
|
@ -356,7 +390,6 @@ fn parse_delete_statement() {
|
||||||
name: ObjectName(vec![Ident::with_quote('"', "table")]),
|
name: ObjectName(vec![Ident::with_quote('"', "table")]),
|
||||||
alias: None,
|
alias: None,
|
||||||
args: None,
|
args: None,
|
||||||
columns_definition: None,
|
|
||||||
with_hints: vec![],
|
with_hints: vec![],
|
||||||
},
|
},
|
||||||
table_name
|
table_name
|
||||||
|
@ -383,7 +416,6 @@ fn parse_where_delete_statement() {
|
||||||
name: ObjectName(vec![Ident::new("foo")]),
|
name: ObjectName(vec![Ident::new("foo")]),
|
||||||
alias: None,
|
alias: None,
|
||||||
args: None,
|
args: None,
|
||||||
columns_definition: None,
|
|
||||||
with_hints: vec![],
|
with_hints: vec![],
|
||||||
},
|
},
|
||||||
table_name,
|
table_name,
|
||||||
|
@ -424,7 +456,6 @@ fn parse_where_delete_with_alias_statement() {
|
||||||
columns: vec![],
|
columns: vec![],
|
||||||
}),
|
}),
|
||||||
args: None,
|
args: None,
|
||||||
columns_definition: None,
|
|
||||||
with_hints: vec![],
|
with_hints: vec![],
|
||||||
},
|
},
|
||||||
table_name,
|
table_name,
|
||||||
|
@ -438,7 +469,6 @@ fn parse_where_delete_with_alias_statement() {
|
||||||
columns: vec![],
|
columns: vec![],
|
||||||
}),
|
}),
|
||||||
args: None,
|
args: None,
|
||||||
columns_definition: None,
|
|
||||||
with_hints: vec![],
|
with_hints: vec![],
|
||||||
}),
|
}),
|
||||||
using
|
using
|
||||||
|
@ -3465,7 +3495,6 @@ fn parse_interval_and_or_xor() {
|
||||||
}]),
|
}]),
|
||||||
alias: None,
|
alias: None,
|
||||||
args: None,
|
args: None,
|
||||||
columns_definition: None,
|
|
||||||
with_hints: vec![],
|
with_hints: vec![],
|
||||||
},
|
},
|
||||||
joins: vec![],
|
joins: vec![],
|
||||||
|
@ -3981,7 +4010,6 @@ fn parse_implicit_join() {
|
||||||
name: ObjectName(vec!["t1".into()]),
|
name: ObjectName(vec!["t1".into()]),
|
||||||
alias: None,
|
alias: None,
|
||||||
args: None,
|
args: None,
|
||||||
columns_definition: None,
|
|
||||||
with_hints: vec![],
|
with_hints: vec![],
|
||||||
},
|
},
|
||||||
joins: vec![],
|
joins: vec![],
|
||||||
|
@ -3991,7 +4019,6 @@ fn parse_implicit_join() {
|
||||||
name: ObjectName(vec!["t2".into()]),
|
name: ObjectName(vec!["t2".into()]),
|
||||||
alias: None,
|
alias: None,
|
||||||
args: None,
|
args: None,
|
||||||
columns_definition: None,
|
|
||||||
with_hints: vec![],
|
with_hints: vec![],
|
||||||
},
|
},
|
||||||
joins: vec![],
|
joins: vec![],
|
||||||
|
@ -4009,7 +4036,6 @@ fn parse_implicit_join() {
|
||||||
name: ObjectName(vec!["t1a".into()]),
|
name: ObjectName(vec!["t1a".into()]),
|
||||||
alias: None,
|
alias: None,
|
||||||
args: None,
|
args: None,
|
||||||
columns_definition: None,
|
|
||||||
with_hints: vec![],
|
with_hints: vec![],
|
||||||
},
|
},
|
||||||
joins: vec![Join {
|
joins: vec![Join {
|
||||||
|
@ -4017,7 +4043,6 @@ fn parse_implicit_join() {
|
||||||
name: ObjectName(vec!["t1b".into()]),
|
name: ObjectName(vec!["t1b".into()]),
|
||||||
alias: None,
|
alias: None,
|
||||||
args: None,
|
args: None,
|
||||||
columns_definition: None,
|
|
||||||
with_hints: vec![],
|
with_hints: vec![],
|
||||||
},
|
},
|
||||||
join_operator: JoinOperator::Inner(JoinConstraint::Natural),
|
join_operator: JoinOperator::Inner(JoinConstraint::Natural),
|
||||||
|
@ -4028,7 +4053,6 @@ fn parse_implicit_join() {
|
||||||
name: ObjectName(vec!["t2a".into()]),
|
name: ObjectName(vec!["t2a".into()]),
|
||||||
alias: None,
|
alias: None,
|
||||||
args: None,
|
args: None,
|
||||||
columns_definition: None,
|
|
||||||
with_hints: vec![],
|
with_hints: vec![],
|
||||||
},
|
},
|
||||||
joins: vec![Join {
|
joins: vec![Join {
|
||||||
|
@ -4036,7 +4060,6 @@ fn parse_implicit_join() {
|
||||||
name: ObjectName(vec!["t2b".into()]),
|
name: ObjectName(vec!["t2b".into()]),
|
||||||
alias: None,
|
alias: None,
|
||||||
args: None,
|
args: None,
|
||||||
columns_definition: None,
|
|
||||||
with_hints: vec![],
|
with_hints: vec![],
|
||||||
},
|
},
|
||||||
join_operator: JoinOperator::Inner(JoinConstraint::Natural),
|
join_operator: JoinOperator::Inner(JoinConstraint::Natural),
|
||||||
|
@ -4057,7 +4080,6 @@ fn parse_cross_join() {
|
||||||
name: ObjectName(vec![Ident::new("t2")]),
|
name: ObjectName(vec![Ident::new("t2")]),
|
||||||
alias: None,
|
alias: None,
|
||||||
args: None,
|
args: None,
|
||||||
columns_definition: None,
|
|
||||||
with_hints: vec![],
|
with_hints: vec![],
|
||||||
},
|
},
|
||||||
join_operator: JoinOperator::CrossJoin,
|
join_operator: JoinOperator::CrossJoin,
|
||||||
|
@ -4078,7 +4100,6 @@ fn parse_joins_on() {
|
||||||
name: ObjectName(vec![Ident::new(relation.into())]),
|
name: ObjectName(vec![Ident::new(relation.into())]),
|
||||||
alias,
|
alias,
|
||||||
args: None,
|
args: None,
|
||||||
columns_definition: None,
|
|
||||||
with_hints: vec![],
|
with_hints: vec![],
|
||||||
},
|
},
|
||||||
join_operator: f(JoinConstraint::On(Expr::BinaryOp {
|
join_operator: f(JoinConstraint::On(Expr::BinaryOp {
|
||||||
|
@ -4148,7 +4169,6 @@ fn parse_joins_using() {
|
||||||
name: ObjectName(vec![Ident::new(relation.into())]),
|
name: ObjectName(vec![Ident::new(relation.into())]),
|
||||||
alias,
|
alias,
|
||||||
args: None,
|
args: None,
|
||||||
columns_definition: None,
|
|
||||||
with_hints: vec![],
|
with_hints: vec![],
|
||||||
},
|
},
|
||||||
join_operator: f(JoinConstraint::Using(vec!["c1".into()])),
|
join_operator: f(JoinConstraint::Using(vec!["c1".into()])),
|
||||||
|
@ -4210,7 +4230,6 @@ fn parse_natural_join() {
|
||||||
name: ObjectName(vec![Ident::new("t2")]),
|
name: ObjectName(vec![Ident::new("t2")]),
|
||||||
alias,
|
alias,
|
||||||
args: None,
|
args: None,
|
||||||
columns_definition: None,
|
|
||||||
with_hints: vec![],
|
with_hints: vec![],
|
||||||
},
|
},
|
||||||
join_operator: f(JoinConstraint::Natural),
|
join_operator: f(JoinConstraint::Natural),
|
||||||
|
@ -4475,7 +4494,6 @@ fn parse_derived_tables() {
|
||||||
name: ObjectName(vec!["t2".into()]),
|
name: ObjectName(vec!["t2".into()]),
|
||||||
alias: None,
|
alias: None,
|
||||||
args: None,
|
args: None,
|
||||||
columns_definition: None,
|
|
||||||
with_hints: vec![],
|
with_hints: vec![],
|
||||||
},
|
},
|
||||||
join_operator: JoinOperator::Inner(JoinConstraint::Natural),
|
join_operator: JoinOperator::Inner(JoinConstraint::Natural),
|
||||||
|
@ -5767,7 +5785,6 @@ fn parse_merge() {
|
||||||
columns: vec![],
|
columns: vec![],
|
||||||
}),
|
}),
|
||||||
args: None,
|
args: None,
|
||||||
columns_definition: None,
|
|
||||||
with_hints: vec![],
|
with_hints: vec![],
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -5791,7 +5808,6 @@ fn parse_merge() {
|
||||||
name: ObjectName(vec![Ident::new("s"), Ident::new("foo")]),
|
name: ObjectName(vec![Ident::new("s"), Ident::new("foo")]),
|
||||||
alias: None,
|
alias: None,
|
||||||
args: None,
|
args: None,
|
||||||
columns_definition: None,
|
|
||||||
with_hints: vec![],
|
with_hints: vec![],
|
||||||
},
|
},
|
||||||
joins: vec![],
|
joins: vec![],
|
||||||
|
|
|
@ -320,13 +320,11 @@ fn parse_delimited_identifiers() {
|
||||||
name,
|
name,
|
||||||
alias,
|
alias,
|
||||||
args,
|
args,
|
||||||
columns_definition,
|
|
||||||
with_hints,
|
with_hints,
|
||||||
} => {
|
} => {
|
||||||
assert_eq!(vec![Ident::with_quote('"', "a table")], name.0);
|
assert_eq!(vec![Ident::with_quote('"', "a table")], name.0);
|
||||||
assert_eq!(Ident::with_quote('"', "alias"), alias.unwrap().name);
|
assert_eq!(Ident::with_quote('"', "alias"), alias.unwrap().name);
|
||||||
assert!(args.is_none());
|
assert!(args.is_none());
|
||||||
assert!(columns_definition.is_none());
|
|
||||||
assert!(with_hints.is_empty());
|
assert!(with_hints.is_empty());
|
||||||
}
|
}
|
||||||
_ => panic!("Expecting TableFactor::Table"),
|
_ => panic!("Expecting TableFactor::Table"),
|
||||||
|
|
|
@ -152,13 +152,11 @@ fn parse_delimited_identifiers() {
|
||||||
name,
|
name,
|
||||||
alias,
|
alias,
|
||||||
args,
|
args,
|
||||||
columns_definition,
|
|
||||||
with_hints,
|
with_hints,
|
||||||
} => {
|
} => {
|
||||||
assert_eq!(vec![Ident::with_quote('"', "a table")], name.0);
|
assert_eq!(vec![Ident::with_quote('"', "a table")], name.0);
|
||||||
assert_eq!(Ident::with_quote('"', "alias"), alias.unwrap().name);
|
assert_eq!(Ident::with_quote('"', "alias"), alias.unwrap().name);
|
||||||
assert!(args.is_none());
|
assert!(args.is_none());
|
||||||
assert!(columns_definition.is_none());
|
|
||||||
assert!(with_hints.is_empty());
|
assert!(with_hints.is_empty());
|
||||||
}
|
}
|
||||||
_ => panic!("Expecting TableFactor::Table"),
|
_ => panic!("Expecting TableFactor::Table"),
|
||||||
|
|
|
@ -870,7 +870,6 @@ fn parse_update_with_joins() {
|
||||||
columns: vec![]
|
columns: vec![]
|
||||||
}),
|
}),
|
||||||
args: None,
|
args: None,
|
||||||
columns_definition: None,
|
|
||||||
with_hints: vec![],
|
with_hints: vec![],
|
||||||
},
|
},
|
||||||
joins: vec![Join {
|
joins: vec![Join {
|
||||||
|
@ -881,7 +880,6 @@ fn parse_update_with_joins() {
|
||||||
columns: vec![]
|
columns: vec![]
|
||||||
}),
|
}),
|
||||||
args: None,
|
args: None,
|
||||||
columns_definition: None,
|
|
||||||
with_hints: vec![],
|
with_hints: vec![],
|
||||||
},
|
},
|
||||||
join_operator: JoinOperator::Inner(JoinConstraint::On(Expr::BinaryOp {
|
join_operator: JoinOperator::Inner(JoinConstraint::On(Expr::BinaryOp {
|
||||||
|
@ -1003,7 +1001,6 @@ fn parse_substring_in_select() {
|
||||||
}]),
|
}]),
|
||||||
alias: None,
|
alias: None,
|
||||||
args: None,
|
args: None,
|
||||||
columns_definition: None,
|
|
||||||
with_hints: vec![]
|
with_hints: vec![]
|
||||||
},
|
},
|
||||||
joins: vec![]
|
joins: vec![]
|
||||||
|
|
|
@ -2189,13 +2189,11 @@ fn parse_delimited_identifiers() {
|
||||||
name,
|
name,
|
||||||
alias,
|
alias,
|
||||||
args,
|
args,
|
||||||
columns_definition,
|
|
||||||
with_hints,
|
with_hints,
|
||||||
} => {
|
} => {
|
||||||
assert_eq!(vec![Ident::with_quote('"', "a table")], name.0);
|
assert_eq!(vec![Ident::with_quote('"', "a table")], name.0);
|
||||||
assert_eq!(Ident::with_quote('"', "alias"), alias.unwrap().name);
|
assert_eq!(Ident::with_quote('"', "alias"), alias.unwrap().name);
|
||||||
assert!(args.is_none());
|
assert!(args.is_none());
|
||||||
assert!(columns_definition.is_none());
|
|
||||||
assert!(with_hints.is_empty());
|
assert!(with_hints.is_empty());
|
||||||
}
|
}
|
||||||
_ => panic!("Expecting TableFactor::Table"),
|
_ => panic!("Expecting TableFactor::Table"),
|
||||||
|
|
|
@ -44,7 +44,6 @@ fn test_square_brackets_over_db_schema_table_name() {
|
||||||
]),
|
]),
|
||||||
alias: None,
|
alias: None,
|
||||||
args: None,
|
args: None,
|
||||||
columns_definition: None,
|
|
||||||
with_hints: vec![],
|
with_hints: vec![],
|
||||||
},
|
},
|
||||||
joins: vec![],
|
joins: vec![],
|
||||||
|
@ -89,7 +88,6 @@ fn test_double_quotes_over_db_schema_table_name() {
|
||||||
]),
|
]),
|
||||||
alias: None,
|
alias: None,
|
||||||
args: None,
|
args: None,
|
||||||
columns_definition: None,
|
|
||||||
with_hints: vec![],
|
with_hints: vec![],
|
||||||
},
|
},
|
||||||
joins: vec![],
|
joins: vec![],
|
||||||
|
@ -109,13 +107,11 @@ fn parse_delimited_identifiers() {
|
||||||
name,
|
name,
|
||||||
alias,
|
alias,
|
||||||
args,
|
args,
|
||||||
columns_definition,
|
|
||||||
with_hints,
|
with_hints,
|
||||||
} => {
|
} => {
|
||||||
assert_eq!(vec![Ident::with_quote('"', "a table")], name.0);
|
assert_eq!(vec![Ident::with_quote('"', "a table")], name.0);
|
||||||
assert_eq!(Ident::with_quote('"', "alias"), alias.unwrap().name);
|
assert_eq!(Ident::with_quote('"', "alias"), alias.unwrap().name);
|
||||||
assert!(args.is_none());
|
assert!(args.is_none());
|
||||||
assert!(columns_definition.is_none());
|
|
||||||
assert!(with_hints.is_empty());
|
assert!(with_hints.is_empty());
|
||||||
}
|
}
|
||||||
_ => panic!("Expecting TableFactor::Table"),
|
_ => panic!("Expecting TableFactor::Table"),
|
||||||
|
@ -276,72 +272,3 @@ fn test_sharp() {
|
||||||
select.projection[0]
|
select.projection[0]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_parse_pg_get_late_binding_view_cols() {
|
|
||||||
let sql = "select * from pg_get_late_binding_view_cols() some_name_cols(view_schema name, view_name name, col_name name)";
|
|
||||||
let expected = "SELECT * FROM pg_get_late_binding_view_cols() some_name_cols(view_schema name, view_name name, col_name name)";
|
|
||||||
redshift().one_statement_parses_to(sql, expected);
|
|
||||||
|
|
||||||
let select = redshift().verified_only_select(expected);
|
|
||||||
assert_eq!(
|
|
||||||
TableFactor::Table {
|
|
||||||
name: ObjectName(vec![Ident::new("pg_get_late_binding_view_cols")],),
|
|
||||||
args: Some(vec![]),
|
|
||||||
alias: None,
|
|
||||||
columns_definition: Some(TableAliasDefinition {
|
|
||||||
name: Ident::new("some_name_cols"),
|
|
||||||
args: vec![
|
|
||||||
IdentPair(Ident::new("view_schema"), Ident::new("name")),
|
|
||||||
IdentPair(Ident::new("view_name"), Ident::new("name")),
|
|
||||||
IdentPair(Ident::new("col_name"), Ident::new("name"))
|
|
||||||
]
|
|
||||||
}),
|
|
||||||
with_hints: vec![]
|
|
||||||
},
|
|
||||||
select.from[0].relation
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_parse_pg_get_cols() {
|
|
||||||
let sql =
|
|
||||||
"SELECT * FROM pg_get_cols() some_name(view_schema name, view_name name, col_name name)";
|
|
||||||
redshift().verified_stmt(sql);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_parse_pg_get_grantee_by_iam_role() {
|
|
||||||
let sql = "SELECT grantee, grantee_type, cmd_type FROM pg_get_grantee_by_iam_role('arn:aws:iam::123456789012:role/Redshift-S3-Write') res_grantee(grantee text, grantee_type text, cmd_type text)";
|
|
||||||
redshift().verified_stmt(sql);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_parse_pg_get_iam_role_by_user() {
|
|
||||||
let sql = "SELECT username, iam_role, cmd FROM pg_get_iam_role_by_user('reg_user1') res_iam_role(username text, iam_role text, cmd text)";
|
|
||||||
redshift().verified_stmt(sql);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_parse_pg_get_late_binding_view_cols_in_select() {
|
|
||||||
let sql = "SELECT pg_get_late_binding_view_cols()";
|
|
||||||
redshift().verified_stmt(sql);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_parse_pg_get_cols_in_select() {
|
|
||||||
let sql = "SELECT pg_get_cols()";
|
|
||||||
redshift().verified_stmt(sql);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_parse_pg_get_grantee_by_iam_role_in_select() {
|
|
||||||
let sql = "SELECT pg_get_grantee_by_iam_role()";
|
|
||||||
redshift().verified_stmt(sql);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_parse_pg_get_iam_role_by_user_in_select() {
|
|
||||||
let sql = "SELECT pg_get_iam_role_by_user()";
|
|
||||||
redshift().verified_stmt(sql);
|
|
||||||
}
|
|
||||||
|
|
|
@ -220,13 +220,11 @@ fn parse_delimited_identifiers() {
|
||||||
name,
|
name,
|
||||||
alias,
|
alias,
|
||||||
args,
|
args,
|
||||||
columns_definition,
|
|
||||||
with_hints,
|
with_hints,
|
||||||
} => {
|
} => {
|
||||||
assert_eq!(vec![Ident::with_quote('"', "a table")], name.0);
|
assert_eq!(vec![Ident::with_quote('"', "a table")], name.0);
|
||||||
assert_eq!(Ident::with_quote('"', "alias"), alias.unwrap().name);
|
assert_eq!(Ident::with_quote('"', "alias"), alias.unwrap().name);
|
||||||
assert!(args.is_none());
|
assert!(args.is_none());
|
||||||
assert!(columns_definition.is_none());
|
|
||||||
assert!(with_hints.is_empty());
|
assert!(with_hints.is_empty());
|
||||||
}
|
}
|
||||||
_ => panic!("Expecting TableFactor::Table"),
|
_ => panic!("Expecting TableFactor::Table"),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue