Back to home page

OSCL-LXR

 
 

    


0001 ---
0002 layout: global
0003 title: DROP FUNCTION
0004 displayTitle: DROP FUNCTION 
0005 license: |
0006   Licensed to the Apache Software Foundation (ASF) under one or more
0007   contributor license agreements.  See the NOTICE file distributed with
0008   this work for additional information regarding copyright ownership.
0009   The ASF licenses this file to You under the Apache License, Version 2.0
0010   (the "License"); you may not use this file except in compliance with
0011   the License.  You may obtain a copy of the License at
0012  
0013      http://www.apache.org/licenses/LICENSE-2.0
0014  
0015   Unless required by applicable law or agreed to in writing, software
0016   distributed under the License is distributed on an "AS IS" BASIS,
0017   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0018   See the License for the specific language governing permissions and
0019   limitations under the License.
0020 ---
0021 
0022 ### Description
0023 
0024 The `DROP FUNCTION` statement drops a temporary or user defined function (UDF). An exception will
0025 be thrown if the function does not exist. 
0026 
0027 ### Syntax
0028 
0029 ```sql
0030 DROP [ TEMPORARY ] FUNCTION [ IF EXISTS ] function_name
0031 ```
0032 
0033 ### Parameters
0034 
0035 * **function_name**
0036 
0037     Specifies the name of an existing function. The function name may be
0038     optionally qualified with a database name.
0039 
0040     **Syntax:** `[ database_name. ] function_name`
0041 
0042 * **TEMPORARY**
0043 
0044     Should be used to delete the `TEMPORARY` function.
0045 
0046 * **IF EXISTS**
0047 
0048     If specified, no exception is thrown when the function does not exist.
0049 
0050 ### Examples
0051 
0052 ```sql
0053 -- Create a permanent function `test_avg`
0054 CREATE FUNCTION test_avg AS 'org.apache.hadoop.hive.ql.udf.generic.GenericUDAFAverage';
0055 
0056 -- List user functions
0057 SHOW USER FUNCTIONS;
0058 +----------------+
0059 |        function|
0060 +----------------+
0061 |default.test_avg|
0062 +----------------+
0063 
0064 -- Create Temporary function `test_avg`
0065 CREATE TEMPORARY FUNCTION test_avg AS
0066     'org.apache.hadoop.hive.ql.udf.generic.GenericUDAFAverage';
0067 
0068 -- List user functions
0069 SHOW USER FUNCTIONS;
0070 +----------------+
0071 |        function|
0072 +----------------+
0073 |default.test_avg|
0074 |        test_avg|
0075 +----------------+
0076 
0077 -- Drop Permanent function
0078 DROP FUNCTION test_avg;
0079 
0080 -- Try to drop Permanent function which is not present
0081 DROP FUNCTION test_avg;
0082 Error: Error running query:
0083 org.apache.spark.sql.catalyst.analysis.NoSuchPermanentFunctionException:
0084 Function 'default.test_avg' not found in database 'default'; (state=,code=0)
0085 
0086 -- List the functions after dropping, it should list only temporary function
0087 SHOW USER FUNCTIONS;
0088 +--------+
0089 |function|
0090 +--------+
0091 |test_avg|
0092 +--------+
0093   
0094 -- Drop Temporary function
0095 DROP TEMPORARY FUNCTION IF EXISTS test_avg;
0096 ```
0097 
0098 ### Related Statements
0099 
0100 * [CREATE FUNCTION](sql-ref-syntax-ddl-create-function.html)
0101 * [DESCRIBE FUNCTION](sql-ref-syntax-aux-describe-function.html)
0102 * [SHOW FUNCTION](sql-ref-syntax-aux-show-functions.html)