-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-8826] [SQL] Fix ClassCastException in GeneratedAggregate #7225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -241,7 +241,7 @@ case class GeneratedAggregate( | |
| child.execute().mapPartitions { iter => | ||
| // Builds a new custom class for holding the results of aggregation for a group. | ||
| val initialValues = computeFunctions.flatMap(_.initialValues) | ||
| val newAggregationBuffer = newProjection(initialValues, child.output) | ||
| val newAggregationBuffer = newProjection(initialValues, child.output, mutableRow = true) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We wrote |
||
| log.info(s"Initial values: ${initialValues.mkString(",")}") | ||
|
|
||
| // A projection that computes the group given an input tuple. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /* | ||
| * 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.spark.sql.execution | ||
|
|
||
| import org.apache.spark.sql.SQLConf | ||
| import org.apache.spark.sql.catalyst.expressions._ | ||
| import org.apache.spark.sql.test.TestSQLContext | ||
| import org.apache.spark.sql.types.DataTypes._ | ||
|
|
||
| class AggregateSuite extends SparkPlanTest { | ||
|
|
||
| test("SPARK-8826 Fix ClassCastException in GeneratedAggregate") { | ||
|
|
||
| // when codegen = false, CCE is thrown if group-by expression is empty or unsafe is disabled | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't the use of
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Basically, I'm wondering if this is a bug. If this problem only occurs when mis-using GeneratedAggregate, then I think we should resolve this by adding an assertion / precondition check to GeneratedAggregate to ensure that codgen is enabled.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @navis, can you comment on this? |
||
| val input = Seq(("Hello", 4, 2.0)) | ||
|
|
||
| val codegenDefault = TestSQLContext.getConf(SQLConf.CODEGEN_ENABLED) | ||
| TestSQLContext.setConf(SQLConf.CODEGEN_ENABLED, false) | ||
| try { | ||
| val df = input.toDF("a", "b", "c") | ||
| val colB = df.col("b").expr | ||
| val colC = df.col("c").expr | ||
| val aggrExpr = Alias(Count(Cast(colC, LongType)), "Count")() | ||
|
|
||
| for (groupExpr <- Seq(Seq.empty, Seq(colB))) { | ||
| val aggregate = GeneratedAggregate(true, groupExpr, Seq(aggrExpr), false, _: SparkPlan) | ||
| // ok if it's not throws exception | ||
| checkAnswer(df, aggregate, (_, _) => None) | ||
| } | ||
| } finally { | ||
| TestSQLContext.setConf(SQLConf.CODEGEN_ENABLED, codegenDefault) | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change? If you want to use mutable row in projection, you can use
InterpretedMutableProjection.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but InterpretedProjection and InterpretedMutableProjection has different semantic on returning object. It would be same thing if call setTarget() before each apply() call but I wanted keep it simple without incurring another problem.