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


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/literals.scala:
##########
@@ -247,6 +251,67 @@ object Literal {
       s"Literal must have a corresponding value to ${dataType.catalogString}, 
" +
       s"but class ${Utils.getSimpleName(value.getClass)} found.")
   }
+
+  /**
+   * Parse and analyze the .sql string of a Literal, construct the Literal 
given the data type json.
+   * Example usage:
+   *   val serializedValue = lit.sql
+   *   val dataTypeJson = lit.dataType.json
+   *   val deserializedLit: Literal = Literal.fromSQL(serializedValue, 
dataTypeJson)
+   *
+   * @param valueSqlStr the .sql string of the Literal
+   * @param dataTypeJson the json format data type of the Literal
+   * @throws AnalysisException 
INVALID_LITERAL_VALUE_SQL_STRING_FOR_DESERIALIZATION
+   */
+  private[sql] def fromSQL(valueSqlStr: String, dataTypeJson: String): Literal 
= {
+    def parseAndAnalyze(valueSqlStr: String, dataType: DataType): Expression = 
{
+      lazy val parser = new CatalystSqlParser()

Review Comment:
   ```suggestion
        val parser = new CatalystSqlParser()
   ```



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/literals.scala:
##########
@@ -247,6 +251,67 @@ object Literal {
       s"Literal must have a corresponding value to ${dataType.catalogString}, 
" +
       s"but class ${Utils.getSimpleName(value.getClass)} found.")
   }
+
+  /**
+   * Parse and analyze the .sql string of a Literal, construct the Literal 
given the data type json.
+   * Example usage:
+   *   val serializedValue = lit.sql
+   *   val dataTypeJson = lit.dataType.json
+   *   val deserializedLit: Literal = Literal.fromSQL(serializedValue, 
dataTypeJson)
+   *
+   * @param valueSqlStr the .sql string of the Literal
+   * @param dataTypeJson the json format data type of the Literal
+   * @throws AnalysisException 
INVALID_LITERAL_VALUE_SQL_STRING_FOR_DESERIALIZATION
+   */
+  private[sql] def fromSQL(valueSqlStr: String, dataTypeJson: String): Literal 
= {
+    def parseAndAnalyze(valueSqlStr: String, dataType: DataType): Expression = 
{
+      lazy val parser = new CatalystSqlParser()
+      val parsed: Expression = try {
+        parser.parseExpression(valueSqlStr)
+      } catch {
+        case e: Exception =>
+          throw 
QueryCompilationErrors.invalidLiteralValueSQLStringForDeserialization(
+            "PARSE_FAILURE", valueSqlStr, dataType, Some(e))
+      }
+
+      val analyzer: Analyzer = ResolveDefaultColumns.DefaultColumnAnalyzer

Review Comment:
   maybe we can move `DefaultColumnAnalyzer` to a more common place now.



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