yihua commented on code in PR #13868:
URL: https://github.com/apache/hudi/pull/13868#discussion_r2342551330
##########
hudi-spark-datasource/hudi-spark/src/main/scala/org/apache/spark/sql/hudi/command/procedures/SetAuditLockProcedure.scala:
##########
@@ -82,36 +83,46 @@ class AuditLockSetProcedure extends BaseProcedure with
ProcedureBuilder {
/**
* Executes the audit lock set procedure.
*
- * @param args Procedure arguments containing table name and desired state
+ * @param args Procedure arguments containing table name or path and desired
state
* @return Sequence containing a single Row with execution results
* @throws IllegalArgumentException if state parameter is not 'enabled' or
'disabled'
*/
override def call(args: ProcedureArgs): Seq[Row] = {
super.checkArgs(PARAMETERS, args)
- val tableName = getArgValueOrDefault(args,
PARAMETERS(0)).get.asInstanceOf[String]
- val state = getArgValueOrDefault(args,
PARAMETERS(1)).get.asInstanceOf[String].toLowerCase
+ val tableName = getArgValueOrDefault(args, PARAMETERS(0))
+ val tablePath = getArgValueOrDefault(args, PARAMETERS(1))
+ val state = getArgValueOrDefault(args,
PARAMETERS(2)).get.asInstanceOf[String].toLowerCase
+
+ // Validate that both table and path are not provided
+ if (tableName.isDefined && tablePath.isDefined) {
+ throw new IllegalArgumentException("Cannot specify both table and path
parameters")
+ }
Review Comment:
To remove
##########
hudi-spark-datasource/hudi-spark/src/main/scala/org/apache/spark/sql/hudi/command/procedures/ShowAuditLockStatusProcedure.scala:
##########
@@ -0,0 +1,173 @@
+/*
+ * 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.hudi.command.procedures
+
+import
org.apache.hudi.client.transaction.lock.audit.StorageLockProviderAuditService
+import org.apache.hudi.common.util.FileIOUtils
+import org.apache.hudi.storage.StoragePath
+
+import com.fasterxml.jackson.databind.{JsonNode, ObjectMapper}
+import org.apache.spark.sql.Row
+import org.apache.spark.sql.types.{DataTypes, Metadata, StructField,
StructType}
+
+import java.util.function.Supplier
+
+import scala.util.{Failure, Success, Try}
+
+/**
+ * Spark SQL procedure for showing the current audit logging status for Hudi
tables.
+ *
+ * This procedure allows users to check whether audit logging is currently
enabled
+ * or disabled for storage lock operations. It reads the audit configuration
file
+ * and reports the current status along with relevant paths.
+ *
+ * Usage:
+ * {{{
+ * CALL show_audit_lock_status(table => 'my_table')
+ * CALL show_audit_lock_status(path => '/path/to/table')
+ * }}}
+ *
+ * The procedure reads the audit configuration file from:
+ * `{table_path}/.hoodie/.locks/audit_enabled.json`
+ *
+ * @author Apache Hudi
+ * @since 1.0.0
+ */
+class ShowAuditLockStatusProcedure extends BaseProcedure with ProcedureBuilder
{
+ private val PARAMETERS = Array[ProcedureParameter](
+ ProcedureParameter.optional(0, "table", DataTypes.StringType),
+ ProcedureParameter.optional(1, "path", DataTypes.StringType)
+ )
+
+ private val OUTPUT_TYPE = new StructType(Array[StructField](
+ StructField("table", DataTypes.StringType, nullable = false,
Metadata.empty),
+ StructField("audit_enabled", DataTypes.BooleanType, nullable = false,
Metadata.empty),
+ StructField("config_path", DataTypes.StringType, nullable = false,
Metadata.empty),
+ StructField("audit_folder_path", DataTypes.StringType, nullable = false,
Metadata.empty)
+ ))
+
+ private val OBJECT_MAPPER = new ObjectMapper()
+
+ /**
+ * Returns the procedure parameters definition.
+ *
+ * @return Array of parameters: table (optional String) and path (optional
String)
+ */
+ def parameters: Array[ProcedureParameter] = PARAMETERS
+
+ /**
+ * Returns the output schema for the procedure result.
+ *
+ * @return StructType containing table, audit_enabled, config_path, and
audit_folder_path columns
+ */
+ def outputType: StructType = OUTPUT_TYPE
+
+ /**
+ * Executes the show audit lock status procedure.
+ *
+ * @param args Procedure arguments containing table name or path
+ * @return Sequence containing a single Row with status information
+ * @throws IllegalArgumentException if neither table nor path is provided,
or both are provided
+ */
+ override def call(args: ProcedureArgs): Seq[Row] = {
+ super.checkArgs(PARAMETERS, args)
+
+ val tableName = getArgValueOrDefault(args, PARAMETERS(0))
+ val tablePath = getArgValueOrDefault(args, PARAMETERS(1))
+
+ // Validate that both table and path are not provided
+ if (tableName.isDefined && tablePath.isDefined) {
+ throw new IllegalArgumentException("Cannot specify both table and path
parameters")
+ }
Review Comment:
nit: similar here
--
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]