Enum datafusion_expr::logical_plan::LogicalPlan
source · pub enum LogicalPlan {
Show 28 variants
Projection(Projection),
Filter(Filter),
Window(Window),
Aggregate(Aggregate),
Sort(Sort),
Join(Join),
CrossJoin(CrossJoin),
Repartition(Repartition),
Union(Union),
TableScan(TableScan),
EmptyRelation(EmptyRelation),
Subquery(Subquery),
SubqueryAlias(SubqueryAlias),
Limit(Limit),
CreateExternalTable(CreateExternalTable),
CreateMemoryTable(CreateMemoryTable),
CreateView(CreateView),
CreateCatalogSchema(CreateCatalogSchema),
CreateCatalog(CreateCatalog),
DropTable(DropTable),
DropView(DropView),
Values(Values),
Explain(Explain),
Analyze(Analyze),
Extension(Extension),
Distinct(Distinct),
SetVariable(SetVariable),
Prepare(Prepare),
}
Expand description
A LogicalPlan represents the different types of relational operators (such as Projection, Filter, etc) and can be created by the SQL query planner and the DataFrame API.
A LogicalPlan represents transforming an input relation (table) to an output relation (table) with a (potentially) different schema. A plan represents a dataflow tree where data flows from leaves up to the root to produce the query result.
Variants§
Projection(Projection)
Evaluates an arbitrary list of expressions (essentially a SELECT with an expression list) on its input.
Filter(Filter)
Filters rows from its input that do not match an expression (essentially a WHERE clause with a predicate expression).
Semantically, <predicate>
is evaluated for each row of the input;
If the value of <predicate>
is true, the input row is passed to
the output. If the value of <predicate>
is false, the row is
discarded.
Window(Window)
Window its input based on a set of window spec and window function (e.g. SUM or RANK)
Aggregate(Aggregate)
Aggregates its input based on a set of grouping and aggregate expressions (e.g. SUM).
Sort(Sort)
Sorts its input according to a list of sort expressions.
Join(Join)
Join two logical plans on one or more join columns
CrossJoin(CrossJoin)
Apply Cross Join to two logical plans
Repartition(Repartition)
Repartition the plan based on a partitioning scheme.
Union(Union)
Union multiple inputs
TableScan(TableScan)
Produces rows from a table provider by reference or from the context
EmptyRelation(EmptyRelation)
Produces no rows: An empty relation with an empty schema
Subquery(Subquery)
Subquery
SubqueryAlias(SubqueryAlias)
Aliased relation provides, or changes, the name of a relation.
Limit(Limit)
Skip some number of rows, and then fetch some number of rows.
CreateExternalTable(CreateExternalTable)
Creates an external table.
CreateMemoryTable(CreateMemoryTable)
Creates an in memory table.
CreateView(CreateView)
Creates a new view.
CreateCatalogSchema(CreateCatalogSchema)
Creates a new catalog schema.
CreateCatalog(CreateCatalog)
Creates a new catalog (aka “Database”).
DropTable(DropTable)
Drops a table.
DropView(DropView)
Drops a view.
Values(Values)
Values expression. See Postgres VALUES documentation for more details.
Explain(Explain)
Produces a relation with string representations of various parts of the plan
Analyze(Analyze)
Runs the actual plan, and then prints the physical plan with with execution metrics.
Extension(Extension)
Extension operator defined outside of DataFusion
Distinct(Distinct)
Remove duplicate rows from the input
SetVariable(SetVariable)
Set a Variable
Prepare(Prepare)
Prepare a statement
Implementations§
source§impl LogicalPlan
impl LogicalPlan
sourcepub fn schema(&self) -> &DFSchemaRef
pub fn schema(&self) -> &DFSchemaRef
Get a reference to the logical plan’s schema
sourcepub fn all_schemas(&self) -> Vec<&DFSchemaRef> ⓘ
pub fn all_schemas(&self) -> Vec<&DFSchemaRef> ⓘ
Get a vector of references to all schemas in every node of the logical plan
sourcepub fn explain_schema() -> SchemaRef
pub fn explain_schema() -> SchemaRef
Returns the (fixed) output schema for explain plans
sourcepub fn expressions(self: &LogicalPlan) -> Vec<Expr> ⓘ
pub fn expressions(self: &LogicalPlan) -> Vec<Expr> ⓘ
returns all expressions (non-recursively) in the current logical plan node. This does not include expressions in any children
sourcepub fn inputs(self: &LogicalPlan) -> Vec<&LogicalPlan> ⓘ
pub fn inputs(self: &LogicalPlan) -> Vec<&LogicalPlan> ⓘ
returns all inputs of this LogicalPlan
node. Does not
include inputs to inputs, or subqueries.
sourcepub fn using_columns(&self) -> Result<Vec<HashSet<Column>>, DataFusionError>
pub fn using_columns(&self) -> Result<Vec<HashSet<Column>>, DataFusionError>
returns all Using
join columns in a logical plan
pub fn with_new_inputs(
&self,
inputs: &[LogicalPlan]
) -> Result<LogicalPlan, DataFusionError>
sourcepub fn with_param_values(
self,
param_values: Vec<ScalarValue>
) -> Result<LogicalPlan, DataFusionError>
pub fn with_param_values(
self,
param_values: Vec<ScalarValue>
) -> Result<LogicalPlan, DataFusionError>
Convert a prepare logical plan into its inner logical plan with all params replaced with their corresponding values
source§impl LogicalPlan
impl LogicalPlan
sourcepub fn accept<V>(&self, visitor: &mut V) -> Result<bool, V::Error>where
V: PlanVisitor,
pub fn accept<V>(&self, visitor: &mut V) -> Result<bool, V::Error>where
V: PlanVisitor,
returns all inputs in the logical plan. Returns Ok(true) if
all nodes were visited, and Ok(false) if any call to
pre_visit
or post_visit
returned Ok(false) and may have
cut short the recursion
sourcepub fn visit_all_inputs<V>(&self, visitor: &mut V) -> Result<bool, V::Error>where
V: PlanVisitor,
pub fn visit_all_inputs<V>(&self, visitor: &mut V) -> Result<bool, V::Error>where
V: PlanVisitor,
Visit all inputs, including subqueries
sourcepub fn replace_params_with_values(
&self,
param_values: &Vec<ScalarValue>
) -> Result<LogicalPlan, DataFusionError>
pub fn replace_params_with_values(
&self,
param_values: &Vec<ScalarValue>
) -> Result<LogicalPlan, DataFusionError>
Return a logical plan with all placeholders/params (e.g $1 $2, …) replaced with corresponding values provided in the prams_values
source§impl LogicalPlan
impl LogicalPlan
sourcepub fn display_indent(&self) -> impl Display + '_
pub fn display_indent(&self) -> impl Display + '_
Return a format
able structure that produces a single line
per node. For example:
Projection: employee.id
Filter: employee.state Eq Utf8(\"CO\")\
CsvScan: employee projection=Some([0, 3])
use arrow::datatypes::{Field, Schema, DataType};
use datafusion_expr::{lit, col, LogicalPlanBuilder, logical_plan::table_scan};
let schema = Schema::new(vec![
Field::new("id", DataType::Int32, false),
]);
let plan = table_scan(Some("t1"), &schema, None).unwrap()
.filter(col("id").eq(lit(5))).unwrap()
.build().unwrap();
// Format using display_indent
let display_string = format!("{}", plan.display_indent());
assert_eq!("Filter: t1.id = Int32(5)\n TableScan: t1",
display_string);
sourcepub fn display_indent_schema(&self) -> impl Display + '_
pub fn display_indent_schema(&self) -> impl Display + '_
Return a format
able structure that produces a single line
per node that includes the output schema. For example:
Projection: employee.id [id:Int32]\
Filter: employee.state = Utf8(\"CO\") [id:Int32, state:Utf8]\
TableScan: employee projection=[0, 3] [id:Int32, state:Utf8]";
use arrow::datatypes::{Field, Schema, DataType};
use datafusion_expr::{lit, col, LogicalPlanBuilder, logical_plan::table_scan};
let schema = Schema::new(vec![
Field::new("id", DataType::Int32, false),
]);
let plan = table_scan(Some("t1"), &schema, None).unwrap()
.filter(col("id").eq(lit(5))).unwrap()
.build().unwrap();
// Format using display_indent_schema
let display_string = format!("{}", plan.display_indent_schema());
assert_eq!("Filter: t1.id = Int32(5) [id:Int32]\
\n TableScan: t1 [id:Int32]",
display_string);
sourcepub fn display_graphviz(&self) -> impl Display + '_
pub fn display_graphviz(&self) -> impl Display + '_
Return a format
able structure that produces lines meant for
graphical display using the DOT
language. This format can be
visualized using software from
graphviz
This currently produces two graphs – one with the basic structure, and one with additional details such as schema.
use arrow::datatypes::{Field, Schema, DataType};
use datafusion_expr::{lit, col, LogicalPlanBuilder, logical_plan::table_scan};
let schema = Schema::new(vec![
Field::new("id", DataType::Int32, false),
]);
let plan = table_scan(Some("t1"), &schema, None).unwrap()
.filter(col("id").eq(lit(5))).unwrap()
.build().unwrap();
// Format using display_graphviz
let graphviz_string = format!("{}", plan.display_graphviz());
If graphviz string is saved to a file such as /tmp/example.dot
, the following
commands can be used to render it as a pdf:
dot -Tpdf < /tmp/example.dot > /tmp/example.pdf
sourcepub fn display(&self) -> impl Display + '_
pub fn display(&self) -> impl Display + '_
Return a format
able structure with the a human readable
description of this LogicalPlan node per node, not including
children. For example:
Projection: id
use arrow::datatypes::{Field, Schema, DataType};
use datafusion_expr::{lit, col, LogicalPlanBuilder, logical_plan::table_scan};
let schema = Schema::new(vec![
Field::new("id", DataType::Int32, false),
]);
let plan = table_scan(Some("t1"), &schema, None).unwrap()
.build().unwrap();
// Format using display
let display_string = format!("{}", plan.display());
assert_eq!("TableScan: t1", display_string);
Trait Implementations§
source§impl Clone for LogicalPlan
impl Clone for LogicalPlan
source§fn clone(&self) -> LogicalPlan
fn clone(&self) -> LogicalPlan
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more