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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use std::fmt;
use anyhow::bail;
use repr::RelationDesc;
use crate::ast::Ident;
use crate::normalize;
pub fn maybe_rename_columns(
context: impl fmt::Display,
desc: RelationDesc,
column_names: &[Ident],
) -> Result<RelationDesc, anyhow::Error> {
if column_names.is_empty() {
return Ok(desc);
}
if column_names.len() != desc.typ().column_types.len() {
bail!(
"{0} definition names {1} column{2}, but {0} has {3} column{4}",
context,
column_names.len(),
if column_names.len() == 1 { "" } else { "s" },
desc.typ().column_types.len(),
if desc.typ().column_types.len() == 1 {
""
} else {
"s"
},
)
}
let new_names = column_names
.iter()
.map(|n| normalize::column_name(n.clone()));
Ok(desc.with_names(new_names))
}
#[derive(Debug, Clone, Copy)]
pub enum JoinSide {
Left,
Right,
}
impl fmt::Display for JoinSide {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
JoinSide::Left => f.write_str("left"),
JoinSide::Right => f.write_str("right"),
}
}
}