Struct datafusion::logical_plan::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 = LogicalPlanBuilder::scan_empty(
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
sourceimpl 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.
sourcepub fn scan_memory(
partitions: Vec<Vec<RecordBatch>>,
schema: SchemaRef,
projection: Option<Vec<usize>>
) -> Result<Self>
pub fn scan_memory(
partitions: Vec<Vec<RecordBatch>>,
schema: SchemaRef,
projection: Option<Vec<usize>>
) -> Result<Self>
Scan a memory data source
sourcepub async fn scan_csv(
object_store: Arc<dyn ObjectStore>,
path: impl Into<String>,
options: CsvReadOptions<'_>,
projection: Option<Vec<usize>>,
target_partitions: usize
) -> Result<Self>
pub async fn scan_csv(
object_store: Arc<dyn ObjectStore>,
path: impl Into<String>,
options: CsvReadOptions<'_>,
projection: Option<Vec<usize>>,
target_partitions: usize
) -> Result<Self>
Scan a CSV data source
sourcepub async fn scan_csv_with_name(
object_store: Arc<dyn ObjectStore>,
path: impl Into<String>,
options: CsvReadOptions<'_>,
projection: Option<Vec<usize>>,
table_name: impl Into<String>,
target_partitions: usize
) -> Result<Self>
pub async fn scan_csv_with_name(
object_store: Arc<dyn ObjectStore>,
path: impl Into<String>,
options: CsvReadOptions<'_>,
projection: Option<Vec<usize>>,
table_name: impl Into<String>,
target_partitions: usize
) -> Result<Self>
Scan a CSV data source and register it with a given table name
sourcepub async fn scan_parquet(
object_store: Arc<dyn ObjectStore>,
path: impl Into<String>,
projection: Option<Vec<usize>>,
target_partitions: usize
) -> Result<Self>
pub async fn scan_parquet(
object_store: Arc<dyn ObjectStore>,
path: impl Into<String>,
projection: Option<Vec<usize>>,
target_partitions: usize
) -> Result<Self>
Scan a Parquet data source
sourcepub async fn scan_parquet_with_name(
object_store: Arc<dyn ObjectStore>,
path: impl Into<String>,
projection: Option<Vec<usize>>,
target_partitions: usize,
table_name: impl Into<String>
) -> Result<Self>
pub async fn scan_parquet_with_name(
object_store: Arc<dyn ObjectStore>,
path: impl Into<String>,
projection: Option<Vec<usize>>,
target_partitions: usize,
table_name: impl Into<String>
) -> Result<Self>
Scan a Parquet data source and register it with a given table name
sourcepub async fn scan_avro(
object_store: Arc<dyn ObjectStore>,
path: impl Into<String>,
options: AvroReadOptions<'_>,
projection: Option<Vec<usize>>,
target_partitions: usize
) -> Result<Self>
pub async fn scan_avro(
object_store: Arc<dyn ObjectStore>,
path: impl Into<String>,
options: AvroReadOptions<'_>,
projection: Option<Vec<usize>>,
target_partitions: usize
) -> Result<Self>
Scan an Avro data source
sourcepub async fn scan_avro_with_name(
object_store: Arc<dyn ObjectStore>,
path: impl Into<String>,
options: AvroReadOptions<'_>,
projection: Option<Vec<usize>>,
table_name: impl Into<String>,
target_partitions: usize
) -> Result<Self>
pub async fn scan_avro_with_name(
object_store: Arc<dyn ObjectStore>,
path: impl Into<String>,
options: AvroReadOptions<'_>,
projection: Option<Vec<usize>>,
table_name: impl Into<String>,
target_partitions: usize
) -> Result<Self>
Scan an Avro data source and register it with a given table name
sourcepub fn scan_empty(
name: Option<&str>,
table_schema: &Schema,
projection: Option<Vec<usize>>
) -> Result<Self>
pub fn scan_empty(
name: Option<&str>,
table_schema: &Schema,
projection: Option<Vec<usize>>
) -> Result<Self>
Scan an empty data source, mainly used in tests
sourcepub fn scan(
table_name: impl Into<String>,
provider: Arc<dyn TableProvider>,
projection: Option<Vec<usize>>
) -> Result<Self>
pub fn scan(
table_name: impl Into<String>,
provider: Arc<dyn TableProvider>,
projection: Option<Vec<usize>>
) -> Result<Self>
Convert a table provider into a builder with a TableScan
sourcepub fn scan_with_filters(
table_name: impl Into<String>,
provider: Arc<dyn TableProvider>,
projection: Option<Vec<usize>>,
filters: Vec<Expr>
) -> Result<Self>
pub fn scan_with_filters(
table_name: impl Into<String>,
provider: Arc<dyn TableProvider>,
projection: Option<Vec<usize>>,
filters: Vec<Expr>
) -> Result<Self>
Convert a table provider into a builder with a TableScan
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 project_with_alias(
&self,
expr: impl IntoIterator<Item = impl Into<Expr>>,
alias: Option<String>
) -> Result<Self>
pub fn project_with_alias(
&self,
expr: impl IntoIterator<Item = impl Into<Expr>>,
alias: Option<String>
) -> Result<Self>
Apply a projection with 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
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>>)
) -> Result<Self>
pub fn join(
&self,
right: &LogicalPlan,
join_type: JoinType,
join_keys: (Vec<impl Into<Column>>, Vec<impl Into<Column>>)
) -> Result<Self>
Apply a join with on constraint
sourcepub fn join_detailed(
&self,
right: &LogicalPlan,
join_type: JoinType,
join_keys: (Vec<impl Into<Column>>, Vec<impl Into<Column>>),
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>>),
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 build(&self) -> Result<LogicalPlan>
pub fn build(&self) -> Result<LogicalPlan>
Build the plan
Auto Trait Implementations
impl !RefUnwindSafe for LogicalPlanBuilder
impl Send for LogicalPlanBuilder
impl Sync for LogicalPlanBuilder
impl Unpin for LogicalPlanBuilder
impl !UnwindSafe for LogicalPlanBuilder
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more