Java 类名:com.alibaba.alink.operator.batch.feature.OverWindowBatchOp
Python 类名:OverWindowBatchOp

功能介绍

批式OverWindow特征构造组件。

参数说明

名称 中文名称 描述 类型 是否必须? 取值范围 默认值
clause 运算语句 运算语句 String
orderBy 排序列 排序列 String
groupCols 分组列名数组 分组列名,多列,可选,默认不选 String[] null
reservedCols 算法保留列名 算法保留列 String[] null

代码示例

Python 代码

  1. from pyalink.alink import *
  2. import pandas as pd
  3. useLocalEnv(1)
  4. df = pd.DataFrame([
  5. [2, 8, 2.2],
  6. [2, 7, 3.3],
  7. [5, 6, 4.4],
  8. [5, 6, 5.5],
  9. [7, 5, 6.6],
  10. [1, 8, 1.1],
  11. [1, 9, 1.0],
  12. [7, 5, 7.7],
  13. [9, 5, 8.8],
  14. [9, 4, 9.8],
  15. [19, 4, 8.8]])
  16. data = BatchOperator.fromDataframe(df, schemaStr="f0 bigint, f1 bigint, f2 double")
  17. OverWindowBatchOp().setOrderBy("f0, f1 desc").setClause("count_preceding(*) as cc").linkFrom(data).print()

Java 代码

  1. import org.apache.flink.types.Row;
  2. import com.alibaba.alink.operator.batch.BatchOperator;
  3. import com.alibaba.alink.operator.batch.feature.OverWindowBatchOp;
  4. import com.alibaba.alink.operator.batch.source.MemSourceBatchOp;
  5. import org.junit.Test;
  6. import java.util.Arrays;
  7. import java.util.List;
  8. public class OverWindowBatchOpTest {
  9. @Test
  10. public void testOverWindowBatchOp() throws Exception {
  11. List <Row> df = Arrays.asList(
  12. Row.of(2, 8, 2.2),
  13. Row.of(2, 7, 3.3),
  14. Row.of(5, 6, 4.4),
  15. Row.of(5, 6, 5.5),
  16. Row.of(7, 5, 6.6),
  17. Row.of(1, 8, 1.1),
  18. Row.of(1, 9, 1.0),
  19. Row.of(7, 5, 7.7),
  20. Row.of(9, 5, 8.8),
  21. Row.of(9, 4, 9.8)
  22. );
  23. BatchOperator <?> data = new MemSourceBatchOp(df, "f0 int, f1 int, f2 double");
  24. new OverWindowBatchOp().setOrderBy("f0, f1 desc").setClause("count_preceding(*) as cc").linkFrom(data).print();
  25. }
  26. }

运行结果

| f0 | f1 | f2 | cc | | —- | —- | —- | —- |

| 1 | 9 | 1.0000 | 0 |

| 1 | 8 | 1.1000 | 1 |

| 2 | 8 | 2.2000 | 2 |

| 2 | 7 | 3.3000 | 3 |

| 5 | 6 | 4.4000 | 4 |

| 5 | 6 | 5.5000 | 5 |

| 7 | 5 | 6.6000 | 6 |

| 7 | 5 | 7.7000 | 7 |

| 9 | 5 | 8.8000 | 8 |

| 9 | 4 | 9.8000 | 9 |