Github user fhueske commented on a diff in the pull request:

    https://github.com/apache/flink/pull/1862#discussion_r59025508
  
    --- Diff: 
flink-libraries/flink-table/src/test/scala/org/apache/flink/api/scala/sql/test/JoinITCase.scala
 ---
    @@ -0,0 +1,239 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.flink.api.scala.sql.test
    +
    +import org.apache.calcite.tools.ValidationException
    +import org.apache.flink.api.scala._
    +import org.apache.flink.api.scala.table._
    +import org.apache.flink.api.scala.util.CollectionDataSets
    +import org.apache.flink.api.table.{TableException, Row}
    +import org.apache.flink.api.table.plan.TranslationContext
    +import org.apache.flink.api.table.test.utils.TableProgramsTestBase
    +import 
org.apache.flink.api.table.test.utils.TableProgramsTestBase.TableConfigMode
    +import 
org.apache.flink.test.util.MultipleProgramsTestBase.TestExecutionMode
    +import org.apache.flink.test.util.TestBaseUtils
    +import org.junit._
    +import org.junit.runner.RunWith
    +import org.junit.runners.Parameterized
    +
    +import scala.collection.JavaConverters._
    +
    +@RunWith(classOf[Parameterized])
    +class JoinITCase(
    +    mode: TestExecutionMode,
    +    configMode: TableConfigMode)
    +  extends TableProgramsTestBase(mode, configMode) {
    +
    +  @Test
    +  def testJoin(): Unit = {
    +
    +    val env = ExecutionEnvironment.getExecutionEnvironment
    +    val tEnv = getScalaTableEnvironment
    +    TranslationContext.reset()
    +
    +    val sqlQuery = "SELECT c, g FROM Table3, Table5 WHERE b = e"
    +
    +    val ds1 = CollectionDataSets.getSmall3TupleDataSet(env).toTable.as('a, 
'b, 'c)
    +    val ds2 = CollectionDataSets.get5TupleDataSet(env).toTable.as('d, 'e, 
'f, 'g, 'h)
    +    tEnv.registerTable("Table3", ds1)
    +    tEnv.registerTable("Table5", ds2)
    +
    +    val result = tEnv.sql(sqlQuery)
    +
    +    val expected = "Hi,Hallo\n" + "Hello,Hallo Welt\n" + "Hello 
world,Hallo Welt\n"
    +    val results = result.toDataSet[Row](getConfig).collect()
    +    TestBaseUtils.compareResultAsText(results.asJava, expected)
    +  }
    +
    +  @Test
    +  def testJoinWithFilter(): Unit = {
    +
    +    val env = ExecutionEnvironment.getExecutionEnvironment
    +    val tEnv = getScalaTableEnvironment
    +    TranslationContext.reset()
    +
    +    val sqlQuery = "SELECT c, g FROM Table3, Table5 WHERE b = e AND b < 2"
    +
    +    val ds1 = CollectionDataSets.getSmall3TupleDataSet(env).toTable.as('a, 
'b, 'c)
    +    val ds2 = CollectionDataSets.get5TupleDataSet(env).toTable.as('d, 'e, 
'f, 'g, 'h)
    +    tEnv.registerTable("Table3", ds1)
    +    tEnv.registerTable("Table5", ds2)
    +
    +    val result = tEnv.sql(sqlQuery)
    +
    +    val expected = "Hi,Hallo\n"
    +    val results = result.toDataSet[Row](getConfig).collect()
    +    TestBaseUtils.compareResultAsText(results.asJava, expected)
    +  }
    +
    +  @Test
    +  def testJoinWithJoinFilter(): Unit = {
    +
    +    val env = ExecutionEnvironment.getExecutionEnvironment
    +    val tEnv = getScalaTableEnvironment
    +    TranslationContext.reset()
    +
    +    val sqlQuery = "SELECT c, g FROM Table3, Table5 WHERE b = e AND a < 6 
AND h < b"
    +
    +    val ds1 = CollectionDataSets.get3TupleDataSet(env).toTable.as('a, 'b, 
'c)
    +    val ds2 = CollectionDataSets.get5TupleDataSet(env).toTable.as('d, 'e, 
'f, 'g, 'h)
    +    tEnv.registerTable("Table3", ds1)
    +    tEnv.registerTable("Table5", ds2)
    +
    +    val result = tEnv.sql(sqlQuery)
    +
    +    val expected = "Hello world, how are you?,Hallo Welt wie\n" +
    +      "I am fine.,Hallo Welt wie\n"
    +    val results = result.toDataSet[Row](getConfig).collect()
    +    TestBaseUtils.compareResultAsText(results.asJava, expected)
    +  }
    +
    +  @Test
    +  def testJoinWithMultipleKeys(): Unit = {
    +
    +    val env = ExecutionEnvironment.getExecutionEnvironment
    +    val tEnv = getScalaTableEnvironment
    +    TranslationContext.reset()
    +
    +    val sqlQuery = "SELECT c, g FROM Table3, Table5 WHERE a = d AND b = h"
    +
    +    val ds1 = CollectionDataSets.get3TupleDataSet(env).toTable.as('a, 'b, 
'c)
    +    val ds2 = CollectionDataSets.get5TupleDataSet(env).toTable.as('d, 'e, 
'f, 'g, 'h)
    +    tEnv.registerTable("Table3", ds1)
    +    tEnv.registerTable("Table5", ds2)
    +
    +    val result = tEnv.sql(sqlQuery)
    +
    +    val expected = "Hi,Hallo\n" + "Hello,Hallo Welt\n" + "Hello 
world,Hallo Welt wie gehts?\n" +
    +      "Hello world,ABC\n" + "I am fine.,HIJ\n" + "I am fine.,IJK\n"
    +    val results = result.toDataSet[Row](getConfig).collect()
    +    TestBaseUtils.compareResultAsText(results.asJava, expected)
    +  }
    +
    +  @Test(expected = classOf[ValidationException])
    +  def testJoinNonExistingKey(): Unit = {
    +
    +    val env = ExecutionEnvironment.getExecutionEnvironment
    +    val tEnv = getScalaTableEnvironment
    +    TranslationContext.reset()
    +
    +    val sqlQuery = "SELECT c, g FROM Table3, Table5 WHERE foo = e"
    +
    +    val ds1 = CollectionDataSets.get3TupleDataSet(env).toTable.as('a, 'b, 
'c)
    +    val ds2 = CollectionDataSets.get5TupleDataSet(env).toTable.as('d, 'e, 
'f, 'g, 'h)
    +    tEnv.registerTable("Table3", ds1)
    +    tEnv.registerTable("Table5", ds2)
    +
    +    tEnv.sql(sqlQuery)
    +  }
    +
    +  @Test(expected = classOf[TableException])
    +  def testJoinNonMatchingKeyTypes(): Unit = {
    +
    +    val env = ExecutionEnvironment.getExecutionEnvironment
    +    val tEnv = getScalaTableEnvironment
    +    TranslationContext.reset()
    +
    +    val sqlQuery = "SELECT c, g FROM Table3, Table5 WHERE a = g"
    +
    +    val ds1 = CollectionDataSets.get3TupleDataSet(env).toTable.as('a, 'b, 
'c)
    +    val ds2 = CollectionDataSets.get5TupleDataSet(env).toTable.as('d, 'e, 
'f, 'g, 'h)
    +    tEnv.registerTable("Table3", ds1)
    +    tEnv.registerTable("Table5", ds2)
    +
    +    tEnv.sql(sqlQuery).toDataSet[Row].collect()
    +  }
    +
    +  @Test(expected = classOf[ValidationException])
    +  def testJoinWithAmbiguousFields(): Unit = {
    --- End diff --
    
    Can you add another test that resolves the ambiguous field using a table 
alias, i.e., `SELECT Table5.c, g FROM Table3, Table5 WHERE a = d`?


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to