dongjoon-hyun commented on a change in pull request #24158: [SPARK-26847][SQL] Pruning nested serializers from object serializers: MapType support URL: https://github.com/apache/spark/pull/24158#discussion_r268033297
########## File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/objects.scala ########## @@ -132,49 +130,74 @@ object ObjectSerializerPruning extends Rule[LogicalPlan] { fields.map(f => collectStructType(f.dataType, structs)) case ArrayType(elementType, _) => collectStructType(elementType, structs) + case MapType(_, valueType, _) => + // Because we can't select a field from struct in key, so we skip key type. + collectStructType(valueType, structs) case _ => } structs } + /** + * This method returns pruned `CreateNamedStruct` expression given an original `CreateNamedStruct` + * and a pruned `StructType`. + */ + private def pruneNamedStruct(struct: CreateNamedStruct, prunedType: StructType) = { + // Filters out the pruned fields. + val prunedFields = struct.nameExprs.zip(struct.valExprs).filter { case (nameExpr, _) => + val name = nameExpr.eval(EmptyRow).toString + prunedType.fieldNames.exists { fieldName => + if (SQLConf.get.caseSensitiveAnalysis) { + fieldName.equals(name) + } else { + fieldName.equalsIgnoreCase(name) + } + } + }.flatMap(pair => Seq(pair._1, pair._2)) + + CreateNamedStruct(prunedFields) + } + + /** + * When we change nested serializer data type, `If` expression will be unresolved because + * literal null's data type doesn't match now. We need to align it with new data type. + * Note: we should do `transformUp` explicitly to change data types. + */ + private def alignNullTypeInIf(expr: Expression) = expr.transformUp { + case i @ If(_: IsNull, Literal(null, dt), ser) if !dt.sameType(ser.dataType) => Review comment: ~Do you have a test case for this?~ Sorry, I realized that this is just a refactoring. ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org