Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

common: Make sure + - * / % binary operators work the same in all dialects #1025

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/dialect/bigquery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ impl Dialect for BigQueryDialect {
}

fn is_identifier_part(&self, ch: char) -> bool {
ch.is_ascii_lowercase()
|| ch.is_ascii_uppercase()
|| ch.is_ascii_digit()
|| ch == '_'
|| ch == '-'
ch.is_ascii_lowercase() || ch.is_ascii_uppercase() || ch.is_ascii_digit() || ch == '_'
}
}
2 changes: 0 additions & 2 deletions tests/sqlparser_bigquery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,8 +615,6 @@ fn parse_table_identifiers() {
assert!(bigquery().parse_sql_statements(&sql).is_err());
}

test_table_ident("da-sh-es", None, vec![Ident::new("da-sh-es")]);
lustefaniak marked this conversation as resolved.
Show resolved Hide resolved

test_table_ident("`spa ce`", None, vec![Ident::with_quote('`', "spa ce")]);

test_table_ident(
Expand Down
58 changes: 58 additions & 0 deletions tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7744,3 +7744,61 @@ fn parse_create_type() {
fn parse_create_table_collate() {
pg_and_generic().verified_stmt("CREATE TABLE tbl (foo INT, bar TEXT COLLATE \"de_DE\")");
}

#[test]
fn parse_binary_operators_without_whitespace() {
// x + y
all_dialects().one_statement_parses_to(
"SELECT field+1000 FROM tbl1",
"SELECT field + 1000 FROM tbl1",
);

all_dialects().one_statement_parses_to(
"SELECT tbl1.field+tbl2.field FROM tbl1 JOIN tbl2 ON tbl1.id = tbl2.entity_id",
"SELECT tbl1.field + tbl2.field FROM tbl1 JOIN tbl2 ON tbl1.id = tbl2.entity_id",
);

// x - y
all_dialects().one_statement_parses_to(
"SELECT field-1000 FROM tbl1",
"SELECT field - 1000 FROM tbl1",
);

all_dialects().one_statement_parses_to(
"SELECT tbl1.field-tbl2.field FROM tbl1 JOIN tbl2 ON tbl1.id = tbl2.entity_id",
"SELECT tbl1.field - tbl2.field FROM tbl1 JOIN tbl2 ON tbl1.id = tbl2.entity_id",
);

// x * y
all_dialects().one_statement_parses_to(
"SELECT field*1000 FROM tbl1",
"SELECT field * 1000 FROM tbl1",
);

all_dialects().one_statement_parses_to(
"SELECT tbl1.field*tbl2.field FROM tbl1 JOIN tbl2 ON tbl1.id = tbl2.entity_id",
"SELECT tbl1.field * tbl2.field FROM tbl1 JOIN tbl2 ON tbl1.id = tbl2.entity_id",
);

// x / y
all_dialects().one_statement_parses_to(
"SELECT field/1000 FROM tbl1",
"SELECT field / 1000 FROM tbl1",
);

all_dialects().one_statement_parses_to(
"SELECT tbl1.field/tbl2.field FROM tbl1 JOIN tbl2 ON tbl1.id = tbl2.entity_id",
"SELECT tbl1.field / tbl2.field FROM tbl1 JOIN tbl2 ON tbl1.id = tbl2.entity_id",
);

// x % y
all_dialects().one_statement_parses_to(
"SELECT field%1000 FROM tbl1",
"SELECT field % 1000 FROM tbl1",
);

all_dialects().one_statement_parses_to(
"SELECT tbl1.field%tbl2.field FROM tbl1 JOIN tbl2 ON tbl1.id = tbl2.entity_id",
"SELECT tbl1.field % tbl2.field FROM tbl1 JOIN tbl2 ON tbl1.id = tbl2.entity_id",
);
}
Loading