Dollar sign in function call in Java using Spark SQL

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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=36423&siteId=1