Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the =!= operator in Scala?

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.

like image 617
conner.xyz Avatar asked Sep 27 '18 20:09

conner.xyz


People also ask

What are the operators in Scala?

There are five relational operators in Scala: Greater than (>) Less than (<) Greater than or equal to (>=)

What is the use of the &= operator in Scala?

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.

What does === mean in Scala?

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.

How do you use not equal to in Scala?

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.


3 Answers

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")) );
like image 146
Jörg W Mittag Avatar answered Sep 18 '22 12:09

Jörg W Mittag


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

like image 32
selvaram s Avatar answered Sep 18 '22 12:09

selvaram s


That is this method in org.apache.spark.sql.Column which serves as an inequality test.

like image 38
Levi Ramsey Avatar answered Sep 20 '22 12:09

Levi Ramsey