flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fhueske <...@git.apache.org>
Subject [GitHub] flink pull request #3889: [FLINK-6075] - Support Limit/Top(Sort) for Stream ...
Date Fri, 30 Jun 2017 15:16:40 GMT
Github user fhueske commented on a diff in the pull request:

    https://github.com/apache/flink/pull/3889#discussion_r125058944
  
    --- Diff: flink-libraries/flink-table/src/test/scala/org/apache/flink/table/runtime/aggregate/TimeSortProcessFunctionTest.scala
---
    @@ -0,0 +1,256 @@
    +/*
    + * 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.aggregate
    +
    +import java.util.Comparator
    +import java.util.concurrent.ConcurrentLinkedQueue
    +import java.lang.{Integer => JInt, Long => JLong}
    +
    +import org.apache.flink.api.common.typeinfo.BasicTypeInfo._
    +import org.apache.flink.api.common.typeinfo.{BasicTypeInfo, TypeInformation}
    +import org.apache.flink.api.java.functions.KeySelector
    +import org.apache.flink.api.java.typeutils.RowTypeInfo
    +import org.apache.flink.streaming.api.operators.KeyedProcessOperator
    +import org.apache.flink.streaming.api.watermark.Watermark
    +import org.apache.flink.streaming.runtime.streamrecord.StreamRecord
    +import org.apache.flink.streaming.util.{KeyedOneInputStreamOperatorTestHarness, TestHarnessUtil}
    +import org.apache.flink.types.Row
    +import org.junit.Test
    +import org.apache.flink.table.runtime.aggregate.ProcTimeSortProcessFunction
    +import org.apache.flink.table.runtime.aggregate.RowTimeSortProcessFunction
    +import org.apache.flink.table.runtime.aggregate.TimeSortProcessFunctionTest._
    +import org.apache.flink.api.java.typeutils.runtime.RowComparator
    +import org.apache.flink.api.common.typeutils.TypeSerializer
    +import org.apache.flink.api.common.typeutils.TypeComparator
    +import org.apache.flink.table.runtime.types.{CRow, CRowTypeInfo}
    +import org.apache.flink.streaming.api.TimeCharacteristic
    +
    +class TimeSortProcessFunctionTest{
    +
    +  
    +  @Test
    +  def testSortProcTimeHarnessPartitioned(): Unit = {
    +    
    +    val rT =  new RowTypeInfo(Array[TypeInformation[_]](
    +      INT_TYPE_INFO,
    +      LONG_TYPE_INFO,
    +      INT_TYPE_INFO,
    +      STRING_TYPE_INFO,
    +      LONG_TYPE_INFO),
    +      Array("a","b","c","d","e"))
    +    
    +    val rTA =  new RowTypeInfo(Array[TypeInformation[_]](
    +     LONG_TYPE_INFO), Array("count"))
    +    val indexes = Array(1,2)
    +      
    +    val fieldComps = Array[TypeComparator[AnyRef]](
    +      LONG_TYPE_INFO.createComparator(true, null).asInstanceOf[TypeComparator[AnyRef]],
    +      INT_TYPE_INFO.createComparator(false, null).asInstanceOf[TypeComparator[AnyRef]]
)
    +    val booleanOrders = Array(true, false)    
    +    
    +
    +    val rowComp = new RowComparator(
    +      rT.getTotalFields,
    +      indexes,
    +      fieldComps,
    +      new Array[TypeSerializer[AnyRef]](0), //used only for serialized comparisons
    +      booleanOrders)
    +    
    +    val collectionRowComparator = new CollectionRowComparator(rowComp)
    +    
    +    val inputCRowType = CRowTypeInfo(rT)
    +    
    +    val processFunction = new KeyedProcessOperator[Integer,CRow,CRow](
    +      new ProcTimeSortProcessFunction(
    +        inputCRowType,
    +        collectionRowComparator))
    +  
    +   val testHarness = new KeyedOneInputStreamOperatorTestHarness[Integer,CRow,CRow](
    +      processFunction, 
    +      new TupleRowSelector(0), 
    +      BasicTypeInfo.INT_TYPE_INFO)
    +    
    +   testHarness.open();
    +
    +   testHarness.setProcessingTime(3)
    +
    +      // timestamp is ignored in processing time
    +    testHarness.processElement(new StreamRecord(new CRow(
    +      Row.of(1: JInt, 11L: JLong, 1: JInt, "aaa", 11L: JLong), true), 1001))
    +    testHarness.processElement(new StreamRecord(new CRow(
    +        Row.of(1: JInt, 12L: JLong, 1: JInt, "aaa", 11L: JLong), true), 2002))
    +    testHarness.processElement(new StreamRecord(new CRow(
    +        Row.of(1: JInt, 12L: JLong, 2: JInt, "aaa", 11L: JLong), true), 2003))
    +    testHarness.processElement(new StreamRecord(new CRow(
    +        Row.of(1: JInt, 12L: JLong, 0: JInt, "aaa", 11L: JLong), true), 2004))
    +    testHarness.processElement(new StreamRecord(new CRow(
    +        Row.of(1: JInt, 10L: JLong, 0: JInt, "aaa", 11L: JLong), true), 2006))
    +
    +    //move the timestamp to ensure the execution
    +    testHarness.setProcessingTime(1005)
    --- End diff --
    
    I wanted to trigger a sort a second time by adding more data and setting the processing
time another time. Basically, just what you did. Same would have been good for the rowtime
test.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message