aokolnychyi commented on code in PR #47190:
URL: https://github.com/apache/spark/pull/47190#discussion_r1664459676


##########
sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/ProcedureParameter.java:
##########
@@ -0,0 +1,84 @@
+/*
+ * 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.connector.catalog;
+
+import java.util.Optional;
+
+import org.apache.spark.annotation.Experimental;
+import org.apache.spark.sql.connector.expressions.Literal;
+import org.apache.spark.sql.types.DataType;
+
+import static 
org.apache.spark.sql.connector.catalog.ProcedureParameter.Mode.IN;
+
+/**
+ * A {@link Procedure stored procedure} parameter.
+ */
+@Experimental
+public interface ProcedureParameter {
+  /**
+   * Creates an input stored procedure parameter without a default value.
+   *
+   * @param name the name of the parameter
+   * @param dataType the type of the parameter
+   * @return the constructed stored procedure parameter
+   */
+  static ProcedureParameter input(String name, DataType dataType) {
+    return new ProcedureParameterImpl(IN, name, dataType, Optional.empty());
+  }
+
+  /**
+   * Creates an input stored procedure parameter with a default value.
+   *
+   * @param name the name of the parameter
+   * @param dataType the type of the parameter
+   * @param defaultValue the default value of the parameter
+   * @return the constructed stored procedure parameter
+   */
+  static ProcedureParameter input(String name, DataType dataType, Literal<?> 
defaultValue) {
+    return new ProcedureParameterImpl(IN, name, dataType, 
Optional.ofNullable(defaultValue));
+  }
+
+  /**
+   * Returns the mode of this parameter.
+   */
+  Mode mode();
+
+  /**
+   * Returns the name of this parameter.
+   */
+  String name();
+
+  /**
+   * Returns the data type of this parameter.
+   */
+  DataType dataType();
+
+  /**
+   * Returns the default value of this parameter, if provided.
+   */
+  Optional<Literal<?>> defaultValue();

Review Comment:
   I think there are two questions to consider:
   1. If we support CREATE PROCEDURE in the future, will we have a way to 
create a procedure that works with the proposed API? 
   2. Do we let connectors define arbitrary expressions as default values that 
will be evaluated and passed as arguments if none were provided by the user?
   
   The answer to 1 is probably yes as we can have `Supplier<Literal<?>>` that 
internally invokes `eval` on any foldable Catalyst expression and exposes a 
public `Literal` to connectors. The answer may change if we need to persist the 
SQL representation of the expression, however.
   
   The answer to 2 is not so clear. We already use `Literal<?>` in 
`ColumnDefaultValue`. It seems nice to be able to express arbitrary expressions 
but I am not sure it will be helpful. If we support arbitrary expressions here, 
we will have to covert them to internal Catalyst expressions to evaluate (so 
the list of what is supported will always be limited).
   
   How to represent default values is an open question right 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: [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]

Reply via email to