File tree Expand file tree Collapse file tree 2 files changed +17
-2
lines changed
main/scala/org/apache/spark/sql/catalyst/expressions
test/scala/org/apache/spark/sql/catalyst/expressions Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -184,8 +184,8 @@ case class BitwiseNot(child: Expression) extends UnaryExpression {
184184 null
185185 } else {
186186 dataType match {
187- case ByteType => ~ evalE.asInstanceOf [Byte ]
188- case ShortType => ~ evalE.asInstanceOf [Short ]
187+ case ByteType => ( ~ evalE.asInstanceOf [Byte ]).toByte
188+ case ShortType => ( ~ evalE.asInstanceOf [Short ]).toShort
189189 case IntegerType => ~ evalE.asInstanceOf [Int ]
190190 case LongType => ~ evalE.asInstanceOf [Long ]
191191 case other => sys.error(s " Unsupported bitwise ~ operation on $other" )
Original file line number Diff line number Diff line change @@ -42,6 +42,21 @@ class ExpressionEvaluationSuite extends FunSuite {
4242 checkEvaluation(Literal (1 ) + Literal (1 ), 2 )
4343 }
4444
45+ test(" unary BitwiseNOT" ) {
46+ checkEvaluation(BitwiseNot (1 ), - 2 )
47+ assert(BitwiseNot (1 ).dataType === IntegerType )
48+ assert(BitwiseNot (1 ).eval(EmptyRow ).isInstanceOf [Int ])
49+ checkEvaluation(BitwiseNot (1 .toLong), - 2 )
50+ assert(BitwiseNot (1 .toLong).dataType === LongType )
51+ assert(BitwiseNot (1 .toLong).eval(EmptyRow ).isInstanceOf [Long ])
52+ checkEvaluation(BitwiseNot (1 .toShort), - 2 )
53+ assert(BitwiseNot (1 .toShort).dataType === ShortType )
54+ assert(BitwiseNot (1 .toShort).eval(EmptyRow ).isInstanceOf [Short ])
55+ checkEvaluation(BitwiseNot (1 .toByte), - 2 )
56+ assert(BitwiseNot (1 .toByte).dataType === ByteType )
57+ assert(BitwiseNot (1 .toByte).eval(EmptyRow ).isInstanceOf [Byte ])
58+ }
59+
4560 /**
4661 * Checks for three-valued-logic. Based on:
4762 * http://en.wikipedia.org/wiki/Null_(SQL)#Comparisons_with_NULL_and_the_three-valued_logic_.283VL.29
You can’t perform that action at this time.
0 commit comments