flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] twalthr commented on a change in pull request #6815: [FLINK-7062][cep][table] Added basic support for MATCH_RECOGNIZE
Date Thu, 18 Oct 2018 08:01:34 GMT
twalthr commented on a change in pull request #6815:  [FLINK-7062][cep][table] Added basic
support for MATCH_RECOGNIZE
URL: https://github.com/apache/flink/pull/6815#discussion_r226190729
 
 

 ##########
 File path: flink-libraries/flink-table/src/test/scala/org/apache/flink/table/match/PatternTranslatorTestBase.scala
 ##########
 @@ -0,0 +1,164 @@
+/*
+ * 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.`match`
+
+import com.google.common.collect.ImmutableList
+import org.apache.calcite.plan.hep.{HepMatchOrder, HepPlanner, HepProgramBuilder}
+import org.apache.calcite.sql2rel.RelDecorrelator
+import org.apache.calcite.tools.{Programs, RelBuilder}
+import org.apache.flink.api.common.typeinfo.{BasicTypeInfo, TypeInformation}
+import org.apache.flink.api.java.typeutils.RowTypeInfo
+import org.apache.flink.cep.pattern.Pattern
+import org.apache.flink.streaming.api.datastream.{DataStream => JDataStream}
+import org.apache.flink.streaming.api.scala.{DataStream, StreamExecutionEnvironment}
+import org.apache.flink.table.api.scala._
+import org.apache.flink.table.api.{TableConfig, TableEnvironment}
+import org.apache.flink.table.calcite.FlinkPlannerImpl
+import org.apache.flink.table.plan.nodes.FlinkConventions
+import org.apache.flink.table.plan.nodes.datastream.{DataStreamMatch, DataStreamScan, PatternVisitor}
+import org.apache.flink.table.plan.rules.FlinkRuleSets
+import org.apache.flink.types.Row
+import org.apache.flink.util.TestLogger
+import org.junit.Assert._
+import org.junit.rules.ExpectedException
+import org.junit.{ComparisonFailure, Rule}
+import org.mockito.Mockito.{mock, when}
+
+class PatternTranslatorTestBase extends TestLogger{
+
+  private val typeInfo = new RowTypeInfo(BasicTypeInfo.INT_TYPE_INFO)
+
+  private val expectedException = ExpectedException.none()
+
+  @Rule
+  def thrown: ExpectedException = expectedException
+
+  // setup test utils
+  private val tableName = "testTable"
+  private val context = prepareContext(typeInfo)
+  private val planner = new FlinkPlannerImpl(
+    context._2.getFrameworkConfig,
+    context._2.getPlanner,
+    context._2.getTypeFactory)
+  private val logicalOptProgram = Programs.ofRules(FlinkRuleSets.LOGICAL_OPT_RULES)
+  private val dataStreamOptProgram = Programs.ofRules(FlinkRuleSets.DATASTREAM_OPT_RULES)
+
+  private def hepPlanner = {
+    val builder = new HepProgramBuilder
+    builder.addMatchOrder(HepMatchOrder.BOTTOM_UP)
+    val it = FlinkRuleSets.DATASTREAM_NORM_RULES.iterator()
+    while (it.hasNext) {
+      builder.addRuleInstance(it.next())
+    }
+    new HepPlanner(builder.build, context._2.getFrameworkConfig.getContext)
+  }
+
+  private def prepareContext(typeInfo: TypeInformation[Row])
+  : (RelBuilder, TableEnvironment, StreamExecutionEnvironment) = {
+    // create DataSetTable
+    val dataStreamMock = mock(classOf[DataStream[Row]])
+    val jDataStreamMock = mock(classOf[JDataStream[Row]])
+    when(dataStreamMock.javaStream).thenReturn(jDataStreamMock)
+    when(jDataStreamMock.getType).thenReturn(typeInfo)
+
+    val env = StreamExecutionEnvironment.getExecutionEnvironment
+    val tEnv = TableEnvironment.getTableEnvironment(env)
+    tEnv.registerDataStream(tableName, dataStreamMock, 'f0, 'proctime.proctime)
+
+    // prepare RelBuilder
+    val relBuilder = tEnv.getRelBuilder
+    relBuilder.scan(tableName)
+
+    (relBuilder, tEnv, env)
+  }
+
+  def verifyPattern(matchRecognize: String, expected: Pattern[Row, _ <: Row]): Unit =
{
+    // create RelNode from SQL expression
+    val parsed = planner.parse(
+      s"""
+         |SELECT *
+         |FROM $tableName
+         |$matchRecognize
+         |""".stripMargin)
+    val validated = planner.validate(parsed)
+    val converted = planner.rel(validated).rel
+
+    val decorPlan = RelDecorrelator.decorrelateQuery(converted)
+
+    // normalize
+    val normalizedPlan = if (FlinkRuleSets.DATASET_NORM_RULES.iterator().hasNext) {
 
 Review comment:
   You copied a lot of code from `ExpressionTestBase`. However, please check again what you
copied because "data set" parts are still in this class. #6776 refactored the test base so
we should also simplify the code accordingly.

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


With regards,
Apache Git Services

Mime
View raw message