Skip to content
Snippets Groups Projects
Commit b2f3aca1 authored by Josh Rosen's avatar Josh Rosen Committed by Yin Huai
Browse files

[SPARK-9286] [SQL] Methods in Unevaluable should be final and...

[SPARK-9286] [SQL] Methods in Unevaluable should be final and AlgebraicAggregate should extend Unevaluable.

This patch marks the Unevaluable.eval() and UnevaluablegenCode() methods as final and fixes two cases where they were overridden.  It also updates AggregateFunction2 to extend Unevaluable.

Author: Josh Rosen <joshrosen@databricks.com>

Closes #7627 from JoshRosen/unevaluable-fix and squashes the following commits:

8d9ed22 [Josh Rosen] AlgebraicAggregate should extend Unevaluable
65329c2 [Josh Rosen] Do not have AggregateFunction1 inherit from AggregateExpression1
fa68a22 [Josh Rosen] Make eval() and genCode() final
parent 662d60db
No related branches found
No related tags found
No related merge requests found
...@@ -184,10 +184,10 @@ abstract class Expression extends TreeNode[Expression] { ...@@ -184,10 +184,10 @@ abstract class Expression extends TreeNode[Expression] {
*/ */
trait Unevaluable extends Expression { trait Unevaluable extends Expression {
override def eval(input: InternalRow = null): Any = final override def eval(input: InternalRow = null): Any =
throw new UnsupportedOperationException(s"Cannot evaluate expression: $this") throw new UnsupportedOperationException(s"Cannot evaluate expression: $this")
override protected def genCode(ctx: CodeGenContext, ev: GeneratedExpressionCode): String = final override protected def genCode(ctx: CodeGenContext, ev: GeneratedExpressionCode): String =
throw new UnsupportedOperationException(s"Cannot evaluate expression: $this") throw new UnsupportedOperationException(s"Cannot evaluate expression: $this")
} }
......
...@@ -63,10 +63,6 @@ private[sql] case object Complete extends AggregateMode ...@@ -63,10 +63,6 @@ private[sql] case object Complete extends AggregateMode
*/ */
private[sql] case object NoOp extends Expression with Unevaluable { private[sql] case object NoOp extends Expression with Unevaluable {
override def nullable: Boolean = true override def nullable: Boolean = true
override def eval(input: InternalRow): Any = {
throw new TreeNodeException(
this, s"No function to evaluate expression. type: ${this.nodeName}")
}
override def dataType: DataType = NullType override def dataType: DataType = NullType
override def children: Seq[Expression] = Nil override def children: Seq[Expression] = Nil
} }
...@@ -151,8 +147,7 @@ abstract class AggregateFunction2 ...@@ -151,8 +147,7 @@ abstract class AggregateFunction2
/** /**
* A helper class for aggregate functions that can be implemented in terms of catalyst expressions. * A helper class for aggregate functions that can be implemented in terms of catalyst expressions.
*/ */
abstract class AlgebraicAggregate extends AggregateFunction2 with Serializable { abstract class AlgebraicAggregate extends AggregateFunction2 with Serializable with Unevaluable {
self: Product =>
val initialValues: Seq[Expression] val initialValues: Seq[Expression]
val updateExpressions: Seq[Expression] val updateExpressions: Seq[Expression]
...@@ -188,19 +183,15 @@ abstract class AlgebraicAggregate extends AggregateFunction2 with Serializable { ...@@ -188,19 +183,15 @@ abstract class AlgebraicAggregate extends AggregateFunction2 with Serializable {
} }
} }
override def update(buffer: MutableRow, input: InternalRow): Unit = { override final def update(buffer: MutableRow, input: InternalRow): Unit = {
throw new UnsupportedOperationException( throw new UnsupportedOperationException(
"AlgebraicAggregate's update should not be called directly") "AlgebraicAggregate's update should not be called directly")
} }
override def merge(buffer1: MutableRow, buffer2: InternalRow): Unit = { override final def merge(buffer1: MutableRow, buffer2: InternalRow): Unit = {
throw new UnsupportedOperationException( throw new UnsupportedOperationException(
"AlgebraicAggregate's merge should not be called directly") "AlgebraicAggregate's merge should not be called directly")
} }
override def eval(buffer: InternalRow): Any = {
throw new UnsupportedOperationException(
"AlgebraicAggregate's eval should not be called directly")
}
} }
...@@ -20,8 +20,8 @@ package org.apache.spark.sql.catalyst.expressions ...@@ -20,8 +20,8 @@ package org.apache.spark.sql.catalyst.expressions
import com.clearspring.analytics.stream.cardinality.HyperLogLog import com.clearspring.analytics.stream.cardinality.HyperLogLog
import org.apache.spark.sql.catalyst.InternalRow import org.apache.spark.sql.catalyst.InternalRow
import org.apache.spark.sql.catalyst.errors.TreeNodeException
import org.apache.spark.sql.catalyst.analysis.TypeCheckResult import org.apache.spark.sql.catalyst.analysis.TypeCheckResult
import org.apache.spark.sql.catalyst.expressions.codegen.{CodeGenContext, GeneratedExpressionCode}
import org.apache.spark.sql.catalyst.util.TypeUtils import org.apache.spark.sql.catalyst.util.TypeUtils
import org.apache.spark.sql.types._ import org.apache.spark.sql.types._
import org.apache.spark.util.collection.OpenHashSet import org.apache.spark.util.collection.OpenHashSet
...@@ -71,8 +71,7 @@ trait PartialAggregate1 extends AggregateExpression1 { ...@@ -71,8 +71,7 @@ trait PartialAggregate1 extends AggregateExpression1 {
* A specific implementation of an aggregate function. Used to wrap a generic * A specific implementation of an aggregate function. Used to wrap a generic
* [[AggregateExpression1]] with an algorithm that will be used to compute one specific result. * [[AggregateExpression1]] with an algorithm that will be used to compute one specific result.
*/ */
abstract class AggregateFunction1 abstract class AggregateFunction1 extends LeafExpression with Serializable {
extends LeafExpression with AggregateExpression1 with Serializable {
/** Base should return the generic aggregate expression that this function is computing */ /** Base should return the generic aggregate expression that this function is computing */
val base: AggregateExpression1 val base: AggregateExpression1
...@@ -82,9 +81,9 @@ abstract class AggregateFunction1 ...@@ -82,9 +81,9 @@ abstract class AggregateFunction1
def update(input: InternalRow): Unit def update(input: InternalRow): Unit
// Do we really need this? override protected def genCode(ctx: CodeGenContext, ev: GeneratedExpressionCode): String = {
override def newInstance(): AggregateFunction1 = { throw new UnsupportedOperationException(
makeCopy(productIterator.map { case a: AnyRef => a }.toArray) "AggregateFunction1 should not be used for generated aggregates")
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment