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