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 {
184
184
null
185
185
} else {
186
186
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
189
189
case IntegerType => ~ evalE.asInstanceOf [Int ]
190
190
case LongType => ~ evalE.asInstanceOf [Long ]
191
191
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 {
42
42
checkEvaluation(Literal (1 ) + Literal (1 ), 2 )
43
43
}
44
44
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
+
45
60
/**
46
61
* Checks for three-valued-logic. Based on:
47
62
* 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