wuchong commented on a change in pull request #8109: 
[FLINK-12017][table-planner-blink] Support translation from Rank/Deduplicate to 
StreamTransformation
URL: https://github.com/apache/flink/pull/8109#discussion_r275105065
 
 

 ##########
 File path: 
flink-table/flink-table-planner-blink/src/test/scala/org/apache/flink/table/runtime/utils/StreamingWithStateTestBase.scala
 ##########
 @@ -0,0 +1,271 @@
+/*
+ * 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.runtime.utils
+
+import org.apache.flink.api.common.restartstrategy.RestartStrategies
+import org.apache.flink.api.common.typeinfo.TypeInformation
+import org.apache.flink.api.common.typeutils.CompositeType
+import org.apache.flink.configuration.{CheckpointingOptions, Configuration}
+import org.apache.flink.runtime.state.memory.MemoryStateBackend
+import org.apache.flink.streaming.api.CheckpointingMode
+import org.apache.flink.streaming.api.functions.source.FromElementsFunction
+import org.apache.flink.streaming.api.scala.DataStream
+import org.apache.flink.table.api.{TableEnvironment, Types}
+import org.apache.flink.table.dataformat.{BaseRow, BinaryRow, BinaryRowWriter, 
BinaryString}
+import 
org.apache.flink.table.runtime.utils.StreamingWithStateTestBase.{HEAP_BACKEND, 
ROCKSDB_BACKEND, StateBackendMode}
+import 
org.apache.flink.table.`type`.TypeConverters.createInternalTypeFromTypeInfo
+import org.apache.flink.table.`type`.RowType
+
+import scala.collection.JavaConversions._
+import scala.collection.mutable
+import scala.collection.mutable.ArrayBuffer
+
+import java.io.File
+import java.util
+
+import org.junit.runners.Parameterized
+import org.junit.{After, Assert, Before}
+
+import org.apache.flink.contrib.streaming.state.RocksDBStateBackend
+
+class StreamingWithStateTestBase(state: StateBackendMode) extends 
StreamingTestBase {
+
+  enableObjectReuse = state match {
+    case HEAP_BACKEND => false // TODO gemini not support obj reuse now.
+    case ROCKSDB_BACKEND => true
+  }
+
+  private val classLoader = Thread.currentThread.getContextClassLoader
+
+  var baseCheckpointPath: File = _
+
+  @Before
+  override def before(): Unit = {
+    super.before()
+    // set state backend
+    baseCheckpointPath = tempFolder.newFolder().getAbsoluteFile
+    state match {
+      case HEAP_BACKEND =>
+        val conf = new Configuration()
+        conf.setBoolean(CheckpointingOptions.ASYNC_SNAPSHOTS, true)
+        env.setStateBackend(new MemoryStateBackend(
+          "file://" + baseCheckpointPath, null).configure(conf, classLoader))
+      case ROCKSDB_BACKEND =>
+        val conf = new Configuration()
+        conf.setBoolean(CheckpointingOptions.INCREMENTAL_CHECKPOINTS, true)
+        env.setStateBackend(new RocksDBStateBackend(
+          "file://" + baseCheckpointPath).configure(conf, classLoader))
+    }
+    this.tEnv = TableEnvironment.getTableEnvironment(env)
+    FailingCollectionSource.failedBefore = true
+  }
+
+  @After
+  def after(): Unit = {
+    Assert.assertTrue(FailingCollectionSource.failedBefore)
+  }
+
+  /**
+    * Creates a BinaryRow DataStream from the given non-empty [[Seq]].
+    */
+  def failingBinaryRowSource[T: TypeInformation](data: Seq[T]): 
DataStream[BaseRow] = {
+    val typeInfo = 
implicitly[TypeInformation[_]].asInstanceOf[CompositeType[_]]
+    val result = new mutable.MutableList[BaseRow]
+    val reuse = new BinaryRow(typeInfo.getArity)
+    val writer = new BinaryRowWriter(reuse)
+    data.foreach {
+      case p: Product =>
+        for (i <- 0 until typeInfo.getArity) {
+          val fieldType = 
typeInfo.getTypeAt(i).asInstanceOf[TypeInformation[_]]
+          fieldType match {
+            case Types.INT => writer.writeInt(i, 
p.productElement(i).asInstanceOf[Int])
+            case Types.LONG => writer.writeLong(i, 
p.productElement(i).asInstanceOf[Long])
+            case Types.STRING => writer.writeString(i,
+              p.productElement(i).asInstanceOf[BinaryString])
+            case Types.BOOLEAN => writer.writeBoolean(i, 
p.productElement(i).asInstanceOf[Boolean])
+          }
+        }
+        writer.complete()
+        result += reuse.copy()
+      case _ => throw new UnsupportedOperationException
+    }
+    val newTypeInfo = 
createInternalTypeFromTypeInfo(typeInfo).asInstanceOf[RowType].toTypeInfo
+    
failingDataSource(result)(newTypeInfo.asInstanceOf[TypeInformation[BaseRow]])
+  }
+
+  /**
+    * Creates a DataStream from the given non-empty [[Seq]].
+    */
+  def retainStateDataSource[T: TypeInformation](data: Seq[T]): DataStream[T] = 
{
 
 Review comment:
   Currently, this is not used. We can remove this method,  and add it when we 
need it.

----------------------------------------------------------------
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

Reply via email to