risingwave_meta_model/
function.rsuse risingwave_pb::catalog::function::Kind;
use risingwave_pb::catalog::PbFunction;
use sea_orm::entity::prelude::*;
use sea_orm::ActiveValue::Set;
use serde::{Deserialize, Serialize};
use crate::{DataType, DataTypeArray, FunctionId};
#[derive(Clone, Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum, Serialize, Deserialize)]
#[sea_orm(rs_type = "String", db_type = "string(None)")]
pub enum FunctionKind {
#[sea_orm(string_value = "Scalar")]
Scalar,
#[sea_orm(string_value = "Table")]
Table,
#[sea_orm(string_value = "Aggregate")]
Aggregate,
}
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[sea_orm(table_name = "function")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub function_id: FunctionId,
pub name: String,
pub arg_names: String,
pub arg_types: DataTypeArray,
pub return_type: DataType,
pub language: String,
pub runtime: Option<String>,
pub link: Option<String>,
pub identifier: Option<String>,
pub body: Option<String>,
pub compressed_binary: Option<Vec<u8>>,
pub kind: FunctionKind,
pub always_retry_on_network_error: bool,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::object::Entity",
from = "Column::FunctionId",
to = "super::object::Column::Oid",
on_update = "NoAction",
on_delete = "Cascade"
)]
Object,
}
impl Related<super::object::Entity> for Entity {
fn to() -> RelationDef {
Relation::Object.def()
}
}
impl ActiveModelBehavior for ActiveModel {}
impl From<Kind> for FunctionKind {
fn from(kind: Kind) -> Self {
match kind {
Kind::Scalar(_) => Self::Scalar,
Kind::Table(_) => Self::Table,
Kind::Aggregate(_) => Self::Aggregate,
}
}
}
impl From<FunctionKind> for Kind {
fn from(value: FunctionKind) -> Self {
match value {
FunctionKind::Scalar => Self::Scalar(Default::default()),
FunctionKind::Table => Self::Table(Default::default()),
FunctionKind::Aggregate => Self::Aggregate(Default::default()),
}
}
}
impl From<PbFunction> for ActiveModel {
fn from(function: PbFunction) -> Self {
Self {
function_id: Set(function.id as _),
name: Set(function.name),
arg_names: Set(function.arg_names.join(",")),
arg_types: Set(DataTypeArray::from(function.arg_types)),
return_type: Set(DataType::from(&function.return_type.unwrap())),
language: Set(function.language),
runtime: Set(function.runtime),
link: Set(function.link),
identifier: Set(function.identifier),
body: Set(function.body),
compressed_binary: Set(function.compressed_binary),
kind: Set(function.kind.unwrap().into()),
always_retry_on_network_error: Set(function.always_retry_on_network_error),
}
}
}