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

support parse select expr as alias_name #4841

Merged
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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion common/ast/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ common-functions = { path = "../functions" }
# TODO (andylokandy): Use the version from crates.io once
# https://github.com/brendanzab/codespan/pull/331 is released.
codespan-reporting = { git = "https://github.com/brendanzab/codespan", rev = "c84116f5" }
sqlparser = { git = "https://github.com/datafuse-extras/sqlparser-rs", rev = "08b8c31" }
sqlparser = { git = "https://github.com/datafuse-extras/sqlparser-rs", rev = "fa6c4b2" }

# Crates.io dependencies
async-trait = "0.1.53"
Expand Down
6 changes: 5 additions & 1 deletion common/ast/src/parser/expr/expr_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ pub trait ExprVisitor: Sized + Send {
Expr::Subquery(subquery) => self.visit_subquery(subquery),
Expr::Function(function) => self.visit_function(function).await,
Expr::TryCast { expr, data_type } => self.visit_try_cast(expr, data_type).await,
Expr::Cast { expr, data_type } => self.visit_cast(expr, data_type).await,
Expr::Cast {
expr,
data_type,
pg_style: _pg_style,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the new version of sqlparser introduced pg_style params?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O, @b41sh should know it better :D

} => self.visit_cast(expr, data_type).await,
Expr::TypedString { data_type, value } => self.visit_typed_string(data_type, value),
Expr::Position {
substr_expr,
Expand Down
4 changes: 3 additions & 1 deletion common/ast/src/parser/transformer/transform_sqlparser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,9 @@ impl TransformerSqlparser {
op: self.transform_unary_operator(op)?,
expr: Box::new(self.transform_expr(expr)?),
}),
SqlparserExpr::Cast { expr, data_type } => Ok(Expr::Cast {
SqlparserExpr::Cast {
expr, data_type, ..
} => Ok(Expr::Cast {
expr: Box::new(self.transform_expr(expr)?),
target_type: self.transform_data_type(data_type)?,
}),
Expand Down
5 changes: 4 additions & 1 deletion common/ast/src/udfs/udf_transformer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,12 @@ impl UDFTransformer {
op: op.clone(),
expr: Box::new(Self::clone_expr_with_replacement(&**expr, replacement_fn)?),
}),
Expr::Cast { expr, data_type } => Ok(Expr::Cast {
Expr::Cast {
expr, data_type, ..
} => Ok(Expr::Cast {
Copy link
Collaborator Author

@TCeason TCeason Apr 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@b41sh Hi the pg_style can be set false at there?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't used pg_style, i think it's OK here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can set pg_style as false, it is used to distinguish the field names of two different casts.

select cast(a as int8) from test;
select a::int8 from test;

I am working on this modification, you can set it as false first.

expr: Box::new(Self::clone_expr_with_replacement(&**expr, replacement_fn)?),
data_type: data_type.clone(),
pg_style: false,
}),
Expr::TryCast { expr, data_type } => Ok(Expr::TryCast {
expr: Box::new(Self::clone_expr_with_replacement(&**expr, replacement_fn)?),
Expand Down
2 changes: 1 addition & 1 deletion common/exception/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ tonic = "=0.6.2"

# Github dependencies
bincode = { git = "https://github.com/datafuse-extras/bincode", rev = "fd3f9ff" }
sqlparser = { git = "https://github.com/datafuse-extras/sqlparser-rs", rev = "08b8c31" }
sqlparser = { git = "https://github.com/datafuse-extras/sqlparser-rs", rev = "fa6c4b2" }
2 changes: 1 addition & 1 deletion common/functions/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ serde_json = "1.0.79"
sha1 = "0.10.1"
sha2 = "0.10.2"
simdutf8 = "0.1.4"
sqlparser = { git = "https://github.com/datafuse-extras/sqlparser-rs", rev = "08b8c31" }
sqlparser = { git = "https://github.com/datafuse-extras/sqlparser-rs", rev = "fa6c4b2" }
strength_reduce = "0.2.3"
twox-hash = "1.6.2"
uuid = { version = "0.8.2", features = ["v4"] }
Expand Down
2 changes: 1 addition & 1 deletion query/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ common-tracing = { path = "../common/tracing" }
bincode = { git = "https://github.com/datafuse-extras/bincode", rev = "fd3f9ff" }
opensrv-clickhouse = { git = "https://github.com/datafuselabs/opensrv", rev = "9690be9", package = "opensrv-clickhouse" }
opensrv-mysql = { git = "https://github.com/datafuselabs/opensrv", rev = "967477f1", package = "opensrv-mysql" }
sqlparser = { git = "https://github.com/datafuse-extras/sqlparser-rs", rev = "08b8c31" }
sqlparser = { git = "https://github.com/datafuse-extras/sqlparser-rs", rev = "fa6c4b2" }

# Crates.io dependencies
ahash = "0.7.6"
Expand Down
2 changes: 2 additions & 0 deletions tests/suites/0_stateless/03_dml/03_0000_select_aliases.result
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
0
1
1 1
1 1
1 1
2 changes: 2 additions & 0 deletions tests/suites/0_stateless/03_dml/03_0000_select_aliases.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ select 1 as a, 1 + 1 as b, 1 + 1 + 1 as c;
select 3 x;
select 1 - number as number from numbers(3) order by number;
select number * number + 1 as number, number + 1 as b from numbers(1);
select number * number + 1 as `number`, number + 1 as `b` from numbers(1);
select number * number + 1 `number`, number + 1 `b` from numbers(1);