wuchong commented on a change in pull request #8844: [FLINK-12951][table-planner] Add logic to bridge DDL to table source(… URL: https://github.com/apache/flink/pull/8844#discussion_r300266422
########## File path: flink-table/flink-table-planner/src/test/scala/org/apache/flink/table/catalog/CatalogTableITCase.scala ########## @@ -0,0 +1,450 @@ +/* + * 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.catalog + +import org.apache.flink.api.scala.ExecutionEnvironment +import org.apache.flink.streaming.api.scala.StreamExecutionEnvironment +import org.apache.flink.table.api.TableEnvironment +import org.apache.flink.table.api.scala.{BatchTableEnvironment, StreamTableEnvironment} +import org.apache.flink.table.factories.utils.TestCollectionTableFactory +import org.apache.flink.types.Row + +import org.junit.Assert.assertEquals +import org.junit.runner.RunWith +import org.junit.runners.Parameterized +import org.junit.{Before, Ignore, Test} + +import java.util + +import scala.collection.JavaConversions._ + +/** Test cases for catalog table. */ +@RunWith(classOf[Parameterized]) +class CatalogTableITCase(isStreaming: Boolean) { + + private val batchExec: ExecutionEnvironment = ExecutionEnvironment.getExecutionEnvironment + private var batchEnv: BatchTableEnvironment = _ + private val streamExec: StreamExecutionEnvironment = StreamExecutionEnvironment + .getExecutionEnvironment + private var streamEnv: StreamTableEnvironment = _ + + private val SOURCE_DATA = List( + toRow(1, "a"), + toRow(2, "b"), + toRow(3, "c") + ) + + private val DIM_DATA = List( + toRow(1, "aDim"), + toRow(2, "bDim"), + toRow(3, "cDim") + ) + + implicit def rowOrdering: Ordering[Row] = Ordering.by((r : Row) => { + val builder = new StringBuilder + 0 until r.getArity foreach(idx => builder.append(r.getField(idx))) + builder.toString() + }) + + @Before + def before(): Unit = { + batchExec.setParallelism(4) + streamExec.setParallelism(4) + batchEnv = BatchTableEnvironment.create(batchExec) + streamEnv = StreamTableEnvironment.create(streamExec) + TestCollectionTableFactory.reset() + TestCollectionTableFactory.isStreaming = isStreaming + } + + def toRow(args: Any*):Row = { + val row = new Row(args.length) + 0 until args.length foreach { + i => row.setField(i, args(i)) + } + row + } + + def tableEnv: TableEnvironment = { + if (isStreaming) { + streamEnv + } else { + batchEnv + } + } + + def execJob(name: String) = { + if (isStreaming) { + streamExec.execute(name) + } else { + batchExec.execute(name) + } + } + + @Test + def testInsertInto(): Unit = { + val sourceData = List( + toRow(1, "1000", 2), + toRow(2, "1", 3), + toRow(3, "2000", 4), + toRow(1, "2", 2), + toRow(2, "3000", 3) + ) + TestCollectionTableFactory.initData(sourceData) + val sourceDDL = + """ + |create table t1( + | a int, + | b varchar, + | c int + |) with ( + | connector = 'COLLECTION' + |) + """.stripMargin + val sinkDDL = + """ + |create table t2( + | a int, + | b varchar, + | c int + |) with ( + | connector = 'COLLECTION' + |) + """.stripMargin + val query = + """ + |insert into t2 + |select t1.a, t1.b, (t1.a + 1) as c from t1 + """.stripMargin + tableEnv.sql(sourceDDL) + tableEnv.sql(sinkDDL) + tableEnv.sql(query) Review comment: Can we add some tests that covers multiple statements in one sql with ';' delimiter ? Btw, IT cases are very heavy (the community is trying to reduce travis time). I think one for ETL and one for aggregation is enough. We can add some unit tests to verify the plan which is much more lightweight. ---------------------------------------------------------------- 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
