mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-31 03:07:20 +00:00
Support USING method when creating indexes. (#731)
* fix: create index using function * fix: code style Co-authored-by: yangjiaxin <yangjiaxin@qianxin.com>
This commit is contained in:
parent
7101e0021f
commit
316359760d
3 changed files with 58 additions and 9 deletions
|
@ -5162,6 +5162,7 @@ fn parse_create_index() {
|
|||
columns,
|
||||
unique,
|
||||
if_not_exists,
|
||||
..
|
||||
} => {
|
||||
assert_eq!("idx_name", name.to_string());
|
||||
assert_eq!("test", table_name.to_string());
|
||||
|
@ -5173,6 +5174,41 @@ fn parse_create_index() {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_create_index_with_using_function() {
|
||||
let sql = "CREATE UNIQUE INDEX IF NOT EXISTS idx_name ON test USING btree (name,age DESC)";
|
||||
let indexed_columns = vec![
|
||||
OrderByExpr {
|
||||
expr: Expr::Identifier(Ident::new("name")),
|
||||
asc: None,
|
||||
nulls_first: None,
|
||||
},
|
||||
OrderByExpr {
|
||||
expr: Expr::Identifier(Ident::new("age")),
|
||||
asc: Some(false),
|
||||
nulls_first: None,
|
||||
},
|
||||
];
|
||||
match verified_stmt(sql) {
|
||||
Statement::CreateIndex {
|
||||
name,
|
||||
table_name,
|
||||
using,
|
||||
columns,
|
||||
unique,
|
||||
if_not_exists,
|
||||
} => {
|
||||
assert_eq!("idx_name", name.to_string());
|
||||
assert_eq!("test", table_name.to_string());
|
||||
assert_eq!("btree", using.unwrap().to_string());
|
||||
assert_eq!(indexed_columns, columns);
|
||||
assert!(unique);
|
||||
assert!(if_not_exists)
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_drop_index() {
|
||||
let sql = "DROP INDEX idx_a";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue