Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 11 additions & 16 deletions datafusion/common/src/display/graphviz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,17 @@ impl GraphvizBuilder {
label: &str,
tooltip: Option<&str>,
) -> fmt::Result {
if let Some(tooltip) = tooltip {
writeln!(
f,
" {}[shape=box label={}, tooltip={}]",
id,
GraphvizBuilder::quoted(label),
GraphvizBuilder::quoted(tooltip),
)
} else {
writeln!(
f,
" {}[shape=box label={}]",
id,
GraphvizBuilder::quoted(label),
)
}
let tooltip = tooltip
.map(|tooltip| format!(", tooltip={}", GraphvizBuilder::quoted(tooltip)))
.unwrap_or_default();

writeln!(
f,
" {}[shape=box label={}{}]",
id,
GraphvizBuilder::quoted(label),
tooltip,
)
}

pub fn add_edge(
Expand Down
50 changes: 16 additions & 34 deletions datafusion/expr/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3023,23 +3023,14 @@ impl Display for SchemaDisplay<'_> {
low,
high,
}) => {
if *negated {
write!(
f,
"{} NOT BETWEEN {} AND {}",
SchemaDisplay(expr),
SchemaDisplay(low),
SchemaDisplay(high),
)
} else {
write!(
f,
"{} BETWEEN {} AND {}",
SchemaDisplay(expr),
SchemaDisplay(low),
SchemaDisplay(high),
)
}
let not = if *negated { "NOT " } else { "" };
write!(
f,
"{} {not}BETWEEN {} AND {}",
SchemaDisplay(expr),
SchemaDisplay(low),
SchemaDisplay(high),
)
}
Expr::BinaryExpr(BinaryExpr { left, op, right }) => {
write!(f, "{} {op} {}", SchemaDisplay(left), SchemaDisplay(right),)
Expand Down Expand Up @@ -3305,23 +3296,14 @@ impl Display for SqlDisplay<'_> {
low,
high,
}) => {
if *negated {
write!(
f,
"{} NOT BETWEEN {} AND {}",
SqlDisplay(expr),
SqlDisplay(low),
SqlDisplay(high),
)
} else {
write!(
f,
"{} BETWEEN {} AND {}",
SqlDisplay(expr),
SqlDisplay(low),
SqlDisplay(high),
)
}
let not = if *negated { "NOT " } else { "" };
write!(
f,
"{} {not}BETWEEN {} AND {}",
SqlDisplay(expr),
SqlDisplay(low),
SqlDisplay(high),
)
}
Expr::BinaryExpr(BinaryExpr { left, op, right }) => {
write!(f, "{} {op} {}", SqlDisplay(left), SqlDisplay(right),)
Expand Down
33 changes: 12 additions & 21 deletions datafusion/expr/src/logical_plan/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1423,28 +1423,19 @@ impl LogicalPlanBuilder {
)
})
.unzip();
if is_all {
LogicalPlanBuilder::from(left_plan)
.join_detailed(
right_plan,
join_type,
join_keys,
None,
NullEquality::NullEqualsNull,
)?
.build()
} else {
LogicalPlanBuilder::from(left_plan)
.distinct()?
.join_detailed(
right_plan,
join_type,
join_keys,
None,
NullEquality::NullEqualsNull,
)?
.build()
let mut left_builder = LogicalPlanBuilder::from(left_plan);
if !is_all {
left_builder = left_builder.distinct()?;
}
left_builder
.join_detailed(
right_plan,
join_type,
join_keys,
None,
NullEquality::NullEqualsNull,
)?
.build()
}

/// Build the plan
Expand Down
25 changes: 11 additions & 14 deletions datafusion/functions-aggregate/src/sum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,21 +261,18 @@ impl AggregateUDFImpl for Sum {
}

fn accumulator(&self, args: AccumulatorArgs) -> Result<Box<dyn Accumulator>> {
if args.is_distinct {
macro_rules! helper {
($t:ty, $dt:expr) => {
Ok(Box::new(DistinctSumAccumulator::<$t>::new($dt)))
};
}
downcast_sum!(args, helper)
} else {
macro_rules! helper {
($t:ty, $dt:expr) => {
Ok(Box::new(SumAccumulator::<$t>::new($dt)))
};
}
downcast_sum!(args, helper)
let is_distinct = args.is_distinct;
macro_rules! helper {
($t:ty, $dt:expr) => {
if is_distinct {
Ok(Box::new(DistinctSumAccumulator::<$t>::new($dt))
as Box<dyn Accumulator>)
} else {
Ok(Box::new(SumAccumulator::<$t>::new($dt)) as Box<dyn Accumulator>)
}
};
}
downcast_sum!(args, helper)
}

fn state_fields(&self, args: StateFieldsArgs) -> Result<Vec<FieldRef>> {
Expand Down
29 changes: 10 additions & 19 deletions datafusion/physical-plan/src/joins/hash_join/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2964,25 +2964,16 @@ mod tests {
) -> Arc<TaskContext> {
let mut session_config = SessionConfig::default().with_batch_size(batch_size);

if use_perfect_hash_join_as_possible {
session_config
.options_mut()
.execution
.perfect_hash_join_small_build_threshold = 819200;
session_config
.options_mut()
.execution
.perfect_hash_join_min_key_density = 0.0;
} else {
session_config
.options_mut()
.execution
.perfect_hash_join_small_build_threshold = 0;
session_config
.options_mut()
.execution
.perfect_hash_join_min_key_density = f64::INFINITY;
}
// Either always take the perfect hash join path, or never take it.
let (small_build_threshold, min_key_density) =
if use_perfect_hash_join_as_possible {
(819200, 0.0)
} else {
(0, f64::INFINITY)
};
let execution = &mut session_config.options_mut().execution;
execution.perfect_hash_join_small_build_threshold = small_build_threshold;
execution.perfect_hash_join_min_key_density = min_key_density;
Arc::new(TaskContext::default().with_session_config(session_config))
}

Expand Down
39 changes: 20 additions & 19 deletions datafusion/proto/src/logical_plan/to_proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,28 +126,29 @@ pub fn serialize_expr(
escape_char,
case_insensitive,
}) => {
if *case_insensitive {
let pb = Box::new(protobuf::ILikeNode {
negated: *negated,
expr: Some(Box::new(serialize_expr(expr.as_ref(), codec)?)),
pattern: Some(Box::new(serialize_expr(pattern.as_ref(), codec)?)),
escape_char: escape_char.map(|ch| ch.to_string()).unwrap_or_default(),
});
let negated = *negated;
let expr = Some(Box::new(serialize_expr(expr.as_ref(), codec)?));
let pattern = Some(Box::new(serialize_expr(pattern.as_ref(), codec)?));
let escape_char = escape_char.map(|ch| ch.to_string()).unwrap_or_default();

protobuf::LogicalExprNode {
expr_type: Some(ExprType::Ilike(pb)),
}
let expr_type = if *case_insensitive {
ExprType::Ilike(Box::new(protobuf::ILikeNode {
negated,
expr,
pattern,
escape_char,
}))
} else {
let pb = Box::new(protobuf::LikeNode {
negated: *negated,
expr: Some(Box::new(serialize_expr(expr.as_ref(), codec)?)),
pattern: Some(Box::new(serialize_expr(pattern.as_ref(), codec)?)),
escape_char: escape_char.map(|ch| ch.to_string()).unwrap_or_default(),
});
ExprType::Like(Box::new(protobuf::LikeNode {
negated,
expr,
pattern,
escape_char,
}))
};

protobuf::LogicalExprNode {
expr_type: Some(ExprType::Like(pb)),
}
protobuf::LogicalExprNode {
expr_type: Some(expr_type),
}
}
Expr::SimilarTo(Like {
Expand Down
24 changes: 14 additions & 10 deletions datafusion/sql/src/unparser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,22 +371,26 @@ impl Unparser<'_> {
escape_char,
case_insensitive,
}) => {
let negated = *negated;
let expr = Box::new(self.expr_to_sql_inner(expr)?);
let pattern = Box::new(self.expr_to_sql_inner(pattern)?);
let escape_char =
escape_char.map(|c| SingleQuotedString(c.to_string()).into());

if *case_insensitive {
Ok(ast::Expr::ILike {
negated: *negated,
expr: Box::new(self.expr_to_sql_inner(expr)?),
pattern: Box::new(self.expr_to_sql_inner(pattern)?),
escape_char: escape_char
.map(|c| SingleQuotedString(c.to_string()).into()),
negated,
expr,
pattern,
escape_char,
any: false,
})
} else {
Ok(ast::Expr::Like {
negated: *negated,
expr: Box::new(self.expr_to_sql_inner(expr)?),
pattern: Box::new(self.expr_to_sql_inner(pattern)?),
escape_char: escape_char
.map(|c| SingleQuotedString(c.to_string()).into()),
negated,
expr,
pattern,
escape_char,
any: false,
})
}
Expand Down
22 changes: 7 additions & 15 deletions datafusion/sql/src/unparser/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1675,21 +1675,13 @@ impl Unparser<'_> {
Ok(())
}
LogicalPlan::Extension(extension) => {
if let Some(query) = query.as_mut() {
self.extension_to_sql(
extension.node.as_ref(),
&mut Some(query),
&mut Some(select),
&mut Some(relation),
)
} else {
self.extension_to_sql(
extension.node.as_ref(),
&mut None,
&mut Some(select),
&mut Some(relation),
)
}
let mut query = query.as_mut();
self.extension_to_sql(
extension.node.as_ref(),
&mut query,
&mut Some(select),
&mut Some(relation),
)
}
LogicalPlan::Unnest(unnest) => {
if !unnest.struct_type_columns.is_empty() {
Expand Down