Skip to content

Commit 7efefeb

Browse files
authored
Merge pull request #193 from cutiechi/replace-type-check-by-pattern-match
Replace type check by pattern match
2 parents 3477b3e + 04898ac commit 7efefeb

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

core/src/main/scala/org/apache/spark/sql/catalyst/CatalystTypeConverters.scala

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ object CatalystTypeConverters {
8282
final def toCatalyst(@Nullable maybeScalaValue: Any): CatalystType = {
8383
if (maybeScalaValue == null) {
8484
null.asInstanceOf[CatalystType]
85-
} else if (maybeScalaValue.isInstanceOf[Option[ScalaInputType]]) {
86-
val opt = maybeScalaValue.asInstanceOf[Option[ScalaInputType]]
87-
if (opt.isDefined) {
88-
toCatalystImpl(opt.get)
89-
} else {
90-
null.asInstanceOf[CatalystType]
91-
}
92-
} else {
93-
toCatalystImpl(maybeScalaValue.asInstanceOf[ScalaInputType])
85+
} else maybeScalaValue match {
86+
case opt: Option[ScalaInputType] =>
87+
if (opt.isDefined) {
88+
toCatalystImpl(opt.get)
89+
} else {
90+
null.asInstanceOf[CatalystType]
91+
}
92+
case _ =>
93+
toCatalystImpl(maybeScalaValue.asInstanceOf[ScalaInputType])
9494
}
9595
}
9696

@@ -429,10 +429,11 @@ object CatalystTypeConverters {
429429
// a measurable performance impact. Note that this optimization will be unnecessary if we
430430
// use code generation to construct Scala Row -> Catalyst Row converters.
431431
def convert(maybeScalaValue: Any): Any = {
432-
if (maybeScalaValue.isInstanceOf[Option[Any]]) {
433-
maybeScalaValue.asInstanceOf[Option[Any]].orNull
434-
} else {
435-
maybeScalaValue
432+
maybeScalaValue match {
433+
case option: Option[Any] =>
434+
option.orNull
435+
case _ =>
436+
maybeScalaValue
436437
}
437438
}
438439

0 commit comments

Comments
 (0)