Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -19,14 +19,13 @@ package org.apache.spark.sql.catalyst.analysis

import org.apache.spark.sql.catalyst.InternalRow
import org.apache.spark.sql.catalyst.catalog.CatalogTypes.TablePartitionSpec
import org.apache.spark.sql.catalyst.expressions.{Cast, Literal}
import org.apache.spark.sql.catalyst.plans.logical.{LogicalPlan, V2PartitionCommand}
import org.apache.spark.sql.catalyst.rules.Rule
import org.apache.spark.sql.catalyst.trees.TreePattern.COMMAND
import org.apache.spark.sql.catalyst.util.CharVarcharUtils
import org.apache.spark.sql.connector.catalog.SupportsPartitionManagement
import org.apache.spark.sql.types._
import org.apache.spark.sql.util.PartitioningUtils.{normalizePartitionSpec, requireExactMatchedPartitionSpec}
import org.apache.spark.sql.util.PartitioningUtils.{castPartitionSpec, normalizePartitionSpec, requireExactMatchedPartitionSpec}

/**
* Resolve [[UnresolvedPartitionSpec]] to [[ResolvedPartitionSpec]] in partition related commands.
Expand Down Expand Up @@ -78,7 +77,7 @@ object ResolvePartitionSpec extends Rule[LogicalPlan] {
val partValues = schema.map { part =>
val raw = partitionSpec.get(part.name).orNull
val dt = CharVarcharUtils.replaceCharVarcharWithString(part.dataType)
Cast(Literal.create(raw, StringType), dt, Some(conf.sessionLocalTimeZone)).eval()
castPartitionSpec(raw, dt, conf).eval()
}
InternalRow.fromSeq(partValues)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package org.apache.spark.sql.execution.command.v2
import org.apache.spark.sql.{AnalysisException, Row}
import org.apache.spark.sql.catalyst.analysis.PartitionsAlreadyExistException
import org.apache.spark.sql.execution.command
import org.apache.spark.sql.internal.SQLConf

/**
* The class contains tests for the `ALTER TABLE .. ADD PARTITION` command
Expand Down Expand Up @@ -124,18 +123,4 @@ class AlterTableAddPartitionSuite
checkPartitions(t, Map("id" -> "1"), Map("id" -> "2"))
}
}

test("SPARK-40798: Alter partition should verify partition value - legacy") {
withNamespaceAndTable("ns", "tbl") { t =>
sql(s"CREATE TABLE $t (c int) $defaultUsing PARTITIONED BY (p int)")

withSQLConf(
SQLConf.SKIP_TYPE_VALIDATION_ON_ALTER_PARTITION.key -> "true",
SQLConf.ANSI_ENABLED.key -> "false") {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Shouldn't we maybe keep the test after removing SQLConf.ANSI_ENABLED.key -> "false"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Before I thought the storeAssignmentPolicy is enough so this test is corvered by AlterTableAddPartitionSuiteBase. Just change to legacy to restroe previous behavior.

Now I add one more SKIP_TYPE_VALIDATION_ON_ALTER_PARTITION check and keep this test.

sql(s"ALTER TABLE $t ADD PARTITION (p='aaa')")
checkPartitions(t, Map("p" -> defaultPartitionName))
sql(s"ALTER TABLE $t DROP PARTITION (p=null)")
}
}
}
}