@@ -146,11 +146,7 @@ object NestedColumnAliasing {
146
146
val nestedFieldToAlias = attributeToExtractValuesAndAliases.values.flatten.toMap
147
147
148
148
// A reference attribute can have multiple aliases for nested fields.
149
- val attrToAliases = new AttributeMap (
150
- attributeToExtractValuesAndAliases.map { case (attr, evAliasSeq) =>
151
- attr.exprId -> (attr, evAliasSeq.map(_._2))
152
- }
153
- )
149
+ val attrToAliases = AttributeMap (attributeToExtractValuesAndAliases.mapValues(_.map(_._2)))
154
150
155
151
plan match {
156
152
case Project (projectList, child) =>
@@ -245,7 +241,9 @@ object NestedColumnAliasing {
245
241
val otherRootReferences = new mutable.ArrayBuffer [AttributeReference ]()
246
242
exprList.foreach { e =>
247
243
collectRootReferenceAndExtractValue(e).foreach {
248
- case ev : ExtractValue => nestedFieldReferences.append(ev)
244
+ case ev : ExtractValue =>
245
+ assert(ev.references.size == 1 , s " $ev should have one reference " )
246
+ nestedFieldReferences.append(ev)
249
247
case ar : AttributeReference => otherRootReferences.append(ar)
250
248
}
251
249
}
@@ -306,7 +304,7 @@ object GeneratorNestedColumnAliasing {
306
304
// when `nestedSchemaPruningEnabled` is on, nested columns will be pruned further at
307
305
// file format readers if it is supported.
308
306
case Project (projectList, g : Generate ) if (SQLConf .get.nestedPruningOnExpressions ||
309
- SQLConf .get.nestedSchemaPruningEnabled) && canPruneGenerator(g.generator) =>
307
+ SQLConf .get.nestedSchemaPruningEnabled) && canPruneGenerator(g.generator) =>
310
308
// On top on `Generate`, a `Project` that might have nested column accessors.
311
309
// We try to get alias maps for both project list and generator's children expressions.
312
310
val attrToExtractValues = NestedColumnAliasing .getAttributeToExtractValues(
@@ -373,9 +371,7 @@ object GeneratorNestedColumnAliasing {
373
371
val updatedGenerate = rewrittenG.copy(generatorOutput = updatedGeneratorOutput)
374
372
375
373
// Replace nested column accessor with generator output.
376
- val attrExprIdsOnGenerator = attrToExtractValuesOnGenerator.map { case (attr, _) =>
377
- attr.exprId
378
- }.toSet
374
+ val attrExprIdsOnGenerator = attrToExtractValuesOnGenerator.keys.map(_.exprId).toSet
379
375
val updatedProject = p.withNewChildren(Seq (updatedGenerate)).transformExpressions {
380
376
case f : ExtractValue if nestedFieldsOnGenerator.contains(f) =>
381
377
updatedGenerate.output
0 commit comments