Skip to content

Commit

Permalink
SpatialFilterPushdownRules exceptions handling cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pomadchin committed Apr 10, 2022
1 parent d30e97b commit 31fa493
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ val shapelessVersion = "2.3.3" // to be compatible with Spark 3.1.x
val scalaTestVersion = "3.2.11"
val jtsVersion = "1.18.1"
val geomesaVersion = "3.3.0"
val hivelessVersion = "0.0.7"
val hivelessVersion = "0.0.8"
val geotrellisVersion = "3.6.2"

// GeoTrellis depends on Shapeless 2.3.7
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package com.carto.analyticstoolbox.spark.rules
import com.carto.analyticstoolbox.core._
import com.carto.analyticstoolbox.index._
import com.azavea.hiveless.spark.rules.syntax._
import com.azavea.hiveless.serializers.UnaryDeserializer.Errors.ProductDeserializationError
import com.azavea.hiveless.serializers.syntax._
import geotrellis.vector._
import cats.syntax.option._
Expand All @@ -37,7 +38,6 @@ object SpatialFilterPushdownRules extends Rule[LogicalPlan] {

def apply(plan: LogicalPlan): LogicalPlan =
plan.transformDown {
// HiveGenericUDF is a private[hive] case class
case f @ Filter(condition: HiveGenericUDF, plan) if condition.of[ST_Intersects] =>
try {
val Seq(extentExpr, geometryExpr) = condition.children
Expand All @@ -50,15 +50,16 @@ object SpatialFilterPushdownRules extends Rule[LogicalPlan] {
)

// transform expression
val expr = Try {
// ST_Intersects is polymorphic by the second argument
// Extract Extent literal from the right
// The second argument can be Geometry or Extent
val g = geometryExpr.eval(null)
Try(g.convert[Geometry].extent).getOrElse(g.convert[Extent])
} match {
val expr = Try(geometryExpr.eval(null)) match {
// Literals push-down support only
case Success(extent) =>
case Success(g) =>
// ST_Intersects is polymorphic by the second argument
// Extract Extent literal from the right
// The second argument can be Geometry or Extent
val extent = Try(g.convert[Geometry].extent)
.orElse(Try(g.convert[Extent]))
.getOrElse(throw ProductDeserializationError[ST_Intersects.Arg](classOf[ST_Intersects], "second"))

// transform expression
AndList(
List(
Expand Down

0 comments on commit 31fa493

Please sign in to comment.