-
Notifications
You must be signed in to change notification settings - Fork 1k
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
[spark] Spark3.2 insertoverwrite test support #3458
Merged
JingsongLi
merged 11 commits into
apache:master
from
xuzifu666:insertoverwrite_spark32_test
Jun 3, 2024
Merged
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
102ec3e
[spark] Spark3.2 insertoverwrite test support
882a69c
extends from base test
75c28f2
style changed
c0bcf96
add test for spark other versions
7194afc
add test in spark3.X
064486c
refactor with abstract class
7c7c627
remove used dependcy
1745784
remove line
80ed2f4
remove line
c70583a
rename base class
369837a
rename base class
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 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
21 changes: 21 additions & 0 deletions
21
...aimon-spark-3.2/src/test/scala/org/apache/paimon/spark/sql/InsertOverwriteTableTest.scala
This file contains 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,21 @@ | ||
/* | ||
* 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.paimon.spark.sql | ||
|
||
class InsertOverwriteTableTest extends InsertOverwriteTest {} | ||
361 changes: 361 additions & 0 deletions
361
...ark/paimon-spark-3.2/src/test/scala/org/apache/paimon/spark/sql/InsertOverwriteTest.scala
This file contains 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,361 @@ | ||
/* | ||
* 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.paimon.spark.sql | ||
|
||
import org.apache.paimon.spark.PaimonSparkTestBase | ||
|
||
import org.apache.spark.sql.Row | ||
import org.apache.spark.sql.types._ | ||
|
||
class InsertOverwriteTest extends PaimonSparkTestBase { | ||
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. Can this test same to 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. OK,do it latter |
||
|
||
withPk.foreach { | ||
hasPk => | ||
bucketModes.foreach { | ||
bucket => | ||
test(s"insert overwrite non-partitioned table: hasPk: $hasPk, bucket: $bucket") { | ||
val primaryKeysProp = if (hasPk) { | ||
"'primary-key'='a,b'," | ||
} else { | ||
"" | ||
} | ||
|
||
val bucketKeyProp = if (bucket > 0) { | ||
",'bucket-key'='b'" | ||
} else { | ||
"" | ||
} | ||
|
||
spark.sql(s""" | ||
|CREATE TABLE T (a INT, b INT, c STRING) | ||
|TBLPROPERTIES ($primaryKeysProp 'bucket'='$bucket' $bucketKeyProp) | ||
|""".stripMargin) | ||
|
||
spark.sql("INSERT INTO T values (1, 1, '1'), (2, 2, '2')") | ||
checkAnswer( | ||
spark.sql("SELECT * FROM T ORDER BY a, b"), | ||
Row(1, 1, "1") :: Row(2, 2, "2") :: Nil) | ||
|
||
spark.sql("INSERT OVERWRITE T VALUES (1, 3, '3'), (2, 4, '4')"); | ||
checkAnswer( | ||
spark.sql("SELECT * FROM T ORDER BY a, b"), | ||
Row(1, 3, "3") :: Row(2, 4, "4") :: Nil) | ||
} | ||
} | ||
} | ||
|
||
withPk.foreach { | ||
hasPk => | ||
bucketModes.foreach { | ||
bucket => | ||
test(s"insert overwrite single-partitioned table: hasPk: $hasPk, bucket: $bucket") { | ||
val primaryKeysProp = if (hasPk) { | ||
"'primary-key'='a,b'," | ||
} else { | ||
"" | ||
} | ||
|
||
val bucketKeyProp = if (bucket > 0) { | ||
",'bucket-key'='b'" | ||
} else { | ||
"" | ||
} | ||
|
||
spark.sql(s""" | ||
|CREATE TABLE T (a INT, b INT, c STRING) | ||
|TBLPROPERTIES ($primaryKeysProp 'bucket'='$bucket' $bucketKeyProp) | ||
|PARTITIONED BY (a) | ||
|""".stripMargin) | ||
|
||
spark.sql("INSERT INTO T values (1, 1, '1'), (2, 2, '2')") | ||
checkAnswer( | ||
spark.sql("SELECT * FROM T ORDER BY a, b"), | ||
Row(1, 1, "1") :: Row(2, 2, "2") :: Nil) | ||
|
||
// overwrite the whole table | ||
spark.sql("INSERT OVERWRITE T VALUES (1, 3, '3'), (2, 4, '4')") | ||
checkAnswer( | ||
spark.sql("SELECT * FROM T ORDER BY a, b"), | ||
Row(1, 3, "3") :: Row(2, 4, "4") :: Nil) | ||
|
||
// overwrite the a=1 partition | ||
spark.sql("INSERT OVERWRITE T PARTITION (a = 1) VALUES (5, '5'), (7, '7')") | ||
checkAnswer( | ||
spark.sql("SELECT * FROM T ORDER BY a, b"), | ||
Row(1, 5, "5") :: Row(1, 7, "7") :: Row(2, 4, "4") :: Nil) | ||
|
||
} | ||
} | ||
} | ||
|
||
withPk.foreach { | ||
hasPk => | ||
bucketModes.foreach { | ||
bucket => | ||
test(s"insert overwrite mutil-partitioned table: hasPk: $hasPk, bucket: $bucket") { | ||
val primaryKeysProp = if (hasPk) { | ||
"'primary-key'='a,pt1,pt2'," | ||
} else { | ||
"" | ||
} | ||
|
||
val bucketKeyProp = if (bucket > 0) { | ||
",'bucket-key'='a'" | ||
} else { | ||
"" | ||
} | ||
|
||
spark.sql(s""" | ||
|CREATE TABLE T (a INT, b STRING, pt1 STRING, pt2 INT) | ||
|TBLPROPERTIES ($primaryKeysProp 'bucket'='$bucket' $bucketKeyProp) | ||
|PARTITIONED BY (pt1, pt2) | ||
|""".stripMargin) | ||
|
||
spark.sql( | ||
"INSERT INTO T values (1, 'a', 'ptv1', 11), (2, 'b', 'ptv1', 11), (3, 'c', 'ptv1', 22), (4, 'd', 'ptv2', 22)") | ||
checkAnswer( | ||
spark.sql("SELECT * FROM T ORDER BY a"), | ||
Row(1, "a", "ptv1", 11) :: Row(2, "b", "ptv1", 11) :: Row(3, "c", "ptv1", 22) :: Row( | ||
4, | ||
"d", | ||
"ptv2", | ||
22) :: Nil) | ||
|
||
// overwrite the pt2=22 partition | ||
spark.sql( | ||
"INSERT OVERWRITE T PARTITION (pt2 = 22) VALUES (3, 'c2', 'ptv1'), (4, 'd2', 'ptv3')") | ||
checkAnswer( | ||
spark.sql("SELECT * FROM T ORDER BY a"), | ||
Row(1, "a", "ptv1", 11) :: Row(2, "b", "ptv1", 11) :: Row(3, "c2", "ptv1", 22) :: Row( | ||
4, | ||
"d2", | ||
"ptv3", | ||
22) :: Nil) | ||
|
||
// overwrite the pt1=ptv3 partition | ||
spark.sql("INSERT OVERWRITE T PARTITION (pt1 = 'ptv3') VALUES (4, 'd3', 22)") | ||
checkAnswer( | ||
spark.sql("SELECT * FROM T ORDER BY a"), | ||
Row(1, "a", "ptv1", 11) :: Row(2, "b", "ptv1", 11) :: Row(3, "c2", "ptv1", 22) :: Row( | ||
4, | ||
"d3", | ||
"ptv3", | ||
22) :: Nil) | ||
|
||
// overwrite the pt1=ptv1, pt2=11 partition | ||
spark.sql("INSERT OVERWRITE T PARTITION (pt1 = 'ptv1', pt2=11) VALUES (5, 'e')") | ||
checkAnswer( | ||
spark.sql("SELECT * FROM T ORDER BY a"), | ||
Row(3, "c2", "ptv1", 22) :: Row(4, "d3", "ptv3", 22) :: Row( | ||
5, | ||
"e", | ||
"ptv1", | ||
11) :: Nil) | ||
|
||
// overwrite the whole table | ||
spark.sql( | ||
"INSERT OVERWRITE T VALUES (1, 'a5', 'ptv1', 11), (3, 'c5', 'ptv1', 22), (4, 'd5', 'ptv3', 22)") | ||
checkAnswer( | ||
spark.sql("SELECT * FROM T ORDER BY a"), | ||
Row(1, "a5", "ptv1", 11) :: Row(3, "c5", "ptv1", 22) :: Row( | ||
4, | ||
"d5", | ||
"ptv3", | ||
22) :: Nil) | ||
} | ||
} | ||
} | ||
|
||
// These cases that date/timestamp/bool is used as the partition field type are to be supported. | ||
Seq(IntegerType, LongType, FloatType, DoubleType, DecimalType).foreach { | ||
dataType => | ||
test(s"insert overwrite table using $dataType as the partition field type") { | ||
case class PartitionSQLAndValue(sql: Any, value: Any) | ||
|
||
val (ptField, sv1, sv2) = dataType match { | ||
case IntegerType => | ||
("INT", PartitionSQLAndValue(1, 1), PartitionSQLAndValue(2, 2)) | ||
case LongType => | ||
("LONG", PartitionSQLAndValue(1L, 1L), PartitionSQLAndValue(2L, 2L)) | ||
case FloatType => | ||
("FLOAT", PartitionSQLAndValue(12.3f, 12.3f), PartitionSQLAndValue(45.6f, 45.6f)) | ||
case DoubleType => | ||
("DOUBLE", PartitionSQLAndValue(12.3d, 12.3), PartitionSQLAndValue(45.6d, 45.6)) | ||
case DecimalType => | ||
( | ||
"DECIMAL(5, 2)", | ||
PartitionSQLAndValue(11.222, 11.22), | ||
PartitionSQLAndValue(66.777, 66.78)) | ||
} | ||
|
||
spark.sql(s""" | ||
|CREATE TABLE T (a INT, b STRING, pt $ptField) | ||
|PARTITIONED BY (pt) | ||
|""".stripMargin) | ||
|
||
spark.sql(s"INSERT INTO T SELECT 1, 'a', ${sv1.sql} UNION ALL SELECT 2, 'b', ${sv2.sql}") | ||
checkAnswer( | ||
spark.sql("SELECT * FROM T ORDER BY a"), | ||
Row(1, "a", sv1.value) :: Row(2, "b", sv2.value) :: Nil) | ||
|
||
// overwrite the whole table | ||
spark.sql( | ||
s"INSERT OVERWRITE T SELECT 3, 'c', ${sv1.sql} UNION ALL SELECT 4, 'd', ${sv2.sql}") | ||
checkAnswer( | ||
spark.sql("SELECT * FROM T ORDER BY a"), | ||
Row(3, "c", sv1.value) :: Row(4, "d", sv2.value) :: Nil) | ||
|
||
// overwrite the a=1 partition | ||
spark.sql(s"INSERT OVERWRITE T PARTITION (pt = ${sv1.value}) VALUES (5, 'e'), (7, 'g')") | ||
checkAnswer( | ||
spark.sql("SELECT * FROM T ORDER BY a"), | ||
Row(4, "d", sv2.value) :: Row(5, "e", sv1.value) :: Row(7, "g", sv1.value) :: Nil) | ||
} | ||
} | ||
|
||
withPk.foreach { | ||
hasPk => | ||
bucketModes.foreach { | ||
bucket => | ||
test( | ||
s"dynamic insert overwrite single-partitioned table: hasPk: $hasPk, bucket: $bucket") { | ||
val primaryKeysProp = if (hasPk) { | ||
"'primary-key'='a,b'," | ||
} else { | ||
"" | ||
} | ||
|
||
val bucketKeyProp = if (bucket > 0) { | ||
",'bucket-key'='b'" | ||
} else { | ||
"" | ||
} | ||
|
||
spark.sql(s""" | ||
|CREATE TABLE T (a INT, b INT, c STRING) | ||
|TBLPROPERTIES ($primaryKeysProp 'bucket'='$bucket' $bucketKeyProp) | ||
|PARTITIONED BY (a) | ||
|""".stripMargin) | ||
|
||
spark.sql("INSERT INTO T values (1, 1, '1'), (2, 2, '2')") | ||
checkAnswer( | ||
spark.sql("SELECT * FROM T ORDER BY a, b"), | ||
Row(1, 1, "1") :: Row(2, 2, "2") :: Nil) | ||
|
||
// overwrite the whole table | ||
spark.sql("INSERT OVERWRITE T VALUES (1, 3, '3'), (2, 4, '4')") | ||
checkAnswer( | ||
spark.sql("SELECT * FROM T ORDER BY a, b"), | ||
Row(1, 3, "3") :: Row(2, 4, "4") :: Nil) | ||
|
||
withSQLConf("spark.sql.sources.partitionOverwriteMode" -> "dynamic") { | ||
// dynamic overwrite the a=1 partition | ||
spark.sql("INSERT OVERWRITE T VALUES (1, 5, '5'), (1, 7, '7')") | ||
checkAnswer( | ||
spark.sql("SELECT * FROM T ORDER BY a, b"), | ||
Row(1, 5, "5") :: Row(1, 7, "7") :: Row(2, 4, "4") :: Nil) | ||
} | ||
} | ||
} | ||
} | ||
|
||
withPk.foreach { | ||
hasPk => | ||
bucketModes.foreach { | ||
bucket => | ||
test( | ||
s"dynamic insert overwrite mutil-partitioned table: hasPk: $hasPk, bucket: $bucket") { | ||
val primaryKeysProp = if (hasPk) { | ||
"'primary-key'='a,pt1,pt2'," | ||
} else { | ||
"" | ||
} | ||
|
||
val bucketKeyProp = if (bucket > 0) { | ||
",'bucket-key'='a'" | ||
} else { | ||
"" | ||
} | ||
|
||
spark.sql(s""" | ||
|CREATE TABLE T (a INT, b STRING, pt1 STRING, pt2 INT) | ||
|TBLPROPERTIES ($primaryKeysProp 'bucket'='$bucket' $bucketKeyProp) | ||
|PARTITIONED BY (pt1, pt2) | ||
|""".stripMargin) | ||
|
||
spark.sql( | ||
"INSERT INTO T values (1, 'a', 'ptv1', 11), (2, 'b', 'ptv1', 11), (3, 'c', 'ptv1', 22), (4, 'd', 'ptv2', 22)") | ||
checkAnswer( | ||
spark.sql("SELECT * FROM T ORDER BY a, b"), | ||
Row(1, "a", "ptv1", 11) :: Row(2, "b", "ptv1", 11) :: Row(3, "c", "ptv1", 22) :: Row( | ||
4, | ||
"d", | ||
"ptv2", | ||
22) :: Nil) | ||
|
||
withSQLConf("spark.sql.sources.partitionOverwriteMode" -> "dynamic") { | ||
// dynamic overwrite the pt2=22 partition | ||
spark.sql( | ||
"INSERT OVERWRITE T PARTITION (pt2 = 22) VALUES (3, 'c2', 'ptv1'), (4, 'd2', 'ptv3')") | ||
checkAnswer( | ||
spark.sql("SELECT * FROM T ORDER BY a, b"), | ||
Row(1, "a", "ptv1", 11) :: Row(2, "b", "ptv1", 11) :: Row( | ||
3, | ||
"c2", | ||
"ptv1", | ||
22) :: Row(4, "d", "ptv2", 22) :: Row(4, "d2", "ptv3", 22) :: Nil | ||
) | ||
|
||
// dynamic overwrite the pt1=ptv3 partition | ||
spark.sql("INSERT OVERWRITE T PARTITION (pt1 = 'ptv3') VALUES (4, 'd3', 22)") | ||
checkAnswer( | ||
spark.sql("SELECT * FROM T ORDER BY a, b"), | ||
Row(1, "a", "ptv1", 11) :: Row(2, "b", "ptv1", 11) :: Row( | ||
3, | ||
"c2", | ||
"ptv1", | ||
22) :: Row(4, "d", "ptv2", 22) :: Row(4, "d3", "ptv3", 22) :: Nil | ||
) | ||
|
||
// dynamic overwrite the pt1=ptv1, pt2=11 partition | ||
spark.sql("INSERT OVERWRITE T PARTITION (pt1 = 'ptv1', pt2=11) VALUES (5, 'e')") | ||
checkAnswer( | ||
spark.sql("SELECT * FROM T ORDER BY a, b"), | ||
Row(3, "c2", "ptv1", 22) :: Row(4, "d", "ptv2", 22) :: Row( | ||
4, | ||
"d3", | ||
"ptv3", | ||
22) :: Row(5, "e", "ptv1", 11) :: Nil) | ||
|
||
// dynamic overwrite the whole table | ||
spark.sql( | ||
"INSERT OVERWRITE T VALUES (1, 'a5', 'ptv1', 11), (3, 'c5', 'ptv1', 22), (4, 'd5', 'ptv3', 22)") | ||
checkAnswer( | ||
spark.sql("SELECT * FROM T ORDER BY a, b"), | ||
Row(1, "a5", "ptv1", 11) :: Row(3, "c5", "ptv1", 22) :: Row( | ||
4, | ||
"d", | ||
"ptv2", | ||
22) :: Row(4, "d5", "ptv3", 22) :: Nil) | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
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.
Add this to other spark version module too