I've come across this operator in a Spark application written in Scala and would like to understand it. Example...
val filtered = df
.filter(lower('entry) =!= "blah blah")
Thanks.
There are five relational operators in Scala: Greater than (>) Less than (<) Greater than or equal to (>=)
The operators are as follows: The assignment operator ( = ): assigns a value to a variable. Add and assignment ( += ): takes two operands, adds them, and assigns the value to the operand on the left. Subtract and assignment ( -= ): takes two operands, subtracts them, and assigns the value to the operand on the left.
The triple equals operator === is normally the Scala type-safe equals operator, analogous to the one in Javascript. Spark overrides this with a method in Column to create a new Column object that compares the Column to the left with the object on the right, returning a boolean.
Not Equal To(!=)operator checks whether the two given operands are equal or not. If not, it returns true. Otherwise it returns false. It is the exact boolean complement of the '==' operator.
That's just a method name like any other method name. It has no special meaning whatsoever.
It is also not a well-known method name in Scala. It seems to come from some library; you need to look at the documentation of whatever library you are using to figure out what it does.
In this case, it appears to be org.apache.spark.sql.Column.=!=
:
def =!=(other: Any): Column
Inequality test.
// Scala: df.select( df("colA") =!= df("colB") ) df.select( !(df("colA") === df("colB")) ) // Java: import static org.apache.spark.sql.functions.*; df.filter( col("colA").notEqual(col("colB")) );
you must use the =!= operator so that you don’t just compare the unevaluated column expression to a string but instead to the evaluated one
source:spark-the definitive guide
That is this method in org.apache.spark.sql.Column which serves as an inequality test.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With