Skip to content

Commit

Permalink
Move RealWorld type into a separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
pomadchin authored and echeipesh committed Jan 15, 2018
1 parent 1be8222 commit c0b480d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
@@ -0,0 +1,20 @@
package geotrellis.spark.pipeline.ast

import geotrellis.spark.pipeline.json.PipelineExpr

import io.circe.Json
import org.apache.spark.SparkContext

sealed trait RealWorld

object RealWorld {
/** RealWorld node has nothing implemented */
def instance = new Node[RealWorld] {
def get(implicit sc: SparkContext): RealWorld =
throw new UnsupportedOperationException("get function is not supported by a RealWorld node")
def arg: PipelineExpr =
throw new UnsupportedOperationException("arg function is not supported by a RealWorld node")
def asJson: List[Json] =
throw new UnsupportedOperationException("asJson function is not supported by a RealWorld node")
}
}
@@ -1,7 +1,5 @@
package geotrellis.spark.pipeline.ast.untyped

import io.circe.Json

import geotrellis.raster._
import geotrellis.spark._
import geotrellis.spark.pipeline.ast
Expand All @@ -13,27 +11,18 @@ import geotrellis.spark.pipeline.json._
import geotrellis.spark.pipeline.json.read._
import geotrellis.vector._

import org.apache.spark.SparkContext
import org.apache.spark.rdd.RDD

import scala.reflect.runtime.universe.{TypeTag, typeTag}
import scala.reflect.runtime.universe.Type
import scala.util.Try

trait RealWorld

object RealWorld {
/** RealWorld node has nothing implemented */
def instance = new Node[RealWorld] {
def get(implicit sc: SparkContext): RealWorld =
throw new UnsupportedOperationException("get function is not supported by a RealWorld node")
def arg: PipelineExpr =
throw new UnsupportedOperationException("arg function is not supported by a RealWorld node")
def asJson: List[Json] =
throw new UnsupportedOperationException("asJson function is not supported by a RealWorld node")
}
}

/**
* Erased node type, represents a typed Node with types kept inside.
* It is a function, as it should operate with nodes constructor types
* and to "compose" untyped nodes.
*
*/
trait ErasedNode extends (Any => Any) {
def maybeApply(x: Any): Option[Any]

Expand Down Expand Up @@ -104,6 +93,7 @@ case class ErasedTypedNode[Domain: TypeTag, Range: TypeTag](constructor: Node[Do
.map(_.asInstanceOf[Node[Any]])
}

/** Helper functions to convert typed nodes into erased typed nodes */
object ErasedTypedNode {
def fromRead[Range: TypeTag](node: ast.Read[Range]) =
ErasedTypedNode[RealWorld, Range](_ => node)
Expand All @@ -115,8 +105,11 @@ object ErasedTypedNode {
ErasedTypedNode[Domain, Range](constructor)
}

// TODO: support user defined types
/**
* Class that allows to convert node json representation into an ErasedNode
*/
case class ErasedJsonNode(arg: PipelineExpr) {
// TODO: support user defined types
def toErasedNode: ErasedNode = {
arg.`type` match {
case _: SinglebandSpatialExprType => {
Expand Down

0 comments on commit c0b480d

Please sign in to comment.