Vitali Melamud :
I have the following code (Java with Spark SQL) -
import static org.apache.spark.sql.functions.col;
...
System.out.println("=== Filtering records with average age more than 20 ===");
Dataset<Row> result = df.filter(col("age").$less(20));
I never met a function call in Java that starts with a dollar. Tried googling it but my best guess so far is that it's a result of a Java calling Scala code (but in Scala source code there is no $less function)
Could you please provide a solid explanation for this?
Mahmoud Hanafy :
because every allowable symbol in Scala’s method syntax has a corresponding translation of the form “$trans“. so for your question there is a method in scala that called <
and the corresponding method in java will be $less
Other operators will be compiled to:
╔═══════════════════╦══════════════╗
║ Scala Operator ║ Compiles To ║
╠═══════════════════╬══════════════╣
║= ║$eq ║
║> ║$greater ║
║< ║$less ║
║+ ║$plus ║
║- ║$minus ║
║* ║$times ║
║/ ║$div ║
║! ║$bang ║
║@ ║$at ║
║# ║$hash ║
║% ║$percent ║
║^ ║$up ║
║& ║$amp ║
║~ ║$tilde ║
║? ║$qmark ║
║║ ║$bar ║
║\ ║$bslash ║
║: ║$colon ║
╚═══════════════════╩══════════════╝
more information about this can be found here: http://www.codecommit.com/blog/java/interop-between-java-and-scala