Java 类名:com.alibaba.alink.operator.batch.sql.AsBatchOp
Python 类名:AsBatchOp

功能介绍

对批式数据进行sql的AS操作。

参数说明

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

| clause | 运算语句 | 运算语句 | String | ✓ | | |

代码示例

Python 代码

  1. from pyalink.alink import *
  2. import pandas as pd
  3. useLocalEnv(1)
  4. df = 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. batch_data = BatchOperator.fromDataframe(df, schemaStr='f1 string, f2 bigint, f3 double')
  13. op = AsBatchOp().setClause("ff1,ff2,ff3")
  14. batch_data = batch_data.link(op)
  15. batch_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.source.MemSourceBatchOp;
  4. import com.alibaba.alink.operator.batch.sql.AsBatchOp;
  5. import org.junit.Test;
  6. import java.util.Arrays;
  7. import java.util.List;
  8. public class AsBatchOpTest {
  9. @Test
  10. public void testAsBatchOp() throws Exception {
  11. List <Row> df = Arrays.asList(
  12. Row.of("Ohio", 2000, 1.5),
  13. Row.of("Ohio", 2001, 1.7),
  14. Row.of("Ohio", 2002, 3.6),
  15. Row.of("Nevada", 2001, 2.4),
  16. Row.of("Nevada", 2002, 2.9),
  17. Row.of("Nevada", 2003, 3.2)
  18. );
  19. BatchOperator <?> batch_data = new MemSourceBatchOp(df, "f1 string, f2 int, f3 double");
  20. BatchOperator <?> op = new AsBatchOp().setClause("ff1,ff2,ff3");
  21. batch_data = batch_data.link(op);
  22. batch_data.print();
  23. }
  24. }

运行结果

| ff1 | ff2 | ff3 | | —- | —- | —- |

| Ohio | 2000 | 1.5000 |

| Ohio | 2001 | 1.7000 |

| Ohio | 2002 | 3.6000 |

| Nevada | 2001 | 2.4000 |

| Nevada | 2002 | 2.9000 |

| Nevada | 2003 | 3.2000 |