Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
[SPARK-35331][SQL] Attributes become unknown in RepartitionByExpressi…
…on after aliased
  • Loading branch information
yaooqinn committed May 7, 2021
commit 0c711e3a081dc644c3a2d3c47207046eb4457ee1
Original file line number Diff line number Diff line change
Expand Up @@ -1885,6 +1885,15 @@ class Analyzer(override val catalogManager: CatalogManager)
val newFilter = Filter(newCond.head, newChild)
Project(child.output, newFilter)
}

case r @ RepartitionByExpression(partitionExprs, child, _)
if (!r.resolved || r.missingInput.nonEmpty) && child.resolved =>
val (newPartitionExprs, newChild) = resolveExprsAndAddMissingAttrs(partitionExprs, child)
if (child.output == newChild.output) {
r.copy(newPartitionExprs, newChild)
} else {
Project(child.output, r.copy(newPartitionExprs, newChild))
}
}

/**
Expand Down
11 changes: 11 additions & 0 deletions sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4100,6 +4100,17 @@ class SQLQuerySuite extends QueryTest with SharedSparkSession with AdaptiveSpark
}
}
}

test("abcdedg") {
Seq("CLUSTER", "DISTRIBUTE").foreach { keyword =>
Seq("a", "substr(a, 0, 3)").foreach { expr =>
val clause = keyword + " by " + expr
withClue(clause) {
checkAnswer(sql(s"select a b from values('123') t(a) $clause"), Row("123"))
}
}
}
}
}

case class Foo(bar: Option[String])