Skip to content

Commit 2d4b952

Browse files
author
longshan.lu
committed
refactor: Consolidate pushdown filter logic by renaming module and removing obsolete join handling, while enhancing optimizer rule tests
1 parent aa2fd29 commit 2d4b952

File tree

8 files changed

+81
-84
lines changed

8 files changed

+81
-84
lines changed

qurious/src/execution/session.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,8 @@ mod tests {
383383
println!("++++++++++++++");
384384
let batch = session
385385
.sql(
386-
"select
386+
"
387+
select
387388
s_acctbal,
388389
s_name,
389390
n_name,
@@ -426,12 +427,11 @@ order by
426427
n_name,
427428
s_name,
428429
p_partkey
429-
limit 10;",
430+
limit 10;
431+
",
430432
)
431433
.unwrap();
432434

433-
// let batch = session.sql("select avg(l_quantity) as count_order from lineitem")?;
434-
435435
print_batches(&batch)?;
436436

437437
Ok(())

qurious/src/optimizer/rule/eliminate_cross_join.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ impl OptimizerRule for EliminateCrossJoin {
3737
input.apply(|plan| {
3838
if let LogicalPlan::CrossJoin(cross_join) = plan {
3939
all_corss_joins.push(cross_join);
40+
return Ok(TreeNodeRecursion::Continue);
4041
}
41-
Ok(TreeNodeRecursion::Continue)
42+
43+
Ok(TreeNodeRecursion::Stop)
4244
})?;
4345

4446
if all_corss_joins.is_empty() {
@@ -297,7 +299,7 @@ mod tests {
297299
}
298300

299301
#[test]
300-
fn test_tpch_03() {
302+
fn test_eliminate_nested_cross_join() {
301303
assert_after_optimizer(
302304
" select
303305
l_orderkey,

qurious/src/optimizer/rule/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
mod count_wildcard_rule;
22
mod eliminate_cross_join;
33
mod extract_equijoin_predicate;
4-
mod pushdown_filter_join;
4+
mod pushdown_filter;
55
mod rule_optimizer;
66
mod scalar_subquery_to_join;
77
mod simplify_exprs;
@@ -11,6 +11,6 @@ pub use rule_optimizer::*;
1111

1212
pub use count_wildcard_rule::*;
1313
pub use extract_equijoin_predicate::*;
14-
pub use pushdown_filter_join::*;
14+
pub use pushdown_filter::*;
1515
pub use scalar_subquery_to_join::*;
1616
pub use type_coercion::*;

qurious/src/optimizer/rule/pushdown_filter_join.rs renamed to qurious/src/optimizer/rule/pushdown_filter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ mod tests {
249249
LogicalPlanBuilder,
250250
},
251251
optimizer::rule::{
252-
eliminate_cross_join::EliminateCrossJoin, pushdown_filter_join::PushdownFilter, ExtractEquijoinPredicate,
252+
eliminate_cross_join::EliminateCrossJoin, pushdown_filter::PushdownFilter, ExtractEquijoinPredicate,
253253
},
254254
test_utils::{assert_after_optimizer, assert_after_optimizer_with_plan},
255255
};

qurious/src/optimizer/rule/rule_optimizer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::logical::plan::LogicalPlan;
66
use crate::optimizer::rule::count_wildcard_rule::CountWildcardRule;
77
use crate::optimizer::rule::eliminate_cross_join::EliminateCrossJoin;
88
use crate::optimizer::rule::extract_equijoin_predicate::ExtractEquijoinPredicate;
9-
use crate::optimizer::rule::pushdown_filter_join::PushdownFilter;
9+
use crate::optimizer::rule::pushdown_filter::PushdownFilter;
1010
use crate::optimizer::rule::scalar_subquery_to_join::ScalarSubqueryToJoin;
1111
use crate::optimizer::rule::simplify_exprs::SimplifyExprs;
1212
use crate::optimizer::rule::type_coercion::TypeCoercion;

qurious/src/physical/plan/aggregate/hash.rs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::physical::{
77
plan::PhysicalPlan,
88
};
99
use crate::utils::array::create_hashes;
10-
use arrow::compute::TakeOptions;
10+
use arrow::compute::{concat_batches, TakeOptions};
1111
use arrow::row::{RowConverter, SortField};
1212
use arrow::{
1313
array::{ArrayRef, UInt64Array},
@@ -143,24 +143,25 @@ impl PhysicalPlan for HashAggregate {
143143
.map(|e| e.create_accumulator())
144144
.collect::<Result<Vec<_>>>()
145145
};
146-
let mut group_accumulator = GroupAccumulator::try_new(&accumlator_factory)?;
147-
// for each batch from the input executor
148-
for batch in batches {
149-
// evaluate the groupt expression
150-
let group_by_values = self
151-
.group_exprs
152-
.iter()
153-
.map(|e| e.evaluate(&batch))
154-
.collect::<Result<Vec<ArrayRef>>>()?;
155-
// evaluate the aggregate expression
156-
let input_values = self
157-
.aggregate_exprs
158-
.iter()
159-
.map(|e| e.expression().evaluate(&batch))
160-
.collect::<Result<Vec<ArrayRef>>>()?;
161-
162-
group_accumulator.update(batch.num_rows(), &group_by_values, &input_values)?;
146+
if batches.is_empty() {
147+
return Ok(vec![]);
163148
}
149+
let schema = batches[0].schema();
150+
let batch = concat_batches(&schema, &batches)?;
151+
let mut group_accumulator = GroupAccumulator::try_new(&accumlator_factory)?;
152+
let group_by_values = self
153+
.group_exprs
154+
.iter()
155+
.map(|e| e.evaluate(&batch))
156+
.collect::<Result<Vec<ArrayRef>>>()?;
157+
// evaluate the aggregate expression
158+
let input_values = self
159+
.aggregate_exprs
160+
.iter()
161+
.map(|e| e.expression().evaluate(&batch))
162+
.collect::<Result<Vec<ArrayRef>>>()?;
163+
164+
group_accumulator.update(batch.num_rows(), &group_by_values, &input_values)?;
164165

165166
let schema = self.schema.arrow_schema();
166167
RecordBatch::try_new(schema.clone(), group_accumulator.output(&schema)?)

qurious/tests/tpch/q2.slt

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
query RTTITTTT
2+
select
3+
s_acctbal,
4+
s_name,
5+
n_name,
6+
p_partkey,
7+
p_mfgr,
8+
s_address,
9+
s_phone,
10+
s_comment
11+
from
12+
part,
13+
supplier,
14+
partsupp,
15+
nation,
16+
region
17+
where
18+
p_partkey = ps_partkey
19+
and s_suppkey = ps_suppkey
20+
and p_size = 15
21+
and p_type like '%BRASS'
22+
and s_nationkey = n_nationkey
23+
and n_regionkey = r_regionkey
24+
and r_name = 'EUROPE'
25+
and ps_supplycost = (
26+
select
27+
min(ps_supplycost)
28+
from
29+
partsupp,
30+
supplier,
31+
nation,
32+
region
33+
where
34+
p_partkey = ps_partkey
35+
and s_suppkey = ps_suppkey
36+
and s_nationkey = n_nationkey
37+
and n_regionkey = r_regionkey
38+
and r_name = 'EUROPE'
39+
)
40+
order by
41+
s_acctbal desc,
42+
n_name,
43+
s_name,
44+
p_partkey
45+
limit 10;
46+
----
47+
4186.95 Supplier#000000077 GERMANY 249 Manufacturer#4 wVtcr0uH3CyrSiWMLsqnB09Syo,UuZxPMeBghlY 17-281-345-4863 the slyly final asymptotes. blithely pending theodoli
48+
1883.37 Supplier#000000086 ROMANIA 1015 Manufacturer#4 J1fgg5QaqnN 29-903-665-7065 cajole furiously special, final requests: furiously spec
49+
1687.81 Supplier#000000017 ROMANIA 1634 Manufacturer#2 c2d,ESHRSkK3WYnxpgw6aOqN0q 29-601-884-9219 eep against the furiously bold ideas. fluffily bold packa
50+
287.16 Supplier#000000052 ROMANIA 323 Manufacturer#4 WCk XCHYzBA1dvJDSol4ZJQQcQN, 29-974-934-4713 dolites are slyly against the furiously regular packages. ironic, final deposits cajole quickly

qurious/tests/tpch/q2.slt_FIXME

Lines changed: 0 additions & 56 deletions
This file was deleted.

0 commit comments

Comments
 (0)