From issues-return-184210-archive-asf-public=cust-asf.ponee.io@flink.apache.org Mon Aug 13 21:01:05 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id DF845180629 for ; Mon, 13 Aug 2018 21:01:04 +0200 (CEST) Received: (qmail 46071 invoked by uid 500); 13 Aug 2018 19:01:04 -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 46062 invoked by uid 99); 13 Aug 2018 19:01:04 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 13 Aug 2018 19:01:03 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 3D1AF1808E4 for ; Mon, 13 Aug 2018 19:01:03 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -109.501 X-Spam-Level: X-Spam-Status: No, score=-109.501 tagged_above=-999 required=6.31 tests=[ENV_AND_HDR_SPF_MATCH=-0.5, KAM_ASCII_DIVIDERS=0.8, RCVD_IN_DNSWL_MED=-2.3, SPF_PASS=-0.001, USER_IN_DEF_SPF_WL=-7.5, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id UrvZSAkZLxUT for ; Mon, 13 Aug 2018 19:01:01 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTP id 3D75C5F432 for ; Mon, 13 Aug 2018 19:01:01 +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 70C39E0234 for ; Mon, 13 Aug 2018 19:01:00 +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 317D423F9E for ; Mon, 13 Aug 2018 19:01:00 +0000 (UTC) Date: Mon, 13 Aug 2018 19:01:00 +0000 (UTC) From: "Rong Rong (JIRA)" To: issues@flink.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Comment Edited] (FLINK-10019) Fix Composite getResultType of UDF cannot be chained with other operators MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/FLINK-10019?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16578793#comment-16578793 ] Rong Rong edited comment on FLINK-10019 at 8/13/18 7:00 PM: ------------------------------------------------------------ Dug a little deeper in Calcite and found that in: https://github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/sql/type/InferTypes.java#L68 Seems like if the return type is inferred as a record, or {{isStruct()}}, "it must have the same number of fields as the number of operands." which clearly is not the case here since the following expression: **{{AS(func(a), "myRow")}}** only passes over the **{{func(a)}}** for type inference, but not the alias **{{"myRow"}}** was (Author: walterddr): Dug a little deeper in Calcite and found that in: https://github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/sql/type/InferTypes.java#L68 Seems like if the return type is inferred as a record, or {{isStruct()}}, "it must have the same number of fields as the number of operands." which clearly is not the case here since the following expression: {{AS(func(a), "myRow")}} only passes over the {{func(a)}} for type inference, but not the alias {{"myRow"}} > Fix Composite getResultType of UDF cannot be chained with other operators > ------------------------------------------------------------------------- > > Key: FLINK-10019 > URL: https://issues.apache.org/jira/browse/FLINK-10019 > Project: Flink > Issue Type: Bug > Reporter: Rong Rong > Assignee: Rong Rong > Priority: Major > > If explicitly return a CompositeType in {{udf.getResultType}}, will result in some failures in chained operators. > For example: consider a simple UDF, > {code:scala} > object Func extends ScalarFunction { > def eval(row: Row): Row = { > row > } > override def getParameterTypes(signature: Array[Class[_]]): Array[TypeInformation[_]] = > Array(Types.ROW(Types.INT)) > override def getResultType(signature: Array[Class[_]]): TypeInformation[_] = > Types.ROW(Types.INT) > } > {code} > This should work perfectly since it's just a simple pass through, however > {code:scala} > @Test > def testRowType(): Unit = { > val data = List( > Row.of(Row.of(12.asInstanceOf[Integer]), "1") > ) > val env = StreamExecutionEnvironment.getExecutionEnvironment > val stream = env.fromCollection(data)(Types.ROW(Types.ROW(Types.INT), Types.STRING)) > val tEnv = TableEnvironment.getTableEnvironment(env) > val table = stream.toTable(tEnv, 'a, 'b) > tEnv.registerFunction("func", Func) > tEnv.registerTable("t", table) > // This works perfectly > val result1 = tEnv.sqlQuery("SELECT func(a) FROM t").toAppendStream[Row] > result1.addSink(new StreamITCase.StringSink[Row]) > // This throws exception > val result2 = tEnv.sqlQuery("SELECT func(a) as myRow FROM t").toAppendStream[Row] > result2.addSink(new StreamITCase.StringSink[Row]) > env.execute() > } > {code} > Exception code: > {code:java} > java.lang.IndexOutOfBoundsException: index (1) must be less than size (1) > at com.google.common.base.Preconditions.checkElementIndex(Preconditions.java:310) > at com.google.common.base.Preconditions.checkElementIndex(Preconditions.java:293) > at com.google.common.collect.SingletonImmutableList.get(SingletonImmutableList.java:41) > at org.apache.calcite.sql.type.InferTypes$2.inferOperandTypes(InferTypes.java:83) > at org.apache.calcite.sql.validate.SqlValidatorImpl.inferUnknownTypes(SqlValidatorImpl.java:1777) > at org.apache.calcite.sql.validate.SqlValidatorImpl.expandSelectItem(SqlValidatorImpl.java:459) > at org.apache.calcite.sql.validate.SqlValidatorImpl.expandStar(SqlValidatorImpl.java:349) > ... > {code} > This is due to the fact that Calcite inferOperandTypes does not expect to infer a struct RelDataType. -- This message was sent by Atlassian JIRA (v7.6.3#76005)