cloud-fan commented on a change in pull request #30586:
URL: https://github.com/apache/spark/pull/30586#discussion_r535421523



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/CharVarcharUtils.scala
##########
@@ -45,6 +47,41 @@ object CharVarcharUtils {
     })
   }
 
+  /**
+   * Validate the given schema to fail if it contains char or varchar types
+   *
+   * @param schema the given struct type
+   * @return
+   */
+  def failWithCharLikeTypes(schema: StructType): StructType = {
+    if (schema.exists(f => hasCharVarchar(f.dataType) ||
+      f.metadata.contains(CHAR_VARCHAR_TYPE_STRING_METADATA_KEY))) {
+      throw new AnalysisException(s"Cannot use char/varchar type in this 
caller")
+    }
+    schema
+  }
+
+  /**
+   * Validate the given [[DataType]] to fail if it is char or varchar types or 
contains nested ones
+   *
+   * @param dt the given struct type
+   * @return
+   */
+  def failOrWarnWithCharLikeType(dt: DataType, fail: Boolean = true): DataType 
= {

Review comment:
       let's have 2 methods instead of using a boolean flag.
   ```
   def failIfHasCharVarchar(dt: DataType)...
   def warnIfHasCharVarchar(dt: DataType)...
   ```




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

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