## Coverage Report

#### Created: 2025-11-22 06:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)

    /Users/andrewlamb/Software/datafusion/datafusion/functions/src/core/mod.rs

    Line
    Count
    Source
    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
    18
    //! "core" DataFusion functions
    19
    20
    use datafusion_expr::ScalarUDF;
    21
    use std::sync::Arc;
    22
    23
    pub mod arrow_cast;
    24
    pub mod arrowtypeof;
    25
    pub mod coalesce;
    26
    pub mod expr_ext;
    27
    pub mod getfield;
    28
    pub mod greatest;
    29
    mod greatest_least_utils;
    30
    pub mod least;
    31
    pub mod named_struct;
    32
    pub mod nullif;
    33
    pub mod nvl;
    34
    pub mod nvl2;
    35
    pub mod overlay;
    36
    pub mod planner;
    37
    pub mod r#struct;
    38
    pub mod union_extract;
    39
    pub mod union_tag;
    40
    pub mod version;
    41
    42
    // create UDFs
    43
    make_udf_function!(arrow_cast::ArrowCastFunc, arrow_cast);
    44
    make_udf_function!(nullif::NullIfFunc, nullif);
    45
    make_udf_function!(nvl::NVLFunc, nvl);
    46
    make_udf_function!(nvl2::NVL2Func, nvl2);
    47
    make_udf_function!(overlay::OverlayFunc, overlay);
    48
    make_udf_function!(arrowtypeof::ArrowTypeOfFunc, arrow_typeof);
    49
    make_udf_function!(r#struct::StructFunc, r#struct);
    50
    make_udf_function!(named_struct::NamedStructFunc, named_struct);
    51
    make_udf_function!(getfield::GetFieldFunc, get_field);
    52
    make_udf_function!(coalesce::CoalesceFunc, coalesce);
    53
    make_udf_function!(greatest::GreatestFunc, greatest);
    54
    make_udf_function!(least::LeastFunc, least);
    55
    make_udf_function!(union_extract::UnionExtractFun, union_extract);
    56
    make_udf_function!(union_tag::UnionTagFunc, union_tag);
    57
    make_udf_function!(version::VersionFunc, version);
    58
    59
    pub mod expr_fn {
    60
        use datafusion_expr::{Expr, Literal};
    61
    62
        export_functions!((
    63
            nullif,
    64
            "Returns NULL if value1 equals value2; otherwise it returns value1. This can be used to perform the inverse operation of the COALESCE expression",
    65
            arg1 arg2
    66
        ),(
    67
            arrow_cast,
    68
            "Returns value2 if value1 is NULL; otherwise it returns value1",
    69
            arg1 arg2
    70
        ),(
    71
            nvl,
    72
            "Returns value2 if value1 is NULL; otherwise it returns value1",
    73
            arg1 arg2
    74
        ),(
    75
            nvl2,
    76
            "Returns value2 if value1 is not NULL; otherwise, it returns value3.",
    77
            arg1 arg2 arg3
    78
        ),(
    79
            overlay,
    80
            "replace the substring of string that starts at the start'th character and extends for count characters with new substring",
    81
            args,
    82
        ),(
    83
            arrow_typeof,
    84
            "Returns the Arrow type of the input expression.",
    85
            arg1
    86
        ),(
    87
            r#struct,
    88
            "Returns a struct with the given arguments",
    89
            args,
    90
        ),(
    91
            named_struct,
    92
            "Returns a struct with the given names and arguments pairs",
    93
            args,
    94
        ),(
    95
            coalesce,
    96
            "Returns `coalesce(args...)`, which evaluates to the value of the first expr which is not NULL",
    97
            args,
    98
        ),(
    99
            greatest,
    100
            "Returns `greatest(args...)`, which evaluates to the greatest value in the list of expressions or NULL if all the expressions are NULL",
    101
            args,
    102
        ),(
    103
            least,
    104
            "Returns `least(args...)`, which evaluates to the smallest value in the list of expressions or NULL if all the expressions are NULL",
    105
            args,
    106
        ),(
    107
            union_tag,
    108
            "Returns the name of the currently selected field in the union",
    109
            arg1
    110
        ));
    111
    112
        #[doc = "Returns the value of the field with the given name from the struct"]
    113
    0
        pub fn get_field(arg1: Expr, arg2: impl Literal) -> Expr {
    114
    0
            super::get_field().call(vec![arg1, arg2.lit()])
    115
    0
        }
    116
    117
        #[doc = "Returns the value of the field with the given name from the union when it's selected, or NULL otherwise"]
    118
    0
        pub fn union_extract(arg1: Expr, arg2: impl Literal) -> Expr {
    119
    0
            super::union_extract().call(vec![arg1, arg2.lit()])
    120
    0
        }
    121
    }
    122
    123
    /// Returns all DataFusion functions defined in this package
    124
    0
    pub fn functions() -> Vec<Arc<ScalarUDF>> {
    125
    0
        vec![
    126
    0
            nullif(),
    127
    0
            arrow_cast(),
    128
    0
            nvl(),
    129
    0
            nvl2(),
    130
    0
            overlay(),
    131
    0
            arrow_typeof(),
    132
    0
            named_struct(),
    133
            // Note: most users invoke `get_field` indirectly via field access
    134
            // syntax like `my_struct_col['field_name']`, which results in a call to
    135
            // `get_field(my_struct_col, "field_name")`.
    136
            //
    137
            // However, it is also exposed directly for use cases such as
    138
            // serializing / deserializing plans with the field access desugared to
    139
            // calls to [`get_field`]
    140
    0
            get_field(),
    141
    0
            coalesce(),
    142
    0
            greatest(),
    143
    0
            least(),
    144
    0
            union_extract(),
    145
    0
            union_tag(),
    146
    0
            version(),
    147
    0
            r#struct(),
    148
        ]
    149
    0
    }