cloud-fan commented on code in PR #40734:
URL: https://github.com/apache/spark/pull/40734#discussion_r1164819937


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/v2Commands.scala:
##########
@@ -389,6 +389,46 @@ case class WriteDelta(
   }
 }
 
+trait V2CreateTableAsSelectPlan extends V2CreateTablePlan with 
AnalysisOnlyCommand {
+  def name: LogicalPlan
+  def query: LogicalPlan
+
+  override lazy val resolved: Boolean = childrenResolved && {
+    // the table schema is created from the query schema, so the only 
resolution needed is to check
+    // that the columns referenced by the table's partitioning exist in the 
query schema
+    val references = partitioning.flatMap(_.references).toSet
+    
references.map(_.fieldNames).forall(query.schema.findNestedField(_).isDefined)
+  }
+
+  override def childrenToAnalyze: Seq[LogicalPlan] = Seq(name, query)
+
+  override def tableSchema: StructType = query.schema
+
+  override def tableName: Identifier = {
+    assert(name.resolved)
+    name.asInstanceOf[ResolvedIdentifier].identifier
+  }
+
+  override protected def withNewChildrenInternal(
+      newChildren: IndexedSeq[LogicalPlan]): V2CreateTableAsSelectPlan = {
+    assert(!isAnalyzed)
+    newChildren match {
+      case Seq(newName, newQuery) =>
+        withNewNameAndQuery(newName, newQuery)
+      case Seq(newName) =>

Review Comment:
   when can this happen?



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