更新时间:2023-05-16 GMT+08:00
分享

普通表转KV表

概述

将普通的table表转为KV(Key:Value)格式的表。

KV表格式定义:Key是列名的index,Value支持BIGINT,DOUBLE和STRING类型。在该组件中可以输入用户定义的key_map表,是列名和Key的映射,但无论是否输入key_map表,该组件都会输出key_map表记录转化后的列名和Key的映射。例如1:10,2:20和3:30。

key_map表格式定义:包含列名和index的映射以及类型信息的col_name,col_index和col_datatype,这三列类型要求是STRING。

说明与约束

  • 转换后的结果表不会显示原表中的空值。您可以在结果表中指定需要保留的列,并且输出的列与原表的列一致。
  • 如果存在输入Key_map表,则转化的列为Key_map表与KV表中Key的交集。(在col和keymap表中都存在)
  • 如果存在的输入Key_map表与输入表类型冲突,则输出的Key_map表使用您指定的类型。(和读入的keymap中col_datatype和判断得到的datatype不同 以keymap的类型为主)
  • 输入表中需要转换为KV的列只能为BIGINT或DOUBLE类型。
  • 当selected_col_name 为空时,默认选择整张表。

输入

参数

子参数

参数说明

inputs

dataframe

inputs为字典类型,dataframe为pyspark中的DataFrame类型对象

keymap_dataframe

keymap_dataframe为输入的keymap表,类型:pyspark中的DataFrame类型对象

输出

参数

子参数

参数说明

outputs

output_dataframe

转化后的dataframe表

output_keymap_dataframe

转化后的keymap_dataframe表

参数说明

参数名称

是否必选

参数描述

默认值

selected_col_names

选择的列名称,只能为BIGINT或DOUBLE类型。

默认选择整张表。

append_col_names

需要保留的列名称,该列会被原样写入至输出表中。

kv_delimiter

Key和Value的分割符。

半角冒号(:)

item_delimiter

KV间的分割符。默认为半角逗号(,)。

半角逗号(,)

convert_col2indexId

指定是否将列转换为编号。取值如下:

1为转换。

0不转换

0

keymap_dataframe

输入的索引表。

该参数仅当convertColToIndexId=1时有效。如果未指定该参数,则程序自动计算一套编号。

None

样例

数据样本

table表

rowid

col0

col1

col2

0

1

2

3

1

4

5

6

2

7

8

  

3

10

11

12

input_keymap表

col_name

col_index

col_datatype

col

mycol1

bigint

col2

mycol2

bigint

convert=0

inputs = {
    "dataframe": input_df,  
    "keymap_dataframe": None
}
params = {
    "inputs": inputs,
    "selected_col_names": "col1,col2",
    "append_col_names": "rowid",
    "kv_delimiter": ":",
    "item_delimiter": ",",
    "convert_col2indexId": 0,
}

convert=1,无输入的keymap表

inputs = {
    "dataframe": input_df,  
    "keymap_dataframe": None
}
params = {
    "inputs": inputs,
    "selected_col_names": "col1,col2",
    "append_col_names": "rowid",
    "kv_delimiter": ":",
    "item_delimiter": ",",
    "convert_col2indexId": 1,
}

convert=1,有输入的keymap表

inputs = {
    "dataframe": input_df,  
    "keymap_dataframe": input_key_map_df 
}
params = {
    "inputs": inputs,
    "selected_col_names": "col1,col2",
    "append_col_names": "rowid",
    "kv_delimiter": ":",
    "item_delimiter": ",",
    "convert_col2indexId": 1,
}

配置流程

运行流程

分享:

    相关文档

    相关产品