MCPcopy Create free account
hub / github.com/apache/datafusion / head_output_expr

Method head_output_expr

datafusion/expr/src/logical_plan/plan.rs:528–602  ·  view source on GitHub ↗

returns the first output expression of this `LogicalPlan` node.

(&self)

Source from the content-addressed store, hash-verified

526
527 /// returns the first output expression of this `LogicalPlan` node.
528 pub fn head_output_expr(&self) -> Result<Option<Expr>> {
529 match self {
530 LogicalPlan::Projection(projection) => {
531 Ok(Some(projection.expr.as_slice()[0].clone()))
532 }
533 LogicalPlan::Aggregate(agg) => {
534 if agg.group_expr.is_empty() {
535 Ok(Some(agg.aggr_expr.as_slice()[0].clone()))
536 } else {
537 Ok(Some(agg.group_expr.as_slice()[0].clone()))
538 }
539 }
540 LogicalPlan::Distinct(Distinct::On(DistinctOn { select_expr, .. })) => {
541 Ok(Some(select_expr[0].clone()))
542 }
543 LogicalPlan::Filter(Filter { input, .. })
544 | LogicalPlan::Distinct(Distinct::All(input))
545 | LogicalPlan::Sort(Sort { input, .. })
546 | LogicalPlan::Limit(Limit { input, .. })
547 | LogicalPlan::Repartition(Repartition { input, .. })
548 | LogicalPlan::Window(Window { input, .. }) => input.head_output_expr(),
549 LogicalPlan::Join(Join {
550 left,
551 right,
552 join_type,
553 ..
554 }) => match join_type {
555 JoinType::Inner | JoinType::Left | JoinType::Right | JoinType::Full => {
556 if left.schema().fields().is_empty() {
557 right.head_output_expr()
558 } else {
559 left.head_output_expr()
560 }
561 }
562 JoinType::LeftSemi | JoinType::LeftAnti | JoinType::LeftMark => {
563 left.head_output_expr()
564 }
565 JoinType::RightSemi | JoinType::RightAnti | JoinType::RightMark => {
566 right.head_output_expr()
567 }
568 },
569 LogicalPlan::RecursiveQuery(RecursiveQuery { static_term, .. }) => {
570 static_term.head_output_expr()
571 }
572 LogicalPlan::Union(union) => Ok(Some(Expr::Column(Column::from(
573 union.schema.qualified_field(0),
574 )))),
575 LogicalPlan::TableScan(table) => Ok(Some(Expr::Column(Column::from(
576 table.projected_schema.qualified_field(0),
577 )))),
578 LogicalPlan::SubqueryAlias(subquery_alias) => {
579 let expr_opt = subquery_alias.input.head_output_expr()?;
580 expr_opt
581 .map(|expr| {
582 Ok(Expr::Column(create_col_from_scalar_expr(
583 &expr,
584 subquery_alias.alias.to_string(),
585 )?))

Callers 4

rewrite_inner_subqueriesFunction · 0.80
build_join_topFunction · 0.80
f_downMethod · 0.80

Calls 9

qualified_fieldMethod · 0.80
ColumnClass · 0.50
cloneMethod · 0.45
is_emptyMethod · 0.45
fieldsMethod · 0.45
schemaMethod · 0.45
mapMethod · 0.45
to_stringMethod · 0.45

Tested by 1