1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use crate::common::DataType;
use crate::common::{ColumnDefinition, FQName};
use itertools::Itertools;
use std::fmt::{Display, Formatter};
#[derive(PartialEq, Debug, Clone)]
pub struct CreateFunction {
pub or_replace: bool,
pub not_exists: bool,
pub name: FQName,
pub params: Vec<ColumnDefinition>,
pub return_null: bool,
pub return_type: DataType,
pub language: String,
pub code_block: String,
}
impl Display for CreateFunction {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(
f,
"CREATE {}FUNCTION {}{} ({}) {} ON NULL INPUT RETURNS {} LANGUAGE {} AS {}",
if self.or_replace { "OR REPLACE " } else { "" },
if self.not_exists {
"IF NOT EXISTS "
} else {
""
},
self.name,
self.params.iter().map(|x| x.to_string()).join(", "),
if self.return_null {
"RETURNS NULL"
} else {
"CALLED"
},
self.return_type,
self.language,
self.code_block
)
}
}