DROP FUNCTION

Description

The DROP FUNCTION statement drops a temporary or user defined function (UDF). An exception will be thrown if the function does not exist.

Syntax

  1. DROP [ TEMPORARY ] FUNCTION [ IF EXISTS ] function_name

Parameters

  • function_name

    Specifies the name of an existing function. The function name may be optionally qualified with a database name.

    Syntax: [ database_name. ] function_name

  • TEMPORARY

    Should be used to delete the TEMPORARY function.

  • IF EXISTS

    If specified, no exception is thrown when the function does not exist.

Examples

  1. -- Create a permanent function `test_avg`
  2. CREATE FUNCTION test_avg AS 'org.apache.hadoop.hive.ql.udf.generic.GenericUDAFAverage';
  3. -- List user functions
  4. SHOW USER FUNCTIONS;
  5. +----------------+
  6. | function|
  7. +----------------+
  8. |default.test_avg|
  9. +----------------+
  10. -- Create Temporary function `test_avg`
  11. CREATE TEMPORARY FUNCTION test_avg AS
  12. 'org.apache.hadoop.hive.ql.udf.generic.GenericUDAFAverage';
  13. -- List user functions
  14. SHOW USER FUNCTIONS;
  15. +----------------+
  16. | function|
  17. +----------------+
  18. |default.test_avg|
  19. | test_avg|
  20. +----------------+
  21. -- Drop Permanent function
  22. DROP FUNCTION test_avg;
  23. -- Try to drop Permanent function which is not present
  24. DROP FUNCTION test_avg;
  25. Error: Error running query:
  26. org.apache.spark.sql.catalyst.analysis.NoSuchPermanentFunctionException:
  27. Function 'default.test_avg' not found in database 'default'; (state=,code=0)
  28. -- List the functions after dropping, it should list only temporary function
  29. SHOW USER FUNCTIONS;
  30. +--------+
  31. |function|
  32. +--------+
  33. |test_avg|
  34. +--------+
  35. -- Drop Temporary function
  36. DROP TEMPORARY FUNCTION IF EXISTS test_avg;