maropu commented on a change in pull request #30421:
URL: https://github.com/apache/spark/pull/30421#discussion_r530024935
##########
File path: docs/sql-ref-syntax-dml-insert-into.md
##########
@@ -198,6 +198,21 @@ SELECT * FROM students;
+-------------+-------------------------+----------+
```
+#### Insert Using a type constructed partition col value
+```sql
+CREATE TABLE students(name STRING, address STRING) PARTITIONED BY (birthday
DATE);
+
+INSERT INTO students PARTITION(birthday = date'2019-01-02')
+ VALUES('Amy Smith', '123 Park Ave, San Jose');
Review comment:
nit: `VALUES(` -> `VALUES (`
##########
File path: docs/sql-ref-syntax-dml-insert-into.md
##########
@@ -198,6 +198,21 @@ SELECT * FROM students;
+-------------+-------------------------+----------+
```
+#### Insert Using a type constructed partition col value
Review comment:
`#### Insert Using a Type Constructed Partition Column Value`
##########
File path: docs/sql-ref-syntax-dml-insert-into.md
##########
@@ -41,7 +41,7 @@ INSERT INTO [ TABLE ] table_identifier [ partition_spec ]
* **partition_spec**
An optional parameter that specifies a comma separated list of key and
value pairs
- for partitions.
+ for partitions. Here we support use type constructed value as partition
col value.
Review comment:
`Note that one can use a type constructed value (e.g., date'2019-01-02')
for a partition column value.`?
##########
File path: docs/sql-ref-syntax-dml-insert-into.md
##########
@@ -198,6 +198,21 @@ SELECT * FROM students;
+-------------+-------------------------+----------+
```
+#### Insert Using a type constructed partition col value
+```sql
+CREATE TABLE students(name STRING, address STRING) PARTITIONED BY (birthday
DATE);
+
+INSERT INTO students PARTITION(birthday = date'2019-01-02')
Review comment:
nit: `PARTITION(` -> `PARTITION (`
##########
File path: docs/sql-ref-syntax-dml-insert-into.md
##########
@@ -198,6 +198,21 @@ SELECT * FROM students;
+-------------+-------------------------+----------+
```
+#### Insert Using a type constructed partition col value
+```sql
+CREATE TABLE students(name STRING, address STRING) PARTITIONED BY (birthday
DATE);
Review comment:
nit: `students(` -> `students (`
##########
File path: docs/sql-ref-syntax-dml-insert-overwrite-table.md
##########
@@ -41,7 +41,7 @@ INSERT OVERWRITE [ TABLE ] table_identifier [ partition_spec
[ IF NOT EXISTS ] ]
* **partition_spec**
An optional parameter that specifies a comma separated list of key and
value pairs
- for partitions.
+ for partitions. Here we support use type constructed value as partition
col value.
Review comment:
I have the same comment with `sql-ref-syntax-dml-insert-into.md `
##########
File path: docs/sql-ref-syntax-dml-insert-into.md
##########
@@ -198,6 +198,21 @@ SELECT * FROM students;
+-------------+-------------------------+----------+
```
+#### Insert Using a type constructed partition col value
+```sql
+CREATE TABLE students(name STRING, address STRING) PARTITIONED BY (birthday
DATE);
+
+INSERT INTO students PARTITION(birthday = date'2019-01-02')
+ VALUES('Amy Smith', '123 Park Ave, San Jose');
+
+SELECT * FROM students;
Review comment:
nit: a unnecessary space found.
##########
File path: docs/sql-ref-syntax-dml-insert-into.md
##########
@@ -41,7 +41,7 @@ INSERT INTO [ TABLE ] table_identifier [ partition_spec ]
* **partition_spec**
An optional parameter that specifies a comma separated list of key and
value pairs
- for partitions.
+ for partitions. Here we support use type constructed value as partition
col value.
Review comment:
btw, `a type constructed value` is a common word in the user's doc? I've
checked the literal doc, but I couldn't find it:
https://spark.apache.org/docs/3.0.1/sql-ref-literals.html
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
##########
@@ -503,13 +503,32 @@ class AstBuilder extends SqlBaseBaseVisitor[AnyRef] with
SQLConfHelper with Logg
}
}
+ private def convertTypeConstructedLiteralToString(literal: Literal): String
= literal match {
+ case Literal(data: Int, dataType: DateType) =>
+ UTF8String.fromString(
+ DateFormatter(getZoneId(SQLConf.get.sessionLocalTimeZone))
+ .format(data)).toString
+ case Literal(data: Long, dataType: TimestampType) =>
+ UTF8String.fromString(
+
TimestampFormatter.getFractionFormatter(getZoneId(SQLConf.get.sessionLocalTimeZone))
+ .format(data)).toString
+ case Literal(data: CalendarInterval, dataType: CalendarIntervalType) =>
+ UTF8String.fromString(data.toString).toString
+ case Literal(data: Array[Byte], dataType: BinaryType) =>
+ UTF8String.fromBytes(data).toString
+ case Literal(data, dataType) =>
+ UTF8String.fromString(data.toString).toString
Review comment:
how about throwing an illegal state exception in the case?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]