From issues-return-234049-archive-asf-public=cust-asf.ponee.io@spark.apache.org Fri Aug 16 21:20:04 2019 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 [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id 2B61118057A for ; Fri, 16 Aug 2019 23:20:04 +0200 (CEST) Received: (qmail 54077 invoked by uid 500); 16 Aug 2019 21:20:02 -0000 Mailing-List: contact issues-help@spark.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list issues@spark.apache.org Received: (qmail 53988 invoked by uid 99); 16 Aug 2019 21:20:02 -0000 Received: from mailrelay1-us-west.apache.org (HELO mailrelay1-us-west.apache.org) (209.188.14.139) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 16 Aug 2019 21:20:02 +0000 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 0A078E3066 for ; Fri, 16 Aug 2019 21:20:01 +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 643D0277B2 for ; Fri, 16 Aug 2019 21:20:00 +0000 (UTC) Date: Fri, 16 Aug 2019 21:20:00 +0000 (UTC) From: "Liang-Chi Hsieh (JIRA)" To: issues@spark.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Comment Edited] (SPARK-28732) org.apache.spark.sql.catalyst.expressions.codegen.CodeGenerator - failed to compile: org.codehaus.commons.compiler.CompileException: File 'generated.java' when storing the result of a count aggregation in an integer MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/SPARK-28732?page=3Dcom.atlassia= n.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=3D169= 09409#comment-16909409 ]=20 Liang-Chi Hsieh edited comment on SPARK-28732 at 8/16/19 9:19 PM: ------------------------------------------------------------------ As {{count}} return type is LongType, I think it is reasonable that it can'= t be fit into an Int column. The problem here might be the error is not fri= endly. Normally, if we want to map dataset to specified type, an exception like th= is should be thrown, if it is incompatible: {code} org.apache.spark.sql.AnalysisException: Cannot up cast `b` from bigint to i= nt. = =20 The type path of the target object is: = = =20 - field (class: "scala.Int", name: "b") = =20 - root class: "Test" =20 You can either add an explicit cast to the input data or choose a higher pr= ecision type of the field in the target object; = =20 at org.apache.spark.sql.catalyst.analysis.Analyzer$ResolveUpCast$.org$apa= che$spark$sql$catalyst$analysis$Analyzer$ResolveUpCast$$fail(Analyzer.scala= :2801) =20 at org.apache.spark.sql.catalyst.analysis.Analyzer$ResolveUpCast$$anonfun= $apply$32$$anonfun$applyOrElse$143.applyOrElse(Analyzer.scala:2821) = =20 at org.apache.spark.sql.catalyst.analysis.Analyzer$ResolveUpCast$$anonfun= $apply$32$$anonfun$applyOrElse$143.applyOrElse(Analyzer.scala:2812) = =20 {code} was (Author: viirya): As {{count}} return type is LongType, I think it is reasonable that it can'= t be fit into an Int column. The problem here might be the error is not fri= endly. Normally, if we want to map dataset to specified type, an exception like th= is should be thrown, if it is incompatible: {code} You can either add an explicit cast to the input data or choose a higher pr= ecision type of the field in the target object; = =20 at org.apache.spark.sql.catalyst.analysis.Analyzer$ResolveUpCast$.org$apa= che$spark$sql$catalyst$analysis$Analyzer$ResolveUpCast$$fail(Analyzer.scala= :2801) =20 at org.apache.spark.sql.catalyst.analysis.Analyzer$ResolveUpCast$$anonfun= $apply$32$$anonfun$applyOrElse$143.applyOrElse(Analyzer.scala:2821) = =20 at org.apache.spark.sql.catalyst.analysis.Analyzer$ResolveUpCast$$anonfun= $apply$32$$anonfun$applyOrElse$143.applyOrElse(Analyzer.scala:2812) = =20 {code} > org.apache.spark.sql.catalyst.expressions.codegen.CodeGenerator - failed = to compile: org.codehaus.commons.compiler.CompileException: File 'generated= .java' when storing the result of a count aggregation in an integer > -------------------------------------------------------------------------= ---------------------------------------------------------------------------= ------------------------------------------------------------------- > > Key: SPARK-28732 > URL: https://issues.apache.org/jira/browse/SPARK-28732 > Project: Spark > Issue Type: Bug > Components: SQL > Affects Versions: 2.1.0, 2.2.0, 2.3.0, 2.4.0 > Reporter: Alix M=C3=A9tivier > Priority: Major > > I am using agg function on a dataset, and i want to count the number of l= ines upon grouping columns. I would like to store the result of this count = in an integer, but it fails with this output :=C2=A0 > {code} > [ERROR]: org.apache.spark.sql.catalyst.expressions.codegen.CodeGenerator = - failed to compile: org.codehaus.commons.compiler.CompileException: File '= generated.java', Line 89, Column 53: No applicable constructor/method found= for actual parameters "long"; candidates are: "java.lang.Integer(int)", "j= ava.lang.Integer(java.lang.String)" > Here is the line 89 and a few others to understand : > /* 085 */ long value13 =3D i.getLong(5); > /* 086 */ argValue4 =3D value13; > /* 087 */ > /* 088 */ > /* 089 */ final java.lang.Integer value12 =3D false ? null : new java.la= ng.Integer(argValue4); > {code} > =C2=A0 > As per Integer documentation, there is not constructor for the type Long,= so this is why the generated code fails. > Here is my code :=C2=A0 > {code} > org.apache.spark.sql.Dataset ds_row2 =3D ds_conntAggregateRow= _1_Out_1 > .groupBy(org.apache.spark.sql.functions.col("n_name").as("n_nameN"), > org.apache.spark.sql.functions.col("o_year").as("o_yearN")) > .agg(org.apache.spark.sql.functions.count("n_name").as("countN"), > .as(org.apache.spark.sql.Encoders.bean(row2Struct.class)); > {code} > row2Struct=C2=A0class is composed of=C2=A0n_nameN: String,=C2=A0o_yearN: = String,=C2=A0countN: Int > If=C2=A0countN is a Long, code above wont fail > If it is an Int, it works in 1.6 and 2.0, but fails on version 2.1+ > =C2=A0 -- This message was sent by Atlassian JIRA (v7.6.14#76016) --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscribe@spark.apache.org For additional commands, e-mail: issues-help@spark.apache.org