-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-18635] [SQL] Partition name/values not escaped correctly in some cases #16071
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -205,6 +205,58 @@ class PartitionProviderCompatibilitySuite | |
| } | ||
| } | ||
| } | ||
|
|
||
| test(s"SPARK-18635 special chars in partition values - partition management $enabled") { | ||
| withTable("test") { | ||
| spark.range(10) | ||
| .selectExpr("id", "id as A", "'%' as B") | ||
| .write.partitionBy("A", "B").mode("overwrite") | ||
| .saveAsTable("test") | ||
| assert(spark.sql("select * from test").count() == 10) | ||
| assert(spark.sql("select * from test where B = '%'").count() == 10) | ||
| assert(spark.sql("select * from test where B = '$'").count() == 0) | ||
| spark.range(10) | ||
| .selectExpr("id", "id as A", "'=' as B") | ||
| .write.mode("append").insertInto("test") | ||
| spark.sql("insert into test partition (A, B) select id, id, '%=' from range(10)") | ||
| assert(spark.sql("select * from test").count() == 30) | ||
| assert(spark.sql("select * from test where B = '%'").count() == 10) | ||
| assert(spark.sql("select * from test where B = '='").count() == 10) | ||
| assert(spark.sql("select * from test where B = '%='").count() == 10) | ||
|
|
||
| // show partitions sanity check | ||
| val parts = spark.sql("show partitions test").collect().map(_.get(0)).toSeq | ||
| assert(parts.length == 30) | ||
| assert(parts.contains("A=0/B=%25")) | ||
| assert(parts.contains("A=0/B=%3D")) | ||
| assert(parts.contains("A=0/B=%25%3D")) | ||
|
|
||
| // custom locations sanity check | ||
| withTempDir { dir => | ||
| spark.sql(s""" | ||
| |alter table test partition (A=0, B='%') | ||
| |set location '${dir.getAbsolutePath}'""".stripMargin) | ||
| assert(spark.sql("select * from test").count() == 29) // missing 1 | ||
| } | ||
|
|
||
| // drop partition sanity check | ||
| spark.sql("alter table test drop partition (A=1, B='%')") | ||
| assert(spark.sql("select * from test").count() == 28) | ||
|
|
||
| // TODO(ekl) fix rename partition | ||
| // withTempDir { dir => | ||
| // spark.sql(s""" | ||
| // |alter table test partition (A=0, B='%') | ||
| // |rename to partition (A=100, B='%')""".stripMargin) | ||
| // assert(spark.sql("select * from test where a = 100").count() == 1) | ||
|
||
| // } | ||
|
|
||
| // TODO(ekl) fix overwrite table | ||
| // spark.sql("show partitions test").show(false) | ||
| // spark.sql("insert overwrite table test partition (a, b) select id, id, '%' from range(1)") | ||
|
||
| // assert(spark.sql("select * from test").count() == 1) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
|
|
||
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.
Why is this 29 instead of 30?
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.
Since the partition was moved, there are no files in the new location. Hence -1 file
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.
Ah. I see. So Hive/Spark doesn't move partition data when the partition location is changed. Might be clearer to call that out in your comment rather than just "missing 1".