From 53b7636860b1ed3cf1bdea8547de88255510ce2d Mon Sep 17 00:00:00 2001 From: zwang28 <70626450+zwang28@users.noreply.github.com> Date: Wed, 13 Sep 2023 21:52:49 +0800 Subject: [PATCH 1/8] refactor(expr): allow defining function in frontend Signed-off-by: TennyZhuang --- Cargo.lock | 2 + Cargo.toml | 1 + proto/expr.proto | 3 ++ src/expr/macro/src/gen.rs | 40 +++++++++---------- src/expr/src/lib.rs | 4 +- src/frontend/Cargo.toml | 2 + src/frontend/src/binder/expr/function.rs | 2 +- .../src/expr/function/col_description.rs | 11 +++++ src/frontend/src/expr/function/mod.rs | 1 + src/frontend/src/expr/mod.rs | 1 + src/frontend/src/expr/pure.rs | 4 +- 11 files changed, 48 insertions(+), 23 deletions(-) create mode 100644 src/frontend/src/expr/function/col_description.rs create mode 100644 src/frontend/src/expr/function/mod.rs diff --git a/Cargo.lock b/Cargo.lock index 1069bd493b209..081644f23759b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7019,6 +7019,7 @@ dependencies = [ "bk-tree", "bytes", "clap", + "ctor", "downcast-rs", "dyn-clone", "easy-ext", @@ -7051,6 +7052,7 @@ dependencies = [ "risingwave_common_service", "risingwave_connector", "risingwave_expr", + "risingwave_expr_macro", "risingwave_pb", "risingwave_rpc_client", "risingwave_source", diff --git a/Cargo.toml b/Cargo.toml index e33c09ddc5734..7aba5fdccc46c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -123,6 +123,7 @@ risingwave_compute = { path = "./src/compute" } risingwave_ctl = { path = "./src/ctl" } risingwave_connector = { path = "./src/connector" } risingwave_expr = { path = "./src/expr" } +risingwave_expr_macro = { path = "./src/expr/macro" } risingwave_frontend = { path = "./src/frontend" } risingwave_hummock_sdk = { path = "./src/storage/hummock_sdk" } risingwave_hummock_test = { path = "./src/storage/hummock_test" } diff --git a/proto/expr.proto b/proto/expr.proto index c4779deafacb4..edba9a9af89d7 100644 --- a/proto/expr.proto +++ b/proto/expr.proto @@ -220,6 +220,9 @@ message ExprNode { VNODE = 1101; // Non-deterministic functions PROCTIME = 2023; + + // Adminitration functions + COL_DESCRIPTION = 2100; } Type function_type = 1; data.DataType return_type = 3; diff --git a/src/expr/macro/src/gen.rs b/src/expr/macro/src/gen.rs index 9dcde3c6ffdc2..1f611278a041d 100644 --- a/src/expr/macro/src/gen.rs +++ b/src/expr/macro/src/gen.rs @@ -67,7 +67,7 @@ impl FunctionAttr { let pb_type = format_ident!("{}", utils::to_camel_case(&name)); let ctor_name = format_ident!("{}", self.ident_name()); - let descriptor_type = quote! { crate::sig::func::FuncSign }; + let descriptor_type = quote! { risingwave_expr::sig::func::FuncSign }; let build_fn = if build_fn { let name = format_ident!("{}", user_fn.name); quote! { #name } @@ -79,7 +79,7 @@ impl FunctionAttr { #[ctor::ctor] fn #ctor_name() { use risingwave_common::types::{DataType, DataTypeName}; - unsafe { crate::sig::func::_register(#descriptor_type { + unsafe { risingwave_expr::sig::func::_register(#descriptor_type { func: risingwave_pb::expr::expr_node::Type::#pb_type, inputs_type: &[#(#args),*], ret_type: #ret, @@ -199,7 +199,7 @@ impl FunctionAttr { let #prebuilt_inputs = match &#prebuilt_inputs { Some(s) => s.as_scalar_ref_impl().try_into()?, // the function should always return null if any const argument is null - None => return Ok(Box::new(crate::expr::LiteralExpression::new( + None => return Ok(Box::new(risingwave_expr::expr::LiteralExpression::new( return_type, None, ))), @@ -358,8 +358,8 @@ impl FunctionAttr { }; Ok(quote! { - |return_type: DataType, children: Vec| - -> crate::Result + |return_type: DataType, children: Vec| + -> risingwave_expr::Result { use std::sync::Arc; use risingwave_common::array::*; @@ -369,10 +369,10 @@ impl FunctionAttr { use risingwave_common::util::iter_util::ZipEqFast; use itertools::multizip; - use crate::expr::{Context, BoxedExpression}; - use crate::Result; + use risingwave_expr::expr::{Context, BoxedExpression}; + use risingwave_expr::Result; - crate::ensure!(children.len() == #num_args); + risingwave_expr::ensure!(children.len() == #num_args); let prebuilt_arg = #prebuild_const; let context = Context { return_type, @@ -388,7 +388,7 @@ impl FunctionAttr { prebuilt_arg: #prebuilt_arg_type, } #[async_trait::async_trait] - impl crate::expr::Expression for #struct_name { + impl risingwave_expr::expr::Expression for #struct_name { fn return_type(&self) -> DataType { self.context.return_type.clone() } @@ -436,7 +436,7 @@ impl FunctionAttr { let pb_type = format_ident!("{}", utils::to_camel_case(&name)); let ctor_name = format_ident!("{}", self.ident_name()); - let descriptor_type = quote! { crate::sig::agg::AggFuncSig }; + let descriptor_type = quote! { risingwave_expr::sig::agg::AggFuncSig }; let build_fn = if build_fn { let name = format_ident!("{}", user_fn.name); quote! { #name } @@ -447,8 +447,8 @@ impl FunctionAttr { #[ctor::ctor] fn #ctor_name() { use risingwave_common::types::{DataType, DataTypeName}; - unsafe { crate::sig::agg::_register(#descriptor_type { - func: crate::agg::AggKind::#pb_type, + unsafe { risingwave_expr::sig::agg::_register(#descriptor_type { + func: risingwave_expr::agg::AggKind::#pb_type, inputs_type: &[#(#args),*], ret_type: #ret, build: #build_fn, @@ -561,8 +561,8 @@ impl FunctionAttr { use risingwave_common::buffer::Bitmap; use risingwave_common::estimate_size::EstimateSize; - use crate::Result; - use crate::agg::AggregateState; + use risingwave_expr::Result; + use risingwave_expr::agg::AggregateState; #[derive(Clone)] struct Agg { @@ -570,7 +570,7 @@ impl FunctionAttr { } #[async_trait::async_trait] - impl crate::agg::AggregateFunction for Agg { + impl risingwave_expr::agg::AggregateFunction for Agg { fn return_type(&self) -> DataType { self.return_type.clone() } @@ -664,7 +664,7 @@ impl FunctionAttr { let pb_type = format_ident!("{}", utils::to_camel_case(&name)); let ctor_name = format_ident!("{}", self.ident_name()); - let descriptor_type = quote! { crate::sig::table_function::FuncSign }; + let descriptor_type = quote! { risingwave_expr::sig::table_function::FuncSign }; let build_fn = if build_fn { let name = format_ident!("{}", user_fn.name); quote! { #name } @@ -687,7 +687,7 @@ impl FunctionAttr { #[ctor::ctor] fn #ctor_name() { use risingwave_common::types::{DataType, DataTypeName}; - unsafe { crate::sig::table_function::_register(#descriptor_type { + unsafe { risingwave_expr::sig::table_function::_register(#descriptor_type { func: risingwave_pb::expr::table_function::Type::#pb_type, inputs_type: &[#(#args),*], ret_type: #ret, @@ -794,7 +794,7 @@ impl FunctionAttr { use risingwave_common::util::iter_util::ZipEqFast; use itertools::multizip; - crate::ensure!(children.len() == #num_args); + risingwave_expr::ensure!(children.len() == #num_args); let mut iter = children.into_iter(); #(let #all_child = iter.next().unwrap();)* #( @@ -802,7 +802,7 @@ impl FunctionAttr { let #const_child = match &#const_child { Some(s) => s.as_scalar_ref_impl().try_into()?, // the function should always return empty if any const argument is null - None => return Ok(crate::table_function::empty(return_type)), + None => return Ok(risingwave_expr::table_function::empty(return_type)), }; )* @@ -814,7 +814,7 @@ impl FunctionAttr { prebuilt_arg: #prebuilt_arg_type, } #[async_trait::async_trait] - impl crate::table_function::TableFunction for #struct_name { + impl risingwave_expr::table_function::TableFunction for #struct_name { fn return_type(&self) -> DataType { self.return_type.clone() } diff --git a/src/expr/src/lib.rs b/src/expr/src/lib.rs index ee4cea38e4bb5..6c4694a81cbe9 100644 --- a/src/expr/src/lib.rs +++ b/src/expr/src/lib.rs @@ -24,6 +24,8 @@ #![feature(test)] #![feature(arc_unwrap_or_clone)] +extern crate self as risingwave_expr; + pub mod agg; mod error; pub mod expr; @@ -34,5 +36,5 @@ pub mod vector_op; pub mod window_function; pub use error::{ExprError, Result}; -use risingwave_common::{bail, ensure}; +pub use risingwave_common::{bail, ensure}; pub use risingwave_expr_macro::*; diff --git a/src/frontend/Cargo.toml b/src/frontend/Cargo.toml index a80aa743d9c4b..22f56c5e5af60 100644 --- a/src/frontend/Cargo.toml +++ b/src/frontend/Cargo.toml @@ -24,6 +24,7 @@ auto_enums = { version = "0.8", features = ["futures03"] } bk-tree = "0.5.0" bytes = "1" clap = { version = "4", features = ["derive"] } +ctor = "0.2" downcast-rs = "1.2" dyn-clone = "1.0.13" easy-ext = "1" @@ -54,6 +55,7 @@ risingwave_common = { workspace = true } risingwave_common_service = { workspace = true } risingwave_connector = { workspace = true } risingwave_expr = { workspace = true } +risingwave_expr_macro = { workspace = true } risingwave_pb = { workspace = true } risingwave_rpc_client = { workspace = true } risingwave_source = { workspace = true } diff --git a/src/frontend/src/binder/expr/function.rs b/src/frontend/src/binder/expr/function.rs index 6bfa4883c6a5e..b167d460929af 100644 --- a/src/frontend/src/binder/expr/function.rs +++ b/src/frontend/src/binder/expr/function.rs @@ -1127,7 +1127,7 @@ impl Binder { // TODO: really implement them. // https://www.postgresql.org/docs/9.5/functions-info.html#FUNCTIONS-INFO-COMMENT-TABLE // WARN: Hacked in [`Binder::bind_function`]!!! - ("col_description", raw_literal(ExprImpl::literal_varchar("".to_string()))), + ("col_description", raw_call(ExprType::ColDescription)), ("obj_description", raw_literal(ExprImpl::literal_varchar("".to_string()))), ("shobj_description", raw_literal(ExprImpl::literal_varchar("".to_string()))), ("pg_is_in_recovery", raw_literal(ExprImpl::literal_bool(false))), diff --git a/src/frontend/src/expr/function/col_description.rs b/src/frontend/src/expr/function/col_description.rs new file mode 100644 index 0000000000000..8894ac0d21b26 --- /dev/null +++ b/src/frontend/src/expr/function/col_description.rs @@ -0,0 +1,11 @@ +use std::fmt::Write; + +use risingwave_expr::ExprError; +use risingwave_expr_macro::function; + +#[function("col_description(varchar, int32) -> varchar")] +fn col_description(_name: &str, _col: i32, writer: &mut impl Write) -> Result<(), ExprError> { + writer.write_str("").unwrap(); + + Ok(()) +} diff --git a/src/frontend/src/expr/function/mod.rs b/src/frontend/src/expr/function/mod.rs new file mode 100644 index 0000000000000..4565ac7bca1e3 --- /dev/null +++ b/src/frontend/src/expr/function/mod.rs @@ -0,0 +1 @@ +mod col_description; diff --git a/src/frontend/src/expr/mod.rs b/src/frontend/src/expr/mod.rs index d999fcbe4c1e8..07b8b032332c4 100644 --- a/src/frontend/src/expr/mod.rs +++ b/src/frontend/src/expr/mod.rs @@ -46,6 +46,7 @@ pub use order_by_expr::{OrderBy, OrderByExpr}; mod expr_mutator; mod expr_rewriter; mod expr_visitor; +mod function; mod session_timezone; mod type_inference; mod utils; diff --git a/src/frontend/src/expr/pure.rs b/src/frontend/src/expr/pure.rs index a229fed79b4f0..d635bd2bde332 100644 --- a/src/frontend/src/expr/pure.rs +++ b/src/frontend/src/expr/pure.rs @@ -207,7 +207,9 @@ impl ExprVisitor for ImpureAnalyzer { x } // expression output is not deterministic - expr_node::Type::Vnode | expr_node::Type::Proctime => true, + expr_node::Type::Vnode + | expr_node::Type::Proctime + | expr_node::Type::ColDescription => true, } } } From 06f81bebe13efd931fae7799feb13bce8e49c483 Mon Sep 17 00:00:00 2001 From: TennyZhuang Date: Thu, 14 Sep 2023 00:09:17 +0800 Subject: [PATCH 2/8] Update src/frontend/src/expr/function/col_description.rs Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/frontend/src/expr/function/col_description.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/frontend/src/expr/function/col_description.rs b/src/frontend/src/expr/function/col_description.rs index 8894ac0d21b26..58efd0a1ad775 100644 --- a/src/frontend/src/expr/function/col_description.rs +++ b/src/frontend/src/expr/function/col_description.rs @@ -1,3 +1,17 @@ +// Copyright 2023 RisingWave Labs +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + use std::fmt::Write; use risingwave_expr::ExprError; From 903131df5cb86999c60bf7a87083294d83d05ba2 Mon Sep 17 00:00:00 2001 From: TennyZhuang Date: Thu, 14 Sep 2023 00:09:27 +0800 Subject: [PATCH 3/8] Update src/frontend/src/expr/function/mod.rs Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/frontend/src/expr/function/mod.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/frontend/src/expr/function/mod.rs b/src/frontend/src/expr/function/mod.rs index 4565ac7bca1e3..33d402b4bb6af 100644 --- a/src/frontend/src/expr/function/mod.rs +++ b/src/frontend/src/expr/function/mod.rs @@ -1 +1,15 @@ +// Copyright 2023 RisingWave Labs +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + mod col_description; From a021d63e0023d6c0e06616f3284aaf934444a0c7 Mon Sep 17 00:00:00 2001 From: TennyZhuang Date: Sun, 17 Sep 2023 21:57:17 +0800 Subject: [PATCH 4/8] function -> function_impl Signed-off-by: TennyZhuang --- .../src/expr/{function => function_impl}/col_description.rs | 0 src/frontend/src/expr/{function => function_impl}/mod.rs | 0 src/frontend/src/expr/mod.rs | 2 +- 3 files changed, 1 insertion(+), 1 deletion(-) rename src/frontend/src/expr/{function => function_impl}/col_description.rs (100%) rename src/frontend/src/expr/{function => function_impl}/mod.rs (100%) diff --git a/src/frontend/src/expr/function/col_description.rs b/src/frontend/src/expr/function_impl/col_description.rs similarity index 100% rename from src/frontend/src/expr/function/col_description.rs rename to src/frontend/src/expr/function_impl/col_description.rs diff --git a/src/frontend/src/expr/function/mod.rs b/src/frontend/src/expr/function_impl/mod.rs similarity index 100% rename from src/frontend/src/expr/function/mod.rs rename to src/frontend/src/expr/function_impl/mod.rs diff --git a/src/frontend/src/expr/mod.rs b/src/frontend/src/expr/mod.rs index 07b8b032332c4..11fa86d682b7b 100644 --- a/src/frontend/src/expr/mod.rs +++ b/src/frontend/src/expr/mod.rs @@ -46,7 +46,7 @@ pub use order_by_expr::{OrderBy, OrderByExpr}; mod expr_mutator; mod expr_rewriter; mod expr_visitor; -mod function; +mod function_impl; mod session_timezone; mod type_inference; mod utils; From a53a0d02819fa37fc3c084ed2ea3206fa70a5b71 Mon Sep 17 00:00:00 2001 From: TennyZhuang Date: Sun, 17 Sep 2023 22:00:09 +0800 Subject: [PATCH 5/8] add a comment Signed-off-by: TennyZhuang --- src/frontend/src/expr/function_impl/col_description.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/frontend/src/expr/function_impl/col_description.rs b/src/frontend/src/expr/function_impl/col_description.rs index 58efd0a1ad775..adb16aabc99fe 100644 --- a/src/frontend/src/expr/function_impl/col_description.rs +++ b/src/frontend/src/expr/function_impl/col_description.rs @@ -19,6 +19,7 @@ use risingwave_expr_macro::function; #[function("col_description(varchar, int32) -> varchar")] fn col_description(_name: &str, _col: i32, writer: &mut impl Write) -> Result<(), ExprError> { + // TODO: Currently we don't support `COMMENT` statement, so we just return empty string. writer.write_str("").unwrap(); Ok(()) From dc18a2482985fd04d2775591fbbac1c2c4e77951 Mon Sep 17 00:00:00 2001 From: TennyZhuang Date: Mon, 18 Sep 2023 15:22:00 +0800 Subject: [PATCH 6/8] remove expr::function::window Signed-off-by: TennyZhuang --- src/batch/src/executor/sort_over_window.rs | 5 +++-- src/expr/src/function/mod.rs | 17 ----------------- src/expr/src/function/window/mod.rs | 15 --------------- src/expr/src/lib.rs | 1 - src/expr/src/window_function/state/aggregate.rs | 2 +- src/expr/src/window_function/state/buffer.rs | 4 ++-- src/expr/src/window_function/state/mod.rs | 3 +-- .../src/window_function/state/row_number.rs | 4 ++-- src/frontend/src/binder/expr/function.rs | 2 +- src/frontend/src/expr/window_function.rs | 2 +- .../optimizer/plan_node/generic/over_window.rs | 2 +- .../optimizer/plan_node/logical_over_window.rs | 2 +- .../rule/over_window_to_agg_and_join_rule.rs | 2 +- .../optimizer/rule/over_window_to_topn_rule.rs | 2 +- src/stream/src/from_proto/eowc_over_window.rs | 2 +- src/stream/src/from_proto/over_window.rs | 2 +- .../tests/integration_tests/eowc_over_window.rs | 2 +- .../tests/integration_tests/over_window.rs | 2 +- 18 files changed, 19 insertions(+), 52 deletions(-) delete mode 100644 src/expr/src/function/mod.rs delete mode 100644 src/expr/src/function/window/mod.rs diff --git a/src/batch/src/executor/sort_over_window.rs b/src/batch/src/executor/sort_over_window.rs index f12ebc2452384..c8b6c7ef9388c 100644 --- a/src/batch/src/executor/sort_over_window.rs +++ b/src/batch/src/executor/sort_over_window.rs @@ -19,8 +19,9 @@ use risingwave_common::error::{Result, RwError}; use risingwave_common::row::{OwnedRow, Row, RowExt}; use risingwave_common::util::chunk_coalesce::DataChunkBuilder; use risingwave_common::util::iter_util::ZipEqFast; -use risingwave_expr::function::window::WindowFuncCall; -use risingwave_expr::window_function::{create_window_state, StateKey, WindowStates}; +use risingwave_expr::window_function::{ + create_window_state, StateKey, WindowFuncCall, WindowStates, +}; use risingwave_pb::batch_plan::plan_node::NodeBody; use super::{BoxedDataChunkStream, BoxedExecutor, BoxedExecutorBuilder, Executor, ExecutorBuilder}; diff --git a/src/expr/src/function/mod.rs b/src/expr/src/function/mod.rs deleted file mode 100644 index ed628e99398ca..0000000000000 --- a/src/expr/src/function/mod.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2023 RisingWave Labs -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -pub mod window; - -// TODO(rc): this module is to be removed diff --git a/src/expr/src/function/window/mod.rs b/src/expr/src/function/window/mod.rs deleted file mode 100644 index add145718c948..0000000000000 --- a/src/expr/src/function/window/mod.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2023 RisingWave Labs -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -pub use crate::window_function::*; diff --git a/src/expr/src/lib.rs b/src/expr/src/lib.rs index 6c4694a81cbe9..639e66da19df2 100644 --- a/src/expr/src/lib.rs +++ b/src/expr/src/lib.rs @@ -29,7 +29,6 @@ extern crate self as risingwave_expr; pub mod agg; mod error; pub mod expr; -pub mod function; pub mod sig; pub mod table_function; pub mod vector_op; diff --git a/src/expr/src/window_function/state/aggregate.rs b/src/expr/src/window_function/state/aggregate.rs index b67d42042bc91..749baf7784343 100644 --- a/src/expr/src/window_function/state/aggregate.rs +++ b/src/expr/src/window_function/state/aggregate.rs @@ -25,7 +25,7 @@ use smallvec::SmallVec; use super::buffer::WindowBuffer; use super::{StateEvictHint, StateKey, StatePos, WindowState}; use crate::agg::{build_append_only, AggArgs, AggCall, BoxedAggregateFunction}; -use crate::function::window::{WindowFuncCall, WindowFuncKind}; +use crate::window_function::{WindowFuncCall, WindowFuncKind}; use crate::Result; pub struct AggregateState { diff --git a/src/expr/src/window_function/state/buffer.rs b/src/expr/src/window_function/state/buffer.rs index 97f68b18375b2..a375c7bfec225 100644 --- a/src/expr/src/window_function/state/buffer.rs +++ b/src/expr/src/window_function/state/buffer.rs @@ -17,7 +17,7 @@ use std::ops::Range; use either::Either; -use crate::function::window::{Frame, FrameBounds, FrameExclusion}; +use crate::window_function::{Frame, FrameBounds, FrameExclusion}; struct Entry { key: K, @@ -238,7 +238,7 @@ mod tests { use itertools::Itertools; use super::*; - use crate::function::window::{Frame, FrameBound}; + use crate::window_function::{Frame, FrameBound}; #[test] fn test_rows_frame_unbounded_preceding_to_current_row() { diff --git a/src/expr/src/window_function/state/mod.rs b/src/expr/src/window_function/state/mod.rs index fe6e47b016d40..977a04b2a7a70 100644 --- a/src/expr/src/window_function/state/mod.rs +++ b/src/expr/src/window_function/state/mod.rs @@ -20,8 +20,7 @@ use risingwave_common::types::{Datum, DefaultOrdered}; use risingwave_common::util::memcmp_encoding::MemcmpEncoded; use smallvec::SmallVec; -use super::WindowFuncCall; -use crate::function::window::WindowFuncKind; +use super::{WindowFuncCall, WindowFuncKind}; use crate::sig::FuncSigDebug; use crate::{ExprError, Result}; diff --git a/src/expr/src/window_function/state/row_number.rs b/src/expr/src/window_function/state/row_number.rs index 01b713cbc1196..7abf30fc5f5c7 100644 --- a/src/expr/src/window_function/state/row_number.rs +++ b/src/expr/src/window_function/state/row_number.rs @@ -18,7 +18,7 @@ use risingwave_common::types::Datum; use smallvec::SmallVec; use super::{StateEvictHint, StateKey, StatePos, WindowState}; -use crate::function::window::WindowFuncCall; +use crate::window_function::WindowFuncCall; use crate::Result; #[derive(EstimateSize)] @@ -83,7 +83,7 @@ mod tests { use super::*; use crate::agg::AggArgs; - use crate::function::window::{Frame, FrameBound, WindowFuncKind}; + use crate::window_function::{Frame, FrameBound, WindowFuncKind}; fn create_state_key(pk: i64) -> StateKey { StateKey { diff --git a/src/frontend/src/binder/expr/function.rs b/src/frontend/src/binder/expr/function.rs index 8e6deb14505f2..1146050e8dde4 100644 --- a/src/frontend/src/binder/expr/function.rs +++ b/src/frontend/src/binder/expr/function.rs @@ -26,7 +26,7 @@ use risingwave_common::session_config::USER_NAME_WILD_CARD; use risingwave_common::types::{DataType, ScalarImpl, Timestamptz}; use risingwave_common::{GIT_SHA, RW_VERSION}; use risingwave_expr::agg::{agg_kinds, AggKind}; -use risingwave_expr::function::window::{ +use risingwave_expr::window_function::{ Frame, FrameBound, FrameBounds, FrameExclusion, WindowFuncKind, }; use risingwave_sqlparser::ast::{ diff --git a/src/frontend/src/expr/window_function.rs b/src/frontend/src/expr/window_function.rs index 62f961515cdd0..371a00dc6b62a 100644 --- a/src/frontend/src/expr/window_function.rs +++ b/src/frontend/src/expr/window_function.rs @@ -15,7 +15,7 @@ use itertools::Itertools; use risingwave_common::error::{ErrorCode, RwError}; use risingwave_common::types::DataType; -use risingwave_expr::function::window::{Frame, WindowFuncKind}; +use risingwave_expr::window_function::{Frame, WindowFuncKind}; use super::{AggCall, Expr, ExprImpl, OrderBy, RwResult}; diff --git a/src/frontend/src/optimizer/plan_node/generic/over_window.rs b/src/frontend/src/optimizer/plan_node/generic/over_window.rs index 5f7b0705fba26..c148711698a24 100644 --- a/src/frontend/src/optimizer/plan_node/generic/over_window.rs +++ b/src/frontend/src/optimizer/plan_node/generic/over_window.rs @@ -18,7 +18,7 @@ use risingwave_common::catalog::{Field, Schema}; use risingwave_common::types::DataType; use risingwave_common::util::column_index_mapping::ColIndexMapping; use risingwave_common::util::sort_util::{ColumnOrder, ColumnOrderDisplay}; -use risingwave_expr::function::window::{Frame, WindowFuncKind}; +use risingwave_expr::window_function::{Frame, WindowFuncKind}; use risingwave_pb::expr::PbWindowFunction; use super::{DistillUnit, GenericPlanNode, GenericPlanRef}; diff --git a/src/frontend/src/optimizer/plan_node/logical_over_window.rs b/src/frontend/src/optimizer/plan_node/logical_over_window.rs index b2057f28e05fc..ed74f379cf4ba 100644 --- a/src/frontend/src/optimizer/plan_node/logical_over_window.rs +++ b/src/frontend/src/optimizer/plan_node/logical_over_window.rs @@ -18,7 +18,7 @@ use risingwave_common::error::{ErrorCode, Result, RwError}; use risingwave_common::types::{DataType, Datum, ScalarImpl}; use risingwave_common::util::sort_util::{ColumnOrder, OrderType}; use risingwave_expr::agg::AggKind; -use risingwave_expr::function::window::{Frame, FrameBound, WindowFuncKind}; +use risingwave_expr::window_function::{Frame, FrameBound, WindowFuncKind}; use super::generic::{GenericPlanRef, OverWindow, PlanWindowFunction, ProjectBuilder}; use super::utils::impl_distill_by_unit; diff --git a/src/frontend/src/optimizer/rule/over_window_to_agg_and_join_rule.rs b/src/frontend/src/optimizer/rule/over_window_to_agg_and_join_rule.rs index b9587650f8726..dbf3e9809675c 100644 --- a/src/frontend/src/optimizer/rule/over_window_to_agg_and_join_rule.rs +++ b/src/frontend/src/optimizer/rule/over_window_to_agg_and_join_rule.rs @@ -13,7 +13,7 @@ // limitations under the License. use itertools::Itertools; -use risingwave_expr::function::window::WindowFuncKind; +use risingwave_expr::window_function::WindowFuncKind; use risingwave_pb::expr::expr_node::Type; use risingwave_pb::plan_common::JoinType; diff --git a/src/frontend/src/optimizer/rule/over_window_to_topn_rule.rs b/src/frontend/src/optimizer/rule/over_window_to_topn_rule.rs index 297522a41c8c9..dfb6963c7fb4f 100644 --- a/src/frontend/src/optimizer/rule/over_window_to_topn_rule.rs +++ b/src/frontend/src/optimizer/rule/over_window_to_topn_rule.rs @@ -14,7 +14,7 @@ use fixedbitset::FixedBitSet; use risingwave_common::types::DataType; -use risingwave_expr::function::window::WindowFuncKind; +use risingwave_expr::window_function::WindowFuncKind; use super::Rule; use crate::expr::{collect_input_refs, ExprImpl, ExprType}; diff --git a/src/stream/src/from_proto/eowc_over_window.rs b/src/stream/src/from_proto/eowc_over_window.rs index 0cd0060a40b68..bcee0736ae30f 100644 --- a/src/stream/src/from_proto/eowc_over_window.rs +++ b/src/stream/src/from_proto/eowc_over_window.rs @@ -14,7 +14,7 @@ use std::sync::Arc; -use risingwave_expr::function::window::WindowFuncCall; +use risingwave_expr::window_function::WindowFuncCall; use risingwave_pb::stream_plan::PbEowcOverWindowNode; use risingwave_storage::StateStore; diff --git a/src/stream/src/from_proto/over_window.rs b/src/stream/src/from_proto/over_window.rs index 7d139ca3f74db..e18e753caf126 100644 --- a/src/stream/src/from_proto/over_window.rs +++ b/src/stream/src/from_proto/over_window.rs @@ -16,7 +16,7 @@ use std::sync::Arc; use risingwave_common::session_config::OverWindowCachePolicy; use risingwave_common::util::sort_util::ColumnOrder; -use risingwave_expr::function::window::WindowFuncCall; +use risingwave_expr::window_function::WindowFuncCall; use risingwave_pb::stream_plan::PbOverWindowNode; use risingwave_storage::StateStore; diff --git a/src/stream/tests/integration_tests/eowc_over_window.rs b/src/stream/tests/integration_tests/eowc_over_window.rs index d7d788680af55..35cc4954aff45 100644 --- a/src/stream/tests/integration_tests/eowc_over_window.rs +++ b/src/stream/tests/integration_tests/eowc_over_window.rs @@ -13,7 +13,7 @@ // limitations under the License. use risingwave_expr::agg::{AggArgs, AggKind}; -use risingwave_expr::function::window::{Frame, FrameBound, WindowFuncCall, WindowFuncKind}; +use risingwave_expr::window_function::{Frame, FrameBound, WindowFuncCall, WindowFuncKind}; use risingwave_stream::executor::{EowcOverWindowExecutor, EowcOverWindowExecutorArgs}; use crate::prelude::*; diff --git a/src/stream/tests/integration_tests/over_window.rs b/src/stream/tests/integration_tests/over_window.rs index 4b7b53aaae31b..2377ce12e9147 100644 --- a/src/stream/tests/integration_tests/over_window.rs +++ b/src/stream/tests/integration_tests/over_window.rs @@ -14,7 +14,7 @@ use risingwave_common::session_config::OverWindowCachePolicy; use risingwave_expr::agg::{AggArgs, AggKind}; -use risingwave_expr::function::window::{ +use risingwave_expr::window_function::{ Frame, FrameBound, FrameExclusion, WindowFuncCall, WindowFuncKind, }; use risingwave_stream::executor::monitor::StreamingMetrics; From e36dff343d894dfd964e3650b4da80263c6c4115 Mon Sep 17 00:00:00 2001 From: TennyZhuang Date: Mon, 18 Sep 2023 15:25:15 +0800 Subject: [PATCH 7/8] re-export #[function] macros in expr Signed-off-by: TennyZhuang --- Cargo.lock | 2 -- Cargo.toml | 1 - src/frontend/Cargo.toml | 2 -- src/frontend/src/expr/function_impl/col_description.rs | 3 +-- 4 files changed, 1 insertion(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b16cac04f21eb..6cb0662b32155 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7039,7 +7039,6 @@ dependencies = [ "bk-tree", "bytes", "clap", - "ctor", "downcast-rs", "dyn-clone", "easy-ext", @@ -7072,7 +7071,6 @@ dependencies = [ "risingwave_common_service", "risingwave_connector", "risingwave_expr", - "risingwave_expr_macro", "risingwave_pb", "risingwave_rpc_client", "risingwave_source", diff --git a/Cargo.toml b/Cargo.toml index 515fb828b7eb2..5742b9efc3713 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -127,7 +127,6 @@ risingwave_compute = { path = "./src/compute" } risingwave_ctl = { path = "./src/ctl" } risingwave_connector = { path = "./src/connector" } risingwave_expr = { path = "./src/expr" } -risingwave_expr_macro = { path = "./src/expr/macro" } risingwave_frontend = { path = "./src/frontend" } risingwave_hummock_sdk = { path = "./src/storage/hummock_sdk" } risingwave_hummock_test = { path = "./src/storage/hummock_test" } diff --git a/src/frontend/Cargo.toml b/src/frontend/Cargo.toml index 22f56c5e5af60..a80aa743d9c4b 100644 --- a/src/frontend/Cargo.toml +++ b/src/frontend/Cargo.toml @@ -24,7 +24,6 @@ auto_enums = { version = "0.8", features = ["futures03"] } bk-tree = "0.5.0" bytes = "1" clap = { version = "4", features = ["derive"] } -ctor = "0.2" downcast-rs = "1.2" dyn-clone = "1.0.13" easy-ext = "1" @@ -55,7 +54,6 @@ risingwave_common = { workspace = true } risingwave_common_service = { workspace = true } risingwave_connector = { workspace = true } risingwave_expr = { workspace = true } -risingwave_expr_macro = { workspace = true } risingwave_pb = { workspace = true } risingwave_rpc_client = { workspace = true } risingwave_source = { workspace = true } diff --git a/src/frontend/src/expr/function_impl/col_description.rs b/src/frontend/src/expr/function_impl/col_description.rs index adb16aabc99fe..8b6458eba5d30 100644 --- a/src/frontend/src/expr/function_impl/col_description.rs +++ b/src/frontend/src/expr/function_impl/col_description.rs @@ -14,8 +14,7 @@ use std::fmt::Write; -use risingwave_expr::ExprError; -use risingwave_expr_macro::function; +use risingwave_expr::{function, ExprError}; #[function("col_description(varchar, int32) -> varchar")] fn col_description(_name: &str, _col: i32, writer: &mut impl Write) -> Result<(), ExprError> { From 0b8fbb82a7f20d039a4c2440ca5dc0bbf6bdc99b Mon Sep 17 00:00:00 2001 From: TennyZhuang Date: Mon, 18 Sep 2023 15:36:12 +0800 Subject: [PATCH 8/8] re-export ctor Signed-off-by: TennyZhuang --- src/expr/macro/src/gen.rs | 6 +++--- src/expr/src/lib.rs | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/expr/macro/src/gen.rs b/src/expr/macro/src/gen.rs index acd14a6899019..77026581492c2 100644 --- a/src/expr/macro/src/gen.rs +++ b/src/expr/macro/src/gen.rs @@ -80,7 +80,7 @@ impl FunctionAttr { }; let deprecated = self.deprecated; Ok(quote! { - #[ctor::ctor] + #[risingwave_expr::ctor] fn #ctor_name() { use risingwave_common::types::{DataType, DataTypeName}; unsafe { risingwave_expr::sig::func::_register(#descriptor_type { @@ -505,7 +505,7 @@ impl FunctionAttr { self.generate_agg_build_fn(user_fn)? }; Ok(quote! { - #[ctor::ctor] + #[risingwave_expr::ctor] fn #ctor_name() { use risingwave_common::types::{DataType, DataTypeName}; unsafe { risingwave_expr::sig::agg::_register(#descriptor_type { @@ -800,7 +800,7 @@ impl FunctionAttr { quote! { |_| Ok(#ty) } }; Ok(quote! { - #[ctor::ctor] + #[risingwave_expr::ctor] fn #ctor_name() { use risingwave_common::types::{DataType, DataTypeName}; unsafe { risingwave_expr::sig::table_function::_register(#descriptor_type { diff --git a/src/expr/src/lib.rs b/src/expr/src/lib.rs index 639e66da19df2..c8f2e432f79af 100644 --- a/src/expr/src/lib.rs +++ b/src/expr/src/lib.rs @@ -34,6 +34,7 @@ pub mod table_function; pub mod vector_op; pub mod window_function; +pub use ctor::ctor; pub use error::{ExprError, Result}; pub use risingwave_common::{bail, ensure}; pub use risingwave_expr_macro::*;