Skip to content

Commit

Permalink
[SPARK-28812][SQL][DOC] Document SHOW PARTITIONS in SQL Reference
Browse files Browse the repository at this point in the history
### What changes were proposed in this pull request?
Document SHOW PARTITIONS statement in SQL Reference Guide.

### Why are the changes needed?
Currently Spark lacks documentation on the supported SQL constructs causing
confusion among users who sometimes have to look at the code to understand the
usage. This is aimed at addressing this issue.

### Does this PR introduce any user-facing change?
Yes.

**Before**
**After**
![image](https://user-images.githubusercontent.com/14225158/69405056-89468180-0cb3-11ea-8eb7-93046eaf551c.png)
![image](https://user-images.githubusercontent.com/14225158/69405067-93688000-0cb3-11ea-810a-11cab9e4a041.png)
![image](https://user-images.githubusercontent.com/14225158/69405120-c01c9780-0cb3-11ea-91c0-91eeaa9238a0.png)

Closes #26635 from dilipbiswal/show_partitions.

Authored-by: Dilip Biswal <dkbiswal@gmail.com>
Signed-off-by: Dongjoon Hyun <dhyun@apple.com>
  • Loading branch information
dilipbiswal authored and dongjoon-hyun committed Nov 24, 2019
1 parent 6898be9 commit 564826d
Showing 1 changed file with 82 additions and 1 deletion.
83 changes: 82 additions & 1 deletion docs/sql-ref-syntax-aux-show-partitions.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,86 @@ license: |
See the License for the specific language governing permissions and
limitations under the License.
---
### Description

**This page is under construction**
The `SHOW PARTITIONS` statement is used to list partitions of a table. An optional
partition spec may be specified to return the partitions matching the supplied
partition spec.

### Syntax
{% highlight sql %}
SHOW PARTITIONS table_name
[ PARTITION ( partition_col_name [ = partition_col_val ] [ , ... ] ) ]
{% endhighlight %}

### Parameters
<dl>
<dt><code><em>table_name</em></code></dt>
<dd>The name of an existing table.</dd>
</dl>
<dl>
<dt><code><em>PARTITION ( partition_col_name [ = partition_col_val ] [ , ... ] )</em></code></dt>
<dd>An optional parameter that specifies a comma separated list of key and value pairs for
partitions. When specified, the partitions that match the partition spec are returned.</dd>
</dl>

### Examples
{% highlight sql %}
-- create a partitioned table and insert a few rows.
USE salesdb;
CREATE TABLE customer(id INT, name STRING) PARTITIONED BY (state STRING, city STRING);
INSERT INTO customer PARTITION (state = 'CA', city = 'Fremont') VALUES (100, 'John');
INSERT INTO customer PARTITION (state = 'CA', city = 'San Jose') VALUES (200, 'Marry');
INSERT INTO customer PARTITION (state = 'AZ', city = 'Peoria') VALUES (300, 'Daniel');

-- Lists all partitions for table `customer`
SHOW PARTITIONS customer;
+----------------------+
|partition |
+----------------------+
|state=AZ/city=Peoria |
|state=CA/city=Fremont |
|state=CA/city=San Jose|
+----------------------+

-- Lists all partitions for the qualified table `customer`
SHOW PARTITIONS salesdb.customer;
+----------------------+
|partition |
+----------------------+
|state=AZ/city=Peoria |
|state=CA/city=Fremont |
|state=CA/city=San Jose|
+----------------------+

-- Specify a full partition spec to list specific partition
SHOW PARTITIONS customer PARTITION (state = 'CA', city = 'Fremont');
+---------------------+
|partition |
+---------------------+
|state=CA/city=Fremont|
+---------------------+

-- Specify a partial partition spec to list the specific partitions
SHOW PARTITIONS customer PARTITION (state = 'CA');
+----------------------+
|partition |
+----------------------+
|state=CA/city=Fremont |
|state=CA/city=San Jose|
+----------------------+

-- Specify a partial spec to list specific partition
SHOW PARTITIONS customer PARTITION (city = 'San Jose');
+----------------------+
|partition |
+----------------------+
|state=CA/city=San Jose|
+----------------------+
{% endhighlight %}

### Related statements
- [CREATE TABLE](sql-ref-syntax-ddl-create-table.html)
- [INSERT STATEMENT](sql-ref-syntax-dml-insert.html)
- [DESCRIBE TABLE](sql-ref-syntax-aux-describe-table.html)
- [SHOW TABLE](sql-ref-syntax-aux-show-table.html)

0 comments on commit 564826d

Please sign in to comment.