gengliangwang commented on code in PR #50631:
URL: https://github.com/apache/spark/pull/50631#discussion_r2055013256


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveTableSpec.scala:
##########
@@ -46,20 +47,55 @@ object ResolveTableSpec extends Rule[LogicalPlan] {
 
     preparedPlan.resolveOperatorsWithPruning(_.containsAnyPattern(COMMAND), 
ruleId) {
       case t: CreateTable =>
-        resolveTableSpec(t, t.tableSpec, s => t.copy(tableSpec = s))
+        resolveTableSpec(t, t.tableSpec,
+          fakeRelationFromColumns(t.columns), s => t.copy(tableSpec = s))
       case t: CreateTableAsSelect =>
-        resolveTableSpec(t, t.tableSpec, s => t.copy(tableSpec = s))
+        resolveTableSpec(t, t.tableSpec, None, s => t.copy(tableSpec = s))
       case t: ReplaceTable =>
-        resolveTableSpec(t, t.tableSpec, s => t.copy(tableSpec = s))
+        resolveTableSpec(t, t.tableSpec,
+          fakeRelationFromColumns(t.columns), s => t.copy(tableSpec = s))
       case t: ReplaceTableAsSelect =>
-        resolveTableSpec(t, t.tableSpec, s => t.copy(tableSpec = s))
+        resolveTableSpec(t, t.tableSpec, None, s => t.copy(tableSpec = s))
     }
   }
 
+  private def fakeRelationFromColumns(columns: Seq[ColumnDefinition]): 
Option[LogicalPlan] = {
+    val attributeList = columns.map { col =>
+      AttributeReference(col.name, col.dataType)()
+    }
+    Some(LocalRelation(attributeList))
+  }
+
+  private def analyzeConstraints(

Review Comment:
   There are some differences here. In a create table statement:
   * column default value and option **CANNOT** reference columns
   * constraint **CAN** reference columns
   
   Using a default analyzer with a dummy relation is simple, and it can include 
all other analysis batches other than the main `Resolution` batch. 



-- 
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: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to