Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id AFC16200CA3 for ; Wed, 3 May 2017 01:40:09 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id AE766160BC5; Tue, 2 May 2017 23:40:09 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id CE221160BAC for ; Wed, 3 May 2017 01:40:08 +0200 (CEST) Received: (qmail 28795 invoked by uid 500); 2 May 2017 23:40:08 -0000 Mailing-List: contact issues-help@flink.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@flink.apache.org Delivered-To: mailing list issues@flink.apache.org Received: (qmail 28786 invoked by uid 99); 2 May 2017 23:40:08 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 May 2017 23:40:08 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 0C7C3C05A7 for ; Tue, 2 May 2017 23:40:07 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -100.001 X-Spam-Level: X-Spam-Status: No, score=-100.001 tagged_above=-999 required=6.31 tests=[RP_MATCHES_RCVD=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id 2HdS9jWF7zFV for ; Tue, 2 May 2017 23:40:05 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id D3EEF5FC96 for ; Tue, 2 May 2017 23:40:05 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 514D9E0905 for ; Tue, 2 May 2017 23:40:05 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 852B221DED for ; Tue, 2 May 2017 23:40:04 +0000 (UTC) Date: Tue, 2 May 2017 23:40:04 +0000 (UTC) From: "ASF GitHub Bot (JIRA)" To: issues@flink.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (FLINK-5906) Add support to register UDAGG in Table and SQL API MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Tue, 02 May 2017 23:40:09 -0000 [ https://issues.apache.org/jira/browse/FLINK-5906?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15994026#comment-15994026 ] ASF GitHub Bot commented on FLINK-5906: --------------------------------------- Github user fhueske commented on a diff in the pull request: https://github.com/apache/flink/pull/3809#discussion_r114449859 --- Diff: flink-libraries/flink-table/src/test/scala/org/apache/flink/table/api/scala/stream/table/DStreamUDAGGITCase.scala --- @@ -0,0 +1,309 @@ +/* + * 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.api.scala.stream.table + +import java.math.BigDecimal + +import org.apache.flink.api.java.typeutils.RowTypeInfo +import org.apache.flink.api.scala._ +import org.apache.flink.streaming.api.functions.AssignerWithPunctuatedWatermarks +import org.apache.flink.streaming.api.scala.StreamExecutionEnvironment +import org.apache.flink.streaming.api.TimeCharacteristic +import org.apache.flink.table.utils.TableTestBase +import org.apache.flink.streaming.api.datastream.{DataStream => JDataStream} +import org.apache.flink.streaming.api.environment.{StreamExecutionEnvironment => JavaExecutionEnv} +import org.apache.flink.streaming.api.scala.{DataStream, StreamExecutionEnvironment => ScalaExecutionEnv} +import org.apache.flink.streaming.api.watermark.Watermark +import org.apache.flink.table.api.java.utils.UserDefinedAggFunctions.{WeightedAvg, WeightedAvgWithMerge, WeightedAvgWithRetract} +import org.apache.flink.table.api.scala._ +import org.apache.flink.table.api.scala.stream.table.DStreamUDAGGITCase.TimestampAndWatermarkWithOffset +import org.apache.flink.table.api.scala.stream.utils.StreamITCase +import org.apache.flink.table.api.{SlidingWindow, TableEnvironment, Types} +import org.apache.flink.streaming.util.StreamingMultipleProgramsTestBase +import org.apache.flink.table.functions.aggfunctions.CountAggFunction +import org.apache.flink.types.Row +import org.junit.Assert._ +import org.junit.Test +import org.mockito.Mockito.{mock, when} + +import scala.collection.mutable + +/** + * We only test some aggregations until better testing of constructed DataStream + * programs is possible. + */ +class DStreamUDAGGITCase + extends StreamingMultipleProgramsTestBase { + + val data = List( + //('long, 'int, 'double, 'float, 'bigdec, 'string) + (1000L, 1, 1d, 1f, new BigDecimal("1"), "Hello"), + (2000L, 2, 2d, 2f, new BigDecimal("2"), "Hello"), + (3000L, 3, 3d, 3f, new BigDecimal("3"), "Hello"), + (5000L, 5, 5d, 5f, new BigDecimal("5"), "Hi"), + (6000L, 6, 6d, 6f, new BigDecimal("6"), "Hi"), + (7000L, 7, 7d, 7f, new BigDecimal("7"), "Hi"), + (8000L, 8, 8d, 8f, new BigDecimal("8"), "Hello"), + (9000L, 9, 9d, 9f, new BigDecimal("9"), "Hello"), + (4000L, 4, 4d, 4f, new BigDecimal("4"), "Hello"), + (10000L, 10, 10d, 10f, new BigDecimal("10"), "Hi"), + (11000L, 11, 11d, 11f, new BigDecimal("11"), "Hi"), + (12000L, 12, 12d, 12f, new BigDecimal("12"), "Hi"), + (16000L, 16, 16d, 16f, new BigDecimal("16"), "Hello")) + + @Test + def testUdaggSlidingWindowGroupedAggregate(): Unit = { + val env = StreamExecutionEnvironment.getExecutionEnvironment + env.setParallelism(1) + val tEnv = TableEnvironment.getTableEnvironment(env) + StreamITCase.testResults = mutable.MutableList() + + val stream = env.fromCollection(data).map(t => (t._1, t._2, t._3, t._4, t._6)) + val table = stream.toTable(tEnv, 'long, 'int, 'double, 'float, 'string) + + val countFun = new CountAggFunction + + val weightAvgFun = new WeightedAvg + + val windowedTable = table + .window(Slide over 4.rows every 2.rows as 'w) + .groupBy('w, 'string) + .select( + 'string, + countFun('float), + 'double.sum, + weightAvgFun('long, 'int), + weightAvgFun('int, 'int)) + + val results = windowedTable.toDataStream[Row] + results.addSink(new StreamITCase.StringSink) + env.execute() + + val expected = Seq( + "Hello,2,3.0,1666,1", "Hi,2,11.0,5545,5", "Hello,4,14.0,5571,5", + "Hello,4,24.0,7083,7", "Hi,4,28.0,7500,7", "Hi,4,40.0,10350,10") + assertEquals(expected, StreamITCase.testResults) + } + + @Test + def testUdaggSessionWindowGroupedAggregate(): Unit = { + val env = StreamExecutionEnvironment.getExecutionEnvironment + env.setStreamTimeCharacteristic(TimeCharacteristic.EventTime) + env.setParallelism(1) + val tEnv = TableEnvironment.getTableEnvironment(env) + StreamITCase.testResults = mutable.MutableList() + + val countFun = new CountAggFunction + + val weightAvgWithMergeFun = new WeightedAvgWithMerge + + val stream = env + .fromCollection(data) + .assignTimestampsAndWatermarks(new TimestampAndWatermarkWithOffset(10000)) --- End diff -- use `.assignAscendingTimestamps(_._1)` instead? > Add support to register UDAGG in Table and SQL API > -------------------------------------------------- > > Key: FLINK-5906 > URL: https://issues.apache.org/jira/browse/FLINK-5906 > Project: Flink > Issue Type: Sub-task > Components: Table API & SQL > Reporter: Fabian Hueske > Assignee: Shaoxuan Wang > -- This message was sent by Atlassian JIRA (v6.3.15#6346)