cloud-fan commented on code in PR #38257:
URL: https://github.com/apache/spark/pull/38257#discussion_r998330332
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/util/PartitioningUtils.scala:
##########
@@ -20,14 +20,47 @@ package org.apache.spark.sql.util
import org.apache.spark.sql.catalyst.analysis.Resolver
import org.apache.spark.sql.catalyst.catalog.CatalogTypes.TablePartitionSpec
import
org.apache.spark.sql.catalyst.catalog.ExternalCatalogUtils.DEFAULT_PARTITION_NAME
+import org.apache.spark.sql.catalyst.expressions.{Cast, Expression, Literal}
import org.apache.spark.sql.catalyst.util.CharVarcharCodegenUtils
import org.apache.spark.sql.catalyst.util.CharVarcharUtils
import org.apache.spark.sql.errors.QueryCompilationErrors
import org.apache.spark.sql.internal.SQLConf
-import org.apache.spark.sql.types.{CharType, StructType, VarcharType}
+import org.apache.spark.sql.internal.SQLConf.StoreAssignmentPolicy
+import org.apache.spark.sql.types.{CharType, DataType, StringType,
StructField, StructType, VarcharType}
import org.apache.spark.unsafe.types.UTF8String
private[sql] object PartitioningUtils {
+
+ def castPartitionSpec(value: String, dt: DataType, conf: SQLConf):
Expression = {
+ conf.storeAssignmentPolicy match {
+ // SPARK-30844: try our best to follow StoreAssignmentPolicy for static
partition
+ // values but not completely follow because we can't do static type
checking due to
+ // the reason that the parser has erased the type info of static
partition values
+ // and converted them to string.
+ case StoreAssignmentPolicy.ANSI | StoreAssignmentPolicy.STRICT =>
+ val cast = Cast(Literal(value), dt, Option(conf.sessionLocalTimeZone),
+ ansiEnabled = true)
+ cast.setTagValue(Cast.BY_TABLE_INSERTION, ())
+ cast
+ case _ =>
+ Cast(Literal(value), dt, Option(conf.sessionLocalTimeZone),
+ ansiEnabled = false)
+ }
+ }
+
+ private def castPartitionSpecToString(value: String, field: StructField):
String = {
Review Comment:
the name is weird as the input is already a `String`. How about
`normalizePartitionStringValue`?
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]