jayzhan211 commented on code in PR #10417: URL: https://github.com/apache/datafusion/pull/10417#discussion_r1593356686
########## datafusion/functions/src/core/getfield.rs: ########## @@ -50,10 +50,31 @@ impl ScalarUDFImpl for GetFieldFunc { fn as_any(&self) -> &dyn Any { self } + fn name(&self) -> &str { "get_field" } + fn display_name(&self, args: &[Expr]) -> Result<String> { + if args.len() != 2 { + return exec_err!( + "get_field function requires 2 arguments, got {}", + args.len() + ); + } + + let name = match &args[1] { + Expr::Literal(name) => name, + _ => { + return exec_err!( + "get_field function requires the argument field_name to be a string" + ); + } + }; + + Ok(format!("{}[{}]", args[0].display_name()?, name)) + } + Review Comment: cli in this PR ``` DataFusion CLI v38.0.0 > select struct('a'); +-------------------+ | struct(Utf8("a")) | +-------------------+ | {c0: a} | +-------------------+ 1 row(s) fetched. Elapsed 0.023 seconds. > select get_field(struct('a'), 'c0'); +-----------------------+ | struct(Utf8("a"))[c0] | +-----------------------+ | a | +-----------------------+ 1 row(s) fetched. Elapsed 0.007 seconds. ``` main branch: ``` DataFusion CLI v38.0.0 > select struct('a'); +-------------------+ | struct(Utf8("a")) | +-------------------+ | {c0: a} | +-------------------+ 1 row(s) fetched. Elapsed 0.014 seconds. > select get_field(struct('a'), 'c0'); +-----------------------------------------+ | get_field(struct(Utf8("a")),Utf8("c0")) | +-----------------------------------------+ | a | +-----------------------------------------+ 1 row(s) fetched. Elapsed 0.004 seconds. ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org