Object

io.getquill.norm

SimplifyNullChecks

Related Doc: package norm

Permalink

object SimplifyNullChecks extends StatelessTransformer

Due to the introduction of null checks in map, flatMap, and exists, in FlattenOptionOperation in order to resolve #1053, as well as to support non-ansi compliant string concatenation as outlined in #1295, large conditional composites became common. For example:

case class Holder(value:Option[String])

// The following statement
query[Holder].map(h => h.value.map(_ + "foo"))
// Will yield the following result
SELECT CASE WHEN h.value IS NOT NULL THEN h.value || 'foo' ELSE null END FROM Holder h
Now, let's add a getOrElse statement to the clause that requires an additional wrapped null check. We cannot rely on there being a map call beforehand since we could be reading value as a nullable field directly from the database).
// The following statement
query[Holder].map(h => h.value.map(_ + "foo").getOrElse("bar"))
// Yields the following result:
SELECT CASE WHEN
CASE WHEN h.value IS NOT NULL THEN h.value || 'foo' ELSE null END
IS NOT NULL THEN
CASE WHEN h.value IS NOT NULL THEN h.value || 'foo' ELSE null END
ELSE 'bar' END FROM Holder h
This of course is highly redundant and can be reduced to simply:
SELECT CASE WHEN h.value IS NOT NULL AND (h.value || 'foo') IS NOT NULL THEN h.value || 'foo' ELSE 'bar' END FROM Holder h
This reduction is done by the "Center Rule." There are some other simplification rules as well. Note how we are force to null-check both h.value as well as (h.value || 'foo') because a user may use Option[T].flatMap and explicitly transform a particular value to null.

Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. SimplifyNullChecks
  2. StatelessTransformer
  3. AnyRef
  4. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

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 apply(ast: Ast): Ast

    Permalink
  5. def apply(e: Action): Action

    Permalink
    Definition Classes
    StatelessTransformer
  6. def apply(e: Target): Target

    Permalink
    Definition Classes
    StatelessTransformer
  7. def apply(e: Action): Action

    Permalink
    Definition Classes
    StatelessTransformer
  8. def apply(e: Value): Value

    Permalink
    Definition Classes
    StatelessTransformer
  9. def apply(e: Operation): Operation

    Permalink
    Definition Classes
    StatelessTransformer
  10. def apply(e: Property): Property

    Permalink
    Definition Classes
    StatelessTransformer
  11. def apply(e: Assignment): Assignment

    Permalink
    Definition Classes
    StatelessTransformer
  12. def apply(e: Query): Query

    Permalink
    Definition Classes
    StatelessTransformer
  13. def apply(o: TraversableOperation): TraversableOperation

    Permalink
    Definition Classes
    StatelessTransformer
  14. def apply(o: OptionOperation): OptionOperation

    Permalink
    Definition Classes
    StatelessTransformer
  15. final def asInstanceOf[T0]: T0

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

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  17. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  18. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  19. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  20. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  21. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  22. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  23. final def ne(arg0: AnyRef): Boolean

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

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

    Permalink
    Definition Classes
    AnyRef
  26. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  27. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  28. final def wait(): Unit

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

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

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from StatelessTransformer

Inherited from AnyRef

Inherited from Any

Ungrouped