risingwave_frontend/catalog/
function_catalog.rs1use enum_as_inner::EnumAsInner;
16use parse_display::Display;
17use risingwave_common::catalog::FunctionId;
18use risingwave_common::types::DataType;
19use risingwave_pb::catalog::PbFunction;
20use risingwave_pb::catalog::function::PbKind;
21use risingwave_pb::expr::{PbUdfExprVersion, PbUserDefinedFunctionMetadata};
22
23use crate::catalog::OwnedByUserCatalog;
24
25#[derive(Clone, PartialEq, Eq, Hash, Debug)]
26pub struct FunctionCatalog {
27 pub id: FunctionId,
28 pub name: String,
29 pub owner: u32,
30 pub kind: FunctionKind,
31 pub arg_names: Vec<String>,
32 pub arg_types: Vec<DataType>,
33 pub return_type: DataType,
34 pub language: String,
35 pub runtime: Option<String>,
36 pub name_in_runtime: Option<String>,
37 pub body: Option<String>,
38 pub link: Option<String>,
39 pub compressed_binary: Option<Vec<u8>>,
40 pub always_retry_on_network_error: bool,
41 pub is_async: Option<bool>,
42 pub is_batched: Option<bool>,
43}
44
45#[derive(Clone, Display, PartialEq, Eq, Hash, Debug, EnumAsInner)]
46#[display(style = "UPPERCASE")]
47pub enum FunctionKind {
48 Scalar,
49 Table,
50 Aggregate,
51}
52
53impl From<&PbKind> for FunctionKind {
54 fn from(prost: &PbKind) -> Self {
55 use risingwave_pb::catalog::function::*;
56 match prost {
57 Kind::Scalar(ScalarFunction {}) => Self::Scalar,
58 Kind::Table(TableFunction {}) => Self::Table,
59 Kind::Aggregate(AggregateFunction {}) => Self::Aggregate,
60 }
61 }
62}
63
64impl From<&PbFunction> for FunctionCatalog {
65 fn from(prost: &PbFunction) -> Self {
66 FunctionCatalog {
67 id: prost.id.into(),
68 name: prost.name.clone(),
69 owner: prost.owner,
70 kind: prost.kind.as_ref().unwrap().into(),
71 arg_names: prost.arg_names.clone(),
72 arg_types: prost.arg_types.iter().map(|arg| arg.into()).collect(),
73 return_type: prost.return_type.as_ref().expect("no return type").into(),
74 language: prost.language.clone(),
75 runtime: prost.runtime.clone(),
76 name_in_runtime: prost.name_in_runtime.clone(),
77 body: prost.body.clone(),
78 link: prost.link.clone(),
79 compressed_binary: prost.compressed_binary.clone(),
80 always_retry_on_network_error: prost.always_retry_on_network_error,
81 is_async: prost.is_async,
82 is_batched: prost.is_batched,
83 }
84 }
85}
86
87impl From<&FunctionCatalog> for PbUserDefinedFunctionMetadata {
88 fn from(c: &FunctionCatalog) -> Self {
89 PbUserDefinedFunctionMetadata {
90 arg_names: c.arg_names.clone(),
91 arg_types: c.arg_types.iter().map(|t| t.to_protobuf()).collect(),
92 return_type: Some(c.return_type.to_protobuf()),
93 language: c.language.clone(),
94 runtime: c.runtime.clone(),
95 link: c.link.clone(),
96 identifier: c.name_in_runtime.clone(),
97 body: c.body.clone(),
98 compressed_binary: c.compressed_binary.clone(),
99 version: PbUdfExprVersion::LATEST as _,
100 }
101 }
102}
103
104impl OwnedByUserCatalog for FunctionCatalog {
105 fn owner(&self) -> u32 {
106 self.owner
107 }
108}