luoyuxia commented on code in PR #20696: URL: https://github.com/apache/flink/pull/20696#discussion_r964494659
########## docs/content.zh/docs/dev/table/hiveCompatibility/hiveDialect/Queries/sort-cluster-distribute-by.md: ########## @@ -0,0 +1,94 @@ +--- +title: "Sort/Cluster/Distributed By" +weight: 2 +type: docs +--- +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +# Sort/Cluster/Distributed by Clause + +## Sort By + +### Description + +Unlike [ORDER BY]({{< ref "docs/dev/table/hiveCompatibility/hiveDialect/Queries/overview" >}}#order-by-clause) which guarantees a total order of output, +`SORT BY` only guarantees the result rows with each partition is in the user specified order. +So when there's more than one partition, `SORT BY` may return result that's partially ordered. + +### Syntax + +```sql +colOrder: ( ASC | DESC ) +sortBy: SORT BY BY expression [ , ... ] +query: SELECT expression [ , ... ] FROM src sortBy +``` + +### Parameters +- colOrder + + it's used specified the order of returned rows. The default order is `ASC`. + +### Examples + +```sql +SELECT x, y FROM t SORT BY x; +SELECT x, y FROM t SORT BY abs(y) DESC; +``` + +## Distribute By + +### Description + +The `DISTRIBUTE BY` clause is used to repartition the data. +The data with same value evaluated by the specified expression will be in same partition. + +### Syntax + +```sql +distributeBy: DISTRIBUTE BY expression [ , ... ] +query: SELECT expression [ , ... ] FROM src distributeBy +``` + +### Examples + +```sql +SELECT x, y FROM t DISTRIBUTE BY x; +SELECT x, y FROM t DISTRIBUTE BY abs(y); +``` + +## Cluster By + +### Description + +`CLUSTER BY` is a short-cut for both `DISTRIBUTE BY` and `SORT BY`. Review Comment: no. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
