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
52
53
54
55
56
57
use std::fmt;
use serde::{Deserialize, Serialize};
use lowertest::MzReflect;
use repr::adt::char::{format_str_pad, Char};
use repr::{ColumnType, ScalarType};
use crate::scalar::func::EagerUnaryFunc;
#[derive(Ord, PartialOrd, Clone, Debug, Eq, PartialEq, Serialize, Deserialize, Hash, MzReflect)]
pub struct PadChar {
pub length: Option<usize>,
}
impl<'a> EagerUnaryFunc<'a> for PadChar {
type Input = &'a str;
type Output = Char<String>;
fn call(&self, a: &'a str) -> Char<String> {
Char(format_str_pad(a, self.length))
}
fn output_type(&self, input: ColumnType) -> ColumnType {
ScalarType::Char {
length: self.length,
}
.nullable(input.nullable)
}
}
impl fmt::Display for PadChar {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str("padchar")
}
}
sqlfunc!(
#[sqlname = "chartostr"]
#[preserves_uniqueness = true]
fn cast_char_to_string<'a>(a: Char<&'a str>) -> &'a str {
a.0
}
);