theirix commented on code in PR #21737:
URL: https://github.com/apache/datafusion/pull/21737#discussion_r4188692946
##########
datafusion/catalog/src/information_schema.rs:
##########
@@ -454,118 +455,98 @@ impl InformationSchemaConfig {
}
}
-/// get the arguments and return types of a UDF
-/// returns a tuple of (arg_types, return_type)
+/// Origins used to enumerate the physical types a native type can take
+const RESOLVE_CAST_SOURCES: [DataType; 2] = [DataType::Null,
DataType::LargeUtf8];
+
+/// Build argument fields for `information_schema` to provide possible return
types
+fn resolve_informational_fields(idx: usize, t: &NativeType) ->
Result<Vec<FieldRef>> {
+ // Since native types map to several physical types, resolve it against
+ // ambiguous types to get canonical `DataType`s for the native type
+ let data_types = RESOLVE_CAST_SOURCES
+ .iter()
+ .map(|source| t.default_cast_for(source))
+ .collect::<Result<Vec<DataType>, _>>()?;
+ Ok(data_types
+ .into_iter()
+ .unique()
+ .map(|dt| Arc::new(Field::new(format!("arg_{idx}"), dt, true)))
+ .collect())
+}
+
+/// Function information schema is a set of tuples - argument types and an
optional return type
+type FunctionInformationSchema = BTreeSet<(Vec<String>, Option<String>)>;
+
+/// Get the arguments and return types of a function from its signature
+fn get_args_and_return_types(
+ signature: &Signature,
+ return_field: impl Fn(&[FieldRef]) -> Result<FieldRef>,
+) -> Result<FunctionInformationSchema> {
+ let arg_types = signature.type_signature.get_representative_types();
+ if arg_types.is_empty() {
+ // Edge case if function doesn't have arguments
+ return Ok(BTreeSet::from([(vec![], None)]));
+ }
+ arg_types
+ .into_iter()
+ .map(|arg_types| {
+ // Get possible types for each input arg
+ let arg_fields = arg_types
+ .iter()
+ .enumerate()
+ .map(|(i, t)| resolve_informational_fields(i, t))
+ .collect::<Result<Vec<_>>>()?;
+ // Build combinations of arg types with the return type
+ let return_types = arg_fields
Review Comment:
Added, tests are updated to check `date_trunc` and a new `generate_series`
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]