aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReynold Xin <rxin@databricks.com>2015-07-20 18:23:51 -0700
committerReynold Xin <rxin@databricks.com>2015-07-20 18:23:51 -0700
commite90543e5366808332bbde18d78cccd4d064a3338 (patch)
tree6233120e5cf8e9038ba3e50410bb35f3a74f1758
parent6853ac7c8c76003160fc861ddcc8e8e39e4a5924 (diff)
downloadspark-e90543e5366808332bbde18d78cccd4d064a3338.tar.gz
spark-e90543e5366808332bbde18d78cccd4d064a3338.tar.bz2
spark-e90543e5366808332bbde18d78cccd4d064a3338.zip
[SPARK-9142][SQL] Removing unnecessary self types in expressions.
Also added documentation to expressions to explain the important traits and abstract classes. Author: Reynold Xin <rxin@databricks.com> Closes #7550 from rxin/remove-self-types and squashes the following commits: b2a3ec1 [Reynold Xin] [SPARK-9142][SQL] Removing unnecessary self types in expressions.
-rw-r--r--sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/ExpectsInputTypes.scala4
-rw-r--r--sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Expression.scala33
-rw-r--r--sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/CodegenFallback.scala2
3 files changed, 22 insertions, 17 deletions
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/ExpectsInputTypes.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/ExpectsInputTypes.scala
index ded89e85de..abe6457747 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/ExpectsInputTypes.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/ExpectsInputTypes.scala
@@ -29,7 +29,7 @@ import org.apache.spark.sql.catalyst.analysis.HiveTypeCoercion.ImplicitTypeCasts
*
* Most function expressions (e.g. [[Substring]] should extends [[ImplicitCastInputTypes]]) instead.
*/
-trait ExpectsInputTypes { self: Expression =>
+trait ExpectsInputTypes extends Expression {
/**
* Expected input types from child expressions. The i-th position in the returned seq indicates
@@ -60,6 +60,6 @@ trait ExpectsInputTypes { self: Expression =>
/**
* A mixin for the analyzer to perform implicit type casting using [[ImplicitTypeCasts]].
*/
-trait ImplicitCastInputTypes extends ExpectsInputTypes { self: Expression =>
+trait ImplicitCastInputTypes extends ExpectsInputTypes {
// No other methods
}
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Expression.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Expression.scala
index da599b8963..aada25276a 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Expression.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Expression.scala
@@ -19,19 +19,12 @@ package org.apache.spark.sql.catalyst.expressions
import org.apache.spark.sql.catalyst.InternalRow
import org.apache.spark.sql.catalyst.analysis.{TypeCheckResult, UnresolvedAttribute}
-import org.apache.spark.sql.catalyst.expressions.codegen.{CodeGenContext, GeneratedExpressionCode}
+import org.apache.spark.sql.catalyst.expressions.codegen._
import org.apache.spark.sql.catalyst.trees.TreeNode
import org.apache.spark.sql.types._
////////////////////////////////////////////////////////////////////////////////////////////////////
-// This file defines the basic expression abstract classes in Catalyst, including:
-// Expression: the base expression abstract class
-// LeafExpression
-// UnaryExpression
-// BinaryExpression
-// BinaryOperator
-//
-// For details, see their classdocs.
+// This file defines the basic expression abstract classes in Catalyst.
////////////////////////////////////////////////////////////////////////////////////////////////////
/**
@@ -39,9 +32,21 @@ import org.apache.spark.sql.types._
*
* If an expression wants to be exposed in the function registry (so users can call it with
* "name(arguments...)", the concrete implementation must be a case class whose constructor
- * arguments are all Expressions types.
+ * arguments are all Expressions types. See [[Substring]] for an example.
+ *
+ * There are a few important traits:
+ *
+ * - [[Nondeterministic]]: an expression that is not deterministic.
+ * - [[Unevaluable]]: an expression that is not supposed to be evaluated.
+ * - [[CodegenFallback]]: an expression that does not have code gen implemented and falls back to
+ * interpreted mode.
+ *
+ * - [[LeafExpression]]: an expression that has no child.
+ * - [[UnaryExpression]]: an expression that has one child.
+ * - [[BinaryExpression]]: an expression that has two children.
+ * - [[BinaryOperator]]: a special case of [[BinaryExpression]] that requires two children to have
+ * the same output data type.
*
- * See [[Substring]] for an example.
*/
abstract class Expression extends TreeNode[Expression] {
@@ -176,7 +181,7 @@ abstract class Expression extends TreeNode[Expression] {
* An expression that cannot be evaluated. Some expressions don't live past analysis or optimization
* time (e.g. Star). This trait is used by those expressions.
*/
-trait Unevaluable { self: Expression =>
+trait Unevaluable extends Expression {
override def eval(input: InternalRow = null): Any =
throw new UnsupportedOperationException(s"Cannot evaluate expression: $this")
@@ -185,11 +190,11 @@ trait Unevaluable { self: Expression =>
throw new UnsupportedOperationException(s"Cannot evaluate expression: $this")
}
+
/**
* An expression that is nondeterministic.
*/
-trait Nondeterministic { self: Expression =>
-
+trait Nondeterministic extends Expression {
override def deterministic: Boolean = false
}
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/CodegenFallback.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/CodegenFallback.scala
index bf4f600cb2..6b187f0560 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/CodegenFallback.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/CodegenFallback.scala
@@ -22,7 +22,7 @@ import org.apache.spark.sql.catalyst.expressions.Expression
/**
* A trait that can be used to provide a fallback mode for expression code generation.
*/
-trait CodegenFallback { self: Expression =>
+trait CodegenFallback extends Expression {
protected def genCode(ctx: CodeGenContext, ev: GeneratedExpressionCode): String = {
ctx.references += this