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

Method map_to_sql

datafusion/sql/src/unparser/expr.rs:781–810  ·  view source on GitHub ↗
(&self, args: &[Expr])

Source from the content-addressed store, hash-verified

779 }
780
781 fn map_to_sql(&self, args: &[Expr]) -> Result<ast::Expr> {
782 assert_eq_or_internal_err!(args.len(), 2, "map must have exactly 2 arguments");
783
784 let ast::Expr::Array(Array { elem: keys, .. }) = self.expr_to_sql(&args[0])?
785 else {
786 return internal_err!(
787 "map expects first argument to be an array, but received: {:?}",
788 &args[0]
789 );
790 };
791
792 let ast::Expr::Array(Array { elem: values, .. }) = self.expr_to_sql(&args[1])?
793 else {
794 return internal_err!(
795 "map expects second argument to be an array, but received: {:?}",
796 &args[1]
797 );
798 };
799
800 let entries = keys
801 .into_iter()
802 .zip(values)
803 .map(|(key, value)| ast::MapEntry {
804 key: Box::new(key),
805 value: Box::new(value),
806 })
807 .collect();
808
809 Ok(ast::Expr::Map(ast::Map { entries }))
810 }
811
812 pub fn sort_to_sql(&self, sort: &Sort) -> Result<ast::OrderByExpr> {
813 let Sort {

Callers 1

Calls 6

newFunction · 0.85
expr_to_sqlMethod · 0.80
collectMethod · 0.80
MapEnum · 0.50
mapMethod · 0.45
into_iterMethod · 0.45

Tested by

no test coverage detected