- Functions for data types
- FormatType
- ParseType
- TypeOf
- InstanceOf
- DataType
- OptionalType
- ListType and StreamType
- DictType
- TupleType
- StructType
- VariantType
- ResourceType
- CallableType
- GenericType, UnitType, and VoidType
- OptionalItemType, ListItemType and StreamItemType
- DictKeyType and DictPayloadType
- TupleElementType
- StructMemberType
- CallableResultType and CallableArgumentType
- VariantUnderlyingType
Functions for data types
- FormatType
- ParseType
- TypeOf
- InstanceOf
- DataType
- OptionalType
- ListType and StreamType
- DictType
- TupleType
- StructType
- VariantType
- ResourceType
- CallableType
- GenericType, UnitType, and VoidType
- OptionalItemType, ListItemType and StreamItemType
- DictKeyType and DictPayloadType
- TupleElementType
- StructMemberType
- CallableResultType and CallableArgumentType
- VariantUnderlyingType
FormatType
Serializing a type to a human-readable string. This helps at debugging and will also be used in the next examples of this section. Documentation for the format.
ParseType
Building a type from a string with description. Documentation for its format.
Examples
SELECT FormatType(ParseType("List<Int32>")); -- List<int32>
TypeOf
Getting the type of value passed to the argument.
Examples
SELECT FormatType(TypeOf("foo")); -- String
SELECT FormatType(TypeOf(AsTuple(1, 1u))); -- Tuple<Int32,Uint32>
InstanceOf
Returns an instance of the specified type that can only be used to get the type of the result of an expression that uses this type.
If this instance remains in the computation graph by the end of optimization, the operation fails.
Examples
SELECT FormatType(TypeOf(
InstanceOf(ParseType("Int32")) +
InstanceOf(ParseType("Double"))
)); -- Double, because "Int32 + Double" returns Double
DataType
Returns a type for primitive data types based on type name.
Examples
SELECT FormatType(DataType("Bool")); -- Bool
SELECT FormatType(DataType("Decimal","5","1")); -- Decimal(5,1)
OptionalType
Adds the option to assign NULL
to the passed type.
Examples
SELECT FormatType(OptionalType(DataType("Bool"))); -- Bool?
ListType and StreamType
Builds a list type or stream type based on the passed element type.
Examples
SELECT FormatType(ListType(DataType("Bool"))); -- List<Bool>
DictType
Builds a dictionary type based on the passed key types (first argument) and value types (second argument).
Examples
SELECT FormatType(DictType(
DataType("String"),
DataType("Double")
)); -- Dict<String,Double>
TupleType
Builds the tuple type from the passed element types.
Examples
SELECT FormatType(TupleType(
DataType("String"),
DataType("Double"),
OptionalType(DataType("Bool"))
)); -- Tuple<String,Double,Bool?>
StructType
Builds the structure type based on the passed element types. The standard syntax of named arguments is used to specify the element names.
Examples
SELECT FormatType(StructType(
DataType("Bool") AS MyBool,
ListType(DataType("String")) AS StringList
)); -- Struct<'MyBool':Bool,'StringList':List<String>>
VariantType
Returns the type of a variant based on the underlying type (structure or tuple).
Examples
SELECT FormatType(VariantType(
ParseType("Struct<foo:Int32,bar:Double>")
)); -- Variant<'bar':Double,'foo':Int32>
ResourceType
Returns the type of the resource based on the passed string label.
Examples
SELECT FormatType(ResourceType("Foo")); -- Resource<'Foo'>
CallableType
Constructs the type of the called value using the following arguments:
- Number of optional arguments (if all arguments are required — 0).
- Result type.
- All the next arguments of CallableType are treated as types of arguments of the callable value, but with a shift for two required arguments (for example, the third argument of the CallableType describes the type of the first argument in the callable value).
Examples
SELECT FormatType(CallableType(
1, -- optional args count
DataType("Double"), -- result type
DataType("String"), -- arg #1 type
OptionalType(DataType("Int64")) -- arg #2 type
)); -- Callable<(String,[Int64?])->Double>
GenericType, UnitType, and VoidType
Return the same-name special data types. They have no arguments because they are not parameterized.
Examples
SELECT FormatType(VoidType()); -- Void
OptionalItemType, ListItemType and StreamItemType
Perform the action reverse to OptionalType, ListType, and StreamType: return the item type based on its container type.
Examples
SELECT FormatType(ListItemType(
ParseType("List<Int32>")
)); -- Int32
DictKeyType and DictPayloadType
Returns the type of the key or value based on the dictionary type.
Examples
SELECT FormatType(DictKeyType(
ParseType("Dict<Int32,String>")
)); -- Int32
TupleElementType
Returns the tuple’s element type based on the tuple type and the element index (index starts from zero).
Examples
SELECT FormatType(TupleElementType(
ParseType("Tuple<Int32,Double>"), "1"
)); -- Double
StructMemberType
Returns the type of the structure element based on the structure type and element name.
Examples
SELECT FormatType(StructMemberType(
ParseType("Struct<foo:Int32,bar:Double>"), "foo"
)); -- Int32
CallableResultType and CallableArgumentType
CallableResultType
returns the result type based on the type of the called value. CallableArgumentType
returns the argument type based on the called value type and its index (index starts from zero).
Examples
$callable_type = ParseType("(String,Bool)->Double");
SELECT FormatType(CallableResultType(
$callable_type
)), -- Double
FormatType(CallableArgumentType(
$callable_type, 1
)); -- Bool
VariantUnderlyingType
Performs an action reverse to VariantType: it returns the underlying type based on the variant type.
Examples
SELECT FormatType(VariantUnderlyingType(
ParseType("Variant<foo:Int32,bar:Double>")
)), -- Struct<'bar':Double,'foo':Int32>
FormatType(VariantUnderlyingType(
ParseType("Variant<Int32,Double>")
)); -- Tuple<Int32,Double>