跳转至

Logical type cast(逻辑类型转换(Logical type cast))

Supported in: Batch, Faster, Streaming

Cast expression to given logical type. Unlike the regular cast expression, this expression will not change the underlying base representation of the data, but rather enforce the constraints associated with the specified logical type, so that the output can be used as the input to downstream expressions which specifically demand an instance of that logical type.

Expression categories: Cast

Declared arguments

  • Expression: Expression to cast.
    Expression\
  • Logical type: Logical type to cast to.
    LogicalType
  • optional Default value: Default value in case the specified expression does not fulfill the constraints of the desired logical type. If not specified, this default value will be null. If the default value itself does not fulfill the constraints of the desired logical type, the result of this expression will be null.
    Expression\

Type variable bounds: C accepts AnyType

Output type: C

Examples

Example 1: Base case

Description: Unsuccessful cast to natural number with default

Argument values:

  • Expression: -1234
  • Logical type: Natural number
  • Default value: -1

Output: null


Example 2: Base case

Description: Successful cast to natural number

Argument values:

  • Expression: 1234
  • Logical type: Natural number
  • Default value: null

Output: 1234


Example 3: Base case

Description: Unsuccessful cast to natural number

Argument values:

  • Expression: -1234
  • Logical type: Natural number
  • Default value: null

Output: null


Example 4: Base case

Description: Unsuccessful cast to natural number with default

Argument values:

  • Expression: -1234
  • Logical type: Natural number
  • Default value: 1

Output: 1



中文翻译


逻辑类型转换(Logical type cast)

支持:批处理(Batch)、快速处理(Faster)、流处理(Streaming)

将表达式转换为指定的逻辑类型。与常规的类型转换表达式不同,此表达式不会改变数据的底层基础表示,而是强制执行与指定逻辑类型相关的约束条件,从而使输出结果能够作为下游表达式的输入——这些下游表达式明确要求使用该逻辑类型的实例。

表达式类别: 类型转换(Cast)

声明的参数

  • 表达式(Expression): 待转换的表达式。
    Expression\
  • 逻辑类型(Logical type): 目标转换的逻辑类型。
    LogicalType
  • 可选 默认值(Default value): 当指定表达式不满足目标逻辑类型的约束条件时使用的默认值。若未指定,默认值将为 null。如果默认值本身也不满足目标逻辑类型的约束条件,则此表达式的结果将为 null。
    Expression\

类型变量边界: C 接受 AnyType

输出类型: C

示例

示例 1:基本情况

描述: 转换为自然数失败,使用默认值

参数值:

  • 表达式: -1234
  • 逻辑类型: 自然数(Natural number)
  • 默认值: -1

输出: null


示例 2:基本情况

描述: 成功转换为自然数

参数值:

  • 表达式: 1234
  • 逻辑类型: 自然数
  • 默认值: null

输出: 1234


示例 3:基本情况

描述: 转换为自然数失败

参数值:

  • 表达式: -1234
  • 逻辑类型: 自然数
  • 默认值: null

输出: null


示例 4:基本情况

描述: 转换为自然数失败,使用默认值

参数值:

  • 表达式: -1234
  • 逻辑类型: 自然数
  • 默认值: 1

输出: 1