Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class DDLParser(parseQuery: String => LogicalPlan)
protected val AS = Keyword("AS")
protected val COMMENT = Keyword("COMMENT")
protected val REFRESH = Keyword("REFRESH")
protected val NULL = Keyword("NULL")

protected lazy val ddl: Parser[LogicalPlan] = createTable | describeTable | refreshTable

Expand Down Expand Up @@ -173,13 +174,15 @@ class DDLParser(parseQuery: String => LogicalPlan)
optionName ~ stringLit ^^ { case k ~ v => (k, v) }

protected lazy val column: Parser[StructField] =
ident ~ dataType ~ (COMMENT ~> stringLit).? ^^ { case columnName ~ typ ~ cm =>
val meta = cm match {
case Some(comment) =>
new MetadataBuilder().putString(COMMENT.str.toLowerCase, comment).build()
case None => Metadata.empty
}

StructField(columnName, typ, nullable = true, meta)
ident ~ dataType ~ (NOT ~ NULL).? ~ (COMMENT ~> stringLit).? ^^ {
case columnName ~ typ ~ notNull ~ cm =>
val meta = cm match {
case Some(comment) =>
new MetadataBuilder().putString(COMMENT.str.toLowerCase, comment).build()
case None => Metadata.empty
}

val isNullable = notNull.isEmpty
StructField(columnName, typ, nullable = isNullable, meta)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,23 @@ class DDLTestSuite extends DataSourceTest with SharedSQLContext {
assert(attributes.map(_.name) === Seq("col_name", "data_type", "comment"))
assert(attributes.map(_.dataType).toSet === Set(StringType))
}

test("SPARK-7012 Create table statement should support NOT NULL modifier for columns") {
withTempPath { dir =>
val path = dir.getCanonicalPath
sql(
s"""
|CREATE TEMPORARY TABLE tempTableDDL
|( tCol1 INT NOT NULL,
| tCol2 STRING
|)
|USING parquet
|OPTIONS (
| path '$path'
|)
""".stripMargin
)
caseInsensitiveContext.dropTempTable("tempTableDDL")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

improve this test case to make sure we really make that column not nullable, i.e. read the table out and check its schema.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sabhyankar Do you have time to modify this? I think that once the test is improved with @cloud-fan comment, the change is probably good to merge.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @smola @cloud-fan - I will take a look at the test case this week and update you guys

}
}
}