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

[SPARK-8948][SQL] Remove ExtractValueWithOrdinal abstract class

Also added more documentation for the file.

Author: Reynold Xin <rxin@databricks.com>

Closes #7316 from rxin/extract-value and squashes the following commits:

069cb7e [Reynold Xin] Removed ExtractValueWithOrdinal.
621b705 [Reynold Xin] Reverted a line.
11ebd6c [Reynold Xin] [Minor][SQL] Improve documentation for complex type extractors.
parent 59cc3894
No related branches found
No related tags found
No related merge requests found
......@@ -25,6 +25,11 @@ import org.apache.spark.sql.catalyst.analysis._
import org.apache.spark.sql.catalyst.expressions.codegen.{GeneratedExpressionCode, CodeGenContext}
import org.apache.spark.sql.types._
////////////////////////////////////////////////////////////////////////////////////////////////////
// This file defines all the expressions to extract values out of complex types.
// For example, getting a field out of an array, map, or struct.
////////////////////////////////////////////////////////////////////////////////////////////////////
object ExtractValue {
/**
......@@ -73,11 +78,10 @@ object ExtractValue {
}
}
def unapply(g: ExtractValue): Option[(Expression, Expression)] = {
g match {
case o: ExtractValueWithOrdinal => Some((o.child, o.ordinal))
case s: ExtractValueWithStruct => Some((s.child, null))
}
def unapply(g: ExtractValue): Option[(Expression, Expression)] = g match {
case o: GetArrayItem => Some((o.child, o.ordinal))
case o: GetMapValue => Some((o.child, o.key))
case s: ExtractValueWithStruct => Some((s.child, null))
}
/**
......@@ -117,6 +121,8 @@ abstract class ExtractValueWithStruct extends UnaryExpression with ExtractValue
/**
* Returns the value of fields in the Struct `child`.
*
* No need to do type checking since it is handled by [[ExtractValue]].
*/
case class GetStructField(child: Expression, field: StructField, ordinal: Int)
extends ExtractValueWithStruct {
......@@ -142,6 +148,8 @@ case class GetStructField(child: Expression, field: StructField, ordinal: Int)
/**
* Returns the array of value of fields in the Array of Struct `child`.
*
* No need to do type checking since it is handled by [[ExtractValue]].
*/
case class GetArrayStructFields(
child: Expression,
......@@ -178,25 +186,21 @@ case class GetArrayStructFields(
}
}
abstract class ExtractValueWithOrdinal extends BinaryExpression with ExtractValue {
self: Product =>
/**
* Returns the field at `ordinal` in the Array `child`.
*
* No need to do type checking since it is handled by [[ExtractValue]].
*/
case class GetArrayItem(child: Expression, ordinal: Expression)
extends BinaryExpression with ExtractValue {
def ordinal: Expression
def child: Expression
override def toString: String = s"$child[$ordinal]"
override def left: Expression = child
override def right: Expression = ordinal
/** `Null` is returned for invalid ordinals. */
override def nullable: Boolean = true
override def toString: String = s"$child[$ordinal]"
}
/**
* Returns the field at `ordinal` in the Array `child`
*/
case class GetArrayItem(child: Expression, ordinal: Expression)
extends ExtractValueWithOrdinal {
override def dataType: DataType = child.dataType.asInstanceOf[ArrayType].elementType
......@@ -227,10 +231,20 @@ case class GetArrayItem(child: Expression, ordinal: Expression)
}
/**
* Returns the value of key `ordinal` in Map `child`
* Returns the value of key `ordinal` in Map `child`.
*
* No need to do type checking since it is handled by [[ExtractValue]].
*/
case class GetMapValue(child: Expression, ordinal: Expression)
extends ExtractValueWithOrdinal {
case class GetMapValue(child: Expression, key: Expression)
extends BinaryExpression with ExtractValue {
override def toString: String = s"$child[$key]"
override def left: Expression = child
override def right: Expression = key
/** `Null` is returned for invalid ordinals. */
override def nullable: Boolean = true
override def dataType: DataType = child.dataType.asInstanceOf[MapType].valueType
......
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