Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ private[sql] object PartitioningUtils {
parsePartition(path, defaultPartitionName, typeInference)
}.unzip

// We create pairs of (path -> path's partition value) here
// If the corresponding partition value is None, the pair will be skiped
val pathsWithPartitionValues = paths.zip(partitionValues).flatMap(x => x._2.map(x._1 -> _))

if (pathsWithPartitionValues.isEmpty) {
Expand All @@ -89,11 +91,21 @@ private[sql] object PartitioningUtils {
} else {
// This dataset is partitioned. We need to check whether all partitions have the same
// partition columns and resolve potential type conflicts.

// Check if there is conflicting directory structure.
// For the paths such as:
// var paths = Seq(
// "hdfs://host:9000/invalidPath",
// "hdfs://host:9000/path/a=10/b=20",
// "hdfs://host:9000/path/a=10.5/b=hello")
// It will be recognised as conflicting directory structure:
// "hdfs://host:9000/invalidPath"
// "hdfs://host:9000/path"
val basePaths = optBasePaths.flatMap(x => x)
assert(
basePaths.distinct.size == 1,
"Conflicting directory structures detected. Suspicious paths:\b" +
basePaths.mkString("\n\t", "\n\t", "\n\n"))
basePaths.distinct.mkString("\n\t", "\n\t", "\n\n"))

val resolvedPartitionValues = resolvePartitions(pathsWithPartitionValues)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,22 @@ class ParquetPartitionDiscoverySuite extends QueryTest with ParquetTest with Sha
parsePartitions(paths.map(new Path(_)), defaultPartitionName, true)
}
assert(exception.getMessage().contains("Conflicting directory structures detected"))

// Invalid
// Conflicting directory structure:
// "hdfs://host:9000/tmp/tables/partitionedTable"
// "hdfs://host:9000/tmp/tables/nonPartitionedTable1"
// "hdfs://host:9000/tmp/tables/nonPartitionedTable2"
paths = Seq(
"hdfs://host:9000/tmp/tables/partitionedTable",
"hdfs://host:9000/tmp/tables/partitionedTable/p=1/",
"hdfs://host:9000/tmp/tables/nonPartitionedTable1",
"hdfs://host:9000/tmp/tables/nonPartitionedTable2")

exception = intercept[AssertionError] {
parsePartitions(paths.map(new Path(_)), defaultPartitionName, true)
}
assert(exception.getMessage().contains("Conflicting directory structures detected"))
}

test("parse partition") {
Expand Down