Skip to content

Commit

Permalink
update macro doc
Browse files Browse the repository at this point in the history
Signed-off-by: Runji Wang <wangrunji0408@163.com>
  • Loading branch information
wangrunji0408 committed Sep 15, 2023
1 parent 8b33158 commit c21eaab
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
14 changes: 7 additions & 7 deletions src/expr/macro/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ impl FunctionAttr {
return self.generate_table_function_descriptor(user_fn, build_fn);
}
let name = self.name.clone();
let mut args = Vec::with_capacity(self.args.len());
for ty in &self.args {
if ty == "..." {
break;
}
args.push(data_type_name(ty));
}
let variadic = matches!(self.args.last(), Some(t) if t == "...");
let args = match variadic {
true => &self.args[..self.args.len() - 1],
false => &self.args[..],
}
.iter()
.map(|ty| data_type_name(ty))
.collect_vec();
let ret = data_type_name(&self.ret);

let pb_type = format_ident!("{}", utils::to_camel_case(&name));
Expand Down
26 changes: 22 additions & 4 deletions src/expr/macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ mod utils;
/// - [Rust Function Signature](#rust-function-signature)
/// - [Nullable Arguments](#nullable-arguments)
/// - [Return Value](#return-value)
/// - [Variadic Function](#variadic-function)
/// - [Optimization](#optimization)
/// - [Functions Returning Strings](#functions-returning-strings)
/// - [Preprocessing Constant Arguments](#preprocessing-constant-arguments)
Expand All @@ -62,13 +63,15 @@ mod utils;
/// invocation. The signature follows this pattern:
///
/// ```text
/// name ( [arg_types],* ) [ -> [setof] return_type ]
/// name ( [arg_types],* [...] ) [ -> [setof] return_type ]
/// ```
///
/// Where `name` is the function name, which must match the function name defined in `prost`.
/// Where `name` is the function name in `snake_case`, which must match the function name defined
/// in `prost`.
///
/// The allowed data types are listed in the `name` column of the appendix's [type matrix].
/// Wildcards or `auto` can also be used, as explained below.
/// `arg_types` is a comma-separated list of argument types. The allowed data types are listed in
/// in the `name` column of the appendix's [type matrix]. Wildcards or `auto` can also be used, as
/// explained below. If the function is variadic, the last argument can be denoted as `...`.
///
/// When `setof` appears before the return type, this indicates that the function is a set-returning
/// function (table function), meaning it can return multiple values instead of just one. For more
Expand Down Expand Up @@ -203,6 +206,21 @@ mod utils;
///
/// Therefore, try to avoid returning `Option` and `Result` whenever possible.
///
/// ## Variadic Function
///
/// Variadic functions accept a `impl Row` input to represent tailing arguments.
/// For example:
///
/// ```ignore
/// #[function("concat_ws(varchar, ...) -> varchar")]
/// fn concat_ws(sep: &str, vals: impl Row) -> Option<Box<str>> {
/// let mut string_iter = vals.iter().flatten();
/// // ...
/// }
/// ```
///
/// See `risingwave_common::row::Row` for more details.
///
/// ## Functions Returning Strings
///
/// For functions that return varchar types, you can also use the writer style function signature to
Expand Down

0 comments on commit c21eaab

Please sign in to comment.