0001 ---
0002 layout: global
0003 title: Functions
0004 displayTitle: Functions
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 Spark SQL provides two function features to meet a wide range of user needs: built-in functions and user-defined functions (UDFs).
0023 Built-in functions are commonly used routines that Spark SQL predefines and a complete list of the functions can be found in the [Built-in Functions](api/sql/) API document. UDFs allow users to define their own functions when the system’s built-in functions are not enough to perform the desired task.
0024
0025 ### Built-in Functions
0026
0027 Spark SQL has some categories of frequently-used built-in functions for aggregation, arrays/maps, date/timestamp, and JSON data.
0028 This subsection presents the usages and descriptions of these functions.
0029
0030 #### Scalar Functions
0031 * [Array Functions](sql-ref-functions-builtin.html#array-functions)
0032 * [Map Functions](sql-ref-functions-builtin.html#map-functions)
0033 * [Date and Timestamp Functions](sql-ref-functions-builtin.html#date-and-timestamp-functions)
0034 * [JSON Functions](sql-ref-functions-builtin.html#json-functions)
0035
0036 #### Aggregate-like Functions
0037 * [Aggregate Functions](sql-ref-functions-builtin.html#aggregate-functions)
0038 * [Window Functions](sql-ref-functions-builtin.html#window-functions)
0039
0040 ### UDFs (User-Defined Functions)
0041
0042 User-Defined Functions (UDFs) are a feature of Spark SQL that allows users to define their own functions when the system's built-in functions are not enough to perform the desired task. To use UDFs in Spark SQL, users must first define the function, then register the function with Spark, and finally call the registered function. The User-Defined Functions can act on a single row or act on multiple rows at once. Spark SQL also supports integration of existing Hive implementations of UDFs, UDAFs and UDTFs.
0043
0044 * [Scalar User-Defined Functions (UDFs)](sql-ref-functions-udf-scalar.html)
0045 * [User-Defined Aggregate Functions (UDAFs)](sql-ref-functions-udf-aggregate.html)
0046 * [Integration with Hive UDFs/UDAFs/UDTFs](sql-ref-functions-udf-hive.html)