2016-11-15 187 views
3

排序和orderBy有什麼區別?Spark DataFrame是什麼?Spark中的排序和orderBy函數有什麼區別

scala> zips.printSchema 
root 
|-- _id: string (nullable = true) 
|-- city: string (nullable = true) 
|-- loc: array (nullable = true) 
| |-- element: double (containsNull = true) 
|-- pop: long (nullable = true) 
|-- state: string (nullable = true) 

下面的命令產生相同的結果:

zips.sort(desc("pop")).show 
zips.orderBy(desc("pop")).show 

回答

7

排序依據僅僅是排序函數的別名。

從星火文檔:

/** 
    * Returns a new Dataset sorted by the given expressions. 
    * This is an alias of the `sort` function. 
    * 
    * @group typedrel 
    * @since 2.0.0 
    */ 
    @scala.annotation.varargs 
    def orderBy(sortCol: String, sortCols: String*): Dataset[T] = sort(sortCol, sortCols : _*) 
相關問題