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

Method create_named_struct_expr

datafusion/sql/src/expr/mod.rs:812–848  ·  view source on GitHub ↗

Handles a call to struct(...) where the arguments are named. For example `struct (v as foo, v2 as bar)` by creating a call to the `named_struct` function

(
        &self,
        values: Vec<SQLExpr>,
        input_schema: &DFSchema,
        planner_context: &mut PlannerContext,
    )

Source from the content-addressed store, hash-verified

810 // Handles a call to struct(...) where the arguments are named. For example
811 // `struct (v as foo, v2 as bar)` by creating a call to the `named_struct` function
812 fn create_named_struct_expr(
813 &self,
814 values: Vec<SQLExpr>,
815 input_schema: &DFSchema,
816 planner_context: &mut PlannerContext,
817 ) -> Result<Vec<Expr>> {
818 Ok(values
819 .into_iter()
820 .enumerate()
821 .map(|(i, value)| {
822 let args = if let SQLExpr::Named { expr, name } = value {
823 [
824 name.value.lit(),
825 self.sql_expr_to_logical_expr(
826 *expr,
827 input_schema,
828 planner_context,
829 )?,
830 ]
831 } else {
832 [
833 format!("c{i}").lit(),
834 self.sql_expr_to_logical_expr(
835 value,
836 input_schema,
837 planner_context,
838 )?,
839 ]
840 };
841
842 Ok(args)
843 })
844 .collect::<Result<Vec<_>>>()?
845 .into_iter()
846 .flatten()
847 .collect())
848 }
849
850 // Handles a call to struct(...) where the arguments are not named. For example
851 // `struct (v, v2)` by creating a call to the `struct` function

Callers 1

parse_structMethod · 0.80

Calls 6

collectMethod · 0.80
flattenMethod · 0.80
into_iterMethod · 0.45
mapMethod · 0.45
litMethod · 0.45

Tested by

no test coverage detected