Extend support for INDEX parsing (#1707)

Co-authored-by: Ifeanyi Ubah <ify1992@yahoo.com>
This commit is contained in:
Luca Cappelletti 2025-03-04 06:59:39 +01:00 committed by GitHub
parent d5dbe86da9
commit 6ec5223f50
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 404 additions and 60 deletions

View file

@ -8842,22 +8842,28 @@ fn ensure_multiple_dialects_are_tested() {
#[test]
fn parse_create_index() {
let sql = "CREATE UNIQUE INDEX IF NOT EXISTS idx_name ON test(name,age DESC)";
let indexed_columns = vec![
OrderByExpr {
expr: Expr::Identifier(Ident::new("name")),
options: OrderByOptions {
asc: None,
nulls_first: None,
let indexed_columns: Vec<IndexColumn> = vec![
IndexColumn {
operator_class: None,
column: OrderByExpr {
expr: Expr::Identifier(Ident::new("name")),
with_fill: None,
options: OrderByOptions {
asc: None,
nulls_first: None,
},
},
with_fill: None,
},
OrderByExpr {
expr: Expr::Identifier(Ident::new("age")),
options: OrderByOptions {
asc: Some(false),
nulls_first: None,
IndexColumn {
operator_class: None,
column: OrderByExpr {
expr: Expr::Identifier(Ident::new("age")),
with_fill: None,
options: OrderByOptions {
asc: Some(false),
nulls_first: None,
},
},
with_fill: None,
},
];
match verified_stmt(sql) {
@ -8881,23 +8887,29 @@ 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")),
options: OrderByOptions {
asc: None,
nulls_first: None,
let sql = "CREATE UNIQUE INDEX IF NOT EXISTS idx_name ON test USING BTREE (name,age DESC)";
let indexed_columns: Vec<IndexColumn> = vec![
IndexColumn {
operator_class: None,
column: OrderByExpr {
expr: Expr::Identifier(Ident::new("name")),
with_fill: None,
options: OrderByOptions {
asc: None,
nulls_first: None,
},
},
with_fill: None,
},
OrderByExpr {
expr: Expr::Identifier(Ident::new("age")),
options: OrderByOptions {
asc: Some(false),
nulls_first: None,
IndexColumn {
operator_class: None,
column: OrderByExpr {
expr: Expr::Identifier(Ident::new("age")),
with_fill: None,
options: OrderByOptions {
asc: Some(false),
nulls_first: None,
},
},
with_fill: None,
},
];
match verified_stmt(sql) {
@ -8916,7 +8928,7 @@ fn test_create_index_with_using_function() {
}) => {
assert_eq!("idx_name", name.to_string());
assert_eq!("test", table_name.to_string());
assert_eq!("btree", using.unwrap().to_string());
assert_eq!("BTREE", using.unwrap().to_string());
assert_eq!(indexed_columns, columns);
assert!(unique);
assert!(!concurrently);
@ -8931,13 +8943,16 @@ fn test_create_index_with_using_function() {
#[test]
fn test_create_index_with_with_clause() {
let sql = "CREATE UNIQUE INDEX title_idx ON films(title) WITH (fillfactor = 70, single_param)";
let indexed_columns = vec![OrderByExpr {
expr: Expr::Identifier(Ident::new("title")),
options: OrderByOptions {
asc: None,
nulls_first: None,
let indexed_columns: Vec<IndexColumn> = vec![IndexColumn {
column: OrderByExpr {
expr: Expr::Identifier(Ident::new("title")),
options: OrderByOptions {
asc: None,
nulls_first: None,
},
with_fill: None,
},
with_fill: None,
operator_class: None,
}];
let with_parameters = vec![
Expr::BinaryOp {