Skip to content
Snippets Groups Projects
Commit e90543e5 authored by Reynold Xin's avatar Reynold Xin
Browse files

[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.
parent 6853ac7c
No related branches found
No related tags found
No related merge requests found
......@@ -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
}
......@@ -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
}
......
......@@ -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
......
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