Skip to content

Commit e530f01

Browse files
committed
Remove ExprType.
1 parent 0841c4a commit e530f01

24 files changed

+88
-98
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Expression.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ abstract class Expression extends TreeNode[Expression] {
105105
val isNull = ctx.freshName("isNull")
106106
val value = ctx.freshName("value")
107107
val eval = doGenCode(ctx, ExprCode("",
108-
VariableValue(isNull, ExprType(ctx.JAVA_BOOLEAN)),
109-
VariableValue(value, ExprType(ctx, dataType))))
108+
VariableValue(isNull, ctx.JAVA_BOOLEAN),
109+
VariableValue(value, ctx.javaType(dataType))))
110110
reduceCodeSize(ctx, eval)
111111
if (eval.code.nonEmpty) {
112112
// Add `this` in the comment.
@@ -123,7 +123,7 @@ abstract class Expression extends TreeNode[Expression] {
123123
val setIsNull = if (!eval.isNull.isInstanceOf[LiteralValue]) {
124124
val globalIsNull = ctx.addMutableState(ctx.JAVA_BOOLEAN, "globalIsNull")
125125
val localIsNull = eval.isNull
126-
eval.isNull = GlobalValue(globalIsNull, ExprType(ctx.JAVA_BOOLEAN))
126+
eval.isNull = GlobalValue(globalIsNull, ctx.JAVA_BOOLEAN)
127127
s"$globalIsNull = $localIsNull;"
128128
} else {
129129
""
@@ -142,7 +142,7 @@ abstract class Expression extends TreeNode[Expression] {
142142
|}
143143
""".stripMargin)
144144

145-
eval.value = VariableValue(newValue, ExprType(ctx, dataType))
145+
eval.value = VariableValue(newValue, javaType)
146146
eval.code = s"$javaType $newValue = $funcFullName(${ctx.INPUT_ROW});"
147147
}
148148
}

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/arithmetic.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -602,8 +602,7 @@ case class Least(children: Seq[Expression]) extends Expression {
602602

603603
override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = {
604604
val evalChildren = children.map(_.genCode(ctx))
605-
ev.isNull = GlobalValue(ctx.addMutableState(ctx.JAVA_BOOLEAN, ev.isNull),
606-
ExprType(ctx.JAVA_BOOLEAN))
605+
ev.isNull = GlobalValue(ctx.addMutableState(ctx.JAVA_BOOLEAN, ev.isNull), ctx.JAVA_BOOLEAN)
607606
val evals = evalChildren.map(eval =>
608607
s"""
609608
|${eval.code}
@@ -682,8 +681,7 @@ case class Greatest(children: Seq[Expression]) extends Expression {
682681

683682
override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = {
684683
val evalChildren = children.map(_.genCode(ctx))
685-
ev.isNull = GlobalValue(ctx.addMutableState(ctx.JAVA_BOOLEAN, ev.isNull),
686-
ExprType(ctx.JAVA_BOOLEAN))
684+
ev.isNull = GlobalValue(ctx.addMutableState(ctx.JAVA_BOOLEAN, ev.isNull), ctx.JAVA_BOOLEAN)
687685
val evals = evalChildren.map(eval =>
688686
s"""
689687
|${eval.code}

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/CodeGenerator.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ class CodegenContext {
323323
case _: StructType | _: ArrayType | _: MapType => s"$value = $initCode.copy();"
324324
case _ => s"$value = $initCode;"
325325
}
326-
ExprCode(code, FalseLiteral, GlobalValue(value, ExprType(this, dataType)))
326+
ExprCode(code, FalseLiteral, GlobalValue(value, javaType(dataType)))
327327
}
328328

329329
def declareMutableStates(): String = {
@@ -1208,8 +1208,8 @@ class CodegenContext {
12081208
// at least two nodes) as the cost of doing it is expected to be low.
12091209

12101210
subexprFunctions += s"${addNewFunction(fnName, fn)}($INPUT_ROW);"
1211-
val state = SubExprEliminationState(GlobalValue(isNull, ExprType(JAVA_BOOLEAN)),
1212-
GlobalValue(value, ExprType(this, expr.dataType)))
1211+
val state = SubExprEliminationState(GlobalValue(isNull, JAVA_BOOLEAN),
1212+
GlobalValue(value, javaType(expr.dataType)))
12131213
e.foreach(subExprEliminationExprs.put(_, state))
12141214
}
12151215
}

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/ExprValue.scala

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,62 +24,53 @@ import org.apache.spark.sql.types.DataType
2424
// An abstraction that represents the evaluation result of [[ExprCode]].
2525
abstract class ExprValue {
2626

27-
val javaType: ExprType
27+
val javaType: String
2828

2929
// Whether we can directly access the evaluation value anywhere.
3030
// For example, a variable created outside a method can not be accessed inside the method.
3131
// For such cases, we may need to pass the evaluation as parameter.
3232
val canDirectAccess: Boolean
3333

34-
def isPrimitive(ctx: CodegenContext): Boolean = javaType.isPrimitive(ctx)
34+
def isPrimitive(ctx: CodegenContext): Boolean = ctx.isPrimitiveType(javaType)
3535
}
3636

3737
object ExprValue {
3838
implicit def exprValueToString(exprValue: ExprValue): String = exprValue.toString
3939
}
4040

4141
// A literal evaluation of [[ExprCode]].
42-
class LiteralValue(val value: String, val javaType: ExprType) extends ExprValue {
42+
class LiteralValue(val value: String, val javaType: String) extends ExprValue {
4343
override def toString: String = value
4444
override val canDirectAccess: Boolean = true
4545
}
4646

4747
object LiteralValue {
48-
def apply(value: String, javaType: ExprType): LiteralValue = new LiteralValue(value, javaType)
49-
def unapply(literal: LiteralValue): Option[(String, ExprType)] =
48+
def apply(value: String, javaType: String): LiteralValue = new LiteralValue(value, javaType)
49+
def unapply(literal: LiteralValue): Option[(String, String)] =
5050
Some((literal.value, literal.javaType))
5151
}
5252

5353
// A variable evaluation of [[ExprCode]].
5454
case class VariableValue(
5555
val variableName: String,
56-
val javaType: ExprType) extends ExprValue {
56+
val javaType: String) extends ExprValue {
5757
override def toString: String = variableName
5858
override val canDirectAccess: Boolean = false
5959
}
6060

6161
// A statement evaluation of [[ExprCode]].
6262
case class StatementValue(
6363
val statement: String,
64-
val javaType: ExprType,
64+
val javaType: String,
6565
val canDirectAccess: Boolean = false) extends ExprValue {
6666
override def toString: String = statement
6767
}
6868

6969
// A global variable evaluation of [[ExprCode]].
70-
case class GlobalValue(val value: String, val javaType: ExprType) extends ExprValue {
70+
case class GlobalValue(val value: String, val javaType: String) extends ExprValue {
7171
override def toString: String = value
7272
override val canDirectAccess: Boolean = true
7373
}
7474

75-
case object TrueLiteral extends LiteralValue("true", ExprType("boolean"))
76-
case object FalseLiteral extends LiteralValue("false", ExprType("boolean"))
77-
78-
// Represents the java type of an evaluation.
79-
case class ExprType(val typeName: String) {
80-
def isPrimitive(ctx: CodegenContext): Boolean = ctx.isPrimitiveType(typeName)
81-
}
82-
83-
object ExprType {
84-
def apply(ctx: CodegenContext, dataType: DataType): ExprType = ExprType(ctx.javaType(dataType))
85-
}
75+
case object TrueLiteral extends LiteralValue("true", "boolean")
76+
case object FalseLiteral extends LiteralValue("false", "boolean")

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/GenerateMutableProjection.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ object GenerateMutableProjection extends CodeGenerator[Seq[Expression], MutableP
6969
|${ev.code}
7070
|$isNull = ${ev.isNull};
7171
|$value = ${ev.value};
72-
""".stripMargin, GlobalValue(isNull, ExprType(ctx.JAVA_BOOLEAN)), value, i)
72+
""".stripMargin, GlobalValue(isNull, ctx.JAVA_BOOLEAN), value, i)
7373
} else {
7474
(s"""
7575
|${ev.code}
@@ -83,7 +83,7 @@ object GenerateMutableProjection extends CodeGenerator[Seq[Expression], MutableP
8383

8484
val updates = validExpr.zip(projectionCodes).map {
8585
case (e, (_, isNull, value, i)) =>
86-
val ev = ExprCode("", isNull, GlobalValue(value, ExprType(ctx, e.dataType)))
86+
val ev = ExprCode("", isNull, GlobalValue(value, ctx.javaType(e.dataType)))
8787
ctx.updateColumn("mutableRow", e.dataType, i, ev, e.nullable)
8888
}
8989

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/GenerateSafeProjection.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ object GenerateSafeProjection extends CodeGenerator[Seq[Expression], Projection]
5454

5555
val fieldWriters = schema.map(_.dataType).zipWithIndex.map { case (dt, i) =>
5656
val converter = convertToSafe(ctx, StatementValue(ctx.getValue(tmpInput, dt, i.toString),
57-
ExprType(ctx, dt)), dt)
57+
ctx.javaType(dt)), dt)
5858
s"""
5959
if (!$tmpInput.isNullAt($i)) {
6060
${converter.code}
@@ -75,7 +75,7 @@ object GenerateSafeProjection extends CodeGenerator[Seq[Expression], Projection]
7575
|final InternalRow $output = new $rowClass($values);
7676
""".stripMargin
7777

78-
ExprCode(code, FalseLiteral, VariableValue(output, ExprType("InternalRow")))
78+
ExprCode(code, FalseLiteral, VariableValue(output, "InternalRow"))
7979
}
8080

8181
private def createCodeForArray(
@@ -91,7 +91,7 @@ object GenerateSafeProjection extends CodeGenerator[Seq[Expression], Projection]
9191
val arrayClass = classOf[GenericArrayData].getName
9292

9393
val elementConverter = convertToSafe(
94-
ctx, StatementValue(ctx.getValue(tmpInput, elementType, index), ExprType(ctx, elementType)),
94+
ctx, StatementValue(ctx.getValue(tmpInput, elementType, index), ctx.javaType(elementType)),
9595
elementType)
9696
val code = s"""
9797
final ArrayData $tmpInput = $input;
@@ -106,7 +106,7 @@ object GenerateSafeProjection extends CodeGenerator[Seq[Expression], Projection]
106106
final ArrayData $output = new $arrayClass($values);
107107
"""
108108

109-
ExprCode(code, FalseLiteral, VariableValue(output, ExprType("ArrayData")))
109+
ExprCode(code, FalseLiteral, VariableValue(output, "ArrayData"))
110110
}
111111

112112
private def createCodeForMap(
@@ -127,7 +127,7 @@ object GenerateSafeProjection extends CodeGenerator[Seq[Expression], Projection]
127127
final MapData $output = new $mapClass(${keyConverter.value}, ${valueConverter.value});
128128
"""
129129

130-
ExprCode(code, FalseLiteral, VariableValue(output, ExprType("MapData")))
130+
ExprCode(code, FalseLiteral, VariableValue(output, "MapData"))
131131
}
132132

133133
@tailrec

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/GenerateUnsafeProjection.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ object GenerateUnsafeProjection extends CodeGenerator[Seq[Expression], UnsafePro
5252
// Puts `input` in a local variable to avoid to re-evaluate it if it's a statement.
5353
val tmpInput = ctx.freshName("tmpInput")
5454
val fieldEvals = fieldTypes.zipWithIndex.map { case (dt, i) =>
55-
ExprCode("", StatementValue(s"$tmpInput.isNullAt($i)", ExprType(ctx.JAVA_BOOLEAN)),
56-
StatementValue(ctx.getValue(tmpInput, dt, i.toString), ExprType(ctx, dt)))
55+
ExprCode("", StatementValue(s"$tmpInput.isNullAt($i)", ctx.JAVA_BOOLEAN),
56+
StatementValue(ctx.getValue(tmpInput, dt, i.toString), ctx.javaType(dt)))
5757
}
5858

5959
s"""
@@ -348,7 +348,7 @@ object GenerateUnsafeProjection extends CodeGenerator[Seq[Expression], UnsafePro
348348
$writeExpressions
349349
$updateRowSize
350350
"""
351-
ExprCode(code, FalseLiteral, GlobalValue(result, ExprType("UnsafeRow")))
351+
ExprCode(code, FalseLiteral, GlobalValue(result, "UnsafeRow"))
352352
}
353353

354354
protected def canonicalize(in: Seq[Expression]): Seq[Expression] =

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/complexTypeCreator.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ case class CreateArray(children: Seq[Expression]) extends Expression {
6464
GenArrayData.genCodeToCreateArrayData(ctx, et, evals, false)
6565
ev.copy(
6666
code = preprocess + assigns + postprocess,
67-
value = VariableValue(arrayData, ExprType(ctx, dataType)),
67+
value = VariableValue(arrayData, ctx.javaType(dataType)),
6868
isNull = FalseLiteral)
6969
}
7070

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/conditionalExpressions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ case class CaseWhen(
192192
// We won't go on anymore on the computation.
193193
val resultState = ctx.freshName("caseWhenResultState")
194194
ev.value = GlobalValue(ctx.addMutableState(ctx.javaType(dataType), ev.value),
195-
ExprType(ctx, dataType))
195+
ctx.javaType(dataType))
196196

197197
// these blocks are meant to be inside a
198198
// do {

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ abstract class UnixTime
678678
val df = classOf[DateFormat].getName
679679
if (formatter == null) {
680680
ExprCode("", TrueLiteral, LiteralValue(ctx.defaultValue(dataType),
681-
ExprType(ctx, dataType)))
681+
ctx.javaType(dataType)))
682682
} else {
683683
val formatterName = ctx.addReferenceObj("formatter", formatter, df)
684684
val eval1 = left.genCode(ctx)
@@ -813,7 +813,7 @@ case class FromUnixTime(sec: Expression, format: Expression, timeZoneId: Option[
813813
val df = classOf[DateFormat].getName
814814
if (format.foldable) {
815815
if (formatter == null) {
816-
ExprCode("", TrueLiteral, LiteralValue("(UTF8String) null", ExprType(ctx, dataType)))
816+
ExprCode("", TrueLiteral, LiteralValue("(UTF8String) null", ctx.javaType(dataType)))
817817
} else {
818818
val formatterName = ctx.addReferenceObj("formatter", formatter, df)
819819
val t = left.genCode(ctx)

0 commit comments

Comments
 (0)