Enum sql::func::ParamList [−][src]
Expand description
Describes possible types of function parameters.
Note that this is not exhaustive and will likely require additions.
Variants
Exact(Vec<ParamType>)
Variadic(ParamType)
Tuple Fields
0: ParamType
Implementations
Determines whether typs
are compatible with self
.
Validates that the number of input elements are viable for self
.
Reports whether the parameter list contains any polymorphic parameters.
Enforces polymorphic type consistency by finding the concrete type that satisfies the constraints expressed by the polymorphic types in the parameter list.
Polymorphic type consistency constraints include:
- All arguments passed to
ArrayAny
must beScalarType::Array
s with the same types of elements. All arguments passed toArrayElementAny
must also be of these elements’ type. - All arguments passed to
ListAny
must beScalarType::List
s with the same types of elements. All arguments passed toListElementAny
must also be of these elements’ type. - All arguments passed to
MapAny
must beScalarType::Map
s with the same type of value in each key, value pair.
Returns Some
if the constraints were successfully resolved, or None
otherwise.
Custom types
Materialize supports two classes of types:
-
Custom types, which are defined by
CREATE TYPE
or contain a reference to a type that was. -
Built-in types, which are all other types, e.g.
int4
,int4 list
.Among built-in types there are:
- Complex types, which contain references to other types
- Simple types, which do not contain referneces to other types
To support accepting custom type values passed to polymorphic parameters, we must handle polymorphism for custom types. To understand how we assess custom types’ polymorphism, it’s useful to categorize polymorphic parameters in MZ.
-
Complex parameters include complex built-in types’ polymorphic parameters, e.g.
ListAny
andMapAny
.Valid
ScalarType
s passed to these parameters have acustom_oid
field and some embedded type, which we’ll refer to as its element. -
Element parameters which include
ArrayElementAny
,ListElementAny
andNonVecAny
.
Note that:
- Custom types can be used as values for either complex or element parameters; we’ll refer to these as custom complex values and custom element values, or collectively as custom values.
ArrayAny
is slightly different from either case, but is uncommonly used and not addressed further.
Resolution
-
Upon encountering the first custom complex value:
- All other custom complex types must exactly match both its
custom_oid
and embedded element. - All custom element types must exactly match its embedded element type.
One of the complexities here is that the custom complex value’s element can be built-in type, meaning any custom element values will cause polymorphic resolution to fail.
- All other custom complex types must exactly match both its
-
Upon encountering the first custom element value:
- All other custom element values must exactly match its type.
- All custom complex types’ embedded elements must exactly match its type.
Custom + built-in types
If you use both custom and built-in types, the resultant type will be the least-custom custom type that fulfills the above requirements.
For example if you list_append(int4 list list, custom_int4_list)
, the
resulant type will be complex: its custom_oid
will be None
, but its
embedded element will be the custom element type, i.e. custom_int4_list list
).
However, it’s also important to note that a complex value whose
custom_oid
is None
are still considered complex if its embedded
element is complex. Consider the following scenario:
CREATE TYPE int4_list_custom AS LIST (element_type=int4);
CREATE TYPE int4_list_list_custom AS LIST (element_type=int4_list_custom);
/* Errors because we won't coerce int4_list_custom list to
int4_list_list_custom */
SELECT '{{1}}'::int4_list_list_custom || '{{2}}'::int4_list_custom list;
We will not coerce int4_list_custom list
to
int4_list_list_custom
––only built-in types are ever coerced into
custom types. It’s also trivial for users to add a cast to ensure custom
type consistency.
Matches a &[ScalarType]
derived from the user’s function argument
against this ParamList
’s permitted arguments.
Generates values underlying data for for mz_catalog.mz_functions.arg_ids
.
Generates values for mz_catalog.mz_functions.variadic_id
.
fn contrive_coercible_exprs(&self) -> Vec<CoercibleScalarExpr>ⓘ
fn contrive_coercible_exprs(&self) -> Vec<CoercibleScalarExpr>ⓘ
Trait Implementations
Provides a shorthand function for writing ParamList::Exact
.
Auto Trait Implementations
impl RefUnwindSafe for ParamList
impl UnwindSafe for ParamList
Blanket Implementations
Mutably borrows from an owned value. Read more
Compare self to key
and return true
if they are equal.
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more