Github user yhuai commented on a diff in the pull request:
https://github.com/apache/spark/pull/8889#discussion_r40340163
--- Diff:
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/LogicalRelation.scala
---
@@ -17,23 +17,44 @@
package org.apache.spark.sql.execution.datasources
import org.apache.spark.sql.catalyst.analysis.MultiInstanceRelation
-import org.apache.spark.sql.catalyst.expressions.{AttributeMap,
AttributeReference}
+import org.apache.spark.sql.catalyst.expressions.{Attribute, AttributeMap,
AttributeReference}
import org.apache.spark.sql.catalyst.plans.logical.{LeafNode, LogicalPlan,
Statistics}
import org.apache.spark.sql.sources.BaseRelation
/**
* Used to link a [[BaseRelation]] in to a logical query plan.
+ *
+ * Note that sometimes we need to use `LogicalRelation` to replace an
existing leaf node without
+ * changing the output attributes' IDs. The `expectedOutputAttributes`
parameter is used for
+ * this purpose.
*/
-private[sql] case class LogicalRelation(relation: BaseRelation)
- extends LeafNode
- with MultiInstanceRelation {
+private[sql] case class LogicalRelation(
+ relation: BaseRelation,
+ expectedOutputAttributes: Seq[Attribute] = Nil)
+ extends LeafNode with MultiInstanceRelation {
+
+ assert(expectedOutputAttributes == Nil ||
+ relation.schema.length == expectedOutputAttributes.length)
- override val output: Seq[AttributeReference] =
relation.schema.toAttributes
+ override val output: Seq[AttributeReference] = {
+ val attrs = relation.schema.toAttributes
+ if (expectedOutputAttributes == Nil) {
+ attrs
+ } else {
+ attrs.zip(expectedOutputAttributes).map {
--- End diff --
Then, let's add a comment to say where we check the length.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]