docete commented on a change in pull request #11727: [FLINK-17106][table]
Support create and drop view in Flink SQL
URL: https://github.com/apache/flink/pull/11727#discussion_r410194442
##########
File path:
flink-table/flink-table-planner/src/test/scala/org/apache/flink/table/catalog/CatalogTableITCase.scala
##########
@@ -670,6 +670,409 @@ class CatalogTableITCase(isStreaming: Boolean) extends
AbstractTestBase {
expectedProperty.put("k2", "b")
assertEquals(expectedProperty, database.getProperties)
}
+
+ @Test(expected = classOf[ValidationException])
+ def testCreateViewTwice(): Unit = {
+ val sourceData = List(
+ toRow(1, 1000),
+ toRow(2, 2000),
+ toRow(3, 3000)
+ )
+
+ TestCollectionTableFactory.initData(sourceData)
+
+ val sourceDDL =
+ """
+ |CREATE TABLE T1(
+ | a int,
+ | b int
+ |) with (
+ | 'connector' = 'COLLECTION'
+ |)
+ """.stripMargin
+
+ val sinkDDL =
+ """
+ |CREATE TABLE T2(
+ | a int,
+ | b int
+ |) with (
+ | 'connector' = 'COLLECTION'
+ |)
+ """.stripMargin
+
+ val viewDDL =
+ """
+ |CREATE VIEW T3(c, d) AS SELECT a, b FROM T1
+ """.stripMargin
+
+ tableEnv.sqlUpdate(sourceDDL)
+ tableEnv.sqlUpdate(sinkDDL)
+ tableEnv.sqlUpdate(viewDDL)
+ tableEnv.sqlUpdate(viewDDL)
+ }
+
+ @Test(expected = classOf[ValidationException])
+ def testCreateTemporaryViewTwice(): Unit = {
+ val sourceData = List(
+ toRow(1, 1000),
+ toRow(2, 2000),
+ toRow(3, 3000)
+ )
+
+ TestCollectionTableFactory.initData(sourceData)
+
+ val sourceDDL =
+ """
+ |CREATE TABLE T1(
+ | a int,
+ | b int
+ |) with (
+ | 'connector' = 'COLLECTION'
+ |)
+ """.stripMargin
+
+ val sinkDDL =
+ """
+ |CREATE TABLE T2(
+ | a int,
+ | b int
+ |) with (
+ | 'connector' = 'COLLECTION'
+ |)
+ """.stripMargin
+
+ val viewDDL =
+ """
+ |CREATE TEMPORARY VIEW T3(c, d) AS SELECT a, b FROM T1
+ """.stripMargin
+
+ tableEnv.sqlUpdate(sourceDDL)
+ tableEnv.sqlUpdate(sinkDDL)
+ tableEnv.sqlUpdate(viewDDL)
+ tableEnv.sqlUpdate(viewDDL)
+ }
+
+ @Test
+ def testCreateViewIfNotExistsTwice(): Unit = {
+ val sourceData = List(
+ toRow(1, 1000),
+ toRow(2, 2000),
+ toRow(3, 3000)
+ )
+
+ TestCollectionTableFactory.initData(sourceData)
+
+ val sourceDDL =
+ """
+ |CREATE TABLE T1(
+ | a int,
+ | b int
+ |) with (
+ | 'connector' = 'COLLECTION'
+ |)
+ """.stripMargin
+
+ val sinkDDL =
+ """
+ |CREATE TABLE T2(
+ | a int,
+ | b int
+ |) with (
+ | 'connector' = 'COLLECTION'
+ |)
+ """.stripMargin
+
+ val viewDDL =
+ """
+ |CREATE VIEW IF NOT EXISTS T3(c, d) AS SELECT a, b FROM T1
+ """.stripMargin
+
+ val query = "SELECT c, d FROM T3"
+
+ tableEnv.sqlUpdate(sourceDDL)
+ tableEnv.sqlUpdate(sinkDDL)
+ tableEnv.sqlUpdate(viewDDL)
+ tableEnv.sqlUpdate(viewDDL)
+
+ val result = tableEnv.sqlQuery(query)
+ result.insertInto("T2")
+ execJob("testJob")
+ assertEquals(sourceData.sorted, TestCollectionTableFactory.RESULT.sorted)
+ }
+
+ @Test
+ def testCreateTemporaryViewIfNotExistsTwice(): Unit = {
Review comment:
Will add a case with `select *`
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services