viirya commented on a change in pull request #27728:
[SPARK-25556][SPARK-17636][SPARK-31026][SQL][test-hive1.2] Nested Column
Predicate Pushdown for Parquet
URL: https://github.com/apache/spark/pull/27728#discussion_r387264452
##########
File path:
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetFilters.scala
##########
@@ -49,15 +49,34 @@ class ParquetFilters(
pushDownInFilterThreshold: Int,
caseSensitive: Boolean) {
// A map which contains parquet field name and data type, if predicate push
down applies.
- private val nameToParquetField : Map[String, ParquetField] = {
- // Here we don't flatten the fields in the nested schema but just look up
through
- // root fields. Currently, accessing to nested fields does not push down
filters
- // and it does not support to create filters for them.
- val primitiveFields =
-
schema.getFields.asScala.filter(_.isPrimitive).map(_.asPrimitiveType()).map { f
=>
- f.getName -> ParquetField(f.getName,
- ParquetSchemaType(f.getOriginalType,
- f.getPrimitiveTypeName, f.getTypeLength, f.getDecimalMetadata))
+ // The keys are the column names. For nested column, `dot` will be used as a
separator.
+ // For column name that contains `dot`, backquote will be used.
+ // See `org.apache.spark.sql.connector.catalog.quote` for implementation
details.
+ private val nameToParquetField : Map[String, ParquetPrimitiveField] = {
+ // Recursively traverse the parquet schema to get primitive fields that
can be pushed-down.
+ // `parentFieldNames` is used to keep track of the current nested level
when traversing.
+ def getPrimitiveFields(
+ fields: Seq[Type],
+ parentFieldNames: Array[String] = Array.empty):
Seq[ParquetPrimitiveField] = {
+ fields.flatMap {
+ case p: PrimitiveType =>
+ Some(ParquetPrimitiveField(fieldNames = parentFieldNames :+
p.getName,
+ fieldType = ParquetSchemaType(p.getOriginalType,
+ p.getPrimitiveTypeName, p.getTypeLength, p.getDecimalMetadata)))
+ // Note that when g is a `Struct`, `g.getOriginalType` is `null`.
+ // When g is a `Map`, `g.getOriginalType` is `MAP`.
+ // When g is a `List`, `g.getOriginalType` is `LIST`.
+ case g: GroupType if g.getOriginalType == null =>
+ getPrimitiveFields(g.getFields.asScala, parentFieldNames :+
g.getName)
+ // Parquet only supports push-down for primitive types; as a result,
Map and List types
+ // are removed.
+ case _ => None
+ }
+ }
+
+ val primitiveFields = getPrimitiveFields(schema.getFields.asScala).map {
field =>
+ import
org.apache.spark.sql.connector.catalog.CatalogV2Implicits.MultipartIdentifierHelper
Review comment:
nit: move `import` outside `map?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]