You often need to sort data when processing it. This document describes how to use Spark SQL for data sorting in FineDataLink.
You can use the ORDER BY clause in Spark SQL to perform a global sorting on the query result set. For large datasets, this process will take a long time to execute.
DESC: It stands for descending order.
ASC: It stands for ascending order.
Example 1: You need to sort the daily sales amount in the Daily_Sales_Summary table in ascending order.
select * FROMDB Table Inputorder by DB Table Input.`Daily_Sales` ASC
You can click Data Preview to view the results sorted in ascending order, as shown in the following figure.
Example 2: You need to sort the sales amount in the Daily_Sales_Summary dataset in descending order.
select * FROMDB Table Input-3order by DB Table Input-1.`Daily_Sales` DESC
You can click Data Preview to view the results sorted in descending order, as shown in the following figure.
Typically, local sorting is implemented by the combination of SORT BY and DISTRIBUTE BY.
SORT BY performs local sorting, which ensures that data within each group is sorted in order, yet it cannot guarantee that the entire dataset is globally sorted unless the data belongs to only one group. Its advantage is that local sorting can greatly improve the efficiency of subsequent global sorting.
DISTRIBUTE BY sorts data in the form of groups. Its functionality is somewhat similar to that of GROUP BY.
Example 1: You can sort the daily sales amount in the Daily_Sales_Summary table in ascending order, grouped by store number.
select * FROMDB Table Input-2distribute by DB Table Input-2.`Store` sort by DB Table Input-2.`Store`, DB Table Input-2.`Daily_Sales` ASC
The store numbers are sorted in ascending order, and the daily sales amount of the same store is sorted in ascending order, as shown in the following figure.
CLUSTER BY combines the functionalities of DISTRIBUTE BY and SORT BY.
Example 1:
select * FROMDB Table Input-3distribute by DB Table Input-3.`Store` sort by DB Table Input-3.`Store` ASC
Example 2:
select * FROMDB Table Input-3cluster by DB Table Input-3.`Store`
You can click Data Preview to view the results, where the store numbers are sorted in ascending order, as shown in the following figure.
滑鼠選中內容,快速回饋問題
滑鼠選中存在疑惑的內容,即可快速回饋問題,我們將會跟進處理。
不再提示
10s後關閉
Submitted successfully
Network busy