Enum datafusion::logical_expr::LogicalPlan
source · pub enum LogicalPlan {
Show 25 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),
Statement(Statement),
Values(Values),
Explain(Explain),
Analyze(Analyze),
Extension(Extension),
Distinct(Distinct),
Prepare(Prepare),
Dml(DmlStatement),
Ddl(DdlStatement),
DescribeTable(DescribeTable),
Unnest(Unnest),
}
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.
Statement(Statement)
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
Prepare(Prepare)
Prepare a statement
Dml(DmlStatement)
Insert / Update / Delete
Ddl(DdlStatement)
CREATE / DROP TABLES / VIEWS / SCHEMAs
DescribeTable(DescribeTable)
Describe the schema of table
Unnest(Unnest)
Unnest a column that contains a nested list type.
Implementations§
source§impl LogicalPlan
impl LogicalPlan
sourcepub fn fallback_normalize_schemas(&self) -> Vec<&DFSchema, Global>
pub fn fallback_normalize_schemas(&self) -> Vec<&DFSchema, Global>
Used for normalizing columns, as the fallback schemas to the main schema of the plan.
sourcepub fn all_schemas(&self) -> Vec<&Arc<DFSchema, Global>, Global>
👎Deprecated since 20.0.0
pub fn all_schemas(&self) -> Vec<&Arc<DFSchema, Global>, Global>
Get all meaningful schemas of a plan and its children plan.
sourcepub fn explain_schema() -> Arc<Schema, Global>
pub fn explain_schema() -> Arc<Schema, Global>
Returns the (fixed) output schema for explain plans
sourcepub fn expressions(&self) -> Vec<Expr, Global>
pub fn expressions(&self) -> Vec<Expr, Global>
returns all expressions (non-recursively) in the current logical plan node. This does not include expressions in any children
sourcepub fn all_out_ref_exprs(&self) -> Vec<Expr, Global>
pub fn all_out_ref_exprs(&self) -> Vec<Expr, Global>
Returns all the out reference(correlated) expressions (recursively) in the current logical plan nodes and all its descendant nodes.
sourcepub fn inspect_expressions<F, E>(&self, f: F) -> Result<(), E>where
F: FnMut(&Expr) -> Result<(), E>,
pub fn inspect_expressions<F, E>(&self, f: F) -> Result<(), E>where F: FnMut(&Expr) -> Result<(), E>,
Calls f
on all expressions (non-recursively) in the current
logical plan node. This does not include expressions in any
children.
sourcepub fn inputs(&self) -> Vec<&LogicalPlan, Global>
pub fn inputs(&self) -> Vec<&LogicalPlan, Global>
returns all inputs of this LogicalPlan
node. Does not
include inputs to inputs, or subqueries.
sourcepub fn using_columns(
&self
) -> Result<Vec<HashSet<Column, RandomState>, Global>, DataFusionError>
pub fn using_columns( &self ) -> Result<Vec<HashSet<Column, RandomState>, Global>, DataFusionError>
returns all Using
join columns in a logical plan
sourcepub fn head_output_expr(&self) -> Result<Option<Expr>, DataFusionError>
pub fn head_output_expr(&self) -> Result<Option<Expr>, DataFusionError>
returns the first output expression of this LogicalPlan
node.
pub fn with_new_inputs( &self, inputs: &[LogicalPlan] ) -> Result<LogicalPlan, DataFusionError>
sourcepub fn with_param_values(
self,
param_values: Vec<ScalarValue, Global>
) -> Result<LogicalPlan, DataFusionError>
pub fn with_param_values( self, param_values: Vec<ScalarValue, Global> ) -> Result<LogicalPlan, DataFusionError>
Convert a prepared LogicalPlan
into its inner logical plan
with all params replaced with their corresponding values
source§impl LogicalPlan
impl LogicalPlan
sourcepub fn replace_params_with_values(
&self,
param_values: &[ScalarValue]
) -> Result<LogicalPlan, DataFusionError>
pub fn replace_params_with_values( &self, param_values: &[ScalarValue] ) -> Result<LogicalPlan, DataFusionError>
Return a logical plan with all placeholders/params (e.g $1 $2, …) replaced with corresponding values provided in the params_values
sourcepub fn get_parameter_types(
&self
) -> Result<HashMap<String, Option<DataType>, RandomState>, DataFusionError>
pub fn get_parameter_types( &self ) -> Result<HashMap<String, Option<DataType>, RandomState>, DataFusionError>
Walk the logical plan, find any PlaceHolder
tokens, and return a map of their IDs and DataTypes
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 moresource§impl Debug for LogicalPlan
impl Debug for LogicalPlan
source§impl Hash for LogicalPlan
impl Hash for LogicalPlan
source§impl PartialEq<LogicalPlan> for LogicalPlan
impl PartialEq<LogicalPlan> for LogicalPlan
source§fn eq(&self, other: &LogicalPlan) -> bool
fn eq(&self, other: &LogicalPlan) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl ToStringifiedPlan for LogicalPlan
impl ToStringifiedPlan for LogicalPlan
source§fn to_stringified(&self, plan_type: PlanType) -> StringifiedPlan
fn to_stringified(&self, plan_type: PlanType) -> StringifiedPlan
source§impl TreeNode for LogicalPlan
impl TreeNode for LogicalPlan
source§fn visit<V>(&self, visitor: &mut V) -> Result<VisitRecursion, DataFusionError>where
V: TreeNodeVisitor<N = LogicalPlan>,
fn visit<V>(&self, visitor: &mut V) -> Result<VisitRecursion, DataFusionError>where V: TreeNodeVisitor<N = LogicalPlan>,
To use, define a struct that implements the trait TreeNodeVisitor
and then invoke
LogicalPlan::visit
.
For example, for a logical plan like:
Projection: id
Filter: state Eq Utf8(\"CO\")\
CsvScan: employee.csv projection=Some([0, 3])";
The sequence of visit operations would be:
visitor.pre_visit(Projection)
visitor.pre_visit(Filter)
visitor.pre_visit(CsvScan)
visitor.post_visit(CsvScan)
visitor.post_visit(Filter)
visitor.post_visit(Projection)
source§fn apply<F>(&self, op: &mut F) -> Result<VisitRecursion, DataFusionError>where
F: FnMut(&LogicalPlan) -> Result<VisitRecursion, DataFusionError>,
fn apply<F>(&self, op: &mut F) -> Result<VisitRecursion, DataFusionError>where F: FnMut(&LogicalPlan) -> Result<VisitRecursion, DataFusionError>,
source§fn apply_children<F>(
&self,
op: &mut F
) -> Result<VisitRecursion, DataFusionError>where
F: FnMut(&LogicalPlan) -> Result<VisitRecursion, DataFusionError>,
fn apply_children<F>( &self, op: &mut F ) -> Result<VisitRecursion, DataFusionError>where F: FnMut(&LogicalPlan) -> Result<VisitRecursion, DataFusionError>,
F
to the node’s childrensource§fn map_children<F>(self, transform: F) -> Result<LogicalPlan, DataFusionError>where
F: FnMut(LogicalPlan) -> Result<LogicalPlan, DataFusionError>,
fn map_children<F>(self, transform: F) -> Result<LogicalPlan, DataFusionError>where F: FnMut(LogicalPlan) -> Result<LogicalPlan, DataFusionError>,
F
to the node’s children, the transform F
might have a direction(Preorder or Postorder)source§fn transform<F>(self, op: &F) -> Result<Self, DataFusionError>where
F: Fn(Self) -> Result<Transformed<Self>, DataFusionError>,
fn transform<F>(self, op: &F) -> Result<Self, DataFusionError>where F: Fn(Self) -> Result<Transformed<Self>, DataFusionError>,
op
to the node tree.
When op
does not apply to a given node, it is left unchanged.
The default tree traversal direction is transform_up(Postorder Traversal).source§fn transform_down<F>(self, op: &F) -> Result<Self, DataFusionError>where
F: Fn(Self) -> Result<Transformed<Self>, DataFusionError>,
fn transform_down<F>(self, op: &F) -> Result<Self, DataFusionError>where F: Fn(Self) -> Result<Transformed<Self>, DataFusionError>,
op
does not apply to a given node, it is left unchanged.source§fn transform_up<F>(self, op: &F) -> Result<Self, DataFusionError>where
F: Fn(Self) -> Result<Transformed<Self>, DataFusionError>,
fn transform_up<F>(self, op: &F) -> Result<Self, DataFusionError>where F: Fn(Self) -> Result<Transformed<Self>, DataFusionError>,
op
does not apply to a given node, it is left unchanged.source§fn rewrite<R>(self, rewriter: &mut R) -> Result<Self, DataFusionError>where
R: TreeNodeRewriter<N = Self>,
fn rewrite<R>(self, rewriter: &mut R) -> Result<Self, DataFusionError>where R: TreeNodeRewriter<N = Self>,
impl Eq for LogicalPlan
impl StructuralEq for LogicalPlan
impl StructuralPartialEq for LogicalPlan
Auto Trait Implementations§
impl !RefUnwindSafe for LogicalPlan
impl Send for LogicalPlan
impl Sync for LogicalPlan
impl Unpin for LogicalPlan
impl !UnwindSafe for LogicalPlan
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<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.