-
Notifications
You must be signed in to change notification settings - Fork 28.5k
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-11678] [SQL] Partition discovery should stop at the root path of the table. #9651
Changes from 1 commit
e406792
28a1227
df48220
1744624
89f21ba
d784a52
240bcf3
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 |
---|---|---|
|
@@ -66,7 +66,7 @@ class ParquetPartitionDiscoverySuite extends QueryTest with ParquetTest with Sha | |
"hdfs://host:9000/path/a=10.5/b=hello") | ||
|
||
var exception = intercept[AssertionError] { | ||
parsePartitions(paths.map(new Path(_)), defaultPartitionName, true) | ||
parsePartitions(paths.map(new Path(_)), defaultPartitionName, true, Set.empty[Path]) | ||
} | ||
assert(exception.getMessage().contains("Conflicting directory structures detected")) | ||
|
||
|
@@ -76,7 +76,37 @@ class ParquetPartitionDiscoverySuite extends QueryTest with ParquetTest with Sha | |
"hdfs://host:9000/path/a=10/b=20", | ||
"hdfs://host:9000/path/_temporary/path") | ||
|
||
parsePartitions(paths.map(new Path(_)), defaultPartitionName, true) | ||
parsePartitions( | ||
paths.map(new Path(_)), | ||
defaultPartitionName, | ||
true, | ||
Set(new Path("hdfs://host:9000/path/"))) | ||
|
||
// Valid | ||
paths = Seq( | ||
"hdfs://host:9000/path/something=true/table/", | ||
"hdfs://host:9000/path/something=true/table/_temporary", | ||
"hdfs://host:9000/path/something=true/table/a=10/b=20", | ||
"hdfs://host:9000/path/something=true/table/_temporary/path") | ||
|
||
parsePartitions( | ||
paths.map(new Path(_)), | ||
defaultPartitionName, | ||
true, | ||
Set(new Path("hdfs://host:9000/path/something=true/table"))) | ||
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. This will fail without the change. |
||
|
||
// Valid | ||
paths = Seq( | ||
"hdfs://host:9000/path/table=true/", | ||
"hdfs://host:9000/path/table=true/_temporary", | ||
"hdfs://host:9000/path/table=true/a=10/b=20", | ||
"hdfs://host:9000/path/table=true/_temporary/path") | ||
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. If we the table's root is 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. Yeah, I don't realize that it is possible to have such base path. |
||
|
||
parsePartitions( | ||
paths.map(new Path(_)), | ||
defaultPartitionName, | ||
true, | ||
Set(new Path("hdfs://host:9000/path/table=true"))) | ||
|
||
// Invalid | ||
paths = Seq( | ||
|
@@ -85,7 +115,11 @@ class ParquetPartitionDiscoverySuite extends QueryTest with ParquetTest with Sha | |
"hdfs://host:9000/path/path1") | ||
|
||
exception = intercept[AssertionError] { | ||
parsePartitions(paths.map(new Path(_)), defaultPartitionName, true) | ||
parsePartitions( | ||
paths.map(new Path(_)), | ||
defaultPartitionName, | ||
true, | ||
Set(new Path("hdfs://host:9000/path/"))) | ||
} | ||
assert(exception.getMessage().contains("Conflicting directory structures detected")) | ||
|
||
|
@@ -101,19 +135,24 @@ class ParquetPartitionDiscoverySuite extends QueryTest with ParquetTest with Sha | |
"hdfs://host:9000/tmp/tables/nonPartitionedTable2") | ||
|
||
exception = intercept[AssertionError] { | ||
parsePartitions(paths.map(new Path(_)), defaultPartitionName, true) | ||
parsePartitions( | ||
paths.map(new Path(_)), | ||
defaultPartitionName, | ||
true, | ||
Set(new Path("hdfs://host:9000/tmp/tables/"))) | ||
} | ||
assert(exception.getMessage().contains("Conflicting directory structures detected")) | ||
} | ||
|
||
test("parse partition") { | ||
def check(path: String, expected: Option[PartitionValues]): Unit = { | ||
assert(expected === parsePartition(new Path(path), defaultPartitionName, true)._1) | ||
val actual = parsePartition(new Path(path), defaultPartitionName, true, Set.empty[Path])._1 | ||
assert(expected === actual) | ||
} | ||
|
||
def checkThrows[T <: Throwable: Manifest](path: String, expected: String): Unit = { | ||
val message = intercept[T] { | ||
parsePartition(new Path(path), defaultPartitionName, true) | ||
parsePartition(new Path(path), defaultPartitionName, true, Set.empty[Path]) | ||
}.getMessage | ||
|
||
assert(message.contains(expected)) | ||
|
@@ -152,8 +191,17 @@ class ParquetPartitionDiscoverySuite extends QueryTest with ParquetTest with Sha | |
} | ||
|
||
test("parse partitions") { | ||
def check(paths: Seq[String], spec: PartitionSpec): Unit = { | ||
assert(parsePartitions(paths.map(new Path(_)), defaultPartitionName, true) === spec) | ||
def check( | ||
paths: Seq[String], | ||
spec: PartitionSpec, | ||
rootPaths: Set[Path] = Set.empty[Path]): Unit = { | ||
val actualSpec = | ||
parsePartitions( | ||
paths.map(new Path(_)), | ||
defaultPartitionName, | ||
true, | ||
rootPaths) | ||
assert(actualSpec === spec) | ||
} | ||
|
||
check(Seq( | ||
|
@@ -232,7 +280,9 @@ class ParquetPartitionDiscoverySuite extends QueryTest with ParquetTest with Sha | |
|
||
test("parse partitions with type inference disabled") { | ||
def check(paths: Seq[String], spec: PartitionSpec): Unit = { | ||
assert(parsePartitions(paths.map(new Path(_)), defaultPartitionName, false) === spec) | ||
val actualSpec = | ||
parsePartitions(paths.map(new Path(_)), defaultPartitionName, false, Set.empty[Path]) | ||
assert(actualSpec === spec) | ||
} | ||
|
||
check(Seq( | ||
|
@@ -590,6 +640,40 @@ class ParquetPartitionDiscoverySuite extends QueryTest with ParquetTest with Sha | |
} | ||
} | ||
|
||
test("SPARK-11678: Partition discovery stops at the root path of the dataset") { | ||
withTempPath { dir => | ||
val tablePath = new File(dir, "key=value") | ||
val df = (1 to 3).map(i => (i, i, i, i)).toDF("a", "b", "c", "d") | ||
|
||
df.write | ||
.format("parquet") | ||
.partitionBy("b", "c", "d") | ||
.save(tablePath.getCanonicalPath) | ||
|
||
Files.touch(new File(s"${tablePath.getCanonicalPath}/", "_SUCCESS")) | ||
Files.createParentDirs(new File(s"${dir.getCanonicalPath}/b=1/c=1/.foo/bar")) | ||
|
||
checkAnswer(sqlContext.read.format("parquet").load(tablePath.getCanonicalPath), df) | ||
} | ||
|
||
withTempPath { dir => | ||
val path = new File(dir, "key=value") | ||
val tablePath = new File(path, "table") | ||
|
||
val df = (1 to 3).map(i => (i, i, i, i)).toDF("a", "b", "c", "d") | ||
|
||
df.write | ||
.format("parquet") | ||
.partitionBy("b", "c", "d") | ||
.save(tablePath.getCanonicalPath) | ||
|
||
Files.touch(new File(s"${tablePath.getCanonicalPath}/", "_SUCCESS")) | ||
Files.createParentDirs(new File(s"${dir.getCanonicalPath}/b=1/c=1/.foo/bar")) | ||
|
||
checkAnswer(sqlContext.read.format("parquet").load(tablePath.getCanonicalPath), df) | ||
} | ||
} | ||
|
||
test("listConflictingPartitionColumns") { | ||
def makeExpectedMessage(colNameLists: Seq[String], paths: Seq[String]): String = { | ||
val conflictingColNameLists = colNameLists.zipWithIndex.map { case (list, index) => | ||
|
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 we will stop when
rootPaths.contains(basePath) == true
and in this casecolumns
will not be modified and we don't care the content ofmaybeColumn
, maybe we can skipparsePartitionColumn
too?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.
We can do it in this way: