Skip to content

Commit f21fe35

Browse files
committed
refine
1 parent 7ea6e7f commit f21fe35

34 files changed

+6030
-6015
lines changed

src/query/functions/tests/it/scalars/cast.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ fn test_decimal_to_decimal() {
764764
let file = &mut mint.new_goldenfile("decimal_to_decimal_cast.txt").unwrap();
765765

766766
run_ast_with_context(file, "a::decimal(15,2)", TestContext {
767-
columns: &[("a", UInt64Type::from_data(vec![0_u64, 100]))],
767+
entries: &[("a", UInt64Type::from_data(vec![0_u64, 100]).into())],
768768
input_domains: Some(&[(
769769
"a",
770770
Domain::Number(NumberDomain::UInt64(UInt64Type::full_domain())),
@@ -916,12 +916,13 @@ fn test_cast_decimal_scale_reduction(file: &mut impl Write, is_try: bool, roundi
916916

917917
// Test scale reduction with column data
918918
let test_ctx = TestContext {
919-
columns: &[(
919+
entries: &[(
920920
"c",
921921
Decimal128Type::from_data_with_size(
922922
[12345i128, 67890, -11111, 99999, 0, -99999, 123456],
923923
Some(DecimalSize::new_unchecked(8, 3)),
924-
),
924+
)
925+
.into(),
925926
)],
926927
func_ctx,
927928
..TestContext::default()

src/query/functions/tests/it/scalars/mod.rs

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub use databend_common_functions::test_utils as parser;
6464

6565
#[derive(Clone)]
6666
pub struct TestContext<'a> {
67-
pub columns: &'a [(&'a str, Column)],
67+
pub entries: &'a [(&'a str, BlockEntry)],
6868
pub input_domains: Option<&'a [(&'a str, Domain)]>,
6969
pub func_ctx: FunctionContext,
7070
pub strict_eval: bool,
@@ -73,7 +73,7 @@ pub struct TestContext<'a> {
7373
impl Default for TestContext<'_> {
7474
fn default() -> Self {
7575
Self {
76-
columns: &[],
76+
entries: &[],
7777
input_domains: None,
7878
func_ctx: FunctionContext::default(),
7979
strict_eval: true,
@@ -83,26 +83,36 @@ impl Default for TestContext<'_> {
8383

8484
impl<'a> TestContext<'a> {
8585
pub fn input_domains(&mut self) -> HashMap<usize, Domain> {
86-
self.columns
86+
self.entries
8787
.iter()
88-
.map(|(name, col)| {
88+
.map(|(name, entry)| {
8989
self.input_domains
9090
.and_then(|domains| {
9191
domains
9292
.iter()
9393
.find(|(n, _)| n == name)
9494
.map(|(_, domain)| domain.clone())
9595
})
96-
.unwrap_or_else(|| col.domain())
96+
.unwrap_or_else(|| match entry {
97+
BlockEntry::Const(scalar, data_type, _) => {
98+
scalar.as_ref().domain(data_type)
99+
}
100+
BlockEntry::Column(column) => column.domain(),
101+
})
97102
})
98103
.enumerate()
99104
.collect()
100105
}
101106
}
102107

103108
pub fn run_ast(file: &mut impl Write, text: impl AsRef<str>, columns: &[(&str, Column)]) {
109+
let entries = &columns
110+
.iter()
111+
.map(|(name, column)| (*name, column.clone().into()))
112+
.collect::<Vec<_>>();
113+
104114
run_ast_with_context(file, text, TestContext {
105-
columns,
115+
entries,
106116
func_ctx: FunctionContext::default(),
107117
input_domains: None,
108118
strict_eval: true,
@@ -115,9 +125,9 @@ pub fn run_ast_with_context(file: &mut impl Write, text: impl AsRef<str>, mut ct
115125
let result: Result<_> = try {
116126
let raw_expr = parser::parse_raw_expr(
117127
text,
118-
&ctx.columns
128+
&ctx.entries
119129
.iter()
120-
.map(|(name, c)| (*name, c.data_type()))
130+
.map(|(name, entry)| (*name, entry.data_type()))
121131
.collect::<Vec<_>>(),
122132
);
123133

@@ -136,17 +146,21 @@ pub fn run_ast_with_context(file: &mut impl Write, text: impl AsRef<str>, mut ct
136146
let remote_expr = optimized_expr.as_remote_expr();
137147
let optimized_expr = remote_expr.as_expr(&BUILTIN_FUNCTIONS);
138148

139-
let num_rows = ctx.columns.iter().map(|col| col.1.len()).max().unwrap_or(1);
149+
let num_rows = ctx
150+
.entries
151+
.iter()
152+
.map(|(_, entry)| entry.len())
153+
.max()
154+
.unwrap_or(1);
140155
let block = DataBlock::new(
141-
ctx.columns
142-
.iter()
143-
.map(|(_, col)| col.clone().into())
144-
.collect(),
156+
ctx.entries.iter().map(|(_, entry)| entry.clone()).collect(),
145157
num_rows,
146158
);
147159

148-
ctx.columns.iter().for_each(|(_, col)| {
149-
test_arrow_conversion(col, false);
160+
ctx.entries.iter().for_each(|(_, entry)| {
161+
if let BlockEntry::Column(col) = entry {
162+
test_arrow_conversion(col, false);
163+
}
150164
});
151165

152166
let evaluator = Evaluator::new(&block, &ctx.func_ctx, &BUILTIN_FUNCTIONS);
@@ -216,7 +230,7 @@ pub fn run_ast_with_context(file: &mut impl Write, text: impl AsRef<str>, mut ct
216230
.collect::<Vec<_>>();
217231
let columns = used_columns
218232
.into_iter()
219-
.map(|i| ctx.columns[i].clone())
233+
.map(|i| ctx.entries[i].clone())
220234
.collect::<Vec<_>>();
221235

222236
let mut table = Table::new();

0 commit comments

Comments
 (0)