Skip to content

Commit

Permalink
[SQL] Make Options in the data source API CREATE TABLE statements opt…
Browse files Browse the repository at this point in the history
…ional.

Users will not need to put `Options()` in a CREATE TABLE statement when there is not option provided.

Author: Yin Huai <yhuai@databricks.com>

Closes #4515 from yhuai/makeOptionsOptional and squashes the following commits:

1a898d3 [Yin Huai] Make options optional.

(cherry picked from commit e28b6bd)
Signed-off-by: Michael Armbrust <michael@databricks.com>
  • Loading branch information
yhuai authored and marmbrus committed Feb 11, 2015
1 parent f43bc3d commit 445dbc7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
Expand Up @@ -106,13 +106,14 @@ private[sql] class DDLParser extends AbstractSparkSQLParser with Logging {
protected lazy val createTable: Parser[LogicalPlan] =
(
(CREATE ~> TEMPORARY.? <~ TABLE) ~ (IF ~> NOT <~ EXISTS).? ~ ident
~ (tableCols).? ~ (USING ~> className) ~ (OPTIONS ~> options) ~ (AS ~> restInput).? ^^ {
~ (tableCols).? ~ (USING ~> className) ~ (OPTIONS ~> options).? ~ (AS ~> restInput).? ^^ {
case temp ~ allowExisting ~ tableName ~ columns ~ provider ~ opts ~ query =>
if (temp.isDefined && allowExisting.isDefined) {
throw new DDLException(
"a CREATE TEMPORARY TABLE statement does not allow IF NOT EXISTS clause.")
}

val options = opts.getOrElse(Map.empty[String, String])
if (query.isDefined) {
if (columns.isDefined) {
throw new DDLException(
Expand All @@ -121,7 +122,7 @@ private[sql] class DDLParser extends AbstractSparkSQLParser with Logging {
CreateTableUsingAsSelect(tableName,
provider,
temp.isDefined,
opts,
options,
allowExisting.isDefined,
query.get)
} else {
Expand All @@ -131,7 +132,7 @@ private[sql] class DDLParser extends AbstractSparkSQLParser with Logging {
userSpecifiedSchema,
provider,
temp.isDefined,
opts,
options,
allowExisting.isDefined)
}
}
Expand Down
Expand Up @@ -361,9 +361,7 @@ class MetastoreDataSourcesSuite extends QueryTest with BeforeAndAfterEach {
s"""
|CREATE TABLE ctasJsonTable
|USING org.apache.spark.sql.json.DefaultSource
|OPTIONS (
|
|) AS
|AS
|SELECT * FROM jsonTable
""".stripMargin)

Expand Down

0 comments on commit 445dbc7

Please sign in to comment.