viirya commented on code in PR #37248:
URL: https://github.com/apache/spark/pull/37248#discussion_r927314233


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/ExistingRDD.scala:
##########
@@ -116,37 +119,78 @@ case class LogicalRDD(
       case e: Attribute => rewrite.getOrElse(e, e)
     }.asInstanceOf[SortOrder])
 
-    val rewrittenOriginLogicalPlan = originLogicalPlan.map { plan =>
-      assert(output == plan.output, "The output columns are expected to the 
same for output " +
-        s"and originLogicalPlan. output: $output / output in 
originLogicalPlan: ${plan.output}")
+    val rewrittenStatistics = originStats.map { s =>
+      Statistics(
+        s.sizeInBytes,
+        s.rowCount,
+        AttributeMap[ColumnStat](s.attributeStats.map {
+          case (attr, v) => (rewrite.getOrElse(attr, attr), v)
+        }),
+        s.isRuntime
+      )
+    }
 
-      val projectList = output.map { attr =>
-        Alias(attr, attr.name)(exprId = rewrite(attr).exprId)
-      }
-      Project(projectList, plan)
+    val rewrittenConstraints = originConstraints.map { c =>
+      c.map(_.transform {
+        case e: Attribute => rewrite.getOrElse(e, e)
+      })
     }
 
     LogicalRDD(
       output.map(rewrite),
       rdd,
-      rewrittenOriginLogicalPlan,
       rewrittenPartitioning,
       rewrittenOrdering,
       isStreaming
-    )(session).asInstanceOf[this.type]
+    )(session, rewrittenStatistics, 
rewrittenConstraints).asInstanceOf[this.type]
   }
 
   override protected def stringArgs: Iterator[Any] = Iterator(output, 
isStreaming)
 
   override def computeStats(): Statistics = {
-    originLogicalPlan.map(_.stats).getOrElse {
+    originStats.getOrElse {
       Statistics(
         // TODO: Instead of returning a default value here, find a way to 
return a meaningful size
         // estimate for RDDs. See PR 1238 for more discussions.
         sizeInBytes = BigInt(session.sessionState.conf.defaultSizeInBytes)
       )
     }
   }
+
+  override lazy val constraints: ExpressionSet = 
originConstraints.getOrElse(ExpressionSet())
+}
+
+object LogicalRDD {
+  /**
+   * Create a new LogicalRDD based on existing Dataset. stats and constraints 
are inherited from

Review Comment:
   nit:
   ```suggestion
      * Create a new LogicalRDD based on existing Dataset. Stats and 
constraints are inherited from
   ```



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to