-
Notifications
You must be signed in to change notification settings - Fork 486
[spark] Add Spark show/add/drop partition support #2314
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
Open
Yohahaha
wants to merge
7
commits into
apache:main
Choose a base branch
from
Yohahaha:spark-partition
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b88c68a
stage
Yohahaha 51f83e7
add partition/ show partition
Yohahaha 2efc703
drop partition
Yohahaha bc72c4a
fix spotless
Yohahaha 892a7d8
fix comments
Yohahaha a1c09ab
fix comments
Yohahaha 968af43
fix comments
Yohahaha 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,16 +17,17 @@ | |
|
|
||
| package org.apache.fluss.spark | ||
|
|
||
| import org.apache.fluss.metadata.{DatabaseDescriptor, Schema, TableDescriptor, TablePath} | ||
| import org.apache.fluss.metadata._ | ||
| import org.apache.fluss.types.{DataTypes, RowType} | ||
|
|
||
| import org.apache.spark.sql.Row | ||
| import org.apache.spark.sql.{AnalysisException, Row} | ||
| import org.apache.spark.sql.catalyst.analysis.PartitionsAlreadyExistException | ||
| import org.apache.spark.sql.connector.catalog.Identifier | ||
| import org.assertj.core.api.Assertions.{assertThat, assertThatList} | ||
|
|
||
| import scala.collection.JavaConverters._ | ||
|
|
||
| class FlussCatalogTest extends FlussSparkTestBase { | ||
| class SparkCatalogTest extends FlussSparkTestBase { | ||
|
|
||
| test("Catalog: namespaces") { | ||
| // Always a default database 'fluss'. | ||
|
|
@@ -190,4 +191,63 @@ class FlussCatalogTest extends FlussSparkTestBase { | |
| admin.dropDatabase(dbName, true, true).get() | ||
| checkAnswer(sql("SHOW DATABASES"), Row(DEFAULT_DATABASE) :: Nil) | ||
| } | ||
|
|
||
| test("Partition: show partitions") { | ||
| withTable("t") { | ||
| sql(s"CREATE TABLE t (id int, name string, pt1 string, pt2 int) PARTITIONED BY (pt1, pt2)") | ||
| sql(s"INSERT INTO t values(1, 'a', 'a', 1), (2, 'b', 'a', 2), (3, 'c', 'c', 3)") | ||
|
|
||
| var expect = Seq(Row("pt1=a/pt2=1"), Row("pt1=a/pt2=2"), Row("pt1=c/pt2=3")) | ||
| checkAnswer(sql(s"SHOW PARTITIONS t"), expect) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| expect = Seq(Row("pt1=a/pt2=1"), Row("pt1=a/pt2=2")) | ||
| checkAnswer(sql(s"SHOW PARTITIONS t PARTITION (pt1 = 'a')"), expect) | ||
| } | ||
| } | ||
|
|
||
| test("Partition: add partition") { | ||
| withTable("t") { | ||
| sql("CREATE TABLE t (id int, name string, pt1 string, pt2 int) PARTITIONED BY (pt1, pt2)") | ||
|
|
||
| // add from sparksql | ||
| sql(s"ALTER TABLE t ADD PARTITION (pt1 = 'b', pt2 = 1)") | ||
| var expect = Seq(Row("pt1=b/pt2=1")) | ||
| checkAnswer(sql(s"SHOW PARTITIONS t"), expect) | ||
| sql(s"ALTER TABLE t ADD IF NOT EXISTS PARTITION (pt1 = 'b', pt2 = 1)") | ||
| checkAnswer(sql(s"SHOW PARTITIONS t"), expect) | ||
Yohahaha marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // add from fluss | ||
| val map = Map("pt1" -> "b", "pt2" -> "2") | ||
| admin.createPartition(createTablePath("t"), new PartitionSpec(map.asJava), false).get() | ||
| expect = Seq(Row("pt1=b/pt2=1"), Row("pt1=b/pt2=2")) | ||
| checkAnswer(sql(s"SHOW PARTITIONS t"), expect) | ||
|
|
||
| intercept[AnalysisException](sql(s"ALTER TABLE t ADD PARTITION (pt1 = 'b', pt2 = 1)")) | ||
| intercept[AnalysisException](sql(s"ALTER TABLE t ADD PARTITION (pt1 = 'b', pt3 = 1)")) | ||
| intercept[PartitionsAlreadyExistException]( | ||
| sql(s"ALTER TABLE t ADD PARTITION (pt1 = 'b', pt2 = 1)")) | ||
| } | ||
| } | ||
|
|
||
| test("Partition: drop partition") { | ||
| withTable("t") { | ||
| sql("CREATE TABLE t (id int, name string, pt1 string, pt2 int) PARTITIONED BY (pt1, pt2)") | ||
| sql(s"INSERT INTO t values(1, 'a', 'a', 1), (2, 'b', 'a', 2), (3, 'c', 'c', 3)") | ||
|
|
||
| // drop from sparksql | ||
| sql(s"ALTER TABLE t DROP PARTITION (pt1 = 'a', pt2 = 2)") | ||
| var expect = Seq(Row("pt1=a/pt2=1"), Row("pt1=c/pt2=3")) | ||
| checkAnswer(sql(s"SHOW PARTITIONS t"), expect) | ||
| sql(s"ALTER TABLE t DROP IF EXISTS PARTITION (pt1 = 'a', pt2 = 2)") | ||
| checkAnswer(sql(s"SHOW PARTITIONS t"), expect) | ||
|
|
||
| // drop from fluss | ||
| val map = Map("pt1" -> "c", "pt2" -> "3") | ||
Yohahaha marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| admin.dropPartition(createTablePath("t"), new PartitionSpec(map.asJava), false).get() | ||
| expect = Seq(Row("pt1=a/pt2=1")) | ||
| checkAnswer(sql(s"SHOW PARTITIONS t"), expect) | ||
|
|
||
| // spark does not support drop partial partition | ||
| intercept[AnalysisException](sql(s"ALTER TABLE t DROP PARTITION (pt1 = 'a')")) | ||
| } | ||
| } | ||
| } | ||
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.
Let's keep it here temporarily. I will move this to other place in
to support batch readPR later.