Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
6e41081
[SPARK-4502][SQL] Parquet nested column pruning
Jun 24, 2016
0d0e8a0
Refactor SelectedFieldSuite to make its tests simpler and more
mallman Jun 4, 2018
44e78cb
Remove test "select function over nested data" of unknown origin and
mallman Jun 4, 2018
9488cb5
Improve readability of ParquetSchemaPruning and
mallman Jun 4, 2018
f3735b1
Don't handle non-data-field partition column names specially when
mallman Jun 4, 2018
2120ab5
Add test coverage for ParquetSchemaPruning for partitioned tables whose
mallman Jun 4, 2018
8d53bbd
Remove the ColumnarFileFormat type to put it in another PR
mallman Jun 12, 2018
e213471
Add test coverage for the enhancements to "is not null" constraint
mallman Jun 12, 2018
9e6ef5f
Revert changes to QueryPlanConstraints.scala and basicPhysicalOperato…
mallman Jun 24, 2018
e6ea9c2
Revert a whitespace change in DataSourceScanExec.scala
mallman Jun 24, 2018
2d02ab3
Remove modifications to ParquetFileFormat.scala and
mallman Jul 21, 2018
cfffc95
PR review: simplify some syntax and add a code doc
mallman Jul 21, 2018
2779351
When creating a pruned schema by merging an array of root structs, sort
mallman Jul 28, 2018
9329f77
Re-enable ignored test in ParquetSchemaPruningSuite.scala that is
mallman Aug 4, 2018
ec313c1
Enable schema pruning by default
mallman Aug 4, 2018
42aff39
Revert "Enable schema pruning by default"
mallman Aug 5, 2018
71f4c7b
Add a method to not only check a query's scan schemata, but verify th…
mallman Aug 5, 2018
0e5594b
Revert "Revert "Enable schema pruning by default""
mallman Aug 9, 2018
1573ae8
Revert changes to ParquetTest.scala. I'm sure they were useful at some
mallman Aug 17, 2018
09dd655
Refactor code based on code review comments
ajacques Aug 2, 2018
61c7937
Update terminology for parquet-mr reader in
mallman Aug 20, 2018
97b3a51
Handle differences in letter case in columns and fields between query
mallman Aug 21, 2018
2711746
Add test permutations to the "testMixedCasePruning" method to test
mallman Aug 21, 2018
e6baf68
Disable SQL schema pruning by default and revert changes to
mallman Aug 23, 2018
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
Prev Previous commit
Next Next commit
Improve readability of ParquetSchemaPruning and
ParquetSchemaPruningSuite. Add test to exercise whether the
requested root fields in a query exclude any attributes
  • Loading branch information
mallman committed Aug 9, 2018
commit 9488cb5c9d33670bd05f14ed00a24e68ae79f2ea
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ private[sql] object ParquetSchemaPruning extends Rule[LogicalPlan] {
case op @ PhysicalOperation(projects, filters,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also honestly this logic looks convoluted.

l @ LogicalRelation(hadoopFsRelation @ HadoopFsRelation(_, partitionSchema,
dataSchema, _, parquetFormat: ParquetFileFormat, _), _, _, _)) =>
val projectionFields = projects.flatMap(getFields)
val filterFields = filters.flatMap(getFields)
val requestedFields = (projectionFields ++ filterFields).distinct
val projectionRootFields = projects.flatMap(getRootFields)
val filterRootFields = filters.flatMap(getRootFields)
val requestedRootFields = (projectionRootFields ++ filterRootFields).distinct

// If [[requestedFields]] includes a nested field, continue. Otherwise,
// If [[requestedRootFields]] includes a nested field, continue. Otherwise,
// return [[op]]
if (requestedFields.exists { case (_, optAtt) => optAtt.isEmpty }) {
val prunedSchema = requestedFields
.map { case (field, _) => StructType(Array(field)) }
if (requestedRootFields.exists { case RootField(_, derivedFromAtt) => !derivedFromAtt }) {
val prunedSchema = requestedRootFields
.map { case RootField(field, _) => StructType(Array(field)) }
.reduceLeft(_ merge _)
val dataSchemaFieldNames = dataSchema.fieldNames.toSet
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dataSchema may also contains partition columns(see the doc of HadoopFsRelation), is this rule prepared for this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

val prunedDataSchema =
Expand Down Expand Up @@ -123,17 +123,17 @@ private[sql] object ParquetSchemaPruning extends Rule[LogicalPlan] {
}

/**
* Gets the top-level (no-parent) [[StructField]]s for the given [[Expression]].
* When [[expr]] is an [[Attribute]], construct a field around it and return the
* attribute as the second component of the returned tuple.
* Gets the root (aka top-level, no-parent) [[StructField]]s for the given [[Expression]].
* When [[expr]] is an [[Attribute]], construct a field around it and indicate that that
* field was derived from an attribute.
*/
private def getFields(expr: Expression): Seq[(StructField, Option[Attribute])] = {
private def getRootFields(expr: Expression): Seq[RootField] = {
expr match {
case att: Attribute =>
(StructField(att.name, att.dataType, att.nullable), Some(att)) :: Nil
case SelectedField(field) => (field, None) :: Nil
RootField(StructField(att.name, att.dataType, att.nullable), true) :: Nil
case SelectedField(field) => RootField(field, false) :: Nil
case _ =>
expr.children.flatMap(getFields)
expr.children.flatMap(getRootFields)
}
}

Expand All @@ -151,4 +151,10 @@ private[sql] object ParquetSchemaPruning extends Rule[LogicalPlan] {
case _ => 1
}
}

/**
* A "root" schema field (aka top-level, no-parent) and whether it was derived from
* an attribute or had a proper child.
*/
private case class RootField(field: StructField, derivedFromAtt: Boolean)
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,16 @@ class ParquetSchemaPruningSuite
BriefContact(Name("Janet", "Jones"), "567 Maple Drive") ::
BriefContact(Name("Jim", "Jones"), "6242 Ash Street") :: Nil

testStandardAndLegacyModes("partial schema intersection - select missing subfield") {
withTempPath { dir =>
val path = dir.getCanonicalPath

makeParquetFile(contacts, new File(path + "/contacts/p=1"))
makeParquetFile(briefContacts, new File(path + "/contacts/p=2"))

spark.read.parquet(path + "/contacts").createOrReplaceTempView("contacts")
testStandardAndLegacyModes("prune a single field") {
withContacts {
val query = sql("select name.middle from contacts")
checkScanSchemata(query, "struct<name:struct<middle:string>>")
checkAnswer(query, Row("X.") :: Row("Y.") :: Row(null) :: Row(null) :: Nil)
}
}

testStandardAndLegacyModes("partial schema intersection - select missing subfield") {
withContacts {
val query = sql("select name.middle, address from contacts where p=2")
checkScanSchemata(query, "struct<name:struct<middle:string>,address:string>")
checkAnswer(query,
Expand All @@ -61,14 +62,7 @@ class ParquetSchemaPruningSuite
}

testStandardAndLegacyModes("partial schema intersection - filter on subfield") {
withTempPath { dir =>
val path = dir.getCanonicalPath

makeParquetFile(contacts, new File(path + "/contacts/p=1"))
makeParquetFile(briefContacts, new File(path + "/contacts/p=2"))

spark.read.parquet(path + "/contacts").createOrReplaceTempView("contacts")

withContacts {
val query =
sql("select name.middle, name.first, pets, address from contacts where " +
"name.first = 'Janet' and p=2")
Expand All @@ -80,14 +74,7 @@ class ParquetSchemaPruningSuite
}

testStandardAndLegacyModes("no unnecessary schema pruning") {
withTempPath { dir =>
val path = dir.getCanonicalPath

makeParquetFile(contacts, new File(path + "/contacts/p=1"))
makeParquetFile(briefContacts, new File(path + "/contacts/p=2"))

spark.read.parquet(path + "/contacts").createOrReplaceTempView("contacts")

withContacts {
val query =
sql("select name.last, name.middle, name.first, relatives[''].last, " +
"relatives[''].middle, relatives[''].first, friends[0].last, friends[0].middle, " +
Expand All @@ -107,6 +94,15 @@ class ParquetSchemaPruningSuite
}

testStandardAndLegacyModes("empty schema intersection") {
withContacts {
val query = sql("select name.middle from contacts where p=2")
checkScanSchemata(query, "struct<name:struct<middle:string>>")
checkAnswer(query,
Row(null) :: Row(null) :: Nil)
}
}

private def withContacts(testThunk: => Unit) {
withTempPath { dir =>
val path = dir.getCanonicalPath

Expand All @@ -115,10 +111,7 @@ class ParquetSchemaPruningSuite

spark.read.parquet(path + "/contacts").createOrReplaceTempView("contacts")

val query = sql("select name.middle from contacts where p=2")
checkScanSchemata(query, "struct<name:struct<middle:string>>")
checkAnswer(query,
Row(null) :: Row(null) :: Nil)
testThunk
}
}
}