Skip to content

Commit 071b980

Browse files
committed
Merge branch 'type_check_test' into expr_cast
2 parents f38bf14 + 7299472 commit 071b980

File tree

8 files changed

+16534
-0
lines changed

8 files changed

+16534
-0
lines changed

src/query/functions/tests/it/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@
2121
// We can generate new test files via using `env REGENERATE_GOLDENFILES=1 cargo test` and `git diff` to show differs
2222
mod aggregates;
2323
mod scalars;
24+
mod type_check;
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
// Copyright 2021 Datafuse Labs
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
use databend_common_expression::types::*;
16+
use databend_common_expression::FromData;
17+
use goldenfile::Mint;
18+
19+
use crate::scalars::run_ast;
20+
21+
#[test]
22+
fn test_type_check() {
23+
let mut mint = Mint::new("tests/it/type_check/testdata");
24+
25+
let columns = [
26+
("s", StringType::from_data(vec!["s"])),
27+
("n_s", StringType::from_data(vec!["s"]).wrap_nullable(None)),
28+
("i8", Int8Type::from_data(vec![0])),
29+
("n_i8", Int8Type::from_data(vec![0]).wrap_nullable(None)),
30+
("u8", UInt8Type::from_data(vec![0])),
31+
("n_u8", UInt8Type::from_data(vec![0]).wrap_nullable(None)),
32+
("i16", Int16Type::from_data(vec![0])),
33+
("n_i16", Int16Type::from_data(vec![0]).wrap_nullable(None)),
34+
("u16", UInt16Type::from_data(vec![0])),
35+
("n_u16", UInt16Type::from_data(vec![0]).wrap_nullable(None)),
36+
("i32", Int32Type::from_data(vec![0])),
37+
("n_i32", Int32Type::from_data(vec![0]).wrap_nullable(None)),
38+
("u32", UInt32Type::from_data(vec![0])),
39+
("n_u32", UInt32Type::from_data(vec![0]).wrap_nullable(None)),
40+
("i64", Int64Type::from_data(vec![0])),
41+
("n_i64", Int64Type::from_data(vec![0]).wrap_nullable(None)),
42+
("u64", UInt64Type::from_data(vec![0])),
43+
("n_u64", UInt64Type::from_data(vec![0]).wrap_nullable(None)),
44+
("f32", Float32Type::from_data(vec![0.0])),
45+
(
46+
"n_f32",
47+
Float32Type::from_data(vec![0.0]).wrap_nullable(None),
48+
),
49+
("f64", Float64Type::from_data(vec![0.0])),
50+
(
51+
"n_f64",
52+
Float64Type::from_data(vec![0.0]).wrap_nullable(None),
53+
),
54+
("b", BooleanType::from_data(vec![true])),
55+
(
56+
"n_b",
57+
BooleanType::from_data(vec![true]).wrap_nullable(None),
58+
),
59+
("d", DateType::from_data(vec![0])),
60+
("n_d", DateType::from_data(vec![0]).wrap_nullable(None)),
61+
("ts", TimestampType::from_data(vec![0])),
62+
(
63+
"n_ts",
64+
TimestampType::from_data(vec![0]).wrap_nullable(None),
65+
),
66+
// BinaryColumn != BinaryColumn
67+
// ("j", VariantType::from_data(vec![b"{}".into()])),
68+
// (
69+
// "n_j",
70+
// VariantType::from_data(vec![b"{}".into()]).wrap_nullable(None),
71+
// ),
72+
("d128", Decimal128Type::from_data(vec![0_i128])),
73+
(
74+
"n_d128",
75+
Decimal128Type::from_data(vec![0_i128]).wrap_nullable(None),
76+
),
77+
("d256", Decimal256Type::from_data(vec![ethnum::I256::ZERO])),
78+
(
79+
"n_d256",
80+
Decimal256Type::from_data(vec![ethnum::I256::ZERO]).wrap_nullable(None),
81+
),
82+
];
83+
84+
// 8 and 16 are just smaller 32.
85+
let size = ["32", "64"];
86+
87+
let signed = size.iter().map(|s| format!("i{}", s)).collect::<Vec<_>>();
88+
let unsigned = size.iter().map(|s| format!("u{}", s)).collect::<Vec<_>>();
89+
let nullable_signed = size.iter().map(|s| format!("n_i{}", s)).collect::<Vec<_>>();
90+
let nullable_unsigned = size.iter().map(|s| format!("n_u{}", s)).collect::<Vec<_>>();
91+
let float = size
92+
.iter()
93+
.flat_map(|s| [format!("f{s}"), format!("n_f{s}")].into_iter())
94+
.collect::<Vec<_>>();
95+
let decimal = ["d128", "n_d128", "d256", "n_d256"]
96+
.into_iter()
97+
.map(String::from)
98+
.collect::<Vec<_>>();
99+
100+
let all_num = signed
101+
.iter()
102+
.chain(unsigned.iter())
103+
.chain(nullable_signed.iter())
104+
.chain(nullable_unsigned.iter())
105+
.chain(float.iter())
106+
.chain(decimal.iter())
107+
.collect::<Vec<_>>();
108+
109+
for (name, types) in [
110+
("signed", &signed),
111+
("unsigned", &unsigned),
112+
("nullable_signed", &nullable_signed),
113+
("nullable_unsigned", &nullable_unsigned),
114+
("float", &float),
115+
("decimal", &decimal),
116+
] {
117+
let file = &mut mint.new_goldenfile(format!("{name}.txt")).unwrap();
118+
let pair = types
119+
.iter()
120+
.flat_map(|lhs| all_num.iter().map(move |rhs| (lhs, *rhs)))
121+
.collect::<Vec<_>>();
122+
for (lhs, rhs) in pair {
123+
run_ast(file, format!("{lhs} > {rhs}"), &columns);
124+
run_ast(file, format!("{lhs} = {rhs}"), &columns);
125+
}
126+
127+
for ty in types {
128+
run_ast(file, format!("{ty} > 1"), &columns);
129+
run_ast(file, format!("{ty} = 1"), &columns);
130+
run_ast(file, format!("1 > {ty}"), &columns);
131+
run_ast(file, format!("1 = {ty}"), &columns);
132+
133+
run_ast(file, format!("{ty} > 1.0"), &columns);
134+
run_ast(file, format!("{ty} = 1.0"), &columns);
135+
run_ast(file, format!("1.0 > {ty}"), &columns);
136+
run_ast(file, format!("1.0 = {ty}"), &columns);
137+
138+
run_ast(file, format!("{ty} > '1'"), &columns);
139+
run_ast(file, format!("{ty} = '1'"), &columns);
140+
run_ast(file, format!("'1' > {ty}"), &columns);
141+
run_ast(file, format!("'1' = {ty}"), &columns);
142+
143+
run_ast(file, format!("{ty} > 1::uint64"), &columns);
144+
run_ast(file, format!("{ty} = 1::uint64"), &columns);
145+
run_ast(file, format!("1::uint64 > {ty}"), &columns);
146+
run_ast(file, format!("1::uint64 = {ty}"), &columns);
147+
}
148+
}
149+
}

0 commit comments

Comments
 (0)