Map values(映射值)¶
Supported in: Batch, Faster, Streaming
Changes the values of the input column to new values based on a map of key-value pairs. If the input value is not found in the map, the default value is used.
Expression categories: Data preparation
Declared arguments¶
- Column to replace values in: Column containing the initial values to be mapped to new values.
Expression\ - Default value: The default value to be added to the output column if the input value is not found in the map.
Expression\ - Values map: Map consisting of key-value pairs. The key of the map is the original value found in the input to be mapped to a new one, whereas the value of the map represents the new value to be replaced with.
Expression\
Type variable bounds: T1 accepts ComparableType**T2 accepts AnyType
Output type: T2
Examples¶
Example 1: Base case¶
Argument values:
- Column to replace values in:
country - Default value:
cast(
expression: null,
type: String,
) - Values map: {
Denmark -> DNK,
United Kingdom -> UK,
}
| country | Output |
|---|---|
| United Kingdom | UK |
| Denmark | DNK |
| United States of America | null |
Example 2: Base case¶
Argument values:
- Column to replace values in:
country - Default value:
country - Values map: {
United Kingdom -> null,
}
| country | Output |
|---|---|
| United Kingdom | null |
| null | null |
Example 3: Base case¶
Argument values:
- Column to replace values in:
country - Default value:
country - Values map: {
Denmark -> DNK,
United Kingdom -> null,
}
| country | Output |
|---|---|
| United Kingdom | null |
| null | null |
Example 4: Null case¶
Argument values:
- Column to replace values in:
country - Default value:
country - Values map: {
United Kingdom -> UK,
}
| country | Output |
|---|---|
| United Kingdom | UK |
| null | null |
中文翻译¶
映射值¶
支持:批处理(Batch)、快速处理(Faster)、流处理(Streaming)
根据键值对映射表,将输入列的值替换为新值。若输入值未在映射表中找到,则使用默认值。
表达式类别: 数据准备
声明参数¶
- 要替换值的列(Column to replace values in): 包含待映射初始值的列。
表达式\ - 默认值(Default value): 当输入值未在映射表中找到时,添加到输出列的默认值。
表达式\ - 值映射表(Values map): 由键值对组成的映射表。键为输入中待映射的原始值,值为替换后的新值。
表达式\
类型变量约束: T1 接受 ComparableType**T2 接受 AnyType
输出类型: T2
示例¶
示例 1:基础情况¶
参数值:
- 要替换值的列:
country - 默认值:
cast(
表达式: null,
类型: String,
) - 值映射表: {
Denmark -> DNK,
United Kingdom -> UK,
}
| country | 输出 |
|---|---|
| United Kingdom | UK |
| Denmark | DNK |
| United States of America | null |
示例 2:基础情况¶
参数值:
- 要替换值的列:
country - 默认值:
country - 值映射表: {
United Kingdom -> null,
}
| country | 输出 |
|---|---|
| United Kingdom | null |
| null | null |
示例 3:基础情况¶
参数值:
- 要替换值的列:
country - 默认值:
country - 值映射表: {
Denmark -> DNK,
United Kingdom -> null,
}
| country | 输出 |
|---|---|
| United Kingdom | null |
| null | null |
示例 4:空值情况¶
参数值:
- 要替换值的列:
country - 默认值:
country - 值映射表: {
United Kingdom -> UK,
}
| country | 输出 |
|---|---|
| United Kingdom | UK |
| null | null |