srielau commented on code in PR #57962:
URL: https://github.com/apache/spark/pull/57962#discussion_r3813253070
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala:
##########
@@ -5610,6 +5610,16 @@ object SQLConf {
.booleanConf
.createWithDefault(false)
+ val PARSE_SQL_ENABLED =
+ buildConf("spark.sql.function.parseSql.enabled")
+ .doc("When true, enables the parse_sql SQL function. This feature is
under active " +
+ "development; the JSON contract may change across releases while the
flag remains " +
+ "off by default.")
+ .version("5.0.0")
Review Comment:
Addressed: set `.version("4.4.0")` to match `branch-4.x` (`4.4.0-SNAPSHOT`).
##########
sql/core/src/main/scala/org/apache/spark/sql/catalyst/expressions/ParseSql.scala:
##########
@@ -0,0 +1,113 @@
+/*
+ * 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.expressions
+
+import org.apache.spark.sql.AnalysisException
+import org.apache.spark.sql.catalyst.analysis.{FunctionRegistry,
FunctionRegistryBase, TypeCheckResult}
+import org.apache.spark.sql.catalyst.expressions.codegen.CodegenFallback
+import org.apache.spark.sql.catalyst.parser.ParseSqlResult
+import org.apache.spark.sql.internal.SQLConf
+import org.apache.spark.sql.internal.types.StringTypeWithCollation
+import org.apache.spark.sql.types.{AbstractDataType, DataType, StringType}
+import org.apache.spark.unsafe.types.UTF8String
+
+/**
+ * Parses a SQL statement string and returns a compact JSON description of the
+ * unresolved statement (identifier/code, lineage references, select-list
names,
+ * parameters), or a STANDARD-format error object when the statement does not
+ * parse.
+ *
+ * Behind [[SQLConf.PARSE_SQL_ENABLED]] while the JSON contract is still
+ * evolving. Designed for batch evaluation over DataFrames of SQL text.
+ * User-facing parse errors become JSON; unexpected internal failures
propagate.
+ */
+// scalastyle:off line.size.limit
+@ExpressionDescription(
+ usage = """_FUNC_(sqlStmt) - Parses `sqlStmt` with the stock Spark SQL
parser and
+ returns a JSON string describing the statement (parse success, Table 39
statement
+ identifier/code, target and source table references for lineage,
select-list column
+ names, and parameter markers). Session parser extensions are not applied.
+ Requires spark.sql.function.parseSql.enabled=true. On syntax / parse error
returns JSON
+ with `parse_success` false, source location, and a nested STANDARD error
object
+ instead of throwing.""",
+ arguments = """
+ Arguments:
+ * sqlStmt - A SQL statement string to parse.
+ An expression that evaluates to a string.
+ """,
+ examples = """
+ Examples:
+ > SELECT _FUNC_('SELECT a, b FROM t');
+
{"parse_success":true,"statement_identifier":"SELECT","statement_code":21,"source_table_references":[["t"]],"select_list":[{"name":["a"]},{"name":["b"]}]}
+ > SELECT get_json_object(_FUNC_('SELEC'), '$.error.errorClass');
+ PARSE_SYNTAX_ERROR
+ """,
+ group = "misc_funcs",
+ since = "5.0.0")
Review Comment:
Addressed: set `since` / `FunctionRegistryBase.build` to `4.4.0` to match
`branch-4.x` (`4.4.0-SNAPSHOT`). Used `4.4.0` rather than `4.3.0` so the
annotation stays consistent with the config version and the current feature
branch.
--
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]