flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ex00 <...@git.apache.org>
Subject [GitHub] flink pull request #3033: [FLINK-5256] Extend DataSetSingleRowJoin to suppor...
Date Tue, 17 Jan 2017 08:02:47 GMT
Github user ex00 commented on a diff in the pull request:

    https://github.com/apache/flink/pull/3033#discussion_r96359104
  
    --- Diff: flink-libraries/flink-table/src/test/scala/org/apache/flink/table/api/scala/batch/sql/JoinITCase.scala
---
    @@ -372,9 +372,163 @@ class JoinITCase(
         val table = CollectionDataSets.getSmall3TupleDataSet(env).toTable(tEnv).as('a1, 'a2,
'a3)
         tEnv.registerTable("A", table)
     
    -    val sqlQuery1 = "SELECT * FROM A CROSS JOIN (SELECT count(*) FROM A HAVING count(*)
< 0)"
    -    val result = tEnv.sql(sqlQuery1).count()
    +    val sqlQuery1 = "SELECT * FROM A CROSS JOIN " +
    +      "(SELECT count(*) FROM A HAVING count(*) < 0)"
    +    val result = tEnv.sql(sqlQuery1)
    +    val expected =Seq(
    +      "2,2,Hello,null",
    +      "1,1,Hi,null",
    +      "3,2,Hello world,null").mkString("\n")
     
    -    Assert.assertEquals(0, result)
    +    val results = result.toDataSet[Row].collect()
    +    TestBaseUtils.compareResultAsText(results.asJava, expected)
    +  }
    +
    +  @Test
    +  def testSingleRowLeftOuterJoin(): Unit = {
    +
    +    val env = ExecutionEnvironment.getExecutionEnvironment
    +    val tEnv = TableEnvironment.getTableEnvironment(env, config)
    +
    +    val sqlQuery =
    +      "SELECT  a, cnt FROM t1 " +
    +        "LEFT JOIN (" +
    +        "SELECT COUNT(*) AS cnt FROM t2" +
    +        ") AS x " +
    +        "ON a > cnt"
    +
    +    val ds1 = CollectionDataSets.get5TupleDataSet(env).toTable(tEnv).as('a, 'b, 'c, 'd,
'e)
    +    val ds2 = CollectionDataSets.getSmall3TupleDataSet(env).toTable(tEnv)
    +    tEnv.registerTable("t1", ds1)
    +    tEnv.registerTable("t2", ds2)
    +
    +    val result = tEnv.sql(sqlQuery)
    +
    +    val expected = Seq(
    +      "1,null",
    +      "2,null", "2,null",
    +      "3,null", "3,null", "3,null",
    +      "4,3", "4,3", "4,3", "4,3",
    +      "5,3", "5,3", "5,3", "5,3", "5,3").mkString("\n")
    +
    +    val results = result.toDataSet[Row].collect()
    +    TestBaseUtils.compareResultAsText(results.asJava, expected)
    +  }
    +
    +  @Test
    +  def testSingleRowRightOuterJoin(): Unit = {
    +
    +    val env = ExecutionEnvironment.getExecutionEnvironment
    +    val tEnv = TableEnvironment.getTableEnvironment(env, config)
    +
    +    val sqlQuery =
    +      "SELECT  a, cnt FROM t1 " +
    +        "RIGHT JOIN (" +
    +        "SELECT COUNT(*) AS cnt FROM t2" +
    +        ") AS x " +
    +        "ON a > cnt"
    +
    +    val ds1 = CollectionDataSets.get5TupleDataSet(env).toTable(tEnv).as('a, 'b, 'c, 'd,
'e)
    +    val ds2 = CollectionDataSets.getSmall3TupleDataSet(env).toTable(tEnv)
    +    tEnv.registerTable("t1", ds1)
    +    tEnv.registerTable("t2", ds2)
    +
    +    val result = tEnv.sql(sqlQuery)
    +
    +    val expected = Seq(
    +      "4,3", "4,3", "4,3", "4,3",
    +      "5,3", "5,3", "5,3", "5,3", "5,3").mkString("\n")
    +
    +    val results = result.toDataSet[Row].collect()
    +    TestBaseUtils.compareResultAsText(results.asJava, expected)
    +  }
    +
    +  @Test
    +  def testSingleRowLeftOuterJoinTwoJoinField(): Unit = {
    +
    +    val env = ExecutionEnvironment.getExecutionEnvironment
    +    val tEnv = TableEnvironment.getTableEnvironment(env, config)
    +
    +    val sqlQuery =
    +      "SELECT  a,cnt, cnt2 FROM t1 " +
    +        "LEFT JOIN (" +
    +        "SELECT COUNT(*) AS cnt,COUNT(*) AS cnt2 FROM t2" +
    +        ") AS x " +
    +        "ON a > cnt"
    +
    +    val ds1 = CollectionDataSets.get5TupleDataSet(env).toTable(tEnv).as('a, 'b, 'c, 'd,
'e)
    +    val ds2 = CollectionDataSets.getSmall3TupleDataSet(env).toTable(tEnv)
    +    tEnv.registerTable("t1", ds1)
    +    tEnv.registerTable("t2", ds2)
    +
    +    val result = tEnv.sql(sqlQuery)
    +
    +    val expected = Seq(
    +      "1,null,null",
    +      "2,null,null", "2,null,null",
    +      "3,null,null", "3,null,null", "3,null,null",
    +      "4,3,3", "4,3,3", "4,3,3", "4,3,3",
    +      "5,3,3", "5,3,3", "5,3,3", "5,3,3", "5,3,3").mkString("\n")
    +
    +    val results = result.toDataSet[Row].collect()
    +    TestBaseUtils.compareResultAsText(results.asJava, expected)
    +  }
    +
    +  @Test
    +  def testSingleRowLeftOuterJoinWithNullRecords(): Unit = {
    +
    +    val env = ExecutionEnvironment.getExecutionEnvironment
    +    val tEnv = TableEnvironment.getTableEnvironment(env, config)
    +
    +    val sqlQuery =
    +      "SELECT  a,cnt FROM t1 " +
    +        "LEFT JOIN (" +
    +        "SELECT cnt FROM (SELECT COUNT(*) AS cnt FROM t2) WHERE cnt < 0" +
    +        ") AS x " +
    +        "ON a > cnt"
    +
    +    val ds1 = CollectionDataSets.get5TupleDataSet(env).toTable(tEnv).as('a, 'b, 'c, 'd,
'e)
    +    val ds2 = CollectionDataSets.getSmall3TupleDataSet(env).toTable(tEnv)
    +    tEnv.registerTable("t1", ds1)
    +    tEnv.registerTable("t2", ds2)
    +
    +    val result = tEnv.sql(sqlQuery)
    +
    +    val expected = Seq(
    +      "1,null",
    +      "2,null", "2,null",
    +      "3,null", "3,null", "3,null",
    +      "4,null", "4,null", "4,null", "4,null",
    +      "5,null", "5,null", "5,null", "5,null", "5,null").mkString("\n")
    +
    +    val results = result.toDataSet[Row].collect()
    +    TestBaseUtils.compareResultAsText(results.asJava, expected)
    +  }
    +
    +  @Test
    +  def testSingleRowRightOuterJoinWithNullRecords(): Unit = {
    --- End diff --
    
    This case don't pass. Because ``right join`` in this case execute via ``MapJoinLeftRunner``.
 please see comment in [jira](https://issues.apache.org/jira/browse/FLINK-5256?focusedCommentId=15825599&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-15825599)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message