[jira] [Commented] (SPARK-9435) Java UDFs don't work with GROUP BY expressions
[ https://issues.apache.org/jira/browse/SPARK-9435?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15819117#comment-15819117 ] Apache Spark commented on SPARK-9435: - User 'HyukjinKwon' has created a pull request for this issue: https://github.com/apache/spark/pull/16553 > Java UDFs don't work with GROUP BY expressions > -- > > Key: SPARK-9435 > URL: https://issues.apache.org/jira/browse/SPARK-9435 > Project: Spark > Issue Type: Bug > Components: SQL >Affects Versions: 1.4.1 > Environment: All >Reporter: James Aley > Attachments: IncMain.java, points.txt > > > If you define a UDF in Java, for example by implementing the UDF1 interface, > then try to use that UDF on a column in both the SELECT and GROUP BY clauses > of a query, you'll get an error like this: > {code} > "SELECT inc(y),COUNT(DISTINCT x) FROM test_table GROUP BY inc(y)" > org.apache.spark.sql.AnalysisException: expression 'y' is neither present in > the group by, nor is it an aggregate function. Add to group by or wrap in > first() if you don't care which value you get. > {code} > We put together a minimal reproduction in the attached Java file, which makes > use of the data in the text file attached. > I'm guessing there's some kind of issue with the equality implementation, so > Spark can't tell that those two expressions are the same maybe? If you do the > same thing from Scala, it works fine. > Note for context: we ran into this issue while working around SPARK-9338. -- This message was sent by Atlassian JIRA (v6.3.4#6332) - To unsubscribe, e-mail: issues-unsubscr...@spark.apache.org For additional commands, e-mail: issues-h...@spark.apache.org
[jira] [Commented] (SPARK-9435) Java UDFs don't work with GROUP BY expressions
[ https://issues.apache.org/jira/browse/SPARK-9435?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15813832#comment-15813832 ] Hyukjin Kwon commented on SPARK-9435: - This sill happens in the current master - {code} val df = Seq((1, 10), (2, 11), (3, 12)).toDF("x", "y") val udf = new UDF1[Int, Int] { override def call(i: Int): Int = i + 1 } spark.udf.register("inc", udf, IntegerType) df.createOrReplaceTempView("tmp") spark.sql("SELECT inc(y) FROM tmp GROUP BY inc(y)").show() {code} I tested both Scala and Java ones. and I believe the above one is simpler Scala one to reproduce the same issue. > Java UDFs don't work with GROUP BY expressions > -- > > Key: SPARK-9435 > URL: https://issues.apache.org/jira/browse/SPARK-9435 > Project: Spark > Issue Type: Bug > Components: SQL >Affects Versions: 1.4.1 > Environment: All >Reporter: James Aley > Attachments: IncMain.java, points.txt > > > If you define a UDF in Java, for example by implementing the UDF1 interface, > then try to use that UDF on a column in both the SELECT and GROUP BY clauses > of a query, you'll get an error like this: > {code} > "SELECT inc(y),COUNT(DISTINCT x) FROM test_table GROUP BY inc(y)" > org.apache.spark.sql.AnalysisException: expression 'y' is neither present in > the group by, nor is it an aggregate function. Add to group by or wrap in > first() if you don't care which value you get. > {code} > We put together a minimal reproduction in the attached Java file, which makes > use of the data in the text file attached. > I'm guessing there's some kind of issue with the equality implementation, so > Spark can't tell that those two expressions are the same maybe? If you do the > same thing from Scala, it works fine. > Note for context: we ran into this issue while working around SPARK-9338. -- This message was sent by Atlassian JIRA (v6.3.4#6332) - To unsubscribe, e-mail: issues-unsubscr...@spark.apache.org For additional commands, e-mail: issues-h...@spark.apache.org
[jira] [Commented] (SPARK-9435) Java UDFs don't work with GROUP BY expressions
[ https://issues.apache.org/jira/browse/SPARK-9435?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15001866#comment-15001866 ] DOAN DuyHai commented on SPARK-9435: Same error for me: {code:java} // Register computeDecade() as a SparkSQL function sqlContext.udf().register("computeDecade", (Integer year) -> computeDecade(year), DataTypes.StringType); final List albums = Arrays.asList(new Album(2000, "1"), new Album(2000, "2"), new Album(2000, "3")); final JavaRDD rdd = javaSc.parallelize(albums); final DataFrame df = sqlContext.createDataFrame(rdd, Album.class); df.registerTempTable("albums"); final DataFrame dataFrame = sqlContext.sql("SELECT computeDecade(year),count(title) "+ " FROM albums " + " GROUP BY computeDecade(year)"); {code} > Java UDFs don't work with GROUP BY expressions > -- > > Key: SPARK-9435 > URL: https://issues.apache.org/jira/browse/SPARK-9435 > Project: Spark > Issue Type: Bug > Components: SQL >Affects Versions: 1.4.1 > Environment: All >Reporter: James Aley > Attachments: IncMain.java, points.txt > > > If you define a UDF in Java, for example by implementing the UDF1 interface, > then try to use that UDF on a column in both the SELECT and GROUP BY clauses > of a query, you'll get an error like this: > {code} > "SELECT inc(y),COUNT(DISTINCT x) FROM test_table GROUP BY inc(y)" > org.apache.spark.sql.AnalysisException: expression 'y' is neither present in > the group by, nor is it an aggregate function. Add to group by or wrap in > first() if you don't care which value you get. > {code} > We put together a minimal reproduction in the attached Java file, which makes > use of the data in the text file attached. > I'm guessing there's some kind of issue with the equality implementation, so > Spark can't tell that those two expressions are the same maybe? If you do the > same thing from Scala, it works fine. > Note for context: we ran into this issue while working around SPARK-9338. -- This message was sent by Atlassian JIRA (v6.3.4#6332) - To unsubscribe, e-mail: issues-unsubscr...@spark.apache.org For additional commands, e-mail: issues-h...@spark.apache.org
[jira] [Commented] (SPARK-9435) Java UDFs don't work with GROUP BY expressions
[ https://issues.apache.org/jira/browse/SPARK-9435?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15002126#comment-15002126 ] DOAN DuyHai commented on SPARK-9435: Work-around: *define the UDF using the Scala API instead* {code:java} public static final class ComputeDecadeFn extends AbstractFunction1implements Serializable { @Override public String apply(Integer year) { return computeDecade(year); } } sqlContext.udf().register("computeDecade", new ComputeDecadeFn(), JavaApiHelper.getTypeTag(String.class), JavaApiHelper.getTypeTag(Integer.class)); {code} You cannot use the lambda expression because the UDF function should be serializable. > Java UDFs don't work with GROUP BY expressions > -- > > Key: SPARK-9435 > URL: https://issues.apache.org/jira/browse/SPARK-9435 > Project: Spark > Issue Type: Bug > Components: SQL >Affects Versions: 1.4.1 > Environment: All >Reporter: James Aley > Attachments: IncMain.java, points.txt > > > If you define a UDF in Java, for example by implementing the UDF1 interface, > then try to use that UDF on a column in both the SELECT and GROUP BY clauses > of a query, you'll get an error like this: > {code} > "SELECT inc(y),COUNT(DISTINCT x) FROM test_table GROUP BY inc(y)" > org.apache.spark.sql.AnalysisException: expression 'y' is neither present in > the group by, nor is it an aggregate function. Add to group by or wrap in > first() if you don't care which value you get. > {code} > We put together a minimal reproduction in the attached Java file, which makes > use of the data in the text file attached. > I'm guessing there's some kind of issue with the equality implementation, so > Spark can't tell that those two expressions are the same maybe? If you do the > same thing from Scala, it works fine. > Note for context: we ran into this issue while working around SPARK-9338. -- This message was sent by Atlassian JIRA (v6.3.4#6332) - To unsubscribe, e-mail: issues-unsubscr...@spark.apache.org For additional commands, e-mail: issues-h...@spark.apache.org
[jira] [Commented] (SPARK-9435) Java UDFs don't work with GROUP BY expressions
[ https://issues.apache.org/jira/browse/SPARK-9435?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=14992633#comment-14992633 ] Utkarsh Sengar commented on SPARK-9435: --- I am running into this problem too. Query: sqlContext.sql("SELECT properties.time FROM allEvents WHERE event='abc' AND isSingleSearch(properties.ids) GROUP BY listToSingleId(properties.ids)") UDF: sqlContext.udf.register("listToSingleId", (ids : List[Long]) => ids(0)) Trying the nested select now, but is this a bug or expected outcome when using UDF with group by? > Java UDFs don't work with GROUP BY expressions > -- > > Key: SPARK-9435 > URL: https://issues.apache.org/jira/browse/SPARK-9435 > Project: Spark > Issue Type: Bug > Components: SQL >Affects Versions: 1.4.1 > Environment: All >Reporter: James Aley > Attachments: IncMain.java, points.txt > > > If you define a UDF in Java, for example by implementing the UDF1 interface, > then try to use that UDF on a column in both the SELECT and GROUP BY clauses > of a query, you'll get an error like this: > {code} > "SELECT inc(y),COUNT(DISTINCT x) FROM test_table GROUP BY inc(y)" > org.apache.spark.sql.AnalysisException: expression 'y' is neither present in > the group by, nor is it an aggregate function. Add to group by or wrap in > first() if you don't care which value you get. > {code} > We put together a minimal reproduction in the attached Java file, which makes > use of the data in the text file attached. > I'm guessing there's some kind of issue with the equality implementation, so > Spark can't tell that those two expressions are the same maybe? If you do the > same thing from Scala, it works fine. > Note for context: we ran into this issue while working around SPARK-9338. -- This message was sent by Atlassian JIRA (v6.3.4#6332) - To unsubscribe, e-mail: issues-unsubscr...@spark.apache.org For additional commands, e-mail: issues-h...@spark.apache.org
[jira] [Commented] (SPARK-9435) Java UDFs don't work with GROUP BY expressions
[ https://issues.apache.org/jira/browse/SPARK-9435?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=14735416#comment-14735416 ] Michael Armbrust commented on SPARK-9435: - >From a quick glance, the problem is likely that the {{equals}} function on >Java UDFs is working correctly. As a workaround you could probably calculate >the udf in a nested select. > Java UDFs don't work with GROUP BY expressions > -- > > Key: SPARK-9435 > URL: https://issues.apache.org/jira/browse/SPARK-9435 > Project: Spark > Issue Type: Bug > Components: SQL >Affects Versions: 1.4.1 > Environment: All >Reporter: James Aley > Attachments: IncMain.java, points.txt > > > If you define a UDF in Java, for example by implementing the UDF1 interface, > then try to use that UDF on a column in both the SELECT and GROUP BY clauses > of a query, you'll get an error like this: > {code} > "SELECT inc(y),COUNT(DISTINCT x) FROM test_table GROUP BY inc(y)" > org.apache.spark.sql.AnalysisException: expression 'y' is neither present in > the group by, nor is it an aggregate function. Add to group by or wrap in > first() if you don't care which value you get. > {code} > We put together a minimal reproduction in the attached Java file, which makes > use of the data in the text file attached. > I'm guessing there's some kind of issue with the equality implementation, so > Spark can't tell that those two expressions are the same maybe? If you do the > same thing from Scala, it works fine. > Note for context: we ran into this issue while working around SPARK-9338. -- This message was sent by Atlassian JIRA (v6.3.4#6332) - To unsubscribe, e-mail: issues-unsubscr...@spark.apache.org For additional commands, e-mail: issues-h...@spark.apache.org