pub struct SqlToRel<'a, S: ContextProvider> {
pub(crate) context_provider: &'a S,
pub(crate) options: ParserOptions,
pub(crate) ident_normalizer: IdentNormalizer,
}Expand description
SQL query planner and binder
This struct is used to convert a SQL AST into a LogicalPlan.
You can control the behavior of the planner by providing ParserOptions.
It performs the following tasks:
- Name and type resolution (called “binding” in other systems). This
phase looks up table and column names using the
ContextProvider. - Mechanical translation of the AST into a
LogicalPlan.
It does not perform type coercion, or perform optimization, which are done by subsequent passes.
Key interfaces are:
Self::sql_statement_to_plan: Convert a statement (e.g.SELECT ...) into aLogicalPlanSelf::sql_to_expr: Convert an expression (e.g.1 + 2) into anExpr
Fields§
§context_provider: &'a S§options: ParserOptions§ident_normalizer: IdentNormalizerImplementations§
Source§impl<S: ContextProvider> SqlToRel<'_, S>
impl<S: ContextProvider> SqlToRel<'_, S>
pub(crate) fn plan_with_clause( &self, with: With, planner_context: &mut PlannerContext, ) -> Result<()>
fn non_recursive_cte( &self, cte_query: Query, planner_context: &mut PlannerContext, ) -> Result<LogicalPlan>
fn recursive_cte( &self, cte_name: String, cte_query: Query, planner_context: &mut PlannerContext, ) -> Result<LogicalPlan>
Source§impl<S: ContextProvider> SqlToRel<'_, S>
impl<S: ContextProvider> SqlToRel<'_, S>
pub(crate) fn parse_sql_binary_op(&self, op: BinaryOperator) -> Result<Operator>
Source§impl<S: ContextProvider> SqlToRel<'_, S>
impl<S: ContextProvider> SqlToRel<'_, S>
pub(super) fn sql_function_to_expr( &self, function: SQLFunction, schema: &DFSchema, planner_context: &mut PlannerContext, ) -> Result<Expr>
pub(super) fn sql_fn_name_to_expr( &self, expr: SQLExpr, fn_name: &str, schema: &DFSchema, planner_context: &mut PlannerContext, ) -> Result<Expr>
pub(super) fn find_window_func( &self, name: &str, ) -> Result<WindowFunctionDefinition>
fn sql_fn_arg_to_logical_expr( &self, sql: FunctionArg, schema: &DFSchema, planner_context: &mut PlannerContext, ) -> Result<Expr>
fn sql_fn_arg_to_logical_expr_with_name( &self, sql: FunctionArg, schema: &DFSchema, planner_context: &mut PlannerContext, ) -> Result<(Expr, Option<String>)>
pub(super) fn function_args_to_expr( &self, args: Vec<FunctionArg>, schema: &DFSchema, planner_context: &mut PlannerContext, ) -> Result<Vec<Expr>>
pub(super) fn function_args_to_expr_with_names( &self, args: Vec<FunctionArg>, schema: &DFSchema, planner_context: &mut PlannerContext, ) -> Result<(Vec<Expr>, Vec<Option<String>>)>
pub(crate) fn check_unnest_arg(arg: &Expr, schema: &DFSchema) -> Result<()>
Source§impl<S: ContextProvider> SqlToRel<'_, S>
impl<S: ContextProvider> SqlToRel<'_, S>
pub(super) fn sql_grouping_sets_to_expr( &self, exprs: Vec<Vec<SQLExpr>>, schema: &DFSchema, planner_context: &mut PlannerContext, ) -> Result<Expr>
pub(super) fn sql_rollup_to_expr( &self, exprs: Vec<Vec<SQLExpr>>, schema: &DFSchema, planner_context: &mut PlannerContext, ) -> Result<Expr>
pub(super) fn sql_cube_to_expr( &self, exprs: Vec<Vec<SQLExpr>>, schema: &DFSchema, planner_context: &mut PlannerContext, ) -> Result<Expr>
Source§impl<S: ContextProvider> SqlToRel<'_, S>
impl<S: ContextProvider> SqlToRel<'_, S>
pub(super) fn sql_identifier_to_expr( &self, id: Ident, schema: &DFSchema, planner_context: &mut PlannerContext, ) -> Result<Expr>
pub(crate) fn sql_compound_identifier_to_expr( &self, ids: Vec<Ident>, schema: &DFSchema, planner_context: &mut PlannerContext, ) -> Result<Expr>
pub(super) fn sql_case_identifier_to_expr( &self, operand: Option<Box<SQLExpr>>, conditions: Vec<CaseWhen>, else_result: Option<Box<SQLExpr>>, schema: &DFSchema, planner_context: &mut PlannerContext, ) -> Result<Expr>
Source§impl<S: ContextProvider> SqlToRel<'_, S>
impl<S: ContextProvider> SqlToRel<'_, S>
Sourcepub(crate) fn order_by_to_sort_expr(
&self,
order_by_exprs: Vec<OrderByExpr>,
input_schema: &DFSchema,
planner_context: &mut PlannerContext,
literal_to_column: bool,
additional_schema: Option<&DFSchema>,
) -> Result<Vec<SortExpr>>
pub(crate) fn order_by_to_sort_expr( &self, order_by_exprs: Vec<OrderByExpr>, input_schema: &DFSchema, planner_context: &mut PlannerContext, literal_to_column: bool, additional_schema: Option<&DFSchema>, ) -> Result<Vec<SortExpr>>
Convert sql [OrderByExpr] to Vec<Expr>.
input_schema and additional_schema are used to resolve column references in the order-by expressions.
input_schema is the schema of the input logical plan, typically derived from the SELECT list.
Usually order-by expressions can only reference the input plan’s columns.
But the SELECT ... FROM ... ORDER BY ... syntax is a special case. Besides the input schema,
it can reference an additional_schema derived from the FROM clause.
If literal_to_column is true, treat any numeric literals (e.g. 2) as a 1 based index into the
SELECT list (e.g. SELECT a, b FROM table ORDER BY 2). Literals only reference the input_schema.
If false, interpret numeric literals as constant values.
Source§impl<S: ContextProvider> SqlToRel<'_, S>
impl<S: ContextProvider> SqlToRel<'_, S>
pub(super) fn parse_exists_subquery( &self, subquery: Query, negated: bool, input_schema: &DFSchema, planner_context: &mut PlannerContext, ) -> Result<Expr>
pub(super) fn parse_in_subquery( &self, expr: SQLExpr, subquery: Query, negated: bool, input_schema: &DFSchema, planner_context: &mut PlannerContext, ) -> Result<Expr>
pub(super) fn parse_scalar_subquery( &self, subquery: Query, input_schema: &DFSchema, planner_context: &mut PlannerContext, ) -> Result<Expr>
fn validate_single_column( &self, sub_plan: &LogicalPlan, spans: Spans, error_message: &str, help_message: &str, ) -> Result<()>
fn build_multi_column_diagnostic( &self, spans: Spans, error_message: &str, help_message: &str, ) -> Diagnostic
Source§impl<S: ContextProvider> SqlToRel<'_, S>
impl<S: ContextProvider> SqlToRel<'_, S>
Source§impl<S: ContextProvider> SqlToRel<'_, S>
impl<S: ContextProvider> SqlToRel<'_, S>
pub(crate) fn parse_sql_unary_op( &self, op: UnaryOperator, expr: SQLExpr, schema: &DFSchema, planner_context: &mut PlannerContext, ) -> Result<Expr>
Source§impl<S: ContextProvider> SqlToRel<'_, S>
impl<S: ContextProvider> SqlToRel<'_, S>
pub(crate) fn parse_value( &self, value: Value, param_data_types: &[FieldRef], ) -> Result<Expr>
Sourcepub(super) fn parse_sql_number(
&self,
unsigned_number: &str,
negative: bool,
) -> Result<Expr>
pub(super) fn parse_sql_number( &self, unsigned_number: &str, negative: bool, ) -> Result<Expr>
Parse number in sql string, convert to Expr::Literal
Sourcefn create_placeholder_expr(
param: String,
param_data_types: &[FieldRef],
) -> Result<Expr>
fn create_placeholder_expr( param: String, param_data_types: &[FieldRef], ) -> Result<Expr>
Create a placeholder expression
This is the same as Postgres’s prepare statement syntax in which a placeholder starts with $ sign and then
number 1, 2, … etc. For example, $1 is the first placeholder; $2 is the second one and so on.
pub(super) fn sql_array_literal( &self, elements: Vec<SQLExpr>, schema: &DFSchema, ) -> Result<Expr>
fn try_plan_array_literal( &self, values: Vec<Expr>, schema: &DFSchema, ) -> Result<Expr>
Sourcepub(super) fn sql_interval_to_expr(
&self,
negative: bool,
interval: Interval,
) -> Result<Expr>
pub(super) fn sql_interval_to_expr( &self, negative: bool, interval: Interval, ) -> Result<Expr>
Convert a SQL interval expression to a DataFusion logical plan expression
Source§impl<S: ContextProvider> SqlToRel<'_, S>
impl<S: ContextProvider> SqlToRel<'_, S>
pub(crate) fn sql_expr_to_logical_expr_with_alias( &self, sql: SQLExprWithAlias, schema: &DFSchema, planner_context: &mut PlannerContext, ) -> Result<Expr>
pub(crate) fn sql_expr_to_logical_expr( &self, sql: SQLExpr, schema: &DFSchema, planner_context: &mut PlannerContext, ) -> Result<Expr>
fn build_logical_expr( &self, op: BinaryOperator, left: Expr, right: Expr, schema: &DFSchema, ) -> Result<Expr>
pub fn sql_to_expr_with_alias( &self, sql: SQLExprWithAlias, schema: &DFSchema, planner_context: &mut PlannerContext, ) -> Result<Expr>
Sourcepub fn sql_to_expr(
&self,
sql: SQLExpr,
schema: &DFSchema,
planner_context: &mut PlannerContext,
) -> Result<Expr>
pub fn sql_to_expr( &self, sql: SQLExpr, schema: &DFSchema, planner_context: &mut PlannerContext, ) -> Result<Expr>
Generate a relational expression from a SQL expression
Sourcefn rewrite_partial_qualifier(&self, expr: Expr, schema: &DFSchema) -> Expr
fn rewrite_partial_qualifier(&self, expr: Expr, schema: &DFSchema) -> Expr
Rewrite aliases which are not-complete (e.g. ones that only include only table qualifier in a schema.table qualified relation)
Sourcefn sql_expr_to_logical_expr_internal(
&self,
sql: SQLExpr,
schema: &DFSchema,
planner_context: &mut PlannerContext,
) -> Result<Expr>
fn sql_expr_to_logical_expr_internal( &self, sql: SQLExpr, schema: &DFSchema, planner_context: &mut PlannerContext, ) -> Result<Expr>
Internal implementation. Use
Self::sql_expr_to_logical_expr to plan exprs.
Sourcefn parse_struct(
&self,
schema: &DFSchema,
planner_context: &mut PlannerContext,
values: Vec<SQLExpr>,
fields: Vec<StructField>,
) -> Result<Expr>
fn parse_struct( &self, schema: &DFSchema, planner_context: &mut PlannerContext, values: Vec<SQLExpr>, fields: Vec<StructField>, ) -> Result<Expr>
Parses a struct(..) expression and plans it creation
fn parse_tuple( &self, schema: &DFSchema, planner_context: &mut PlannerContext, values: Vec<SQLExpr>, ) -> Result<Expr>
fn sql_position_to_expr( &self, substr_expr: SQLExpr, str_expr: SQLExpr, schema: &DFSchema, planner_context: &mut PlannerContext, ) -> Result<Expr>
fn try_plan_dictionary_literal( &self, fields: Vec<DictionaryField>, schema: &DFSchema, planner_context: &mut PlannerContext, ) -> Result<Expr>
fn try_plan_map_literal( &self, entries: Vec<MapEntry>, schema: &DFSchema, planner_context: &mut PlannerContext, ) -> Result<Expr>
fn create_named_struct_expr( &self, values: Vec<SQLExpr>, input_schema: &DFSchema, planner_context: &mut PlannerContext, ) -> Result<Vec<Expr>>
fn create_struct_expr( &self, values: Vec<SQLExpr>, input_schema: &DFSchema, planner_context: &mut PlannerContext, ) -> Result<Vec<Expr>>
fn sql_in_list_to_expr( &self, expr: SQLExpr, list: Vec<SQLExpr>, negated: bool, schema: &DFSchema, planner_context: &mut PlannerContext, ) -> Result<Expr>
fn sql_like_to_expr( &self, negated: bool, expr: SQLExpr, pattern: SQLExpr, escape_char: Option<Value>, schema: &DFSchema, planner_context: &mut PlannerContext, case_insensitive: bool, any: bool, ) -> Result<Expr>
fn sql_similarto_to_expr( &self, negated: bool, expr: SQLExpr, pattern: SQLExpr, escape_char: Option<Value>, schema: &DFSchema, planner_context: &mut PlannerContext, ) -> Result<Expr>
fn sql_trim_to_expr( &self, expr: SQLExpr, trim_where: Option<TrimWhereField>, trim_what: Option<Box<SQLExpr>>, trim_characters: Option<Vec<SQLExpr>>, schema: &DFSchema, planner_context: &mut PlannerContext, ) -> Result<Expr>
fn sql_overlay_to_expr( &self, expr: SQLExpr, overlay_what: SQLExpr, overlay_from: SQLExpr, overlay_for: Option<Box<SQLExpr>>, schema: &DFSchema, planner_context: &mut PlannerContext, ) -> Result<Expr>
fn sql_cast_to_expr( &self, expr: SQLExpr, data_type: SQLDataType, format: Option<CastFormat>, schema: &DFSchema, planner_context: &mut PlannerContext, ) -> Result<Expr>
Sourcefn extract_root_and_access_chain(
&self,
root: SQLExpr,
access_chain: Vec<AccessExpr>,
schema: &DFSchema,
planner_context: &mut PlannerContext,
) -> Result<(Expr, Vec<AccessExpr>)>
fn extract_root_and_access_chain( &self, root: SQLExpr, access_chain: Vec<AccessExpr>, schema: &DFSchema, planner_context: &mut PlannerContext, ) -> Result<(Expr, Vec<AccessExpr>)>
Extracts the root expression and access chain from a compound expression.
This function attempts to identify if a compound expression (like a.b.c) should be treated
as a column reference with a qualifier (like table.column) or as a field access expression.
§Arguments
root- The root SQL expression (e.g., the first part ofa.b.c)access_chain- Vector of access expressions (e.g.,.band.cparts)schema- The schema to resolve column references againstplanner_context- Context for planning expressions
§Returns
A tuple containing:
- The resolved root expression
- The remaining access chain that should be processed as field accesses
fn sql_compound_field_access_to_expr( &self, root: SQLExpr, access_chain: Vec<AccessExpr>, schema: &DFSchema, planner_context: &mut PlannerContext, ) -> Result<Expr>
Source§impl<'a, S: ContextProvider> SqlToRel<'a, S>
impl<'a, S: ContextProvider> SqlToRel<'a, S>
Sourcepub fn new(context_provider: &'a S) -> Self
pub fn new(context_provider: &'a S) -> Self
Create a new query planner.
The query planner derives the parser options from the context provider.
Sourcepub fn new_with_options(context_provider: &'a S, options: ParserOptions) -> Self
pub fn new_with_options(context_provider: &'a S, options: ParserOptions) -> Self
Create a new query planner with the given parser options.
The query planner ignores the parser options from the context provider and uses the given parser options instead.
pub fn build_schema(&self, columns: Vec<SQLColumnDef>) -> Result<Schema>
Sourcepub(crate) fn build_column_defaults(
&self,
columns: &Vec<SQLColumnDef>,
planner_context: &mut PlannerContext,
) -> Result<Vec<(String, Expr)>>
pub(crate) fn build_column_defaults( &self, columns: &Vec<SQLColumnDef>, planner_context: &mut PlannerContext, ) -> Result<Vec<(String, Expr)>>
Returns a vector of (column_name, default_expr) pairs
Sourcepub(crate) fn apply_table_alias(
&self,
plan: LogicalPlan,
alias: TableAlias,
) -> Result<LogicalPlan>
pub(crate) fn apply_table_alias( &self, plan: LogicalPlan, alias: TableAlias, ) -> Result<LogicalPlan>
Apply the given TableAlias to the input plan
pub(crate) fn apply_expr_alias( &self, plan: LogicalPlan, idents: Vec<Ident>, ) -> Result<LogicalPlan>
Sourcepub(crate) fn validate_schema_satisfies_exprs(
&self,
schema: &DFSchema,
exprs: &[Expr],
) -> Result<()>
pub(crate) fn validate_schema_satisfies_exprs( &self, schema: &DFSchema, exprs: &[Expr], ) -> Result<()>
Validate the schema provides all of the columns referenced in the expressions.
pub(crate) fn convert_data_type_to_field( &self, sql_type: &SQLDataType, ) -> Result<FieldRef>
fn convert_simple_data_type(&self, sql_type: &SQLDataType) -> Result<DataType>
pub(crate) fn object_name_to_table_reference( &self, object_name: ObjectName, ) -> Result<TableReference>
Source§impl<S: ContextProvider> SqlToRel<'_, S>
impl<S: ContextProvider> SqlToRel<'_, S>
Sourcepub(crate) fn query_to_plan(
&self,
query: Query,
outer_planner_context: &mut PlannerContext,
) -> Result<LogicalPlan>
pub(crate) fn query_to_plan( &self, query: Query, outer_planner_context: &mut PlannerContext, ) -> Result<LogicalPlan>
Generate a logical plan from an SQL query/subquery
Sourcefn pipe_operators(
&self,
plan: LogicalPlan,
pipe_operators: Vec<PipeOperator>,
planner_context: &mut PlannerContext,
) -> Result<LogicalPlan>
fn pipe_operators( &self, plan: LogicalPlan, pipe_operators: Vec<PipeOperator>, planner_context: &mut PlannerContext, ) -> Result<LogicalPlan>
Apply pipe operators to a plan
Sourcefn pipe_operator(
&self,
plan: LogicalPlan,
pipe_operator: PipeOperator,
planner_context: &mut PlannerContext,
) -> Result<LogicalPlan>
fn pipe_operator( &self, plan: LogicalPlan, pipe_operator: PipeOperator, planner_context: &mut PlannerContext, ) -> Result<LogicalPlan>
Apply a pipe operator to a plan
Sourcefn pipe_operator_set(
&self,
plan: LogicalPlan,
set_operator: SetOperator,
set_quantifier: SetQuantifier,
queries: Vec<Query>,
planner_context: &mut PlannerContext,
) -> Result<LogicalPlan>
fn pipe_operator_set( &self, plan: LogicalPlan, set_operator: SetOperator, set_quantifier: SetQuantifier, queries: Vec<Query>, planner_context: &mut PlannerContext, ) -> Result<LogicalPlan>
Handle Union/Intersect/Except pipe operators
Sourcefn limit(
&self,
input: LogicalPlan,
limit_clause: Option<LimitClause>,
planner_context: &mut PlannerContext,
) -> Result<LogicalPlan>
fn limit( &self, input: LogicalPlan, limit_clause: Option<LimitClause>, planner_context: &mut PlannerContext, ) -> Result<LogicalPlan>
Wrap a plan in a limit
Sourcepub(crate) fn order_by(
&self,
plan: LogicalPlan,
order_by: Vec<Sort>,
) -> Result<LogicalPlan>
pub(crate) fn order_by( &self, plan: LogicalPlan, order_by: Vec<Sort>, ) -> Result<LogicalPlan>
Wrap the logical in a sort
Sourcefn pipe_operator_aggregate(
&self,
plan: LogicalPlan,
full_table_exprs: Vec<ExprWithAliasAndOrderBy>,
group_by_expr: Vec<ExprWithAliasAndOrderBy>,
planner_context: &mut PlannerContext,
) -> Result<LogicalPlan>
fn pipe_operator_aggregate( &self, plan: LogicalPlan, full_table_exprs: Vec<ExprWithAliasAndOrderBy>, group_by_expr: Vec<ExprWithAliasAndOrderBy>, planner_context: &mut PlannerContext, ) -> Result<LogicalPlan>
Handle AGGREGATE pipe operator
Sourcefn select_into(
&self,
plan: LogicalPlan,
select_into: Option<SelectInto>,
) -> Result<LogicalPlan>
fn select_into( &self, plan: LogicalPlan, select_into: Option<SelectInto>, ) -> Result<LogicalPlan>
Wrap the logical plan in a SelectInto
Source§impl<S: ContextProvider> SqlToRel<'_, S>
impl<S: ContextProvider> SqlToRel<'_, S>
pub(crate) fn plan_table_with_joins( &self, t: TableWithJoins, planner_context: &mut PlannerContext, ) -> Result<LogicalPlan>
pub(crate) fn parse_relation_join( &self, left: LogicalPlan, join: Join, planner_context: &mut PlannerContext, ) -> Result<LogicalPlan>
fn parse_cross_join( &self, left: LogicalPlan, right: LogicalPlan, ) -> Result<LogicalPlan>
fn parse_join( &self, left: LogicalPlan, right: LogicalPlan, constraint: JoinConstraint, join_type: JoinType, planner_context: &mut PlannerContext, ) -> Result<LogicalPlan>
Source§impl<S: ContextProvider> SqlToRel<'_, S>
impl<S: ContextProvider> SqlToRel<'_, S>
Sourcefn create_relation(
&self,
relation: TableFactor,
planner_context: &mut PlannerContext,
) -> Result<LogicalPlan>
fn create_relation( &self, relation: TableFactor, planner_context: &mut PlannerContext, ) -> Result<LogicalPlan>
Create a LogicalPlan that scans the named relation
pub(crate) fn create_relation_subquery( &self, subquery: TableFactor, planner_context: &mut PlannerContext, ) -> Result<LogicalPlan>
Source§impl<S: ContextProvider> SqlToRel<'_, S>
impl<S: ContextProvider> SqlToRel<'_, S>
Sourcepub(crate) fn select_to_plan(
&self,
select: Select,
query_order_by: Option<OrderBy>,
planner_context: &mut PlannerContext,
) -> Result<LogicalPlan>
pub(crate) fn select_to_plan( &self, select: Select, query_order_by: Option<OrderBy>, planner_context: &mut PlannerContext, ) -> Result<LogicalPlan>
Generate a logic plan from an SQL select
Sourcepub(crate) fn try_process_unnest(
&self,
input: LogicalPlan,
select_exprs: Vec<Expr>,
) -> Result<LogicalPlan>
pub(crate) fn try_process_unnest( &self, input: LogicalPlan, select_exprs: Vec<Expr>, ) -> Result<LogicalPlan>
Try converting Expr(Unnest(Expr)) to Projection/Unnest/Projection
fn try_process_aggregate_unnest( &self, input: LogicalPlan, ) -> Result<LogicalPlan>
Sourcefn try_process_group_by_unnest(
&self,
agg: Aggregate,
) -> Result<(LogicalPlan, Vec<Expr>)>
fn try_process_group_by_unnest( &self, agg: Aggregate, ) -> Result<(LogicalPlan, Vec<Expr>)>
Try converting Unnest(Expr) of group by to Unnest/Projection. Return the new input and group_by_exprs of Aggregate. Select exprs can be different from agg exprs, for example:
pub(crate) fn plan_selection( &self, selection: Option<SQLExpr>, plan: LogicalPlan, planner_context: &mut PlannerContext, ) -> Result<LogicalPlan>
pub(crate) fn plan_from_tables( &self, from: Vec<TableWithJoins>, planner_context: &mut PlannerContext, ) -> Result<LogicalPlan>
Sourcepub(crate) fn prepare_select_exprs(
&self,
plan: &LogicalPlan,
projection: Vec<SelectItem>,
empty_from: bool,
planner_context: &mut PlannerContext,
) -> Result<Vec<SelectExpr>>
pub(crate) fn prepare_select_exprs( &self, plan: &LogicalPlan, projection: Vec<SelectItem>, empty_from: bool, planner_context: &mut PlannerContext, ) -> Result<Vec<SelectExpr>>
Returns the Expr’s corresponding to a SQL query’s SELECT expressions.
Sourcefn sql_select_to_rex(
&self,
sql: SelectItem,
plan: &LogicalPlan,
empty_from: bool,
planner_context: &mut PlannerContext,
) -> Result<SelectExpr>
fn sql_select_to_rex( &self, sql: SelectItem, plan: &LogicalPlan, empty_from: bool, planner_context: &mut PlannerContext, ) -> Result<SelectExpr>
Generate a relational expression from a select SQL expression
fn check_wildcard_options(options: &WildcardAdditionalOptions) -> Result<()>
Sourcefn plan_wildcard_options(
&self,
plan: &LogicalPlan,
empty_from: bool,
planner_context: &mut PlannerContext,
options: WildcardAdditionalOptions,
) -> Result<WildcardOptions>
fn plan_wildcard_options( &self, plan: &LogicalPlan, empty_from: bool, planner_context: &mut PlannerContext, options: WildcardAdditionalOptions, ) -> Result<WildcardOptions>
If there is a REPLACE statement in the projected expression in the form of “REPLACE (some_column_within_an_expr AS some_column)”, we should plan the replace expressions first.
Sourcepub(crate) fn project(
&self,
input: LogicalPlan,
expr: Vec<SelectExpr>,
) -> Result<LogicalPlan>
pub(crate) fn project( &self, input: LogicalPlan, expr: Vec<SelectExpr>, ) -> Result<LogicalPlan>
Wrap a plan in a projection
Sourcefn aggregate(
&self,
input: &LogicalPlan,
select_exprs: &[Expr],
having_expr_opt: Option<&Expr>,
qualify_expr_opt: Option<&Expr>,
group_by_exprs: &[Expr],
aggr_exprs: &[Expr],
) -> Result<(LogicalPlan, Vec<Expr>, Option<Expr>, Option<Expr>)>
fn aggregate( &self, input: &LogicalPlan, select_exprs: &[Expr], having_expr_opt: Option<&Expr>, qualify_expr_opt: Option<&Expr>, group_by_exprs: &[Expr], aggr_exprs: &[Expr], ) -> Result<(LogicalPlan, Vec<Expr>, Option<Expr>, Option<Expr>)>
Create an aggregate plan.
An aggregate plan consists of grouping expressions, aggregate expressions, an optional HAVING expression (which is a filter on the output of the aggregate), and an optional QUALIFY clause which may reference aggregates.
§Arguments
input- The input plan that will be aggregated. The grouping, aggregate, and “having” expressions must all be resolvable from this plan.select_exprs- The projection expressions from the SELECT clause.having_expr_opt- Optional HAVING clause.qualify_expr_opt- Optional QUALIFY clause.group_by_exprs- Grouping expressions from the GROUP BY clause. These can be column references or more complex expressions.aggr_exprs- Aggregate expressions, such asSUM(a)orCOUNT(1).
§Return
The return value is a quadruplet of the following items:
plan- A LogicalPlan::Aggregate plan for the newly created aggregate.select_exprs_post_aggr- The projection expressions rewritten to reference columns from the aggregatehaving_expr_post_aggr- The “having” expression rewritten to reference a column from the aggregatequalify_expr_post_aggr- The “qualify” expression rewritten to reference a column from the aggregate
fn match_window_definitions( &self, projection: &mut [SelectItem], named_windows: &[NamedWindowDefinition], ) -> Result<()>
Source§impl<S: ContextProvider> SqlToRel<'_, S>
impl<S: ContextProvider> SqlToRel<'_, S>
pub(crate) fn set_expr_to_plan( &self, set_expr: SetExpr, planner_context: &mut PlannerContext, ) -> Result<LogicalPlan>
pub(crate) fn is_union_all(set_quantifier: SetQuantifier) -> Result<bool>
fn validate_set_expr_num_of_columns( &self, op: SetOperator, left_span: Option<Span>, right_span: Option<Span>, left_plan: &LogicalPlan, right_plan: &LogicalPlan, set_expr_span: Option<Span>, ) -> Result<()>
pub(crate) fn set_operation_to_plan( &self, op: SetOperator, left_plan: LogicalPlan, right_plan: LogicalPlan, set_quantifier: SetQuantifier, ) -> Result<LogicalPlan>
Source§impl<S: ContextProvider> SqlToRel<'_, S>
impl<S: ContextProvider> SqlToRel<'_, S>
Sourcepub fn statement_to_plan(&self, statement: DFStatement) -> Result<LogicalPlan>
pub fn statement_to_plan(&self, statement: DFStatement) -> Result<LogicalPlan>
Generate a logical plan from an DataFusion SQL statement
Sourcepub fn sql_statement_to_plan(&self, statement: Statement) -> Result<LogicalPlan>
pub fn sql_statement_to_plan(&self, statement: Statement) -> Result<LogicalPlan>
Generate a logical plan from an SQL statement
Sourcepub fn sql_statement_to_plan_with_context(
&self,
statement: Statement,
planner_context: &mut PlannerContext,
) -> Result<LogicalPlan>
pub fn sql_statement_to_plan_with_context( &self, statement: Statement, planner_context: &mut PlannerContext, ) -> Result<LogicalPlan>
Generate a logical plan from an SQL statement
fn sql_statement_to_plan_with_context_impl( &self, statement: Statement, planner_context: &mut PlannerContext, ) -> Result<LogicalPlan>
fn get_delete_target(&self, from: FromTable) -> Result<ObjectName>
Sourcefn show_tables_to_plan(&self) -> Result<LogicalPlan>
fn show_tables_to_plan(&self) -> Result<LogicalPlan>
Generate a logical plan from a “SHOW TABLES” query
fn describe_table_to_plan(&self, table_name: ObjectName) -> Result<LogicalPlan>
fn describe_query_to_plan(&self, query: Query) -> Result<LogicalPlan>
fn copy_to_plan(&self, statement: CopyToStatement) -> Result<LogicalPlan>
fn build_order_by( &self, order_exprs: Vec<Vec<OrderByExpr>>, schema: &DFSchemaRef, planner_context: &mut PlannerContext, ) -> Result<Vec<Vec<SortExpr>>>
Sourcefn external_table_to_plan(
&self,
statement: CreateExternalTable,
) -> Result<LogicalPlan>
fn external_table_to_plan( &self, statement: CreateExternalTable, ) -> Result<LogicalPlan>
Generate a logical plan from a CREATE EXTERNAL TABLE statement
Sourcefn get_constraint_column_indices(
&self,
df_schema: &DFSchemaRef,
columns: &[IndexColumn],
constraint_name: &str,
) -> Result<Vec<usize>>
fn get_constraint_column_indices( &self, df_schema: &DFSchemaRef, columns: &[IndexColumn], constraint_name: &str, ) -> Result<Vec<usize>>
Get the indices of the constraint columns in the schema. If any column is not found, return an error.
Sourcepub fn new_constraint_from_table_constraints(
&self,
constraints: &[TableConstraint],
df_schema: &DFSchemaRef,
) -> Result<Constraints>
pub fn new_constraint_from_table_constraints( &self, constraints: &[TableConstraint], df_schema: &DFSchemaRef, ) -> Result<Constraints>
Convert each [TableConstraint] to corresponding Constraint
fn parse_options_map( &self, options: Vec<(String, Value)>, allow_duplicates: bool, ) -> Result<HashMap<String, String>>
Sourcefn explain_to_plan(
&self,
verbose: bool,
analyze: bool,
format: Option<String>,
statement: DFStatement,
) -> Result<LogicalPlan>
fn explain_to_plan( &self, verbose: bool, analyze: bool, format: Option<String>, statement: DFStatement, ) -> Result<LogicalPlan>
Generate a plan for EXPLAIN … that will print out a plan
Note this is the sqlparser explain statement, not the
datafusion EXPLAIN statement.
fn show_variable_to_plan(&self, variable: &[Ident]) -> Result<LogicalPlan>
fn set_statement_to_plan(&self, statement: Set) -> Result<LogicalPlan>
fn delete_to_plan( &self, table_name: ObjectName, predicate_expr: Option<SQLExpr>, ) -> Result<LogicalPlan>
fn update_to_plan( &self, table: TableWithJoins, assignments: Vec<Assignment>, from: Option<TableWithJoins>, predicate_expr: Option<SQLExpr>, ) -> Result<LogicalPlan>
fn insert_to_plan( &self, table_name: ObjectName, columns: Vec<Ident>, source: Box<Query>, overwrite: bool, replace_into: bool, ) -> Result<LogicalPlan>
fn show_columns_to_plan( &self, extended: bool, full: bool, sql_table_name: ObjectName, ) -> Result<LogicalPlan>
Sourcefn show_functions_to_plan(
&self,
filter: Option<ShowStatementFilter>,
) -> Result<LogicalPlan>
fn show_functions_to_plan( &self, filter: Option<ShowStatementFilter>, ) -> Result<LogicalPlan>
Rewrite SHOW FUNCTIONS to another SQL query
The query is based on the information_schema.routines and information_schema.parameters tables
The output columns:
- function_name: The name of function
- return_type: The return type of the function
- parameters: The name of parameters (ordered by the ordinal position)
- parameter_types: The type of parameters (ordered by the ordinal position)
- description: The description of the function (the description defined in the document)
- syntax_example: The syntax_example of the function (the syntax_example defined in the document)
fn show_create_table_to_plan( &self, sql_table_name: ObjectName, ) -> Result<LogicalPlan>
Sourcefn has_table(&self, schema: &str, table: &str) -> bool
fn has_table(&self, schema: &str, table: &str) -> bool
Return true if there is a table provider available for “schema.table”
fn validate_transaction_kind( &self, kind: Option<BeginTransactionKind>, ) -> Result<()>
Source§impl<S: ContextProvider> SqlToRel<'_, S>
impl<S: ContextProvider> SqlToRel<'_, S>
pub(crate) fn sql_values_to_plan( &self, values: SQLValues, planner_context: &mut PlannerContext, ) -> Result<LogicalPlan>
Auto Trait Implementations§
impl<'a, S> Freeze for SqlToRel<'a, S>
impl<'a, S> RefUnwindSafe for SqlToRel<'a, S>where
S: RefUnwindSafe,
impl<'a, S> Send for SqlToRel<'a, S>where
S: Sync,
impl<'a, S> Sync for SqlToRel<'a, S>where
S: Sync,
impl<'a, S> Unpin for SqlToRel<'a, S>
impl<'a, S> UnwindSafe for SqlToRel<'a, S>where
S: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more