- 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
1. SELECT FormatType(ParseType("List<Int32>")); -- List<int32>

TypeOf
Getting the type of value passed to the argument.
Examples
1. SELECT FormatType(TypeOf("foo")); -- String

1. 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
1. SELECT FormatType(TypeOf(
2. InstanceOf(ParseType("Int32")) +
3. InstanceOf(ParseType("Double"))
4. )); -- Double, because "Int32 + Double" returns Double

DataType
Returns a type for primitive data types based on type name.
Examples
1. SELECT FormatType(DataType("Bool")); -- Bool
2. SELECT FormatType(DataType("Decimal","5","1")); -- Decimal(5,1)

OptionalType
Adds the option to assign NULL to the passed type.
Examples
1. SELECT FormatType(OptionalType(DataType("Bool"))); -- Bool?

ListType and StreamType
Builds a list type or stream type based on the passed element type.
Examples
1. 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
1. SELECT FormatType(DictType(
2. DataType("String"),
3. DataType("Double")
4. )); -- Dict<String,Double>

TupleType
Builds the tuple type from the passed element types.
Examples
1. SELECT FormatType(TupleType(
2. DataType("String"),
3. DataType("Double"),
4. OptionalType(DataType("Bool"))
5. )); -- 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
1. SELECT FormatType(StructType(
2. DataType("Bool") AS MyBool,
3. ListType(DataType("String")) AS StringList
4. )); -- Struct<'MyBool':Bool,'StringList':List<String>>

VariantType
Returns the type of a variant based on the underlying type (structure or tuple).
Examples
1. SELECT FormatType(VariantType(
2. ParseType("Struct<foo:Int32,bar:Double>")
3. )); -- Variant<'bar':Double,'foo':Int32>

ResourceType
Returns the type of the resource based on the passed string label.
Examples
1. 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
1. SELECT FormatType(CallableType(
2. 1, -- optional args count
3. DataType("Double"), -- result type
4. DataType("String"), -- arg #1 type
5. OptionalType(DataType("Int64")) -- arg #2 type
6. )); -- 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
1. 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
1. SELECT FormatType(ListItemType(
2. ParseType("List<Int32>")
3. )); -- Int32

DictKeyType and DictPayloadType
Returns the type of the key or value based on the dictionary type.
Examples
1. SELECT FormatType(DictKeyType(
2. ParseType("Dict<Int32,String>")
3. )); -- Int32

TupleElementType
Returns the tuple’s element type based on the tuple type and the element index (index starts from zero).
Examples
1. SELECT FormatType(TupleElementType(
2. ParseType("Tuple<Int32,Double>"), "1"
3. )); -- Double

StructMemberType
Returns the type of the structure element based on the structure type and element name.
Examples
1. SELECT FormatType(StructMemberType(
2. ParseType("Struct<foo:Int32,bar:Double>"), "foo"
3. )); -- 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
1. $callable_type = ParseType("(String,Bool)->Double");
3. SELECT FormatType(CallableResultType(
4. $callable_type
5. )), -- Double
6. FormatType(CallableArgumentType(
7. $callable_type, 1
8. )); -- Bool

VariantUnderlyingType
Performs an action reverse to VariantType: it returns the underlying type based on the variant type.
Examples
1. SELECT FormatType(VariantUnderlyingType(
2. ParseType("Variant<foo:Int32,bar:Double>")
3. )), -- Struct<'bar':Double,'foo':Int32>
4. FormatType(VariantUnderlyingType(
5. ParseType("Variant<Int32,Double>")
6. )); -- Tuple<Int32,Double>

