Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wugeer committed Nov 12, 2024
1 parent fc01ddb commit 6b47ca1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3331,7 +3331,7 @@ pub enum Statement {
overwrite: bool,
table_name: ObjectName,
partitioned: Option<Vec<Expr>>,
table_format: Option<HiveLoadDataOption>,
table_format: Option<HiveLoadDataFormat>,
},
}

Expand Down Expand Up @@ -3956,7 +3956,7 @@ impl fmt::Display for Statement {
write!(f, " PARTITION ({})", display_comma_separated(parts))?;
}
}
if let Some(HiveLoadDataOption {
if let Some(HiveLoadDataFormat {
serde,
input_format,
}) = &table_format
Expand Down Expand Up @@ -5860,7 +5860,7 @@ pub enum HiveRowFormat {
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub struct HiveLoadDataOption {
pub struct HiveLoadDataFormat {
pub serde: Expr,
pub input_format: Expr,
}
Expand Down
6 changes: 3 additions & 3 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11038,12 +11038,12 @@ impl<'a> Parser<'a> {

pub fn parse_load_data_table_format(
&mut self,
) -> Result<Option<HiveLoadDataOption>, ParserError> {
) -> Result<Option<HiveLoadDataFormat>, ParserError> {
if self.parse_keyword(Keyword::INPUTFORMAT) {
let input_format = self.parse_expr()?;
self.expect_keyword(Keyword::SERDE)?;
let serde = self.parse_expr()?;
Ok(Some(HiveLoadDataOption {
Ok(Some(HiveLoadDataFormat {
input_format,
serde,
}))
Expand Down Expand Up @@ -12079,7 +12079,7 @@ impl<'a> Parser<'a> {
})
} else {
self.expected(
"Expected: dialect supports `LOAD DATA` or `LOAD extension` to parse `LOAD` statements",
"dialect supports `LOAD DATA` or `LOAD extension` to parse `LOAD` statements",
self.peek_token(),
)
}
Expand Down
20 changes: 13 additions & 7 deletions tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11516,10 +11516,6 @@ fn parse_notify_channel() {
dialects.parse_sql_statements(sql).unwrap_err(),
ParserError::ParserError("Expected: an SQL statement, found: NOTIFY".to_string())
);
assert_eq!(
dialects.parse_sql_statements(sql).unwrap_err(),
ParserError::ParserError("Expected: an SQL statement, found: NOTIFY".to_string())
);
}
}

Expand Down Expand Up @@ -11639,11 +11635,21 @@ fn parse_load_data() {
op: BinaryOperator::Eq,
right: Box::new(Expr::Value(Value::Number("11".parse().unwrap(), false))),
}]), partitioned);
assert_eq!(Some(HiveLoadDataOption {serde: Expr::Value(Value::SingleQuotedString("org.apache.hadoop.hive.serde2.OpenCSVSerde".to_string())), input_format: Expr::Value(Value::SingleQuotedString("org.apache.hadoop.mapred.TextInputFormat".to_string()))}), table_format);
assert_eq!(Some(HiveLoadDataFormat {serde: Expr::Value(Value::SingleQuotedString("org.apache.hadoop.hive.serde2.OpenCSVSerde".to_string())), input_format: Expr::Value(Value::SingleQuotedString("org.apache.hadoop.mapred.TextInputFormat".to_string()))}), table_format);
}
_ => unreachable!(),
};

// negative test case
assert_eq!(
dialects
.parse_sql_statements(
"LOAD DATA2 LOCAL INPATH '/local/path/to/data.txt' INTO TABLE test.my_table"
)
.unwrap_err(),
ParserError::ParserError("Expected: dialect supports `LOAD DATA` or `LOAD extension` to parse `LOAD` statements, found: DATA2".to_string())
);

let dialects = all_dialects_where(|d| !d.supports_load_data() && d.supports_load_extension());

assert_eq!(
Expand All @@ -11668,12 +11674,12 @@ fn parse_load_data() {

assert_eq!(
dialects.parse_sql_statements("LOAD DATA LOCAL INPATH '/local/path/to/data.txt' INTO TABLE test.my_table").unwrap_err(),
ParserError::ParserError("Expected: Expected: dialect supports `LOAD DATA` or `LOAD extension` to parse `LOAD` statements, found: LOCAL".to_string())
ParserError::ParserError("Expected: dialect supports `LOAD DATA` or `LOAD extension` to parse `LOAD` statements, found: LOCAL".to_string())
);

assert_eq!(
dialects.parse_sql_statements("LOAD DATA INPATH '/local/path/to/data.txt' INTO TABLE test.my_table").unwrap_err(),
ParserError::ParserError("Expected: Expected: dialect supports `LOAD DATA` or `LOAD extension` to parse `LOAD` statements, found: INPATH".to_string())
ParserError::ParserError("Expected: dialect supports `LOAD DATA` or `LOAD extension` to parse `LOAD` statements, found: INPATH".to_string())
);
}

Expand Down

0 comments on commit 6b47ca1

Please sign in to comment.