Skip to content

Commit

Permalink
remove unalias() TableScan filters when create Physical Filter (#8404)
Browse files Browse the repository at this point in the history
- remove `unalias` TableScan filters
- refactor  CreateExternalTable
- fix typo
  • Loading branch information
jackwener authored Dec 3, 2023
1 parent f6af014 commit 26196e6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
11 changes: 4 additions & 7 deletions datafusion-cli/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,11 @@ async fn exec_and_print(
| LogicalPlan::Analyze(_)
);

let df = match &plan {
LogicalPlan::Ddl(DdlStatement::CreateExternalTable(cmd)) => {
create_external_table(ctx, cmd).await?;
ctx.execute_logical_plan(plan).await?
}
_ => ctx.execute_logical_plan(plan).await?,
};
if let LogicalPlan::Ddl(DdlStatement::CreateExternalTable(cmd)) = &plan {
create_external_table(ctx, cmd).await?;
}

let df = ctx.execute_logical_plan(plan).await?;
let results = df.collect().await?;

let print_options = if should_ignore_maxrows {
Expand Down
5 changes: 2 additions & 3 deletions datafusion/core/src/physical_planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ use datafusion_expr::expr::{
Cast, GetFieldAccess, GetIndexedField, GroupingSet, InList, Like, TryCast,
WindowFunction,
};
use datafusion_expr::expr_rewriter::{unalias, unnormalize_cols};
use datafusion_expr::expr_rewriter::unnormalize_cols;
use datafusion_expr::logical_plan::builder::wrap_projection_for_join_if_necessary;
use datafusion_expr::{
DescribeTable, DmlStatement, ScalarFunctionDefinition, StringifiedPlan, WindowFrame,
Expand Down Expand Up @@ -562,8 +562,7 @@ impl DefaultPhysicalPlanner {
// doesn't know (nor should care) how the relation was
// referred to in the query
let filters = unnormalize_cols(filters.iter().cloned());
let unaliased: Vec<Expr> = filters.into_iter().map(unalias).collect();
source.scan(session_state, projection.as_ref(), &unaliased, *fetch).await
source.scan(session_state, projection.as_ref(), &filters, *fetch).await
}
LogicalPlan::Copy(CopyTo{
input,
Expand Down
6 changes: 3 additions & 3 deletions datafusion/physical-expr/src/array_expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,14 +595,14 @@ fn general_array_pop(
) -> Result<(Vec<i64>, Vec<i64>)> {
if from_back {
let key = vec![0; list_array.len()];
// Atttetion: `arr.len() - 1` in extra key defines the last element position (position = index + 1, not inclusive) we want in the new array.
// Attention: `arr.len() - 1` in extra key defines the last element position (position = index + 1, not inclusive) we want in the new array.
let extra_key: Vec<_> = list_array
.iter()
.map(|x| x.map_or(0, |arr| arr.len() as i64 - 1))
.collect();
Ok((key, extra_key))
} else {
// Atttetion: 2 in the `key`` defines the first element position (position = index + 1) we want in the new array.
// Attention: 2 in the `key`` defines the first element position (position = index + 1) we want in the new array.
// We only handle two cases of the first element index: if the old array has any elements, starts from 2 (index + 1), or starts from initial.
let key: Vec<_> = list_array.iter().map(|x| x.map_or(0, |_| 2)).collect();
let extra_key: Vec<_> = list_array
Expand Down Expand Up @@ -1414,7 +1414,7 @@ pub fn array_replace_n(args: &[ArrayRef]) -> Result<ArrayRef> {
}

pub fn array_replace_all(args: &[ArrayRef]) -> Result<ArrayRef> {
// replace all occurences (up to "i64::MAX")
// replace all occurrences (up to "i64::MAX")
let arr_n = vec![i64::MAX; args[0].len()];
general_replace(as_list_array(&args[0])?, &args[1], &args[2], arr_n)
}
Expand Down

0 comments on commit 26196e6

Please sign in to comment.