Skip to content

Commit df552b8

Browse files
committed
Implement withNewChildrenInternal directly
avoid reflection which is done at runtime by structural types
1 parent b14adaa commit df552b8

File tree

79 files changed

+136
-69
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+136
-69
lines changed

core/src/main/scala/org/locationtech/rasterframes/expressions/BinaryRasterFunction.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,13 @@ import com.typesafe.scalalogging.Logger
2525
import geotrellis.raster.Tile
2626
import org.apache.spark.sql.catalyst.analysis.TypeCheckResult
2727
import org.apache.spark.sql.catalyst.analysis.TypeCheckResult.{TypeCheckFailure, TypeCheckSuccess}
28-
import org.apache.spark.sql.catalyst.expressions.{BinaryExpression, Expression}
28+
import org.apache.spark.sql.catalyst.expressions.BinaryExpression
2929
import org.apache.spark.sql.types.DataType
3030
import org.locationtech.rasterframes.expressions.DynamicExtractors._
3131
import org.slf4j.LoggerFactory
3232

3333
/** Operation combining two tiles or a tile and a scalar into a new tile. */
34-
trait BinaryRasterFunction extends BinaryExpression with RasterResult { self: HasBinaryExpressionCopy =>
35-
override protected def withNewChildrenInternal(newLeft: Expression, newRight: Expression): Expression = copy(newLeft, newRight)
34+
trait BinaryRasterFunction extends BinaryExpression with RasterResult {
3635

3736
@transient protected lazy val logger = Logger(LoggerFactory.getLogger(getClass.getName))
3837

core/src/main/scala/org/locationtech/rasterframes/expressions/OnCellGridExpression.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,15 @@ import geotrellis.raster.CellGrid
2626
import org.apache.spark.sql.catalyst.InternalRow
2727
import org.apache.spark.sql.catalyst.analysis.TypeCheckResult
2828
import org.apache.spark.sql.catalyst.analysis.TypeCheckResult.{TypeCheckFailure, TypeCheckSuccess}
29-
import org.apache.spark.sql.catalyst.expressions.{Expression, UnaryExpression}
29+
import org.apache.spark.sql.catalyst.expressions.UnaryExpression
3030

3131
/**
3232
* Implements boilerplate for subtype expressions processing TileUDT, RasterSourceUDT, and RasterRefs
3333
* as Grid types.
3434
*
3535
* @since 11/4/18
3636
*/
37-
trait OnCellGridExpression extends UnaryExpression { self: HasUnaryExpressionCopy =>
38-
override protected def withNewChildInternal(newChild: Expression): Expression = copy(newChild)
39-
37+
trait OnCellGridExpression extends UnaryExpression {
4038
private lazy val fromRow: InternalRow => CellGrid[Int] = {
4139
if (child.resolved) gridExtractor(child.dataType)
4240
else throw new IllegalStateException(s"Child expression unbound: ${child}")

core/src/main/scala/org/locationtech/rasterframes/expressions/OnTileContextExpression.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import org.locationtech.rasterframes.expressions.DynamicExtractors._
2525
import org.apache.spark.sql.catalyst.InternalRow
2626
import org.apache.spark.sql.catalyst.analysis.TypeCheckResult
2727
import org.apache.spark.sql.catalyst.analysis.TypeCheckResult.{TypeCheckFailure, TypeCheckSuccess}
28-
import org.apache.spark.sql.catalyst.expressions.{Expression, UnaryExpression}
28+
import org.apache.spark.sql.catalyst.expressions.UnaryExpression
2929
import org.locationtech.rasterframes.model.TileContext
3030

3131
/**
@@ -34,9 +34,7 @@ import org.locationtech.rasterframes.model.TileContext
3434
*
3535
* @since 11/3/18
3636
*/
37-
trait OnTileContextExpression extends UnaryExpression { self: HasUnaryExpressionCopy =>
38-
override protected def withNewChildInternal(newChild: Expression): Expression = copy(newChild)
39-
37+
trait OnTileContextExpression extends UnaryExpression {
4038
override def checkInputDataTypes(): TypeCheckResult = {
4139
if (!projectedRasterLikeExtractor.isDefinedAt(child.dataType)) {
4240
TypeCheckFailure(s"Input type '${child.dataType}' does not conform to `ProjectedRasterLike`.")

core/src/main/scala/org/locationtech/rasterframes/expressions/SpatialRelation.scala

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@ import org.locationtech.geomesa.spark.jts.udf.SpatialRelationFunctions._
3939
*
4040
* @since 12/28/17
4141
*/
42-
abstract class SpatialRelation extends BinaryExpression with CodegenFallback { this: HasBinaryExpressionCopy =>
43-
44-
override protected def withNewChildrenInternal(newLeft: Expression, newRight: Expression): Expression =
45-
copy(left = newLeft, right = newRight)
42+
abstract class SpatialRelation extends BinaryExpression with CodegenFallback {
4643

4744
def extractGeometry(expr: Expression, input: Any): Geometry = {
4845
input match {
@@ -78,36 +75,42 @@ object SpatialRelation {
7875
override def nodeName: String = "intersects"
7976
val relation = ST_Intersects
8077

81-
override protected def withNewChildrenInternal(newLeft: Expression, newRight: Expression): Expression =
82-
copy(left = newLeft, right = newRight)
78+
override protected def withNewChildrenInternal(newLeft: Expression, newRight: Expression): Expression = copy(newLeft, newRight)
8379
}
8480
case class Contains(left: Expression, right: Expression) extends SpatialRelation {
8581
override def nodeName = "contains"
8682
val relation = ST_Contains
83+
override protected def withNewChildrenInternal(newLeft: Expression, newRight: Expression): Expression = copy(newLeft, newRight)
8784
}
8885
case class Covers(left: Expression, right: Expression) extends SpatialRelation {
8986
override def nodeName = "covers"
9087
val relation = ST_Covers
88+
override protected def withNewChildrenInternal(newLeft: Expression, newRight: Expression): Expression = copy(newLeft, newRight)
9189
}
9290
case class Crosses(left: Expression, right: Expression) extends SpatialRelation {
9391
override def nodeName = "crosses"
9492
val relation = ST_Crosses
93+
override protected def withNewChildrenInternal(newLeft: Expression, newRight: Expression): Expression = copy(newLeft, newRight)
9594
}
9695
case class Disjoint(left: Expression, right: Expression) extends SpatialRelation {
9796
override def nodeName = "disjoint"
9897
val relation = ST_Disjoint
98+
override protected def withNewChildrenInternal(newLeft: Expression, newRight: Expression): Expression = copy(newLeft, newRight)
9999
}
100100
case class Overlaps(left: Expression, right: Expression) extends SpatialRelation {
101101
override def nodeName = "overlaps"
102102
val relation = ST_Overlaps
103+
override protected def withNewChildrenInternal(newLeft: Expression, newRight: Expression): Expression = copy(newLeft, newRight)
103104
}
104105
case class Touches(left: Expression, right: Expression) extends SpatialRelation {
105106
override def nodeName = "touches"
106107
val relation = ST_Touches
108+
override protected def withNewChildrenInternal(newLeft: Expression, newRight: Expression): Expression = copy(newLeft, newRight)
107109
}
108110
case class Within(left: Expression, right: Expression) extends SpatialRelation {
109111
override def nodeName = "within"
110112
val relation = ST_Within
113+
override protected def withNewChildrenInternal(newLeft: Expression, newRight: Expression): Expression = copy(newLeft, newRight)
111114
}
112115

113116
private val predicateMap = Map(

core/src/main/scala/org/locationtech/rasterframes/expressions/UnaryRasterAggregate.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import org.locationtech.rasterframes.encoders.syntax._
3333
import scala.reflect.runtime.universe._
3434

3535
/** Mixin providing boilerplate for DeclarativeAggrates over tile-conforming columns. */
36-
trait UnaryRasterAggregate extends DeclarativeAggregate { self: HasUnaryExpressionCopy =>
36+
trait UnaryRasterAggregate extends DeclarativeAggregate {
3737
def child: Expression
3838

3939
def nullable: Boolean = child.nullable
@@ -42,8 +42,6 @@ trait UnaryRasterAggregate extends DeclarativeAggregate { self: HasUnaryExpressi
4242

4343
protected def tileOpAsExpression[R: TypeTag](name: String, op: Tile => R): Expression => ScalaUDF =
4444
udfiexpr[R, Any](name, (dataType: DataType) => (a: Any) => if(a == null) null.asInstanceOf[R] else op(UnaryRasterAggregate.extractTileFromAny(dataType, a)))
45-
46-
override protected def withNewChildrenInternal(newChildren: IndexedSeq[Expression]): Expression = copy(newChildren(0))
4745
}
4846

4947
object UnaryRasterAggregate {

core/src/main/scala/org/locationtech/rasterframes/expressions/UnaryRasterFunction.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,11 @@ import org.locationtech.rasterframes.expressions.DynamicExtractors._
2525
import geotrellis.raster.Tile
2626
import org.apache.spark.sql.catalyst.analysis.TypeCheckResult
2727
import org.apache.spark.sql.catalyst.analysis.TypeCheckResult.{TypeCheckFailure, TypeCheckSuccess}
28-
import org.apache.spark.sql.catalyst.expressions.{Expression, UnaryExpression}
28+
import org.apache.spark.sql.catalyst.expressions.UnaryExpression
2929
import org.locationtech.rasterframes.model.TileContext
3030

3131
/** Boilerplate for expressions operating on a single Tile-like . */
32-
trait UnaryRasterFunction extends UnaryExpression { self: HasUnaryExpressionCopy =>
33-
override protected def withNewChildInternal(newChild: Expression): Expression = copy(newChild)
34-
32+
trait UnaryRasterFunction extends UnaryExpression {
3533
override def checkInputDataTypes(): TypeCheckResult = {
3634
if (!tileExtractor.isDefinedAt(child.dataType)) {
3735
TypeCheckFailure(s"Input type '${child.dataType}' does not conform to a raster type.")

core/src/main/scala/org/locationtech/rasterframes/expressions/UnaryRasterOp.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,12 @@ package org.locationtech.rasterframes.expressions
2323

2424
import com.typesafe.scalalogging.Logger
2525
import geotrellis.raster.Tile
26-
import org.apache.spark.sql.catalyst.expressions.Expression
2726
import org.apache.spark.sql.types.DataType
2827
import org.locationtech.rasterframes.model.TileContext
2928
import org.slf4j.LoggerFactory
3029

3130
/** Operation on a tile returning a tile. */
32-
trait UnaryRasterOp extends UnaryRasterFunction with RasterResult { this: HasUnaryExpressionCopy =>
31+
trait UnaryRasterOp extends UnaryRasterFunction with RasterResult {
3332
@transient protected lazy val logger = Logger(LoggerFactory.getLogger(getClass.getName))
3433

3534
def dataType: DataType = child.dataType
@@ -38,7 +37,5 @@ trait UnaryRasterOp extends UnaryRasterFunction with RasterResult { this: HasUna
3837
toInternalRow(op(tile), ctx)
3938

4039
protected def op(child: Tile): Tile
41-
42-
override protected def withNewChildInternal(newChild: Expression): Expression = copy(newChild)
4340
}
4441

core/src/main/scala/org/locationtech/rasterframes/expressions/accessors/ExtractTile.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ case class ExtractTile(child: Expression) extends UnaryRasterFunction with Codeg
4343
case prt: ProjectedRasterTile => tileUDT.serialize(prt.tile)
4444
case tile: Tile => tileSer(tile)
4545
}
46+
47+
def withNewChildInternal(newChild: Expression): Expression = copy(newChild)
4648
}
4749

4850
object ExtractTile {

core/src/main/scala/org/locationtech/rasterframes/expressions/accessors/GetCRS.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ case class GetCRS(child: Expression) extends UnaryExpression with CodegenFallbac
9797
}
9898
}
9999

100-
override protected def withNewChildInternal(newChild: Expression): Expression = copy(newChild)
100+
def withNewChildInternal(newChild: Expression): Expression = copy(newChild)
101101
}
102102

103103
object GetCRS {

core/src/main/scala/org/locationtech/rasterframes/expressions/accessors/GetCellType.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ case class GetCellType(child: Expression) extends OnCellGridExpression with Code
5656
/** Implemented by subtypes to process incoming ProjectedRasterLike entity. */
5757
def eval(cg: CellGrid[Int]): Any = resultConverter(cg.cellType)
5858

59-
override protected def withNewChildInternal(newChild: Expression): Expression = copy(newChild)
59+
def withNewChildInternal(newChild: Expression): Expression = copy(newChild)
6060
}
6161

6262
object GetCellType {

0 commit comments

Comments
 (0)