You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by do...@apache.org on 2023/06/29 16:03:48 UTC

[spark] branch master updated: [SPARK-44227][SQL] Extract SchemaUtils from StructField

This is an automated email from the ASF dual-hosted git repository.

dongjoon pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/master by this push:
     new 0ae86c0492c [SPARK-44227][SQL] Extract SchemaUtils from StructField
0ae86c0492c is described below

commit 0ae86c0492cdeac6240ea8283f5bd93a8bf6e7a8
Author: Rui Wang <ru...@databricks.com>
AuthorDate: Thu Jun 29 09:03:35 2023 -0700

    [SPARK-44227][SQL] Extract SchemaUtils from StructField
    
    ### What changes were proposed in this pull request?
    
    Extract SchemaUtils from StructField so that StructField does not requires anything from Catalyst.
    
    ### Why are the changes needed?
    
    To help StructField get rid of the need to depend on Catalyst.
    
    ### Does this PR introduce _any_ user-facing change?
    
    No
    
    ### How was this patch tested?
    
    Existing tests
    
    Closes #41772 from amaliujia/move_schema_utils.
    
    Authored-by: Rui Wang <ru...@databricks.com>
    Signed-off-by: Dongjoon Hyun <do...@apache.org>
---
 .../org/apache/spark/util/SparkSchemaUtils.scala   | 36 ++++++++++++++++++++++
 .../org/apache/spark/sql/types/StructField.scala   |  4 +--
 .../org/apache/spark/sql/util/SchemaUtils.scala    | 11 ++-----
 3 files changed, 40 insertions(+), 11 deletions(-)

diff --git a/common/utils/src/main/scala/org/apache/spark/util/SparkSchemaUtils.scala b/common/utils/src/main/scala/org/apache/spark/util/SparkSchemaUtils.scala
new file mode 100644
index 00000000000..efb833f0a2b
--- /dev/null
+++ b/common/utils/src/main/scala/org/apache/spark/util/SparkSchemaUtils.scala
@@ -0,0 +1,36 @@
+/*
+ * 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.util
+
+/**
+ * Utils for handling schemas.
+ */
+private[spark] object SparkSchemaUtils {
+  /**
+   * @param str The string to be escaped.
+   * @return The escaped string.
+   */
+  def escapeMetaCharacters(str: String): String = {
+    str.replaceAll("\n", "\\\\n")
+      .replaceAll("\r", "\\\\r")
+      .replaceAll("\t", "\\\\t")
+      .replaceAll("\f", "\\\\f")
+      .replaceAll("\b", "\\\\b")
+      .replaceAll("\u000B", "\\\\v")
+      .replaceAll("\u0007", "\\\\a")
+  }
+}
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/types/StructField.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/types/StructField.scala
index e03b2e8ab3c..dd267ed763e 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/types/StructField.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/types/StructField.scala
@@ -24,7 +24,7 @@ import org.apache.spark.annotation.Stable
 import org.apache.spark.sql.catalyst.util.{escapeSingleQuotedString, quoteIfNeeded}
 import org.apache.spark.sql.catalyst.util.ResolveDefaultColumns._
 import org.apache.spark.sql.catalyst.util.StringConcat
-import org.apache.spark.sql.util.SchemaUtils
+import org.apache.spark.util.SparkSchemaUtils
 
 /**
  * A field inside a StructType.
@@ -51,7 +51,7 @@ case class StructField(
       stringConcat: StringConcat,
       maxDepth: Int): Unit = {
     if (maxDepth > 0) {
-      stringConcat.append(s"$prefix-- ${SchemaUtils.escapeMetaCharacters(name)}: " +
+      stringConcat.append(s"$prefix-- ${SparkSchemaUtils.escapeMetaCharacters(name)}: " +
         s"${dataType.typeName} (nullable = $nullable)\n")
       DataType.buildFormattedString(dataType, s"$prefix    |", stringConcat, maxDepth)
     }
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/util/SchemaUtils.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/util/SchemaUtils.scala
index d202900381a..4b0e5308e65 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/util/SchemaUtils.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/util/SchemaUtils.scala
@@ -25,6 +25,7 @@ import org.apache.spark.sql.catalyst.expressions.{Alias, Attribute, NamedExpress
 import org.apache.spark.sql.connector.expressions.{BucketTransform, FieldReference, NamedTransform, Transform}
 import org.apache.spark.sql.errors.{QueryCompilationErrors, QueryExecutionErrors}
 import org.apache.spark.sql.types.{ArrayType, DataType, MapType, StructField, StructType}
+import org.apache.spark.util.SparkSchemaUtils
 
 
 /**
@@ -278,13 +279,5 @@ private[spark] object SchemaUtils {
    * @param str The string to be escaped.
    * @return The escaped string.
    */
-  def escapeMetaCharacters(str: String): String = {
-    str.replaceAll("\n", "\\\\n")
-      .replaceAll("\r", "\\\\r")
-      .replaceAll("\t", "\\\\t")
-      .replaceAll("\f", "\\\\f")
-      .replaceAll("\b", "\\\\b")
-      .replaceAll("\u000B", "\\\\v")
-      .replaceAll("\u0007", "\\\\a")
-  }
+  def escapeMetaCharacters(str: String): String = SparkSchemaUtils.escapeMetaCharacters(str)
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org