Skip to main content

datafusion_spark/function/array/
mod.rs

1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements.  See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership.  The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License.  You may obtain a copy of the License at
8//
9//   http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied.  See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18pub mod array_contains;
19pub mod repeat;
20pub mod shuffle;
21pub mod slice;
22pub mod spark_array;
23
24use datafusion_expr::ScalarUDF;
25use datafusion_functions::make_udf_function;
26use std::sync::Arc;
27
28make_udf_function!(array_contains::SparkArrayContains, spark_array_contains);
29make_udf_function!(spark_array::SparkArray, array);
30make_udf_function!(shuffle::SparkShuffle, shuffle);
31make_udf_function!(repeat::SparkArrayRepeat, array_repeat);
32make_udf_function!(slice::SparkSlice, slice);
33
34pub mod expr_fn {
35    use datafusion_functions::export_functions;
36
37    export_functions!((
38        spark_array_contains,
39        "Returns true if the array contains the element (Spark semantics).",
40        array element
41    ));
42    export_functions!((array, "Returns an array with the given elements.", args));
43    export_functions!((
44        shuffle,
45        "Returns a random permutation of the given array.",
46        args
47    ));
48    export_functions!((
49        array_repeat,
50        "returns an array containing element count times.",
51        element count
52    ));
53    export_functions!((
54        slice,
55        "Returns a slice of the array from the start index with the given length.",
56        array start length
57    ));
58}
59
60pub fn functions() -> Vec<Arc<ScalarUDF>> {
61    vec![
62        spark_array_contains(),
63        array(),
64        shuffle(),
65        array_repeat(),
66        slice(),
67    ]
68}