From 63d035a9d4f1a1062ce407dc53e64434b882671e Mon Sep 17 00:00:00 2001 From: sharangk Date: Tue, 27 Aug 2019 14:12:18 +0530 Subject: [PATCH 1/5] [SPARK-28792][SQL][DOC] Document CREATE DATABASE statement in SQL Reference # 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. ## How was this patch tested? This is just a documentation change, verified manually. --- docs/sql-ref-syntax-ddl-create-database.md | 37 +++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/docs/sql-ref-syntax-ddl-create-database.md b/docs/sql-ref-syntax-ddl-create-database.md index bbcd34a6d685..fc0d27327bd7 100644 --- a/docs/sql-ref-syntax-ddl-create-database.md +++ b/docs/sql-ref-syntax-ddl-create-database.md @@ -19,4 +19,39 @@ license: | limitations under the License. --- -**This page is under construction** +### Description +Creates a database with the given name. If database with the same name exists an exception will be thrown. + +### Syntax +{% highlight sql %} +CREATE (DATABASE|SCHEMA) [IF NOT EXISTS] database_name + [COMMENT database_comment] + [LOCATION database_directory] + [WITH DBPROPERTIES (property_name=property_value, ...)] + +{% endhighlight %} + +### Parameters +- ##### ***IF NOT EXISTS***: +Creates a database with the given name if it doesn't exists. If a database with the same name already exists, nothing will happen. +- ##### ***LOCATION***: +Path of the file system in which database to be created. If the specified path does not exist in the underlying file system, this command creates a directory with the path. +- ##### ***COMMENT***: +Description for the Database. +- ##### ***WITH DBPROPERTIES***: +Properties for the database in key-value pair. + +### Examples +{% highlight sql %} +-- Create database `customer_db`. This throws exception if database with name customer_db already exists. +CREATE DATABASE customer_db; +-- Create database `customer_db` only if database with same name doesn't exist. +CREATE DATABASE IF NOT EXISTS customer_db; +-- Create database `customer_db` only if database with same name doesn't exist with `Comments`, `Specific Location` and `Database properties`. +CREATE DATABASE IF NOT EXISTS customer_db COMMENT 'This is customer database' LOCATION '/user' WITH DBPROPERTIES (ID=001, Name='John'); +{% endhighlight %} + + +### Related statements. +- [DESCRIBE DATABASE](sql-ref-syntax-aux-describe-database.html) + From 321cff9b5da544a9c70e67d9e07b9d64b11c8ce9 Mon Sep 17 00:00:00 2001 From: sharangk Date: Thu, 5 Sep 2019 16:57:59 +0530 Subject: [PATCH 2/5] [SPARK-28792][SQL][DOC] Document CREATE DATABASE statement in SQL Reference # 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. ## How was this patch tested? This is just a documentation change, verified manually. --- docs/sql-ref-syntax-ddl-create-database.md | 53 +++++++++++++++------- 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/docs/sql-ref-syntax-ddl-create-database.md b/docs/sql-ref-syntax-ddl-create-database.md index fc0d27327bd7..413a725f1edd 100644 --- a/docs/sql-ref-syntax-ddl-create-database.md +++ b/docs/sql-ref-syntax-ddl-create-database.md @@ -20,38 +20,57 @@ license: | --- ### Description -Creates a database with the given name. If database with the same name exists an exception will be thrown. +Creates a database with the specified name. If database with the same name already exists, an exception will be thrown. ### Syntax {% highlight sql %} -CREATE (DATABASE|SCHEMA) [IF NOT EXISTS] database_name - [COMMENT database_comment] - [LOCATION database_directory] - [WITH DBPROPERTIES (property_name=property_value, ...)] - +CREATE {DATABASE | SCHEMA} [ IF NOT EXISTS ] database_name + [ COMMENT database_comment ] + [ LOCATION database_directory ] + [ WITH DBPROPERTIES (property_name=property_value [ , ...]) ] {% endhighlight %} ### Parameters -- ##### ***IF NOT EXISTS***: -Creates a database with the given name if it doesn't exists. If a database with the same name already exists, nothing will happen. -- ##### ***LOCATION***: -Path of the file system in which database to be created. If the specified path does not exist in the underlying file system, this command creates a directory with the path. -- ##### ***COMMENT***: -Description for the Database. -- ##### ***WITH DBPROPERTIES***: -Properties for the database in key-value pair. +
+
database_name
+
Specifies the name of the database to be created.
+ +
IF NOT EXISTS
+
Creates a database with the given name if it doesn't exists. If a database with the same name already exists, nothing will happen.
+ +
database_directory
+
Path of the file system in which database to be created. If the specified path does not exist in the underlying file system, this command creates a directory with the path. If location is not specified, database will be created in default warehouse directory.
+ +
database_comment
+
Description for the database.
+ +
WITH DBPROPERTIES (property_name=property_value [ , ...])
+
Properties for the database in key-value pair.
+
### Examples {% highlight sql %} -- Create database `customer_db`. This throws exception if database with name customer_db already exists. CREATE DATABASE customer_db; + -- Create database `customer_db` only if database with same name doesn't exist. CREATE DATABASE IF NOT EXISTS customer_db; --- Create database `customer_db` only if database with same name doesn't exist with `Comments`, `Specific Location` and `Database properties`. + +-- Create database `customer_db` only if database with same name doesn't exist with `Comments`,`Specific Location` and `Database properties`. CREATE DATABASE IF NOT EXISTS customer_db COMMENT 'This is customer database' LOCATION '/user' WITH DBPROPERTIES (ID=001, Name='John'); -{% endhighlight %} +-- Verify that properties are set. +DESCRIBE DATABASE EXTENDED customer_db; + +----------------------------+-----------------------------+ + | database_description_item | database_description_value | + +----------------------------+-----------------------------+ + | Database Name | customer_db | + | Description | This is customer database | + | Location | hdfs://hacluster/user | + | Properties | ((ID,001), (Name,John)) | + +----------------------------+-----------------------------+ +{% endhighlight %} -### Related statements. +### Related Statements - [DESCRIBE DATABASE](sql-ref-syntax-aux-describe-database.html) From 7ef960b1f760cbdbbf141c61659e9753eda99114 Mon Sep 17 00:00:00 2001 From: sharangk Date: Fri, 13 Sep 2019 16:32:31 +0530 Subject: [PATCH 3/5] updated review comments --- docs/sql-ref-syntax-ddl-create-database.md | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/docs/sql-ref-syntax-ddl-create-database.md b/docs/sql-ref-syntax-ddl-create-database.md index 413a725f1edd..dbc622fd4cf8 100644 --- a/docs/sql-ref-syntax-ddl-create-database.md +++ b/docs/sql-ref-syntax-ddl-create-database.md @@ -42,22 +42,25 @@ CREATE {DATABASE | SCHEMA} [ IF NOT EXISTS ] database_name
Path of the file system in which database to be created. If the specified path does not exist in the underlying file system, this command creates a directory with the path. If location is not specified, database will be created in default warehouse directory.
database_comment
-
Description for the database.
+
Specifies the description for the database.
WITH DBPROPERTIES (property_name=property_value [ , ...])
-
Properties for the database in key-value pair.
+
Specifies the properties for the database in key-value pair.
### Examples {% highlight sql %} --- Create database `customer_db`. This throws exception if database with name customer_db already exists. +-- Create database `customer_db`. This throws exception if database with name customer_db +-- already exists. CREATE DATABASE customer_db; -- Create database `customer_db` only if database with same name doesn't exist. CREATE DATABASE IF NOT EXISTS customer_db; --- Create database `customer_db` only if database with same name doesn't exist with `Comments`,`Specific Location` and `Database properties`. -CREATE DATABASE IF NOT EXISTS customer_db COMMENT 'This is customer database' LOCATION '/user' WITH DBPROPERTIES (ID=001, Name='John'); +-- Create database `customer_db` only if database with same name doesn't exist with +-- `Comments`,`Specific Location` and `Database properties`. +CREATE DATABASE IF NOT EXISTS customer_db COMMENT 'This is customer database' LOCATION '/user' + WITH DBPROPERTIES (ID=001, Name='John'); -- Verify that properties are set. DESCRIBE DATABASE EXTENDED customer_db; @@ -73,4 +76,4 @@ DESCRIBE DATABASE EXTENDED customer_db; ### Related Statements - [DESCRIBE DATABASE](sql-ref-syntax-aux-describe-database.html) - +- [DROP DATABASE](sql-ref-syntax-ddl-drop-database.html) From 5cb4c42778544bb08889afaa1b7f18dfeb4df2d3 Mon Sep 17 00:00:00 2001 From: sharangk Date: Tue, 17 Sep 2019 16:57:33 +0530 Subject: [PATCH 4/5] updated sentence --- docs/sql-ref-syntax-ddl-create-database.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/sql-ref-syntax-ddl-create-database.md b/docs/sql-ref-syntax-ddl-create-database.md index dbc622fd4cf8..1b6ec89d82f8 100644 --- a/docs/sql-ref-syntax-ddl-create-database.md +++ b/docs/sql-ref-syntax-ddl-create-database.md @@ -39,7 +39,7 @@ CREATE {DATABASE | SCHEMA} [ IF NOT EXISTS ] database_name
Creates a database with the given name if it doesn't exists. If a database with the same name already exists, nothing will happen.
database_directory
-
Path of the file system in which database to be created. If the specified path does not exist in the underlying file system, this command creates a directory with the path. If location is not specified, database will be created in default warehouse directory.
+
Path of the file system in which the specified database is to be created. If the specified path does not exist in the underlying file system, this command creates a directory with the path. If location is not specified, database will be created in default warehouse directory.
database_comment
Specifies the description for the database.
From 0225553e7047cec270e8dba8fda983c5cb6920a5 Mon Sep 17 00:00:00 2001 From: Xiao Li Date: Tue, 17 Sep 2019 13:42:04 -0700 Subject: [PATCH 5/5] Update sql-ref-syntax-ddl-create-database.md --- docs/sql-ref-syntax-ddl-create-database.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/sql-ref-syntax-ddl-create-database.md b/docs/sql-ref-syntax-ddl-create-database.md index 1b6ec89d82f8..ed0bbf629b02 100644 --- a/docs/sql-ref-syntax-ddl-create-database.md +++ b/docs/sql-ref-syntax-ddl-create-database.md @@ -39,13 +39,13 @@ CREATE {DATABASE | SCHEMA} [ IF NOT EXISTS ] database_name
Creates a database with the given name if it doesn't exists. If a database with the same name already exists, nothing will happen.
database_directory
-
Path of the file system in which the specified database is to be created. If the specified path does not exist in the underlying file system, this command creates a directory with the path. If location is not specified, database will be created in default warehouse directory.
+
Path of the file system in which the specified database is to be created. If the specified path does not exist in the underlying file system, this command creates a directory with the path. If the location is not specified, the database will be created in the default warehouse directory, whose path is configured by the static configuration spark.sql.warehouse.dir.
database_comment
Specifies the description for the database.
WITH DBPROPERTIES (property_name=property_value [ , ...])
-
Specifies the properties for the database in key-value pair.
+
Specifies the properties for the database in key-value pairs.
### Examples