Skip to content
This repository was archived by the owner on Jan 7, 2025. It is now read-only.

Commit 9ff5a60

Browse files
github-actions[bot]skyzh
authored andcommitted
style: format with nightly toolchain
Signed-off-by: Alex Chi <[email protected]>
1 parent 5360b89 commit 9ff5a60

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+700
-773
lines changed

optd-adaptive-demo/src/bin/optd-adaptive-three-join.rs

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
1+
use std::sync::Arc;
2+
3+
use console::Style;
14
use datafusion::error::Result;
25
use datafusion::execution::context::{SessionConfig, SessionState};
36
use datafusion::execution::runtime_env::{RuntimeConfig, RuntimeEnv};
47
use datafusion::prelude::SessionContext;
5-
use datafusion_optd_cli::exec::exec_from_commands_collect;
6-
use datafusion_optd_cli::{
7-
exec::exec_from_commands,
8-
print_format::PrintFormat,
9-
print_options::{MaxRows, PrintOptions},
10-
};
8+
use datafusion_optd_cli::exec::{exec_from_commands, exec_from_commands_collect};
9+
use datafusion_optd_cli::print_format::PrintFormat;
10+
use datafusion_optd_cli::print_options::{MaxRows, PrintOptions};
1111
use mimalloc::MiMalloc;
1212
use optd_datafusion_bridge::{DatafusionCatalog, OptdQueryPlanner};
1313
use optd_datafusion_repr::DatafusionOptimizer;
1414
use rand::{thread_rng, Rng};
15-
use std::sync::Arc;
16-
17-
use console::Style;
1815

1916
#[global_allocator]
2017
static GLOBAL: MiMalloc = MiMalloc;
@@ -247,8 +244,8 @@ async fn main() -> Result<()> {
247244
// (select count(*) from t3) as t3cnt,
248245
// (select count(*) from (select * from t1, t2 where t1v1 = t2v1)) as t1t2cnt,
249246
// (select count(*) from (select * from t1, t3 where t1v2 = t3v2)) as t1t3cnt,
250-
// (select count(*) from (select * from t1, t2, t3 where t1v1 = t2v1 and t1v2 = t3v2)) as out_cnt;"#
251-
// .to_string()],
247+
// (select count(*) from (select * from t1, t2, t3 where t1v1 = t2v1 and t1v2 =
248+
// t3v2)) as out_cnt;"# .to_string()],
252249
// )
253250
// .await;
254251
}

optd-adaptive-demo/src/bin/optd-adaptive-tpch-q8.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1+
use std::sync::Arc;
2+
use std::time::Duration;
3+
14
use datafusion::error::Result;
25
use datafusion::execution::context::{SessionConfig, SessionState};
36
use datafusion::execution::runtime_env::{RuntimeConfig, RuntimeEnv};
47
use datafusion::prelude::SessionContext;
5-
use datafusion_optd_cli::exec::{exec_from_commands_collect, exec_from_files};
6-
use datafusion_optd_cli::{
7-
exec::exec_from_commands,
8-
print_format::PrintFormat,
9-
print_options::{MaxRows, PrintOptions},
10-
};
8+
use datafusion_optd_cli::exec::{exec_from_commands, exec_from_commands_collect, exec_from_files};
9+
use datafusion_optd_cli::print_format::PrintFormat;
10+
use datafusion_optd_cli::print_options::{MaxRows, PrintOptions};
1111
use mimalloc::MiMalloc;
1212
use optd_datafusion_bridge::{DatafusionCatalog, OptdQueryPlanner};
1313
use optd_datafusion_repr::DatafusionOptimizer;
14-
use std::sync::Arc;
15-
use std::time::Duration;
1614

1715
#[global_allocator]
1816
static GLOBAL: MiMalloc = MiMalloc;

optd-core/src/cascades/memo.rs

+43-36
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
1-
use std::{
2-
collections::{hash_map::Entry, HashMap, HashSet},
3-
sync::Arc,
4-
};
1+
use std::any::Any;
2+
use std::collections::hash_map::Entry;
3+
use std::collections::{HashMap, HashSet};
4+
use std::sync::Arc;
55

66
use anyhow::{bail, Context, Result};
77
use itertools::Itertools;
8-
use std::any::Any;
98
use tracing::trace;
109

11-
use crate::{
12-
cost::{Cost, Statistics},
13-
nodes::{ArcPlanNode, ArcPredNode, NodeType, PlanNode, PlanNodeOrGroup},
14-
property::PropertyBuilderAny,
15-
};
16-
1710
use super::optimizer::{ExprId, GroupId, PredId};
11+
use crate::cost::{Cost, Statistics};
12+
use crate::nodes::{ArcPlanNode, ArcPredNode, NodeType, PlanNode, PlanNodeOrGroup};
13+
use crate::property::PropertyBuilderAny;
1814

1915
pub type ArcMemoPlanNode<T> = Arc<MemoPlanNode<T>>;
2016

21-
/// The RelNode representation in the memo table. Store children as group IDs. Equivalent to MExpr in Columbia/Cascades.
17+
/// The RelNode representation in the memo table. Store children as group IDs. Equivalent to MExpr
18+
/// in Columbia/Cascades.
2219
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
2320
pub struct MemoPlanNode<T: NodeType> {
2421
pub typ: T,
@@ -92,12 +89,13 @@ pub struct Group {
9289

9390
/// Trait for memo table implementations.
9491
pub trait Memo<T: NodeType>: 'static + Send + Sync {
95-
/// Add an expression to the memo table. If the expression already exists, it will return the existing group id and
96-
/// expr id. Otherwise, a new group and expr will be created.
92+
/// Add an expression to the memo table. If the expression already exists, it will return the
93+
/// existing group id and expr id. Otherwise, a new group and expr will be created.
9794
fn add_new_expr(&mut self, rel_node: ArcPlanNode<T>) -> (GroupId, ExprId);
9895

99-
/// Add a new expression to an existing gruop. If the expression is a group, it will merge the two groups. Otherwise,
100-
/// it will add the expression to the group. Returns the expr id if the expression is not a group.
96+
/// Add a new expression to an existing gruop. If the expression is a group, it will merge the
97+
/// two groups. Otherwise, it will add the expression to the group. Returns the expr id if
98+
/// the expression is not a group.
10199
fn add_expr_to_group(
102100
&mut self,
103101
rel_node: PlanNodeOrGroup<T>,
@@ -126,8 +124,8 @@ pub trait Memo<T: NodeType>: 'static + Send + Sync {
126124
/// Update the group info.
127125
fn update_group_info(&mut self, group_id: GroupId, group_info: GroupInfo);
128126

129-
/// Estimated plan space for the memo table, only useful when plan exploration budget is enabled.
130-
/// Returns number of expressions in the memo table.
127+
/// Estimated plan space for the memo table, only useful when plan exploration budget is
128+
/// enabled. Returns number of expressions in the memo table.
131129
fn estimated_plan_space(&self) -> usize;
132130

133131
// The below functions can be overwritten by the memo table implementation if there
@@ -155,15 +153,17 @@ pub trait Memo<T: NodeType>: 'static + Send + Sync {
155153
get_best_group_binding_inner(self, group_id, &mut post_process)
156154
}
157155

158-
/// Get all bindings of a predicate group. Will panic if the group contains more than one bindings. Note that we
159-
/// are currently in the refactor process of having predicates as a separate entity. If the representation stores
160-
/// predicates in the rel node children, the repr should use this function to get the predicate binding. Otherwise,
161-
/// use `ger_pred` for those predicates stored within the `predicates` field.
156+
/// Get all bindings of a predicate group. Will panic if the group contains more than one
157+
/// bindings. Note that we are currently in the refactor process of having predicates as a
158+
/// separate entity. If the representation stores predicates in the rel node children, the
159+
/// repr should use this function to get the predicate binding. Otherwise, use `ger_pred`
160+
/// for those predicates stored within the `predicates` field.
162161
fn get_predicate_binding(&self, group_id: GroupId) -> Option<ArcPlanNode<T>> {
163162
get_predicate_binding_group_inner(self, group_id, true)
164163
}
165164

166-
/// Get all bindings of a predicate group. Returns None if the group contains zero or more than one bindings.
165+
/// Get all bindings of a predicate group. Returns None if the group contains zero or more than
166+
/// one bindings.
167167
fn try_get_predicate_binding(&self, group_id: GroupId) -> Option<ArcPlanNode<T>> {
168168
get_predicate_binding_group_inner(self, group_id, false)
169169
}
@@ -381,21 +381,24 @@ impl<T: NodeType> NaiveMemo<T> {
381381
}
382382
}
383383

384-
/// Get the next group id. Group id and expr id shares the same counter, so as to make it easier to debug...
384+
/// Get the next group id. Group id and expr id shares the same counter, so as to make it easier
385+
/// to debug...
385386
fn next_group_id(&mut self) -> GroupId {
386387
let id = self.group_expr_counter;
387388
self.group_expr_counter += 1;
388389
GroupId(id)
389390
}
390391

391-
/// Get the next expr id. Group id and expr id shares the same counter, so as to make it easier to debug...
392+
/// Get the next expr id. Group id and expr id shares the same counter, so as to make it easier
393+
/// to debug...
392394
fn next_expr_id(&mut self) -> ExprId {
393395
let id = self.group_expr_counter;
394396
self.group_expr_counter += 1;
395397
ExprId(id)
396398
}
397399

398-
/// Get the next pred id. Group id and expr id shares the same counter, so as to make it easier to debug...
400+
/// Get the next pred id. Group id and expr id shares the same counter, so as to make it easier
401+
/// to debug...
399402
fn next_pred_id(&mut self) -> PredId {
400403
let id = self.group_expr_counter;
401404
self.group_expr_counter += 1;
@@ -487,16 +490,18 @@ impl<T: NodeType> NaiveMemo<T> {
487490
.insert(*expr_id, Arc::new(new_expr.clone()));
488491
self.expr_node_to_expr_id.remove(&old_expr);
489492
if let Some(dup_expr) = self.expr_node_to_expr_id.get(&new_expr) {
490-
// If new_expr == some_other_old_expr in the memo table, unless they belong to the same group,
491-
// we should merge the two groups. This should not happen. We should simply drop this expression.
493+
// If new_expr == some_other_old_expr in the memo table, unless they belong
494+
// to the same group, we should merge the two
495+
// groups. This should not happen. We should simply drop this expression.
492496
let dup_group_id = self.expr_id_to_group_id[dup_expr];
493497
if dup_group_id != *group_id {
494498
pending_recursive_merge.push((dup_group_id, *group_id));
495499
}
496500
self.expr_id_to_expr_node.remove(expr_id);
497501
self.expr_id_to_group_id.remove(expr_id);
498502
self.dup_expr_mapping.insert(*expr_id, *dup_expr);
499-
new_expr_list.insert(*dup_expr); // adding this temporarily -- should be removed once recursive merge finishes
503+
new_expr_list.insert(*dup_expr); // adding this temporarily -- should be
504+
// removed once recursive merge finishes
500505
} else {
501506
self.expr_node_to_expr_id.insert(new_expr, *expr_id);
502507
new_expr_list.insert(*expr_id);
@@ -509,7 +514,8 @@ impl<T: NodeType> NaiveMemo<T> {
509514
group.group_exprs = new_expr_list;
510515
}
511516
for (merge_from, merge_into) in pending_recursive_merge {
512-
// We need to reduce because each merge would probably invalidate some groups in the last loop iteration.
517+
// We need to reduce because each merge would probably invalidate some groups in the
518+
// last loop iteration.
513519
let merge_from = self.reduce_group(merge_from);
514520
let merge_into = self.reduce_group(merge_into);
515521
self.merge_group_inner(merge_into, merge_from);
@@ -526,9 +532,11 @@ impl<T: NodeType> NaiveMemo<T> {
526532
.iter()
527533
.map(|child| {
528534
match child {
529-
PlanNodeOrGroup::Group(group) => self.reduce_group(*group), // TODO: can I remove reduce?
535+
// TODO: can I remove reduce?
536+
PlanNodeOrGroup::Group(group) => self.reduce_group(*group),
530537
PlanNodeOrGroup::PlanNode(child) => {
531-
// No merge / modification to the memo should occur for the following operation
538+
// No merge / modification to the memo should occur for the following
539+
// operation
532540
let (group, _) = self
533541
.add_new_group_expr_inner(child.clone(), None)
534542
.expect("should not trigger merge group");
@@ -569,8 +577,8 @@ impl<T: NodeType> NaiveMemo<T> {
569577
Ok((group_id, expr_id))
570578
}
571579

572-
/// This is inefficient: usually the optimizer should have a MemoRef instead of passing the full rel node. Should
573-
/// be only used for debugging purpose.
580+
/// This is inefficient: usually the optimizer should have a MemoRef instead of passing the full
581+
/// rel node. Should be only used for debugging purpose.
574582
#[cfg(test)]
575583
pub(crate) fn get_expr_info(&self, rel_node: ArcPlanNode<T>) -> (GroupId, ExprId) {
576584
let children_group_ids = rel_node
@@ -662,9 +670,8 @@ impl<T: NodeType> NaiveMemo<T> {
662670
#[cfg(test)]
663671
mod tests {
664672

665-
use crate::nodes::{PredNode, Value};
666-
667673
use super::*;
674+
use crate::nodes::{PredNode, Value};
668675

669676
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
670677
enum MemoTestRelTyp {

optd-core/src/cascades/optimizer.rs

+16-20
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,21 @@
1-
use std::{
2-
collections::{BTreeSet, HashMap, HashSet, VecDeque},
3-
fmt::Display,
4-
sync::Arc,
5-
};
1+
use std::collections::{BTreeSet, HashMap, HashSet, VecDeque};
2+
use std::fmt::Display;
3+
use std::sync::Arc;
64

75
use anyhow::Result;
86
use tracing::trace;
97

10-
use crate::{
11-
cascades::memo::Winner,
12-
cost::CostModel,
13-
nodes::{ArcPlanNode, ArcPredNode, NodeType, PlanNodeMeta, PlanNodeMetaMap, PlanNodeOrGroup},
14-
optimizer::Optimizer,
15-
property::{PropertyBuilder, PropertyBuilderAny},
16-
rules::RuleWrapper,
17-
};
18-
19-
use super::{
20-
memo::{ArcMemoPlanNode, GroupInfo, Memo},
21-
tasks::OptimizeGroupTask,
22-
NaiveMemo, Task,
8+
use super::memo::{ArcMemoPlanNode, GroupInfo, Memo};
9+
use super::tasks::OptimizeGroupTask;
10+
use super::{NaiveMemo, Task};
11+
use crate::cascades::memo::Winner;
12+
use crate::cost::CostModel;
13+
use crate::nodes::{
14+
ArcPlanNode, ArcPredNode, NodeType, PlanNodeMeta, PlanNodeMetaMap, PlanNodeOrGroup,
2315
};
16+
use crate::optimizer::Optimizer;
17+
use crate::property::{PropertyBuilder, PropertyBuilderAny};
18+
use crate::rules::RuleWrapper;
2419

2520
pub type RuleId = usize;
2621

@@ -55,8 +50,9 @@ pub struct CascadesOptimizer<T: NodeType, M: Memo<T> = NaiveMemo<T>> {
5550
pub prop: OptimizerProperties,
5651
}
5752

58-
/// `RelNode` only contains the representation of the plan nodes. Sometimes, we need more context, i.e., group id and
59-
/// expr id, during the optimization phase. All these information are collected in this struct.
53+
/// `RelNode` only contains the representation of the plan nodes. Sometimes, we need more context,
54+
/// i.e., group id and expr id, during the optimization phase. All these information are collected
55+
/// in this struct.
6056
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Default, Hash)]
6157
pub struct RelNodeContext {
6258
pub group_id: GroupId,

optd-core/src/cascades/tasks.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use anyhow::Result;
22

3-
use crate::nodes::NodeType;
4-
53
use super::{CascadesOptimizer, Memo};
4+
use crate::nodes::NodeType;
65

76
mod apply_rule;
87
mod explore_group;

optd-core/src/cascades/tasks/apply_rule.rs

+6-11
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,13 @@ use anyhow::Result;
44
use itertools::Itertools;
55
use tracing::trace;
66

7-
use crate::{
8-
cascades::{
9-
memo::ArcMemoPlanNode,
10-
optimizer::{CascadesOptimizer, ExprId, RuleId},
11-
tasks::{OptimizeExpressionTask, OptimizeInputsTask},
12-
GroupId, Memo,
13-
},
14-
nodes::{ArcPlanNode, NodeType, PlanNode, PlanNodeOrGroup},
15-
rules::{OptimizeType, RuleMatcher},
16-
};
17-
187
use super::Task;
8+
use crate::cascades::memo::ArcMemoPlanNode;
9+
use crate::cascades::optimizer::{CascadesOptimizer, ExprId, RuleId};
10+
use crate::cascades::tasks::{OptimizeExpressionTask, OptimizeInputsTask};
11+
use crate::cascades::{GroupId, Memo};
12+
use crate::nodes::{ArcPlanNode, NodeType, PlanNode, PlanNodeOrGroup};
13+
use crate::rules::{OptimizeType, RuleMatcher};
1914

2015
pub struct ApplyRuleTask {
2116
rule_id: RuleId,

optd-core/src/cascades/tasks/explore_group.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
use anyhow::Result;
22
use tracing::trace;
33

4-
use crate::{
5-
cascades::{
6-
optimizer::{CascadesOptimizer, GroupId},
7-
tasks::OptimizeExpressionTask,
8-
Memo,
9-
},
10-
nodes::NodeType,
11-
};
12-
134
use super::Task;
5+
use crate::cascades::optimizer::{CascadesOptimizer, GroupId};
6+
use crate::cascades::tasks::OptimizeExpressionTask;
7+
use crate::cascades::Memo;
8+
use crate::nodes::NodeType;
149

1510
pub struct ExploreGroupTask {
1611
group_id: GroupId,

optd-core/src/cascades/tasks/optimize_expression.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
use anyhow::Result;
22
use tracing::trace;
33

4-
use crate::{
5-
cascades::{
6-
optimizer::{CascadesOptimizer, ExprId},
7-
tasks::{ApplyRuleTask, ExploreGroupTask},
8-
Memo,
9-
},
10-
nodes::NodeType,
11-
rules::RuleMatcher,
12-
};
13-
144
use super::Task;
5+
use crate::cascades::optimizer::{CascadesOptimizer, ExprId};
6+
use crate::cascades::tasks::{ApplyRuleTask, ExploreGroupTask};
7+
use crate::cascades::Memo;
8+
use crate::nodes::NodeType;
9+
use crate::rules::RuleMatcher;
1510

1611
pub struct OptimizeExpressionTask {
1712
expr_id: ExprId,

optd-core/src/cascades/tasks/optimize_group.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
use anyhow::Result;
22
use tracing::trace;
33

4-
use crate::{
5-
cascades::{
6-
optimizer::GroupId,
7-
tasks::{optimize_expression::OptimizeExpressionTask, OptimizeInputsTask},
8-
CascadesOptimizer, Memo,
9-
},
10-
nodes::NodeType,
11-
};
12-
134
use super::Task;
5+
use crate::cascades::optimizer::GroupId;
6+
use crate::cascades::tasks::optimize_expression::OptimizeExpressionTask;
7+
use crate::cascades::tasks::OptimizeInputsTask;
8+
use crate::cascades::{CascadesOptimizer, Memo};
9+
use crate::nodes::NodeType;
1410

1511
pub struct OptimizeGroupTask {
1612
group_id: GroupId,

0 commit comments

Comments
 (0)