File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -189,6 +189,18 @@ abstract class AbstractTypedColumn[T, U]
189189 def + (u : U )(implicit n : CatalystNumeric [U ]): ThisType [T , U ] =
190190 typed(self.untyped.plus(u))
191191
192+ /**
193+ * Inversion of boolean expression, i.e. NOT.
194+ * {{{
195+ * // Select rows that are not active (isActive === false)
196+ * df.filter( !df('isActive) )
197+ * }}}
198+ *
199+ * apache/spark
200+ */
201+ def unary_! (implicit i0 : U <:< Boolean ): ThisType [T , Boolean ] =
202+ typed(! untyped)
203+
192204 /** Unary minus, i.e. negate the expression.
193205 * {{{
194206 * // Select the amount column and negates all values.
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import java.time.Instant
44
55import org .scalacheck .Prop ._
66import org .scalacheck .{Arbitrary , Gen , Prop }
7+ import org .scalatest .Matchers ._
78import shapeless .test .illTyped
89
910import scala .math .Ordering .Implicits ._
@@ -357,4 +358,20 @@ class ColumnTests extends TypedDatasetSuite {
357358 check(forAll(prop[Vector [Vector [String ]], Vector [Vector [BigDecimal ]]] _))
358359 }
359360
361+ test(" unary_!" ) {
362+ val ds = TypedDataset .create((true , false ) :: Nil )
363+
364+ val rs = ds.select(! ds(' _1 ), ! ds(' _2 )).collect().run().head
365+ val expected = (false , true )
366+
367+ rs shouldEqual expected
368+ }
369+
370+ test(" unary_! with non-boolean columns should not compile" ) {
371+ val ds = TypedDataset .create((1 , " a" , 2.0 ) :: Nil )
372+
373+ " ds.select(!ds('_1))" shouldNot typeCheck
374+ " ds.select(!ds('_2))" shouldNot typeCheck
375+ " ds.select(!ds('_3))" shouldNot typeCheck
376+ }
360377}
You can’t perform that action at this time.
0 commit comments