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

功能介绍

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

使用方式

SELECT 语句中支持的内置函数可以参考 Flink
对应版本的官方文档: System (Built-in) Functions
。 但需要注意,有些内置函数在旧 planner
中不支持,在这里列出:Unsupported Built-In Functions

参数说明

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

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

代码示例

Python 代码

  1. df = pd.DataFrame([
  2. ['Ohio', 2000, 1.5],
  3. ['Ohio', 2001, 1.7],
  4. ['Ohio', 2002, 3.6],
  5. ['Nevada', 2001, 2.4],
  6. ['Nevada', 2002, 2.9],
  7. ['Nevada', 2003, 3.2]
  8. ])
  9. batch_data = BatchOperator.fromDataframe(df, schemaStr='f1 string, f2 bigint, f3 double')
  10. batch_data.link(SelectBatchOp().setClause("f1 as name")).print()

Java 代码

  1. import com.alibaba.alink.operator.batch.BatchOperator;
  2. import com.alibaba.alink.operator.batch.source.MemSourceBatchOp;
  3. import com.alibaba.alink.operator.batch.sql.SelectBatchOp;
  4. import org.junit.Test;
  5. public class SelectBatchOpTest {
  6. @Test
  7. public void testSelectBatchOp() throws Exception {
  8. List <Row> df = Arrays.asList(
  9. Row.of("Ohio", 2000, 1.5),
  10. Row.of("Ohio", 2001, 1.7),
  11. Row.of("Ohio", 2002, 3.6),
  12. Row.of("Nevada", 2001, 2.4),
  13. Row.of("Nevada", 2002, 2.9),
  14. Row.of("Nevada", 2003, 3.2)
  15. );
  16. BatchOperator <?> data = new MemSourceBatchOp(df, "f1 string, f2 int, f3 double");
  17. data.link(new SelectBatchOp().setClause("f1 as name")).print();
  18. }
  19. }

运行结果

name

Ohio
Ohio
Ohio
Nevada
Nevada
Nevada