From 0b92277de43723c688af3b34ce14a047b641cb9c Mon Sep 17 00:00:00 2001 From: Dylan Date: Wed, 10 Apr 2024 15:56:13 +0800 Subject: [PATCH] fix(binder): fix user keyword (#16229) --- e2e_test/batch/keyword/user.slt | 16 ++++++++++++++++ src/frontend/src/binder/expr/mod.rs | 2 +- src/sqlparser/src/ast/mod.rs | 4 ++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 e2e_test/batch/keyword/user.slt diff --git a/e2e_test/batch/keyword/user.slt b/e2e_test/batch/keyword/user.slt new file mode 100644 index 0000000000000..353e7f026e6e6 --- /dev/null +++ b/e2e_test/batch/keyword/user.slt @@ -0,0 +1,16 @@ +statement ok +SET RW_IMPLICIT_FLUSH TO true; + +statement ok +create table t (id int, user varchar); + +statement ok +insert into t values (1, 'abc'); + +query I +select id, "user", 'user', user = current_user from t; +---- +1 abc user t + +statement ok +drop table t; \ No newline at end of file diff --git a/src/frontend/src/binder/expr/mod.rs b/src/frontend/src/binder/expr/mod.rs index e0f0892a03db9..0b8b50be0eab6 100644 --- a/src/frontend/src/binder/expr/mod.rs +++ b/src/frontend/src/binder/expr/mod.rs @@ -74,7 +74,7 @@ impl Binder { Expr::Identifier(ident) => { if SYS_FUNCTION_WITHOUT_ARGS .iter() - .any(|e| ident.real_value().as_str() == *e) + .any(|e| ident.real_value().as_str() == *e && ident.quote_style().is_none()) { // Rewrite a system variable to a function call, e.g. `SELECT current_schema;` // will be rewritten to `SELECT current_schema();`. diff --git a/src/sqlparser/src/ast/mod.rs b/src/sqlparser/src/ast/mod.rs index 97cfe41eac320..825418e75ccc5 100644 --- a/src/sqlparser/src/ast/mod.rs +++ b/src/sqlparser/src/ast/mod.rs @@ -167,6 +167,10 @@ impl Ident { _ => self.value.to_lowercase(), } } + + pub fn quote_style(&self) -> Option { + self.quote_style + } } impl From<&str> for Ident {