forked from apache/spark
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rdar://84031512 Add stored procedure API (apache#1801)
* rdar://84031512 Add stored procedure API * Try to fix scala 2.13 build * Trigger build Co-authored-by: Anton Okolnychyi <aokolnychyi@apple.com> Co-authored-by: Szehon Ho <szehon.apache@gmail.com>
- Loading branch information
1 parent
dfecec2
commit 1be6df3
Showing
19 changed files
with
720 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/Procedure.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* 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 org.apache.spark.sql.catalyst.InternalRow; | ||
import org.apache.spark.sql.types.StructType; | ||
|
||
/** | ||
* An interface representing a stored procedure available for execution. | ||
*/ | ||
public interface Procedure { | ||
/** | ||
* Returns the input parameters of this procedure. | ||
*/ | ||
ProcedureParameter[] parameters(); | ||
|
||
/** | ||
* Returns the type of rows produced by this procedure. | ||
*/ | ||
StructType outputType(); | ||
|
||
/** | ||
* Executes this procedure. | ||
* <p> | ||
* Spark will align the provided arguments according to the input parameters | ||
* defined in {@link #parameters()} either by position or by name before execution. | ||
* <p> | ||
* Implementations may provide a summary of execution by returning one or many rows | ||
* as a result. The schema of output rows must match the defined output type | ||
* in {@link #outputType()}. | ||
* | ||
* @param args input arguments | ||
* @return the result of executing this procedure with the given arguments | ||
*/ | ||
InternalRow[] call(InternalRow args); | ||
|
||
/** | ||
* Returns the description of this procedure. | ||
*/ | ||
default String description() { | ||
return this.getClass().toString(); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/ProcedureCatalog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* 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 org.apache.spark.sql.catalyst.analysis.NoSuchProcedureException; | ||
|
||
/** | ||
* A catalog API for working with stored procedures. | ||
* <p> | ||
* Implementations should implement this interface if they expose stored procedures that | ||
* can be called via CALL statements. | ||
*/ | ||
public interface ProcedureCatalog extends CatalogPlugin { | ||
/** | ||
* Load a {@link Procedure stored procedure} by {@link Identifier identifier}. | ||
* | ||
* @param ident a stored procedure identifier | ||
* @return the stored procedure | ||
* @throws NoSuchProcedureException if there is no matching stored procedure | ||
*/ | ||
Procedure loadProcedure(Identifier ident) throws NoSuchProcedureException; | ||
} |
65 changes: 65 additions & 0 deletions
65
sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/ProcedureParameter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* 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 org.apache.spark.sql.types.DataType; | ||
|
||
/** | ||
* An input parameter of a {@link Procedure stored procedure}. | ||
*/ | ||
public interface ProcedureParameter { | ||
|
||
/** | ||
* Creates a required input parameter. | ||
* | ||
* @param name the name of the parameter | ||
* @param dataType the type of the parameter | ||
* @return the constructed stored procedure parameter | ||
*/ | ||
static ProcedureParameter required(String name, DataType dataType) { | ||
return new ProcedureParameterImpl(name, dataType, true); | ||
} | ||
|
||
/** | ||
* Creates an optional input parameter. | ||
* | ||
* @param name the name of the parameter. | ||
* @param dataType the type of the parameter. | ||
* @return the constructed optional stored procedure parameter | ||
*/ | ||
static ProcedureParameter optional(String name, DataType dataType) { | ||
return new ProcedureParameterImpl(name, dataType, false); | ||
} | ||
|
||
/** | ||
* Returns the name of this parameter. | ||
*/ | ||
String name(); | ||
|
||
/** | ||
* Returns the type of this parameter. | ||
*/ | ||
DataType dataType(); | ||
|
||
/** | ||
* Returns true if this parameter is required. | ||
*/ | ||
boolean required(); | ||
} |
80 changes: 80 additions & 0 deletions
80
...catalyst/src/main/java/org/apache/spark/sql/connector/catalog/ProcedureParameterImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* 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.Objects; | ||
|
||
import org.apache.spark.sql.types.DataType; | ||
|
||
/** | ||
* A {@link ProcedureParameter} implementation. | ||
*/ | ||
class ProcedureParameterImpl implements ProcedureParameter { | ||
private final String name; | ||
private final DataType dataType; | ||
private final boolean required; | ||
|
||
ProcedureParameterImpl(String name, DataType dataType, boolean required) { | ||
this.name = name; | ||
this.dataType = dataType; | ||
this.required = required; | ||
} | ||
|
||
@Override | ||
public String name() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public DataType dataType() { | ||
return dataType; | ||
} | ||
|
||
@Override | ||
public boolean required() { | ||
return required; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (this == other) { | ||
return true; | ||
} else if (other == null || getClass() != other.getClass()) { | ||
return false; | ||
} | ||
|
||
ProcedureParameterImpl that = (ProcedureParameterImpl) other; | ||
return required == that.required && | ||
Objects.equals(name, that.name) && | ||
Objects.equals(dataType, that.dataType); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(name, dataType, required); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format( | ||
"ProcedureParameter(name='%s', type=%s, required=%b)", | ||
name, dataType, required); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.