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


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveDefaultStringTypes.scala:
##########
@@ -0,0 +1,201 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.sql.catalyst.analysis
+
+import org.apache.spark.sql.catalyst.expressions.{Cast, Expression, Literal}
+import org.apache.spark.sql.catalyst.plans.logical.{AddColumns, AlterColumn, 
AlterViewAs, ColumnDefinition, CreateView, LogicalPlan, QualifiedColType, 
ReplaceColumns, V1CreateTablePlan, V2CreateTablePlan}
+import org.apache.spark.sql.catalyst.rules.Rule
+import org.apache.spark.sql.internal.SQLConf
+import org.apache.spark.sql.types.{DataType, StringType}
+
+/**
+ * Resolves default string types in DDL commands. For DML commands, the 
default string type is
+ * determined by the session's default string type. For DDL, the default 
string type is the
+ * default type of the object (table -> schema -> catalog). However, this is 
not implemented yet.
+ * So, we will just use UTF8_BINARY for now.
+ *
+ * `replaceWithTempType` is a flag that determines whether to replace the 
default string type with a
+ * [[TemporaryStringType]] object in cases where the old type and new are 
equal and thus would
+ * not change the plan after transformation.
+ */
+class ResolveDefaultStringTypes(replaceWithTempType: Boolean) extends 
Rule[LogicalPlan] {
+  def apply(plan: LogicalPlan): LogicalPlan = {
+
+    val newPlan = if (isDDLCommand(plan)) {

Review Comment:
   I think we can make the code a bit more unified. How about this
   ```
   var hasTempStringType = boolean
   plan.resolveOperators {
     case AddColumn =>
       var defaultStringType = getDefaultStringType(table) // Always return 
utf8 for now.
       if (defaultStringType == StringType) {
         hasTempStringType = true
         defaultStringType = TemporaryStringType...
       }
       do the replacement work
     case other DDL commands =>  ...
     case ctas | rtas | create_view | alter_view => ...
     case normal query => ...
   }
   if (hasTempStringType) {
     the same pattern match but replace TempStringType only.
   }
   ```
   
   This code is closer to the eventual code, as we need to determine the 
default collation with the table/schema/catalog metadata, which is not a global 
thing, must be determined when a certain command is matched.



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