goldmedal commented on code in PR #13255:
URL: https://github.com/apache/datafusion/pull/13255#discussion_r1828693853
##########
datafusion/core/src/catalog_common/information_schema.rs:
##########
@@ -208,6 +212,151 @@ impl InformationSchemaConfig {
builder.add_setting(entry);
}
}
+
+ fn make_routines(
+ &self,
+ udfs: &HashMap<String, Arc<ScalarUDF>>,
+ udafs: &HashMap<String, Arc<AggregateUDF>>,
+ udwfs: &HashMap<String, Arc<WindowUDF>>,
+ config_options: &ConfigOptions,
+ builder: &mut InformationSchemaRoutinesBuilder,
+ ) -> Result<()> {
+ let catalog_name = &config_options.catalog.default_catalog;
+ let schema_name = &config_options.catalog.default_schema;
+
+ for (name, udf) in udfs {
+ let return_types = get_udf_args_and_return_types(udf)?
+ .into_iter()
+ .map(|(_, return_type)| return_type)
+ .collect::<HashSet<_>>();
+ for return_type in return_types {
+ builder.add_routine(
+ catalog_name,
+ schema_name,
+ name,
+ "FUNCTION",
+ Self::is_deterministic(udf.signature()),
+ return_type,
+ "SCALAR",
+ udf.documentation().map(|d| d.description.to_string()),
+ )
+ }
+ }
+
+ for (name, udaf) in udafs {
+ let return_types = get_udaf_args_and_return_types(udaf)?
+ .into_iter()
+ .map(|(_, return_type)| return_type)
+ .collect::<HashSet<_>>();
+ for return_type in return_types {
+ builder.add_routine(
+ catalog_name,
+ schema_name,
+ name,
+ "FUNCTION",
+ Self::is_deterministic(udaf.signature()),
+ return_type,
+ "AGGREGATE",
+ udaf.documentation().map(|d| d.description.to_string()),
+ )
+ }
+ }
+
+ for (name, udwf) in udwfs {
+ let return_types = get_udwf_args_and_return_types(udwf)?
+ .into_iter()
+ .map(|(_, return_type)| return_type)
+ .collect::<HashSet<_>>();
+ for return_type in return_types {
+ builder.add_routine(
+ catalog_name,
+ schema_name,
+ name,
+ "FUNCTION",
+ Self::is_deterministic(udwf.signature()),
+ return_type,
+ "WINDOW",
+ udwf.documentation().map(|d| d.description.to_string()),
+ )
+ }
+ }
+ Ok(())
+ }
+
+ fn is_deterministic(signature: &Signature) -> bool {
+ signature.volatility == Volatility::Immutable
+ }
+}
+
+/// get the arguments and return types of a UDF
+/// returns a tuple of (arg_types, return_type)
+fn get_udf_args_and_return_types(
+ udf: &Arc<ScalarUDF>,
+) -> Result<Vec<(Vec<String>, Option<String>)>> {
+ let signature = udf.signature();
+ let arg_types = signature.type_signature.get_possible_types();
+ if arg_types.is_empty() {
+ Ok(vec![(vec![], None)])
+ } else {
+ Ok(arg_types
+ .into_iter()
+ .map(|arg_types| {
+ // only handle the function which implemented
[`ScalarUDFImpl::return_type`] method
+ let return_type = udf.return_type(&arg_types).ok().map(|t|
t.to_string());
Review Comment:
Some functions only implement `return_type_from_exprs`, e.g., `arrow_cast`.
It's hard to get the return type here. Return null for this case.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]