-
Notifications
You must be signed in to change notification settings - Fork 29.1k
[SPARK-32512][SQL] add alter table add/drop partition command for datasourcev2 #29339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
a57aafc
add table partition API
6efca68
add AlterTableAddPartitionExec and AlterTableDropPartitionExec
f0bc357
redefine AlterTableAddPartitionExec and AlterTableDropPartitionExec
61cae52
fix test failed
b1fc84b
change the warning for purge
67fcb12
add SupportsAtomicPartitionManagement API support
f4a6ee3
reorder match cases
9bd20ba
fix errors
6327ead
change match cases
800c51a
add alter table add/drop partitions suites
60b0a12
Merge branch 'master' into SPARK-32512-new
a4c29a2
restart git action
a6caf68
change code for comments
3405f5b
use UnresolvedTableOrView to resolve the identifier
9bc2e76
add children for AlterTableAddPartitionsStatement and AlterTableDropP…
0740ef5
add ResolvedView analyzed
ad40d7b
add ResolvePartitionSpec rule
8fce669
change scala style
af4b50b
change scala style
b046909
fix scala-2.13 compile failed
fbc2b58
add more implicit method
dedb32a
remove unused imports
41cf069
Merge branch 'master'
96a62be
redefine ResolvePartitionSpec
d5d8f13
fix test failed
6bf49bd
add check in CheckAnalysis
cdd7085
restart test
0545538
change UnresolveTableOrView to UnresolvedTable
f1fcac1
remove implicit class
7014ba1
Merge branch 'master' into SPARK-32512-new
69bbbd5
fix build failed
effd0ed
Merge branch 'SPARK-32512-new' of https://github.com/stczwd/spark int…
7377469
use ResolvedV1TableIdentifier
c6711cd
fix suite test failed
dcd5060
fix suite test failed
d316e56
fix test failed
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
...catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolvePartitionSpec.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.spark.sql.catalyst.analysis | ||
|
|
||
| import org.apache.spark.sql.AnalysisException | ||
| import org.apache.spark.sql.catalyst.InternalRow | ||
| import org.apache.spark.sql.catalyst.catalog.CatalogTypes.TablePartitionSpec | ||
| import org.apache.spark.sql.catalyst.plans.logical.{AlterTableAddPartition, AlterTableDropPartition, LogicalPlan} | ||
| import org.apache.spark.sql.catalyst.rules.Rule | ||
| import org.apache.spark.sql.connector.catalog.SupportsPartitionManagement | ||
| import org.apache.spark.sql.types._ | ||
|
|
||
| /** | ||
| * Resolve [[UnresolvedPartitionSpec]] to [[ResolvedPartitionSpec]] in partition related commands. | ||
| */ | ||
| object ResolvePartitionSpec extends Rule[LogicalPlan] { | ||
|
|
||
| def apply(plan: LogicalPlan): LogicalPlan = plan resolveOperators { | ||
| case r @ AlterTableAddPartition( | ||
| ResolvedTable(_, _, table: SupportsPartitionManagement), partSpecs, _) => | ||
| r.copy(parts = resolvePartitionSpecs(partSpecs, table.partitionSchema())) | ||
|
|
||
| case r @ AlterTableDropPartition( | ||
| ResolvedTable(_, _, table: SupportsPartitionManagement), partSpecs, _, _, _) => | ||
| r.copy(parts = resolvePartitionSpecs(partSpecs, table.partitionSchema())) | ||
| } | ||
|
|
||
| private def resolvePartitionSpecs( | ||
| partSpecs: Seq[PartitionSpec], partSchema: StructType): Seq[ResolvedPartitionSpec] = | ||
| partSpecs.map { | ||
| case unresolvedPartSpec: UnresolvedPartitionSpec => | ||
| ResolvedPartitionSpec( | ||
| convertToPartIdent(unresolvedPartSpec.spec, partSchema), unresolvedPartSpec.location) | ||
| case resolvedPartitionSpec: ResolvedPartitionSpec => | ||
| resolvedPartitionSpec | ||
| } | ||
|
|
||
| private def convertToPartIdent( | ||
| partSpec: TablePartitionSpec, partSchema: StructType): InternalRow = { | ||
| val conflictKeys = partSpec.keys.toSeq.diff(partSchema.map(_.name)) | ||
| if (conflictKeys.nonEmpty) { | ||
| throw new AnalysisException(s"Partition key ${conflictKeys.mkString(",")} not exists") | ||
| } | ||
|
|
||
| val partValues = partSchema.map { part => | ||
| val partValue = partSpec.get(part.name).orNull | ||
| if (partValue == null) { | ||
| null | ||
| } else { | ||
| // TODO: Support other datatypes, such as DateType | ||
| part.dataType match { | ||
| case _: ByteType => | ||
| partValue.toByte | ||
| case _: ShortType => | ||
| partValue.toShort | ||
| case _: IntegerType => | ||
| partValue.toInt | ||
| case _: LongType => | ||
| partValue.toLong | ||
| case _: FloatType => | ||
| partValue.toFloat | ||
| case _: DoubleType => | ||
| partValue.toDouble | ||
| case _: StringType => | ||
| partValue | ||
| case _ => | ||
| throw new AnalysisException( | ||
| s"Type ${part.dataType.typeName} is not supported for partition.") | ||
| } | ||
| } | ||
| } | ||
| InternalRow.fromSeq(partValues) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not related to this PR: I'm wondering if we do need this separation. Do we have a concern that it's hard for implementations to add/drop multiple partitions atomically?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Em, it depends on whether the third-party system or storage supports transaction. MySQL and Hive can support this very well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As an example,
TableCatalog.alterTableaccepts a list ofTableChangewithout adding a new atomic API. I don't know why partition API needs to be different.