You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/03/03 01:20:29 UTC
[GitHub] [spark] HyukjinKwon commented on a change in pull request #35690: [SPARK-38335][SQL] Implement parser support for DEFAULT column values
HyukjinKwon commented on a change in pull request #35690:
URL: https://github.com/apache/spark/pull/35690#discussion_r818235977
##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
##########
@@ -2756,6 +2763,41 @@ class AstBuilder extends SqlBaseBaseVisitor[AnyRef] with SQLConfHelper with Logg
metadata = builder.build())
}
+ /**
+ * Create a [[StructType]] from a number of CREATE TABLE column definitions.
+ */
+ override def visitCreateOrReplaceTableColTypeList(
+ ctx: CreateOrReplaceTableColTypeListContext): Seq[StructField] = withOrigin(ctx) {
+ ctx.createOrReplaceTableColType().asScala.map(visitCreateOrReplaceTableColType).toSeq
+ }
+
+ /**
+ * Create a top level [[StructField]] from a CREATE TABLE column definition.
+ */
+ override def visitCreateOrReplaceTableColType(
+ ctx: CreateOrReplaceTableColTypeContext): StructField = withOrigin(ctx) {
+ import ctx._
+
+ val builder = new MetadataBuilder
+ // Add comment to metadata
+ Option(commentSpec()).map(visitCommentSpec).foreach {
+ builder.putString("comment", _)
+ }
+
+ // Process the 'DEFAULT expression' clause in the column definition, if any.
+ val name: String = colName.getText
+ val defaultExpr = Option(ctx.defaultExpression()).map(visitDefaultExpression)
+ if (defaultExpr != None) {
Review comment:
```suggestion
if (defaultExpr.isDefined) {
```
##########
File path: sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/DDLParserSuite.scala
##########
@@ -1448,6 +1448,7 @@ class DDLParserSuite extends AnalysisTest {
Assignment(UnresolvedAttribute("target.col2"), UnresolvedAttribute("source.col2")))))))
}
+
Review comment:
```suggestion
```
##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
##########
@@ -3813,6 +3871,9 @@ class AstBuilder extends SqlBaseBaseVisitor[AnyRef] with SQLConfHelper with Logg
throw QueryParsingErrors.operationInHiveStyleCommandUnsupportedError(
"Replacing with a nested column", "REPLACE COLUMNS", ctx)
}
+ if (Option(colType.defaultExpression()).map(visitDefaultExpression) != None) {
Review comment:
```suggestion
if (Option(colType.defaultExpression()).map(visitDefaultExpression).isDefined) {
```
##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
##########
@@ -3651,12 +3695,20 @@ class AstBuilder extends SqlBaseBaseVisitor[AnyRef] with SQLConfHelper with Logg
}
}
+ private def defaultColumnNotImplementedYetError = {
+ "Support for DEFAULT column values is not implemented yet"
+ }
+
/**
* Parse new column info from ADD COLUMN into a QualifiedColType.
*/
override def visitQualifiedColTypeWithPosition(
ctx: QualifiedColTypeWithPositionContext): QualifiedColType = withOrigin(ctx) {
val name = typedVisit[Seq[String]](ctx.name)
+ val defaultExpr = Option(ctx.defaultExpression()).map(visitDefaultExpression)
+ if (defaultExpr != None) {
Review comment:
```suggestion
if (defaultExpr.isDefined) {
```
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org