## 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/arrowtypeof.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
    use arrow::datatypes::DataType;
    19
    use datafusion_common::{utils::take_function_args, Result, ScalarValue};
    20
    use datafusion_expr::{ColumnarValue, Documentation, ScalarFunctionArgs};
    21
    use datafusion_expr::{ScalarUDFImpl, Signature, Volatility};
    22
    use datafusion_macros::user_doc;
    23
    use std::any::Any;
    24
    25
    #[user_doc(
    26
        doc_section(label = "Other Functions"),
    27
        description = "Returns the name of the underlying [Arrow data type](https://docs.rs/arrow/latest/arrow/datatypes/enum.DataType.html) of the expression.",
    28
        syntax_example = "arrow_typeof(expression)",
    29
        sql_example = r#"```sql
    30
    > select arrow_typeof('foo'), arrow_typeof(1);
    31
    +---------------------------+------------------------+
    32
    | arrow_typeof(Utf8("foo")) | arrow_typeof(Int64(1)) |
    33
    +---------------------------+------------------------+
    34
    | Utf8                      | Int64                  |
    35
    +---------------------------+------------------------+
    36
    ```
    37
    "#,
    38
        argument(
    39
            name = "expression",
    40
            description = "Expression to evaluate. The expression can be a constant, column, or function, and any combination of operators."
    41
        )
    42
    )]
    43
    #[derive(Debug, PartialEq, Eq, Hash)]
    44
    pub struct ArrowTypeOfFunc {
    45
        signature: Signature,
    46
    }
    47
    48
    impl Default for ArrowTypeOfFunc {
    49
    0
        fn default() -> Self {
    50
    0
            Self::new()
    51
    0
        }
    52
    }
    53
    54
    impl ArrowTypeOfFunc {
    55
    0
        pub fn new() -> Self {
    56
    0
            Self {
    57
    0
                signature: Signature::any(1, Volatility::Immutable),
    58
    0
            }
    59
    0
        }
    60
    }
    61
    62
    impl ScalarUDFImpl for ArrowTypeOfFunc {
    63
    0
        fn as_any(&self) -> &dyn Any {
    64
    0
            self
    65
    0
        }
    66
    0
        fn name(&self) -> &str {
    67
    0
            "arrow_typeof"
    68
    0
        }
    69
    70
    0
        fn signature(&self) -> &Signature {
    71
    0
            &self.signature
    72
    0
        }
    73
    74
    0
        fn return_type(&self, _arg_types: &[DataType]) -> Result<DataType> {
    75
    0
            Ok(DataType::Utf8)
    76
    0
        }
    77
    78
    0
        fn invoke_with_args(&self, args: ScalarFunctionArgs) -> Result<ColumnarValue> {
    79
    0
            let [arg] = take_function_args(self.name(), args.args)?;
    80
    0
            let input_data_type = arg.data_type();
    81
    0
            Ok(ColumnarValue::Scalar(ScalarValue::from(format!(
    82
    0
                "{input_data_type}"
    83
    0
            ))))
    84
    0
        }
    85
    86
    0
        fn documentation(&self) -> Option<&Documentation> {
    87
    0
            self.doc()
    88
    0
        }
    89
    }