Functions for data types

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>

For types - 图1

TypeOf

Getting the type of value passed to the argument.

Examples

  1. SELECT FormatType(TypeOf("foo")); -- String

For types - 图2

  1. SELECT FormatType(TypeOf(AsTuple(1, 1u))); -- Tuple<Int32,Uint32>

For types - 图3

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

For types - 图4

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)

For types - 图5

OptionalType

Adds the option to assign NULL to the passed type.

Examples

  1. SELECT FormatType(OptionalType(DataType("Bool"))); -- Bool?

For types - 图6

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>

For types - 图7

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>

For types - 图8

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?>

For types - 图9

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>>

For types - 图10

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>

For types - 图11

ResourceType

Returns the type of the resource based on the passed string label.

Examples

  1. SELECT FormatType(ResourceType("Foo")); -- Resource<'Foo'>

For types - 图12

CallableType

Constructs the type of the called value using the following arguments:

  1. Number of optional arguments (if all arguments are required — 0).
  2. Result type.
  3. 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>

For types - 图13

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

For types - 图14

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

For types - 图15

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

For types - 图16

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

For types - 图17

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

For types - 图18

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");
  2. SELECT FormatType(CallableResultType(
  3. $callable_type
  4. )), -- Double
  5. FormatType(CallableArgumentType(
  6. $callable_type, 1
  7. )); -- Bool

For types - 图19

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>

For types - 图20