Skip to content
Open
Show file tree
Hide file tree
Changes from 9 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
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ recursive = "0.1.1"
regex = "1.12"
rstest = "0.26.1"
serde_json = "1"
sqlparser = { version = "0.59.0", default-features = false, features = ["std", "visitor"] }
sqlparser = { version = "0.60.0", default-features = false, features = ["std", "visitor"] }
strum = "0.27.2"
strum_macros = "0.27.2"
tempfile = "3"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ impl RelationPlanner for MatchRecognizePlanner {
..
} = relation
else {
return Ok(RelationPlanning::Original(relation));
return Ok(RelationPlanning::Original(Box::new(relation)));
};

// Plan the input table
Expand Down Expand Up @@ -401,6 +401,8 @@ impl RelationPlanner for MatchRecognizePlanner {
node: Arc::new(node),
});

Ok(RelationPlanning::Planned(PlannedRelation::new(plan, alias)))
Ok(RelationPlanning::Planned(Box::new(PlannedRelation::new(
plan, alias,
))))
}
}
10 changes: 7 additions & 3 deletions datafusion-examples/examples/relation_planner/pivot_unpivot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ impl RelationPlanner for PivotUnpivotPlanner {
alias,
),

other => Ok(RelationPlanning::Original(other)),
other => Ok(RelationPlanning::Original(Box::new(other))),
}
}
}
Expand Down Expand Up @@ -459,7 +459,9 @@ fn plan_pivot(
.aggregate(group_by_cols, pivot_exprs)?
.build()?;

Ok(RelationPlanning::Planned(PlannedRelation::new(plan, alias)))
Ok(RelationPlanning::Planned(Box::new(PlannedRelation::new(
plan, alias,
))))
}

// ============================================================================
Expand Down Expand Up @@ -540,7 +542,9 @@ fn plan_unpivot(
.build()?;
}

Ok(RelationPlanning::Planned(PlannedRelation::new(plan, alias)))
Ok(RelationPlanning::Planned(Box::new(PlannedRelation::new(
plan, alias,
))))
}

// ============================================================================
Expand Down
18 changes: 13 additions & 5 deletions datafusion-examples/examples/relation_planner/table_sample.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ impl RelationPlanner for TableSamplePlanner {
index_hints,
} = relation
else {
return Ok(RelationPlanning::Original(relation));
return Ok(RelationPlanning::Original(Box::new(relation)));
};

// Extract sample spec (handles both before/after alias positions)
Expand Down Expand Up @@ -401,7 +401,9 @@ impl RelationPlanner for TableSamplePlanner {

let fraction = bucket_num as f64 / total as f64;
let plan = TableSamplePlanNode::new(input, fraction, seed).into_plan();
return Ok(RelationPlanning::Planned(PlannedRelation::new(plan, alias)));
return Ok(RelationPlanning::Planned(Box::new(PlannedRelation::new(
plan, alias,
))));
}

// Handle quantity-based sampling
Expand All @@ -422,15 +424,19 @@ impl RelationPlanner for TableSamplePlanner {
let plan = LogicalPlanBuilder::from(input)
.limit(0, Some(rows as usize))?
.build()?;
Ok(RelationPlanning::Planned(PlannedRelation::new(plan, alias)))
Ok(RelationPlanning::Planned(Box::new(PlannedRelation::new(
plan, alias,
))))
}

// TABLESAMPLE (N PERCENT) - percentage sampling
Some(TableSampleUnit::Percent) => {
let percent: f64 = parse_literal::<Float64Type>(&quantity_value_expr)?;
let fraction = percent / 100.0;
let plan = TableSamplePlanNode::new(input, fraction, seed).into_plan();
Ok(RelationPlanning::Planned(PlannedRelation::new(plan, alias)))
Ok(RelationPlanning::Planned(Box::new(PlannedRelation::new(
plan, alias,
))))
}

// TABLESAMPLE (N) - fraction if <1.0, row limit if >=1.0
Expand All @@ -448,7 +454,9 @@ impl RelationPlanner for TableSamplePlanner {
// Interpret as fraction
TableSamplePlanNode::new(input, value, seed).into_plan()
};
Ok(RelationPlanning::Planned(PlannedRelation::new(plan, alias)))
Ok(RelationPlanning::Planned(Box::new(PlannedRelation::new(
plan, alias,
))))
}
}
}
Expand Down
16 changes: 10 additions & 6 deletions datafusion/core/tests/user_defined/relation_planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@ fn plan_static_values_table(
.project(vec![col("column1").alias(column_name)])?
.build()?;

Ok(RelationPlanning::Planned(PlannedRelation::new(plan, alias)))
Ok(RelationPlanning::Planned(Box::new(PlannedRelation::new(
plan, alias,
))))
}
other => Ok(RelationPlanning::Original(other)),
other => Ok(RelationPlanning::Original(Box::new(other))),
}
}

Expand Down Expand Up @@ -176,9 +178,11 @@ impl RelationPlanner for SamplingJoinPlanner {
.cross_join(right_sampled)?
.build()?;

Ok(RelationPlanning::Planned(PlannedRelation::new(plan, alias)))
Ok(RelationPlanning::Planned(Box::new(PlannedRelation::new(
plan, alias,
))))
}
other => Ok(RelationPlanning::Original(other)),
other => Ok(RelationPlanning::Original(Box::new(other))),
}
}
}
Expand All @@ -195,7 +199,7 @@ impl RelationPlanner for PassThroughPlanner {
_context: &mut dyn RelationPlannerContext,
) -> Result<RelationPlanning> {
// Never handles anything - always delegates
Ok(RelationPlanning::Original(relation))
Ok(RelationPlanning::Original(Box::new(relation)))
}
}

Expand All @@ -217,7 +221,7 @@ impl RelationPlanner for PremiumFeaturePlanner {
to unlock advanced array operations."
.to_string(),
)),
other => Ok(RelationPlanning::Original(other)),
other => Ok(RelationPlanning::Original(Box::new(other))),
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1306,19 +1306,14 @@ async fn create_scalar_function_from_sql_statement_default_arguments() -> Result
"Error during planning: Non-default arguments cannot follow default arguments.";
assert!(expected.starts_with(&err.strip_backtrace()));

// FIXME: The `DEFAULT` syntax does not work with positional params
let bad_expression_sql = r#"
let expression_sql = r#"
CREATE FUNCTION bad_expression_fun(DOUBLE, DOUBLE DEFAULT 2.0)
RETURNS DOUBLE
RETURN $1 + $2
"#;
let err = ctx
.sql(bad_expression_sql)
.await
.expect_err("sqlparser error");
let expected =
"SQL error: ParserError(\"Expected: ), found: 2.0 at Line: 2, Column: 63\")";
assert!(expected.starts_with(&err.strip_backtrace()));
let result = ctx.sql(expression_sql).await;

assert!(result.is_ok());
Ok(())
}

Expand Down
3 changes: 1 addition & 2 deletions datafusion/expr/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use datafusion_functions_window_common::field::WindowUDFFieldArgs;
#[cfg(feature = "sql")]
use sqlparser::ast::{
ExceptSelectItem, ExcludeSelectItem, IlikeSelectItem, RenameSelectItem,
ReplaceSelectElement, display_comma_separated,
ReplaceSelectElement,
};

// Moved in 51.0.0 to datafusion_common
Expand Down Expand Up @@ -1268,7 +1268,6 @@ impl Display for ExceptSelectItem {
}
}

#[cfg(not(feature = "sql"))]
pub fn display_comma_separated<T>(slice: &[T]) -> String
where
T: Display,
Expand Down
4 changes: 2 additions & 2 deletions datafusion/expr/src/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,9 @@ impl PlannedRelation {
#[derive(Debug)]
pub enum RelationPlanning {
/// The relation was successfully planned by an extension planner
Planned(PlannedRelation),
Planned(Box<PlannedRelation>),
/// No extension planner handled the relation, return it for default processing
Original(TableFactor),
Original(Box<TableFactor>),
}

/// Customize planning SQL table factors to [`LogicalPlan`]s.
Expand Down
2 changes: 1 addition & 1 deletion datafusion/sql/src/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
| SQLDataType::HugeInt
| SQLDataType::UHugeInt
| SQLDataType::UBigInt
| SQLDataType::TimestampNtz
| SQLDataType::TimestampNtz{..}
| SQLDataType::NamedTable { .. }
| SQLDataType::TsVector
| SQLDataType::TsQuery
Expand Down
1 change: 1 addition & 0 deletions datafusion/sql/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
name: alias,
// Apply to all fields
columns: vec![],
explicit: true,
},
),
PipeOperator::Union {
Expand Down
8 changes: 4 additions & 4 deletions datafusion/sql/src/relation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
match self.create_extension_relation(relation, planner_context)? {
RelationPlanning::Planned(planned) => planned,
RelationPlanning::Original(original) => {
self.create_default_relation(original, planner_context)?
Box::new(self.create_default_relation(*original, planner_context)?)
}
};

Expand All @@ -112,7 +112,7 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
) -> Result<RelationPlanning> {
let planners = self.context_provider.get_relation_planners();
if planners.is_empty() {
return Ok(RelationPlanning::Original(relation));
return Ok(RelationPlanning::Original(Box::new(relation)));
}

let mut current_relation = relation;
Expand All @@ -127,12 +127,12 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
return Ok(RelationPlanning::Planned(planned));
}
RelationPlanning::Original(original) => {
current_relation = original;
current_relation = *original;
}
}
}

Ok(RelationPlanning::Original(current_relation))
Ok(RelationPlanning::Original(Box::new(current_relation)))
}

fn create_default_relation(
Expand Down
Loading