From d4197520b5e9c4b68da34f54bc955b094bcb71e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=9E=97=E4=BC=9F?= Date: Sun, 19 May 2024 13:59:08 +0800 Subject: [PATCH] Improve signature of get_field (#10569) --- datafusion/core/tests/expr_api/mod.rs | 4 ++-- datafusion/functions/src/core/mod.rs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/datafusion/core/tests/expr_api/mod.rs b/datafusion/core/tests/expr_api/mod.rs index d7e839824b3b..db75a8c6145a 100644 --- a/datafusion/core/tests/expr_api/mod.rs +++ b/datafusion/core/tests/expr_api/mod.rs @@ -61,7 +61,7 @@ fn test_eq_with_coercion() { #[test] fn test_get_field() { evaluate_expr_test( - get_field(col("props"), lit("a")), + get_field(col("props"), "a"), vec![ "+------------+", "| expr |", @@ -77,7 +77,7 @@ fn test_get_field() { #[test] fn test_nested_get_field() { evaluate_expr_test( - get_field(col("props"), lit("a")) + get_field(col("props"), "a") .eq(lit("2021-02-02")) .or(col("id").eq(lit(1))), vec![ diff --git a/datafusion/functions/src/core/mod.rs b/datafusion/functions/src/core/mod.rs index d60e6017ddcb..491e45c35a9a 100644 --- a/datafusion/functions/src/core/mod.rs +++ b/datafusion/functions/src/core/mod.rs @@ -43,7 +43,7 @@ make_udf_function!(coalesce::CoalesceFunc, COALESCE, coalesce); // Export the functions out of this package, both as expr_fn as well as a list of functions pub mod expr_fn { - use datafusion_expr::Expr; + use datafusion_expr::{Expr, Literal}; /// returns NULL if value1 equals value2; otherwise it returns value1. This /// can be used to perform the inverse operation of the COALESCE expression @@ -83,8 +83,8 @@ pub mod expr_fn { } /// Returns the value of the field with the given name from the struct - pub fn get_field(arg1: Expr, arg2: Expr) -> Expr { - super::get_field().call(vec![arg1, arg2]) + pub fn get_field(arg1: Expr, field_name: impl Literal) -> Expr { + super::get_field().call(vec![arg1, field_name.lit()]) } /// Returns `coalesce(args...)`, which evaluates to the value of the first expr which is not NULL