Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions dataset/src/main/scala/frameless/TypedColumn.scala
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,18 @@ abstract class AbstractTypedColumn[T, U]
def +(u: U)(implicit n: CatalystNumeric[U]): ThisType[T, U] =
typed(self.untyped.plus(u))

/**
* Inversion of boolean expression, i.e. NOT.
* {{{
* // Select rows that are not active (isActive === false)
* df.filter( !df('isActive) )
* }}}
*
* apache/spark
*/
def unary_!(implicit i0: U <:< Boolean): ThisType[T, Boolean] =
typed(!untyped)

/** Unary minus, i.e. negate the expression.
* {{{
* // Select the amount column and negates all values.
Expand Down
17 changes: 17 additions & 0 deletions dataset/src/test/scala/frameless/ColumnTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import java.time.Instant

import org.scalacheck.Prop._
import org.scalacheck.{Arbitrary, Gen, Prop}
import org.scalatest.Matchers._
import shapeless.test.illTyped

import scala.math.Ordering.Implicits._
Expand Down Expand Up @@ -357,4 +358,20 @@ class ColumnTests extends TypedDatasetSuite {
check(forAll(prop[Vector[Vector[String]], Vector[Vector[BigDecimal]]] _))
}

test("unary_!") {
val ds = TypedDataset.create((true, false) :: Nil)

val rs = ds.select(!ds('_1), !ds('_2)).collect().run().head
val expected = (false, true)

rs shouldEqual expected
}

test("unary_! with non-boolean columns should not compile") {
val ds = TypedDataset.create((1, "a", 2.0) :: Nil)

"ds.select(!ds('_1))" shouldNot typeCheck
"ds.select(!ds('_2))" shouldNot typeCheck
"ds.select(!ds('_3))" shouldNot typeCheck
}
}