Java 类名:com.alibaba.alink.operator.stream.dataproc.AppendIdStreamOp
Python 类名:AppendIdStreamOp

功能介绍

将表附加ID列

参数说明

| 名称 | 中文名称 | 描述 | 类型 | 是否必须? | 取值范围 | 默认值 | | —- | —- | —- | —- | —- | —- | —- |

| idCol | ID列名 | ID列名 | String | | | “append_id” |

代码示例

Python 代码

  1. from pyalink.alink import *
  2. import pandas as pd
  3. useLocalEnv(1)
  4. df_data = pd.DataFrame([
  5. ['Ohio', 2000, 1.5],
  6. ['Ohio', 2001, 1.7],
  7. ['Ohio', 2002, 3.6],
  8. ['Nevada', 2001, 2.4],
  9. ['Nevada', 2002, 2.9],
  10. ['Nevada', 2003,3.2]
  11. ])
  12. stream_data = StreamOperator.fromDataframe(df_data, schemaStr='f1 string, f2 bigint, f3 double')
  13. AppendIdStreamOp().linkFrom(stream_data).print()
  14. StreamOperator.execute()

运行结果

  1. ['f1', 'f2', 'f3', 'append_id']
  2. ['Ohio', 2000, 1.5, 0]
  3. ['Ohio', 2001, 1.7, 1]
  4. ['Ohio', 2002, 3.6, 2]
  5. ['Nevada', 2001, 2.4, 3]
  6. ['Nevada', 2002, 2.9, 4]
  7. ['Nevada', 2003, 3.2, 5]