Class/Object

com.eharmony.aloha.semantics.compiled

CompiledSemantics

Related Docs: object CompiledSemantics | package compiled

Permalink

case class CompiledSemantics[A](compiler: ContainerReadable[Try], plugin: CompiledSemanticsPlugin[A], imports: Seq[String], provideSemanticsUdfException: Boolean = true)(implicit ec: ExecutionContext) extends CompiledSemanticsLike[A] with MorphableSemantics[CompiledSemantics, A] with ErrorEnrichingSemantics[A] with Logging with Product with Serializable

A semantics that can interpret complicated expressions by compiling the expressions. This semantics constructs actual working scala code (see the format below).

Notice from the code that is constructed that it calls a function in com.eharmony.aloha.semantics.func.GenFunc. The function that is called is based on the input arity. Aside from the f0 function, fi has i arguments in the first argument list and two arguments in the second argument list. The first argument list represents the definition of the accessor functions. These are the functions created to extract data from the domain object. com.eharmony.aloha.semantics.compiled.CompiledSemanticsPlugin objects are responsible for constructing the function bodies. For instance, (_:Map[String, Long]).get("user.match.TaxBrackets") in the first example. The CompiledSemantics class is responsible for wrapping this code appropriately, constructing the aggregation function and finally putting everything together and compiling it.

Examples

E.g. 1: Two variables are both optional (not necessarily in the input type passed to the model): - user.match.TaxBrackets - cand.taxBracket

val spec1 = "Seq(${user.match.TaxBrackets}) contains ${cand.taxBracket}"
val f1 = s.createFunction[Boolean](spec1, Some(false)).right.get

// Equivalent to:
//    val f1a =
//      com.eharmony.aloha.semantics.compiled.GenFunc.f2(           // f2 b/c 2 variables.
//        com.eharmony.aloha.semantics.compiled.GeneratedAccessor(  // Optional Accessor:
//          "user.match.TaxBrackets",
//          (_:Map[String, Long]).get("user.match.TaxBrackets"),             // <-- get produces Option[Long]
//          Some("(_:Map[String, Long]).get(\"user.match.TaxBrackets\")")),
//        com.eharmony.aloha.semantics.compiled.GeneratedAccessor(  // Optional Accessor:
//          "cand.taxBracket",
//          (_:Map[String, Long]).get("cand.taxBracket"),                    // <-- get produces Option[Long]
//          Some("(_:Map[String, Long]).get(\"cand.taxBracket\")"))
//      )(
//        "Seq(${user.match.TaxBrackets}) contains ${cand.taxBracket}",
//        (o0, o1) => for {
//          _user__match__TaxBrackets <- o0                                  // Optional fields in for comprehension
//          _cand__taxBracket <- o1
//        } yield {
//          Seq(_user__match__TaxBrackets) contains _cand__taxBracket        // Transformed function spec
//        }
//      )
//
//    val f1 = com.eharmony.aloha.semantics.compiled.OptionalFunc(f1a, false)

E.g. 2: Two variables (one required, one optional): - user.inboundComm (required) - user.pageViews (optional)

val spec2 = "${user.inboundComm} / ${user.pageViews}.toDouble"
val f2 = s.createFunction[Double](spec2, Some(Double.NaN)).right.get

// Equivalent to:
//    val f2a =
//      com.eharmony.aloha.semantics.compiled.GenFunc.f2(           // f2 b/c 2 variables.
//        com.eharmony.aloha.semantics.compiled.GeneratedAccessor(  // Optional Accessor:
//          "user.pageViews",
//          (_:Map[String, Long]).get("user.pageViews"),                     // <-- get produces Option[Long]
//          Some("(_:Map[String, Long]).get(\"user.pageViews\")")),
//        com.eharmony.aloha.semantics.compiled.GeneratedAccessor(  // Required Accessor:
//          "user.inboundComm",
//          (_:Map[String, Long]).apply("user.inboundComm"),                 // <-- apply produces Long
//          Some("(_:Map[String, Long]).apply(\"user.inboundComm\")"))
//      )(
//        "${user.inboundComm} / ${user.pageViews}.toDouble",
//        (o0, _user__inboundComm) => for {
//          _user__pageViews <- o0                                           // Optional field in for comprehension
//        } yield {
//          _user__inboundComm / _user__pageViews.toDouble                   // Transformed function spec
//        }
//      )
//
//    val f2 = com.eharmony.aloha.semantics.compiled.OptionalFunc(f2a, Double.NaN)

E.g. 3: Three required variables (one, two, three):

val spec3 = "List(${one}, ${two}, ${three}).sum.toInt"
val f3 = s.createFunction[Int](spec3).right.get

// Equivalent to:
//    val f3 =
//      com.eharmony.aloha.semantics.compiled.GenFunc.f3(           // f3 b/c 3 variables.
//        com.eharmony.aloha.semantics.compiled.GeneratedAccessor(
//          "one",
//          (_:Map[String, Long]).apply("one"),
//          Some("(_:Map[String, Long]).apply(\"one\")")),
//        com.eharmony.aloha.semantics.compiled.GeneratedAccessor(
//          "two",
//          (_:Map[String, Long]).apply("two"),
//          Some("(_:Map[String, Long]).apply(\"two\")")),
//        com.eharmony.aloha.semantics.compiled.GeneratedAccessor(
//          "three",
//          (_:Map[String, Long]).apply("three"),
//          Some("(_:Map[String, Long]).apply(\"three\")"))
//      )(
//        "List(${one}, ${two}, ${three}).sum.toInt",
//        (_one, _two, _three) => {                  // Notice simplified expression when all params are required.
//          List(_one, _two, _three).sum.toInt       // Variable names are in the param list so no need for temp
//        }                                          // variables.
//      )

E.g. 4: Invariant function (not dependent on any input variables).

val spec4 = "new util.Random(System.nanoTime).nextLong"
val f = s.createFunction[Long](spec4).right.get         // f(null) is OK b/c not reliant on input value.

// Equivalent to:
//    val f4 =
//      com.eharmony.aloha.semantics.compiled.GenFunc.f0( // f0 b/c input arity is 0
//        "new util.Random(System.nanoTime).nextLong",
//        (_:Any) => new util.Random(System.nanoTime).nextLong     // Notice input is Any
//      )                                                          // OK b/c of Function1 1st arg contravariance.
A

the input type to the functions that are to be generated. Said another way, this is domain type of the models that will be generated by the ModelFactory to which this com.eharmony.aloha.semantics.Semantics will be passed.

compiler

a compiler capable of compiling real scala code and generating real instances that work at full speed.

plugin

a plugin that can make sense of the variable specifications and generate code to extract data from them.

imports

a list of imports.

provideSemanticsUdfException

whether we should provide com.eharmony.aloha.semantics.SemanticsUdfException instead of raw exceptions in the case that a feature produces an exception. The perceived benefit of this seems to drastically outweigh the performance hit, so this defaults to true (as this is suggested).

ec

an execution context in which to run the Futures that are used in the cache.

Linear Supertypes
Serializable, Serializable, Product, Equals, ErrorEnrichingSemantics[A], MorphableSemantics[CompiledSemantics, A], CompiledSemanticsLike[A], Logging, EitherHelpers, Semantics[A], Closeable, AutoCloseable, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. CompiledSemantics
  2. Serializable
  3. Serializable
  4. Product
  5. Equals
  6. ErrorEnrichingSemantics
  7. MorphableSemantics
  8. CompiledSemanticsLike
  9. Logging
  10. EitherHelpers
  11. Semantics
  12. Closeable
  13. AutoCloseable
  14. AnyRef
  15. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new CompiledSemantics(compiler: ContainerReadable[Try], plugin: CompiledSemanticsPlugin[A], imports: Array[String], ec: ExecutionContext)

    Permalink

    A java (Spring) friendly constructor.

    A java (Spring) friendly constructor.

    compiler

    a compiler capable of compiling real scala code and generating real instances that work at full speed.

    plugin

    a plugin that can make sense of the variable specifications and generate code to extract data from them.

    imports

    an array of imports. Will be cloned before being stored to avoid caller changing array values.

    ec

    an execution context in which to run the Futures that are used in the cache.

  2. new CompiledSemantics(compiler: ContainerReadable[Try], plugin: CompiledSemanticsPlugin[A], imports: Array[String], provideSemanticsUdfException: Boolean, ec: ExecutionContext)

    Permalink

    A java (Spring) friendly constructor.

    A java (Spring) friendly constructor.

    compiler

    a compiler capable of compiling real scala code and generating real instances that work at full speed.

    plugin

    a plugin that can make sense of the variable specifications and generate code to extract data from them.

    imports

    an array of imports. Will be cloned before being stored to avoid caller changing array values.

    provideSemanticsUdfException

    whether we should provide com.eharmony.aloha.semantics.SemanticsUdfException instead of raw exceptions in the case that a feature produces an exception. The perceived benefit of this seems to drastically outweigh the performance hit, so this defaults to true (as this is suggested).

    ec

    an execution context in which to run the Futures that are used in the cache.

  3. new CompiledSemantics(compiler: ContainerReadable[Try], plugin: CompiledSemanticsPlugin[A], imports: Seq[String], provideSemanticsUdfException: Boolean = true)(implicit ec: ExecutionContext)

    Permalink

    compiler

    a compiler capable of compiling real scala code and generating real instances that work at full speed.

    plugin

    a plugin that can make sense of the variable specifications and generate code to extract data from them.

    imports

    a list of imports.

    provideSemanticsUdfException

    whether we should provide com.eharmony.aloha.semantics.SemanticsUdfException instead of raw exceptions in the case that a feature produces an exception. The perceived benefit of this seems to drastically outweigh the performance hit, so this defaults to true (as this is suggested).

    ec

    an execution context in which to run the Futures that are used in the cache.

Type Members

  1. type ENS[+A] = Either[Seq[String], A]

    Permalink

    Either of Non-empty Seq (Like poor man's version of ValidationNel from scalaz)

    Either of Non-empty Seq (Like poor man's version of ValidationNel from scalaz)

    Attributes
    protected[this]
    Definition Classes
    EitherHelpers

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. def accessorFunctionNames: Nothing

    Permalink

    Returns the string representations of all of the data "variables" used by functions created from this Semantics object.

    Returns the string representations of all of the data "variables" used by functions created from this Semantics object.

    Definition Classes
    CompiledSemanticsLikeSemantics
  5. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  6. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  7. def close(): Unit

    Permalink
    Definition Classes
    CompiledSemanticsLike → Closeable → AutoCloseable
  8. val compiler: ContainerReadable[Try]

    Permalink

    a compiler capable of compiling real scala code and generating real instances that work at full speed.

    a compiler capable of compiling real scala code and generating real instances that work at full speed.

    Definition Classes
    CompiledSemanticsCompiledSemanticsLike
  9. def createFunction[B](codeSpec: String, default: Option[B] = None)(implicit arg0: RefInfo[B]): Either[Seq[String], GenAggFunc[A, B]]

    Permalink

    Create a function from A to B.

    Create a function from A to B. If provideSemanticsUdfException is false or the generated function is is com.eharmony.aloha.semantics.func.EnrichedErrorGenAggFunc return the function; otherwise, return the function wrapped in an com.eharmony.aloha.semantics.func.EnrichedErrorGenAggFunc. com.eharmony.aloha.semantics.func.GenAggFunc produced by the underlying semantics.

    B

    The return type of the function.

    codeSpec

    specification for a function to be produced by this semantics.

    default

    a default value in the case that the function would produce an optional type.

    Definition Classes
    ErrorEnrichingSemanticsSemantics
  10. final def debug(msg: ⇒ Any, t: ⇒ Throwable): Unit

    Permalink

    Issue a debug logging message, with an exception.

    Issue a debug logging message, with an exception.

    msg

    the message object. toString() is called to convert it to a loggable string.

    t

    the exception to include with the logged message.

    Attributes
    protected[this]
    Definition Classes
    Logging
  11. final def debug(msg: ⇒ Any): Unit

    Permalink

    Issue a debug logging message.

    Issue a debug logging message.

    msg

    the message object. toString() is called to convert it to a loggable string.

    Attributes
    protected[this]
    Definition Classes
    Logging
  12. implicit val ec: ExecutionContext

    Permalink

    an execution context in which to run the Futures that are used in the cache.

    an execution context in which to run the Futures that are used in the cache.

    Attributes
    protected
    Definition Classes
    CompiledSemanticsCompiledSemanticsLike
  13. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  14. final def error(msg: ⇒ Any, t: ⇒ Throwable): Unit

    Permalink

    Issue a error logging message, with an exception.

    Issue a error logging message, with an exception.

    msg

    the message object. toString() is called to convert it to a loggable string.

    t

    the exception to include with the logged message.

    Attributes
    protected[this]
    Definition Classes
    Logging
  15. final def error(msg: ⇒ Any): Unit

    Permalink

    Issue a error logging message.

    Issue a error logging message.

    msg

    the message object. toString() is called to convert it to a loggable string.

    Attributes
    protected[this]
    Definition Classes
    Logging
  16. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  17. def fromValidationNel[A](v: ValidationNel[String, A]): ENS[A]

    Permalink
    Attributes
    protected[this]
    Definition Classes
    EitherHelpers
  18. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  19. val imports: Seq[String]

    Permalink

    a list of imports.

    a list of imports.

    Definition Classes
    CompiledSemanticsCompiledSemanticsLike
  20. final def info(msg: ⇒ Any, t: ⇒ Throwable): Unit

    Permalink

    Issue a info logging message, with an exception.

    Issue a info logging message, with an exception.

    msg

    the message object. toString() is called to convert it to a loggable string.

    t

    the exception to include with the logged message.

    Attributes
    protected[this]
    Definition Classes
    Logging
  21. final def info(msg: ⇒ Any): Unit

    Permalink

    Issue a info logging message.

    Issue a info logging message.

    msg

    the message object. toString() is called to convert it to a loggable string.

    Attributes
    protected[this]
    Definition Classes
    Logging
  22. final def isDebugEnabled: Boolean

    Permalink

    Determine whether debug logging is enabled.

    Determine whether debug logging is enabled.

    Attributes
    protected[this]
    Definition Classes
    Logging
  23. final def isErrorEnabled: Boolean

    Permalink

    Determine whether error logging is enabled.

    Determine whether error logging is enabled.

    Attributes
    protected[this]
    Definition Classes
    Logging
  24. final def isInfoEnabled: Boolean

    Permalink

    Determine whether info logging is enabled.

    Determine whether info logging is enabled.

    Attributes
    protected[this]
    Definition Classes
    Logging
  25. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  26. final def isTraceEnabled: Boolean

    Permalink

    Determine whether trace logging is enabled.

    Determine whether trace logging is enabled.

    Attributes
    protected[this]
    Definition Classes
    Logging
  27. final def isWarnEnabled: Boolean

    Permalink

    Determine whether warn logging is enabled.

    Determine whether warn logging is enabled.

    Attributes
    protected[this]
    Definition Classes
    Logging
  28. final lazy val logger: Logger

    Permalink

    The logger is a @transient lazy val to enable proper working with Spark.

    The logger is a @transient lazy val to enable proper working with Spark. The logger will not be serialized with the rest of the class with which this trait is mixed-in.

    Attributes
    protected[this]
    Definition Classes
    Logging
  29. def loggerInitName(): String

    Permalink

    The name with which the logger is initialized.

    The name with which the logger is initialized. This can be overridden in a derived class.

    Attributes
    protected
    Definition Classes
    Logging
  30. final def loggerName: String

    Permalink

    Get the name associated with this logger.

    Get the name associated with this logger.

    returns

    the name.

    Attributes
    protected[this]
    Definition Classes
    Logging
  31. def mapSeq[A, B](l: Seq[A])(f: (A) ⇒ ENS[B]): ENS[Seq[B]]

    Permalink

    Like l.map(f).sequence[({type L[+A] = Either[Seq[String], A]})#L, C ] in scalaz except that it short circuits if it finds an error.

    Like l.map(f).sequence[({type L[+A] = Either[Seq[String], A]})#L, C ] in scalaz except that it short circuits if it finds an error. (There must be some better way to do this w/ scalaz).

    If we put a println("folding") at the top of the inner function h, we would get the following:

    scala> mapSeq(Left(Seq("1")) +: (2 to 3).map(Right(_)))(identity)  // Only 1 "folding" instead of 3.
    folding
    res0: ENS[Seq[Int]] = Left(List(0))
    
    scala> mapSeq((1 to 3).map(Right(_)))(identity)
    folding
    folding
    folding
    res1: ENS[Seq[Int]] = Right(List(1, 2, 3))
    A

    type of values in the input sequence in the first parameter list.

    B

    type of values in the output sequence if successful.

    l

    list of values to which f should be applied.

    f

    function to map over l

    Attributes
    protected[this]
    Definition Classes
    EitherHelpers
  32. def morph[B](implicit ri: RefInfo[B]): Option[CompiledSemantics[B]]

    Permalink

    Attempt to create a new CompiledSemantics with a different type parameter.

    Attempt to create a new CompiledSemantics with a different type parameter.

    B

    input type for the new MorphableSemantics instance that might be created. A MorphableSemantics instance may choose not allow morphing to all B. In that case, a None will be returned.

    ri

    reflection information that may be necessary to determine whether to create the MorphableSemantics that was requested.

    Definition Classes
    CompiledSemanticsMorphableSemantics
  33. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  34. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  35. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  36. val plugin: CompiledSemanticsPlugin[A]

    Permalink

    a plugin that can make sense of the variable specifications and generate code to extract data from them.

    a plugin that can make sense of the variable specifications and generate code to extract data from them.

    Definition Classes
    CompiledSemanticsCompiledSemanticsLike
  37. val provideSemanticsUdfException: Boolean

    Permalink

    whether we should provide com.eharmony.aloha.semantics.SemanticsUdfException instead of raw exceptions in the case that a feature produces an exception.

    whether we should provide com.eharmony.aloha.semantics.SemanticsUdfException instead of raw exceptions in the case that a feature produces an exception. The perceived benefit of this seems to drastically outweigh the performance hit, so this defaults to true (as this is suggested).

    Definition Classes
    CompiledSemanticsErrorEnrichingSemantics
  38. def refInfoA: RefInfo[A]

    Permalink

    returns

    a com.eharmony.aloha.reflect.RefInfo for input type A.

    Definition Classes
    CompiledSemanticsLikeSemantics
  39. def retainGeneratedCode(): Boolean

    Permalink

    Generated code will only be retained in the Generated code when debug logging is enabled.

    Generated code will only be retained in the Generated code when debug logging is enabled.

    Definition Classes
    CompiledSemanticsCompiledSemanticsLike
  40. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  41. def toValidationNel[A](e: ENS[A]): ValidationNel[String, A]

    Permalink
    Attributes
    protected[this]
    Definition Classes
    EitherHelpers
  42. final def trace(msg: ⇒ Any, t: ⇒ Throwable): Unit

    Permalink

    Issue a trace logging message, with an exception.

    Issue a trace logging message, with an exception.

    msg

    the message object. toString() is called to convert it to a loggable string.

    t

    the exception to include with the logged message.

    Attributes
    protected[this]
    Definition Classes
    Logging
  43. final def trace(msg: ⇒ Any): Unit

    Permalink

    Issue a trace logging message.

    Issue a trace logging message.

    msg

    the message object. toString() is called to convert it to a loggable string.

    Attributes
    protected[this]
    Definition Classes
    Logging
  44. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  45. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  46. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  47. final def warn(msg: ⇒ Any, t: ⇒ Throwable): Unit

    Permalink

    Issue a warn logging message, with an exception.

    Issue a warn logging message, with an exception.

    msg

    the message object. toString() is called to convert it to a loggable string.

    t

    the exception to include with the logged message.

    Attributes
    protected[this]
    Definition Classes
    Logging
  48. final def warn(msg: ⇒ Any): Unit

    Permalink

    Issue a warn logging message.

    Issue a warn logging message.

    msg

    the message object. toString() is called to convert it to a loggable string.

    Attributes
    protected[this]
    Definition Classes
    Logging

Inherited from Serializable

Inherited from Serializable

Inherited from Product

Inherited from Equals

Inherited from ErrorEnrichingSemantics[A]

Inherited from CompiledSemanticsLike[A]

Inherited from Logging

Inherited from EitherHelpers

Inherited from Semantics[A]

Inherited from Closeable

Inherited from AutoCloseable

Inherited from AnyRef

Inherited from Any

Ungrouped