How to sort by column in descending order in Spark SQL?

You can also sort the column by importing the spark sql functions import org.apache.spark.sql.functions._ df.orderBy(asc(“col1”)) Or import org.apache.spark.sql.functions._ df.sort(desc(“col1″)) importing sqlContext.implicits._ import sqlContext.implicits._ df.orderBy($”col1″.desc) Or import sqlContext.implicits._ df.sort($”col1”.desc)

Scala: write string to file in one statement

It is strange that no one had suggested NIO.2 operations (available since Java 7): import java.nio.file.{Paths, Files} import java.nio.charset.StandardCharsets Files.write(Paths.get(“file.txt”), “file contents”.getBytes(StandardCharsets.UTF_8)) I think this is by far the simplest and easiest and most idiomatic way, and it does not need any dependencies sans Java itself.

How can I change column types in Spark SQL’s DataFrame?

Edit: Newest newest version Since spark 2.x you should use dataset api instead when using Scala [1]. Check docs here: https://spark.apache.org/docs/latest/api/scala/org/apache/spark/sql/Dataset.html#withColumn(colName:String,col:org.apache.spark.sql.Column):org.apache.spark.sql.DataFrame If working with python, even though easier, I leave the link here as it’s a very highly voted question: https://spark.apache.org/docs/latest/api/python/reference/api/pyspark.sql.DataFrame.withColumn.html >>> df.withColumn(‘age2’, df.age + 2).collect() [Row(age=2, name=”Alice”, age2=4), Row(age=5, name=”Bob”, age2=7)] [1] https://spark.apache.org/docs/latest/sql-programming-guide.html: In … Read more

Build.scala, % and %% symbols meaning

From the official documentation: http://www.playframework.com/documentation/2.1.1/SBTDependencies Getting the right Scala version with %% If you use groupID %% artifactID % revision instead of groupID % artifactID % revision (the difference is the double %% after the groupID), SBT will add your project’s Scala version to the artifact name. This is just a shortcut. You could write … Read more

Getting a structural type with an anonymous class’s methods from a macro

This question is answered in duplicate by Travis here. There are links to the issue in the tracker and to Eugene’s discussion (in the comments and mailing list). In the famous “Skylla and Charybdis” section of the type checker, our hero decides what shall escape dark anonymity and see the light as a member of … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)