Skip to content

Commit

Permalink
Cleanup ProductDeserializationError interface (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
pomadchin authored Apr 11, 2022
1 parent 9d702ed commit 91bf6f7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import org.apache.spark.sql.catalyst.util.ArrayData
import shapeless.ops.coproduct.{CoproductToEither, EitherToCoproduct}
import shapeless.{:+:, ::, CNil, Coproduct, Generic, HList, HNil, Inl, Inr, IsTuple}

import scala.reflect.ClassTag
import scala.reflect.{classTag, ClassTag}
import scala.util.Try
import scala.reflect.runtime.universe.TypeTag

Expand All @@ -48,11 +48,11 @@ object HDeserializer extends Serializable {
sealed abstract class Errors(override val getMessage: String) extends RuntimeException
object Errors {
final case object NullArgument extends Errors("NULL argument passed.")
final case class ProductDeserializationError[T: HShow](clz: Class[_], name: String)
final case class ProductDeserializationError[T: ClassTag, A: HShow](name: String)
extends Errors(
s"""
|${clz.getName}: could not deserialize the $name input argument:
|should match one of the following types: ${HShow[T].show()}""".stripMargin
|${classTag[T]}: could not deserialize the $name input argument,
|it should match one of the following types: ${HShow[A].show()}""".stripMargin
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ object SpatialFilterPushdownRules extends Rule[LogicalPlan] {
// The second argument can be Geometry or Extent
val (extent, isGeometry) = Try(g.convert[Geometry].extent -> true)
.orElse(Try(g.convert[Extent] -> false))
.getOrElse(throw ProductDeserializationError[ST_Intersects.Arg](classOf[ST_Intersects], "second"))
.getOrElse(throw ProductDeserializationError[ST_Intersects, ST_Intersects.Arg]("second"))

// transform expression
AndList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ object ST_Intersects {
def parseGeometry(a: Arg): Option[Geometry] = a.select[Geometry].orElse(a.select[Extent].map(_.toPolygon()))

private def parseGeometryUnsafe(a: Arg, aname: String): Geometry =
parseGeometry(a).getOrElse(throw ProductDeserializationError[Arg](classOf[ST_Intersects], aname))
parseGeometry(a).getOrElse(throw ProductDeserializationError[ST_Intersects, Arg](aname))

def function(left: Arg, right: Arg): Boolean = {
val (l, r) = (parseGeometryUnsafe(left, "first"), parseGeometryUnsafe(right, "second"))
Expand Down

0 comments on commit 91bf6f7

Please sign in to comment.