sunjincheng121 commented on a change in pull request #8087: 
[FLINK-12029][table] Add column operations for TableApi
URL: https://github.com/apache/flink/pull/8087#discussion_r271119916
 
 

 ##########
 File path: 
flink-table/flink-table-planner/src/test/scala/org/apache/flink/table/api/batch/table/ColumnsOperationTest.scala
 ##########
 @@ -0,0 +1,282 @@
+/*
+ * 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.table.api.batch.table
+
+import org.apache.flink.api.scala._
+import org.apache.flink.table.api.{Slide, Table}
+import org.apache.flink.table.api.scala._
+import org.apache.flink.table.functions.ScalarFunction
+import org.apache.flink.table.utils.TableTestUtil._
+import org.apache.flink.table.utils.{BatchTableTestUtil, TableFunc0, 
TableTestBase}
+import org.junit.Test
+
+/**
+  * Tests for column operations which includes tests for different column 
operations.
+  */
+class ColumnsOperationTest extends TableTestBase {
+
+  val util = new BatchTableTestUtil()
+
+  private def verifyAll(tab1: Table, tab2: Table, expected: String): Unit = {
+    util.verifyTable(tab1, expected)
+    this.verifyTableEquals(tab1, tab2)
+  }
+
+  @Test
+  def testStar(): Unit = {
+
+    val t = util.addTable[(Double, Long)]('double, 'long)
+
+    util.tableEnv.registerFunction("TestFunc", TestFunc)
+    val tab1 = t.select(TestFunc(columns('*)))
+    val tab2 = t.select("TestFunc(columns(*))")
+
+    val expected =
+      unaryNode(
+        "DataSetCalc",
+        batchTableNode(0),
+        term("select", "TestFunc$(double, long) AS _c0")
+      )
+
+    verifyAll(tab1, tab2, expected)
+  }
+
+  @Test
+  def testColumnRange(): Unit = {
+    val t = util.addTable[(Int, Long, String, Int, Long, String)]('a, 'b, 'c, 
'd, 'e, 'f)
+
+    val tab1 = t.select(columns('b ~ 'c), 'a, columns(5 ~ 6, 'd))
+    val tab2 = t.select("columns(b ~ c), a, columns(5 ~ 6, d)")
+
+    val expected =
+      unaryNode(
+        "DataSetCalc",
+        batchTableNode(0),
+        term("select", "b", "c", "a", "e", "f", "d")
+      )
+
+    verifyAll(tab1, tab2, expected)
+  }
+
+  @Test
+  def testColumnWithoutRange(): Unit = {
+    val t = util.addTable[(Int, Long, String, Int, Long, String)]('a, 'b, 'c, 
'd, 'e, 'f)
+
+    val tab1 = t.select(columns(1, 'b, 'c), 'f)
+    val tab2 = t.select("columns(1, b, c), f")
+
+    val expected =
+      unaryNode(
+        "DataSetCalc",
+        batchTableNode(0),
+        term("select", "a", "b", "c", "f")
+      )
+
+    verifyAll(tab1, tab2, expected)
+  }
+
+  @Test
+  def testInverseSelection(): Unit = {
+    val t = util.addTable[(Int, Long, String, Int, Long, String)]('a, 'b, 'c, 
'd, 'e, 'f)
+
+    val tab1 = t
+      .select(-columns(1, 'b))
+      .select(-columns(1 ~ 2))
+
+    val tab2 = t
+      .select("-columns(1, b)")
+      .select("-columns(1 ~ 2)")
+
+    val expected =
+      unaryNode(
+        "DataSetCalc",
+        batchTableNode(0),
+        term("select", "e", "f")
+      )
+
+    verifyAll(tab1, tab2, expected)
+  }
+
+  @Test
+  def testColumnsOperationInUDF(): Unit = {
+    val t = util.addTable[(Int, Long, String, String)]('int, 'long, 'string1, 
'string2)
+
+    val tab1 = t.select(concat(columns('string1 ~ 'string2)))
+    val tab2 = t.select("concat(columns(string1 ~ string2))")
+
+    val expected =
+      unaryNode(
+        "DataSetCalc",
+        batchTableNode(0),
+        term("select", "CONCAT(string1, string2) AS _c0")
+      )
+
+    verifyAll(tab1, tab2, expected)
+  }
+
+  @Test
+  def testJoin(): Unit = {
+    val t1 = util.addTable[(Int, Long, String)]('int1, 'long1, 'string1)
+    val t2 = util.addTable[(Int, Long, String)]('int2, 'long2, 'string2)
+
+    val tab1 = t1.join(t2, columns(1) === columns(4))
+    val tab2 = t1.join(t2, "columns(1) === columns(4)")
+
+    val expected =
+      binaryNode(
+        "DataSetJoin",
+        batchTableNode(0),
+        batchTableNode(1),
+        term("where", "=(int1, int2)"),
+        term("join", "int1", "long1", "string1", "int2", "long2", "string2"),
+        term("joinType", "InnerJoin")
+      )
+
+    verifyAll(tab1, tab2, expected)
+  }
+
+  @Test
+  def testJoinLateral(): Unit = {
+    val t = util.addTable[(Double, Long, String)]('int, 'long, 'string)
+    val func0 = new TableFunc0
+    util.tableEnv.registerFunction("func0", func0)
+
+    val tab1 = t.joinLateral(func0(columns('string)))
+    val tab2 = t.joinLateral("func0(columns(string))")
+
+    val expected =
+      unaryNode(
+        "DataSetCorrelate",
+        batchTableNode(0),
+        term("invocation",
+          
"org$apache$flink$table$utils$TableFunc0$497a630d2a145bca99673bcd05a53d2b($2)"),
+        term("correlate", "table(TableFunc0(string))"),
+        term("select", "int", "long", "string", "name", "age"),
+        term("rowType",
+          "RecordType(DOUBLE int, BIGINT long, VARCHAR(65536) string, 
VARCHAR(65536) name," +
+            " INTEGER age)"),
+        term("joinType", "INNER")
+      )
+
+    util.verifyTable(tab1, expected)
+    util.verifyTable(tab2, expected)
+  }
+
+  @Test
+  def testFilter(): Unit = {
+    val t = util.addTable[(Int, Long, String, String)]('int, 'long, 'string1, 
'string2)
+
+    val tab1 = t.where(concat(columns('string1 ~ 'string2)) === "a")
+    val tab2 = t.where("concat(columns(string1 ~ string2)) = 'a'")
+
+    val expected =
+      unaryNode(
+        "DataSetCalc",
+        batchTableNode(0),
+        term("select", "int", "long", "string1", "string2"),
+        term("where", "=(CONCAT(string1, string2), 'a')")
+      )
+
+    verifyAll(tab1, tab2, expected)
+  }
+
+  @Test
+  def testGroupBy(): Unit = {
+    val t = util.addTable[(Int, Long, String, Int, Long, String)]('a, 'b, 'c, 
'd, 'e, 'f)
+
+    val tab1 = t
+      .groupBy(columns(1), 'b)
+      .select('a, 'b, 'c.count)
+
+    val tab2 = t
+      .groupBy("columns(1), b")
+      .select("a, b, c.count")
+
+    val expected =
+      unaryNode(
+        "DataSetAggregate",
+        unaryNode(
+          "DataSetCalc",
+          batchTableNode(0),
+          term("select", "a", "b", "c")
+        ),
+        term("groupBy", "a", "b"),
+        term("select", "a", "b", "COUNT(c) AS TMP_0")
+      )
+
+
+    verifyAll(tab1, tab2, expected)
+  }
+
+
+  @Test
+  def testWindowGroupBy(): Unit = {
+    val t = util.addTable[(Int, Long, String, Int)]('a, 'b, 'c, 'd)
+
+    val tab1 = t
+      .window(Slide over 3.milli every 10.milli on columns('b) as 'w)
+      .groupBy(columns('a, 'b), 'w)
+      .select(columns(1 ~ 2), columns('c).count)
+
+    val tab2 = t
+      .window(Slide.over("3.milli").every("10.milli").on("columns(b)").as("w"))
+      .groupBy("columns(a, b), w")
+      .select("columns(1 ~ 2), columns(c).count")
+
+    val expected =
+      unaryNode(
+        "DataSetWindowAggregate",
+        unaryNode(
+          "DataSetCalc",
+          batchTableNode(0),
+          term("select", "a", "b", "c")
+        ),
+        term("groupBy", "a", "b"),
+        term("window", "SlidingGroupWindow('w, 'b, 3.millis, 10.millis)"),
+        term("select", "a", "b", "COUNT(c) AS TMP_0")
+      )
+    verifyAll(tab1, tab2, expected)
+  }
+
+  @Test
+  def testOrderBy(): Unit = {
 
 Review comment:
   We can only keep OrderBy test, due to other operator can be test by 
stream/table/ColumnsOperationsTest, What do you think?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to