Struct datafusion_expr::logical_plan::builder::LogicalPlanBuilder
source · pub struct LogicalPlanBuilder { /* private fields */ }
Expand description
Builder for logical plans
// Create a plan similar to
// SELECT last_name
// FROM employees
// WHERE salary < 1000
let plan = table_scan(
Some("employee"),
&employee_schema(),
None,
)?
// Keep only rows where salary < 1000
.filter(col("salary").lt_eq(lit(1000)))?
// only show "last_name" in the final results
.project(vec![col("last_name")])?
.build()?;
Implementations§
source§impl LogicalPlanBuilder
impl LogicalPlanBuilder
sourcepub fn from(plan: LogicalPlan) -> Self
pub fn from(plan: LogicalPlan) -> Self
Create a builder from an existing plan
sourcepub fn schema(&self) -> &DFSchemaRef
pub fn schema(&self) -> &DFSchemaRef
Return the output schema of the plan build so far
sourcepub fn empty(produce_one_row: bool) -> Self
pub fn empty(produce_one_row: bool) -> Self
Create an empty relation.
produce_one_row
set to true means this empty node needs to produce a placeholder row.
sourcepub fn values(values: Vec<Vec<Expr>>) -> Result<Self>
pub fn values(values: Vec<Vec<Expr>>) -> Result<Self>
Create a values list based relation, and the schema is inferred from data, consuming
value
. See the Postgres VALUES
documentation for more details.
By default, it assigns the names column1, column2, etc. to the columns of a VALUES table. The column names are not specified by the SQL standard and different database systems do it differently, so it’s usually better to override the default names with a table alias list.
If the values include params/binders such as $1, $2, $3, etc, then the param_data_types
should be provided.
sourcepub fn scan(
table_name: impl Into<OwnedTableReference>,
table_source: Arc<dyn TableSource>,
projection: Option<Vec<usize>>
) -> Result<Self>
pub fn scan( table_name: impl Into<OwnedTableReference>, table_source: Arc<dyn TableSource>, projection: Option<Vec<usize>> ) -> Result<Self>
Convert a table provider into a builder with a TableScan
Note that if you pass a string as table_name
, it is treated
as a SQL identifier, as described on TableReference
and
thus is normalized
Example:
// Scan table_source with the name "mytable" (after normalization)
let scan = LogicalPlanBuilder::scan("MyTable", table, None);
// Scan table_source with the name "MyTable" by enclosing in quotes
let scan = LogicalPlanBuilder::scan(r#""MyTable""#, table, None);
// Scan table_source with the name "MyTable" by forming the table reference
let table_reference = TableReference::bare("MyTable");
let scan = LogicalPlanBuilder::scan(table_reference, table, None);
sourcepub fn copy_to(
input: LogicalPlan,
output_url: String,
file_format: FileType,
single_file_output: bool,
copy_options: CopyOptions
) -> Result<Self>
pub fn copy_to( input: LogicalPlan, output_url: String, file_format: FileType, single_file_output: bool, copy_options: CopyOptions ) -> Result<Self>
Create a CopyTo for copying the contents of this builder to the specified file(s)
sourcepub fn insert_into(
input: LogicalPlan,
table_name: impl Into<OwnedTableReference>,
table_schema: &Schema,
overwrite: bool
) -> Result<Self>
pub fn insert_into( input: LogicalPlan, table_name: impl Into<OwnedTableReference>, table_schema: &Schema, overwrite: bool ) -> Result<Self>
Create a DmlStatement for inserting the contents of this builder into the named table
sourcepub fn scan_with_filters(
table_name: impl Into<OwnedTableReference>,
table_source: Arc<dyn TableSource>,
projection: Option<Vec<usize>>,
filters: Vec<Expr>
) -> Result<Self>
pub fn scan_with_filters( table_name: impl Into<OwnedTableReference>, table_source: Arc<dyn TableSource>, projection: Option<Vec<usize>>, filters: Vec<Expr> ) -> Result<Self>
Convert a table provider into a builder with a TableScan
sourcepub fn window_plan(
input: LogicalPlan,
window_exprs: Vec<Expr>
) -> Result<LogicalPlan>
pub fn window_plan( input: LogicalPlan, window_exprs: Vec<Expr> ) -> Result<LogicalPlan>
Wrap a plan in a window
sourcepub fn project(
self,
expr: impl IntoIterator<Item = impl Into<Expr>>
) -> Result<Self>
pub fn project( self, expr: impl IntoIterator<Item = impl Into<Expr>> ) -> Result<Self>
Apply a projection without alias.
sourcepub fn select(self, indices: impl IntoIterator<Item = usize>) -> Result<Self>
pub fn select(self, indices: impl IntoIterator<Item = usize>) -> Result<Self>
Select the given column indices
sourcepub fn prepare(self, name: String, data_types: Vec<DataType>) -> Result<Self>
pub fn prepare(self, name: String, data_types: Vec<DataType>) -> Result<Self>
Make a builder for a prepare logical plan from the builder’s plan
sourcepub fn limit(self, skip: usize, fetch: Option<usize>) -> Result<Self>
pub fn limit(self, skip: usize, fetch: Option<usize>) -> Result<Self>
Limit the number of rows returned
skip
- Number of rows to skip before fetch any row.
fetch
- Maximum number of rows to fetch, after skipping skip
rows,
if specified.
sourcepub fn alias(self, alias: impl Into<OwnedTableReference>) -> Result<Self>
pub fn alias(self, alias: impl Into<OwnedTableReference>) -> Result<Self>
Apply an alias
sourcepub fn sort(
self,
exprs: impl IntoIterator<Item = impl Into<Expr>> + Clone
) -> Result<Self>
pub fn sort( self, exprs: impl IntoIterator<Item = impl Into<Expr>> + Clone ) -> Result<Self>
Apply a sort
sourcepub fn union(self, plan: LogicalPlan) -> Result<Self>
pub fn union(self, plan: LogicalPlan) -> Result<Self>
Apply a union, preserving duplicate rows
sourcepub fn union_distinct(self, plan: LogicalPlan) -> Result<Self>
pub fn union_distinct(self, plan: LogicalPlan) -> Result<Self>
Apply a union, removing duplicate rows
sourcepub fn distinct(self) -> Result<Self>
pub fn distinct(self) -> Result<Self>
Apply deduplication: Only distinct (different) values are returned)
sourcepub fn join(
self,
right: LogicalPlan,
join_type: JoinType,
join_keys: (Vec<impl Into<Column>>, Vec<impl Into<Column>>),
filter: Option<Expr>
) -> Result<Self>
pub fn join( self, right: LogicalPlan, join_type: JoinType, join_keys: (Vec<impl Into<Column>>, Vec<impl Into<Column>>), filter: Option<Expr> ) -> Result<Self>
Apply a join with on constraint.
Filter expression expected to contain non-equality predicates that can not be pushed down to any of join inputs. In case of outer join, filter applied to only matched rows.
sourcepub fn join_detailed(
self,
right: LogicalPlan,
join_type: JoinType,
join_keys: (Vec<impl Into<Column>>, Vec<impl Into<Column>>),
filter: Option<Expr>,
null_equals_null: bool
) -> Result<Self>
pub fn join_detailed( self, right: LogicalPlan, join_type: JoinType, join_keys: (Vec<impl Into<Column>>, Vec<impl Into<Column>>), filter: Option<Expr>, null_equals_null: bool ) -> Result<Self>
Apply a join with on constraint and specified null equality If null_equals_null is true then null == null, else null != null
sourcepub fn join_using(
self,
right: LogicalPlan,
join_type: JoinType,
using_keys: Vec<impl Into<Column> + Clone>
) -> Result<Self>
pub fn join_using( self, right: LogicalPlan, join_type: JoinType, using_keys: Vec<impl Into<Column> + Clone> ) -> Result<Self>
Apply a join with using constraint, which duplicates all join columns in output schema.
sourcepub fn cross_join(self, right: LogicalPlan) -> Result<Self>
pub fn cross_join(self, right: LogicalPlan) -> Result<Self>
Apply a cross join
sourcepub fn repartition(self, partitioning_scheme: Partitioning) -> Result<Self>
pub fn repartition(self, partitioning_scheme: Partitioning) -> Result<Self>
Repartition
sourcepub fn window(
self,
window_expr: impl IntoIterator<Item = impl Into<Expr>>
) -> Result<Self>
pub fn window( self, window_expr: impl IntoIterator<Item = impl Into<Expr>> ) -> Result<Self>
Apply a window functions to extend the schema
sourcepub fn aggregate(
self,
group_expr: impl IntoIterator<Item = impl Into<Expr>>,
aggr_expr: impl IntoIterator<Item = impl Into<Expr>>
) -> Result<Self>
pub fn aggregate( self, group_expr: impl IntoIterator<Item = impl Into<Expr>>, aggr_expr: impl IntoIterator<Item = impl Into<Expr>> ) -> Result<Self>
Apply an aggregate: grouping on the group_expr
expressions
and calculating aggr_expr
aggregates for each distinct
value of the group_expr
;
sourcepub fn explain(self, verbose: bool, analyze: bool) -> Result<Self>
pub fn explain(self, verbose: bool, analyze: bool) -> Result<Self>
Create an expression to represent the explanation of the plan
if analyze
is true, runs the actual plan and produces
information about metrics during run.
if verbose
is true, prints out additional details.
sourcepub fn intersect(
left_plan: LogicalPlan,
right_plan: LogicalPlan,
is_all: bool
) -> Result<LogicalPlan>
pub fn intersect( left_plan: LogicalPlan, right_plan: LogicalPlan, is_all: bool ) -> Result<LogicalPlan>
Process intersect set operator
sourcepub fn except(
left_plan: LogicalPlan,
right_plan: LogicalPlan,
is_all: bool
) -> Result<LogicalPlan>
pub fn except( left_plan: LogicalPlan, right_plan: LogicalPlan, is_all: bool ) -> Result<LogicalPlan>
Process except set operator
sourcepub fn build(self) -> Result<LogicalPlan>
pub fn build(self) -> Result<LogicalPlan>
Build the plan
sourcepub fn join_with_expr_keys(
self,
right: LogicalPlan,
join_type: JoinType,
equi_exprs: (Vec<impl Into<Expr>>, Vec<impl Into<Expr>>),
filter: Option<Expr>
) -> Result<Self>
pub fn join_with_expr_keys( self, right: LogicalPlan, join_type: JoinType, equi_exprs: (Vec<impl Into<Expr>>, Vec<impl Into<Expr>>), filter: Option<Expr> ) -> Result<Self>
Apply a join with the expression on constraint.
equi_exprs are “equijoin” predicates expressions on the existing and right inputs, respectively.
filter: any other filter expression to apply during the join. equi_exprs predicates are likely to be evaluated more quickly than the filter expressions
sourcepub fn unnest_column(self, column: impl Into<Column>) -> Result<Self>
pub fn unnest_column(self, column: impl Into<Column>) -> Result<Self>
Unnest the given column.
sourcepub fn unnest_column_with_options(
self,
column: impl Into<Column>,
options: UnnestOptions
) -> Result<Self>
pub fn unnest_column_with_options( self, column: impl Into<Column>, options: UnnestOptions ) -> Result<Self>
Unnest the given column given UnnestOptions
Trait Implementations§
source§impl Clone for LogicalPlanBuilder
impl Clone for LogicalPlanBuilder
source§fn clone(&self) -> LogicalPlanBuilder
fn clone(&self) -> LogicalPlanBuilder
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more