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

功能介绍

对批式数据进行sql的FULL OUTER JOIN操作。

参数说明

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

| joinPredicate | where语句 | where语句 | String | ✓ | | |

| selectClause | select语句 | select语句 | String | ✓ | | |

| type | join类型 | join类型: “join”, “leftOuterJoin”, “rightOuterJoin” 或 “fullOuterJoin” | String | | “JOIN”, “LEFTOUTERJOIN”, “RIGHTOUTERJOIN”, “FULLOUTERJOIN” | “JOIN” |

代码示例

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_data1 = BatchOperator.fromDataframe(df, schemaStr='f1 string, f2 bigint, f3 double')
  13. batch_data2 = BatchOperator.fromDataframe(df, schemaStr='f1 string, f2 bigint, f3 double')
  14. op = FullOuterJoinBatchOp().setJoinPredicate("a.f1=b.f1 and a.f2=b.f2").setSelectClause("a.f1, a.f2, a.f3")
  15. result = op.linkFrom(batch_data1, batch_data2)
  16. result.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.FullOuterJoinBatchOp;
  4. import org.junit.Test;
  5. public class FullOuterJoinBatchOpTest {
  6. @Test
  7. public void testFullOuterJoinBatchOp() 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 <?> data1 = new MemSourceBatchOp(df, "f1 string, f2 int, f3 double");
  17. BatchOperator <?> data2 = new MemSourceBatchOp(df, "f1 string, f2 int, f3 double");
  18. BatchOperator <?> joinOp =
  19. new FullOuterJoinBatchOp().setJoinPredicate("a.f1=b.f1 and a.f2=b.f2").setSelectClause(
  20. "a.f1, a.f2, a.f3");
  21. joinOp.linkFrom(data1, data2).print();
  22. }
  23. }

运行结果

| f1 | f2 | f3 | | —- | —- | —- |

| Nevada | 2001 | 2.4000 |

| Nevada | 2002 | 2.9000 |

| Nevada | 2003 | 3.2000 |

| Ohio | 2000 | 1.5000 |

| Ohio | 2001 | 1.7000 |

| Ohio | 2002 | 3.6000 |