## 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/version.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
    //! [`VersionFunc`]: Implementation of the `version` function.
    19
    20
    use arrow::datatypes::DataType;
    21
    use datafusion_common::{utils::take_function_args, Result, ScalarValue};
    22
    use datafusion_expr::{
    23
        ColumnarValue, Documentation, ScalarFunctionArgs, ScalarUDFImpl, Signature,
    24
        Volatility,
    25
    };
    26
    use datafusion_macros::user_doc;
    27
    use std::any::Any;
    28
    29
    #[user_doc(
    30
        doc_section(label = "Other Functions"),
    31
        description = "Returns the version of DataFusion.",
    32
        syntax_example = "version()",
    33
        sql_example = r#"```sql
    34
    > select version();
    35
    +--------------------------------------------+
    36
    | version()                                  |
    37
    +--------------------------------------------+
    38
    | Apache DataFusion 42.0.0, aarch64 on macos |
    39
    +--------------------------------------------+
    40
    ```"#
    41
    )]
    42
    #[derive(Debug, PartialEq, Eq, Hash)]
    43
    pub struct VersionFunc {
    44
        signature: Signature,
    45
    }
    46
    47
    impl Default for VersionFunc {
    48
    0
        fn default() -> Self {
    49
    0
            Self::new()
    50
    0
        }
    51
    }
    52
    53
    impl VersionFunc {
    54
    0
        pub fn new() -> Self {
    55
    0
            Self {
    56
    0
                signature: Signature::exact(vec![], Volatility::Immutable),
    57
    0
            }
    58
    0
        }
    59
    }
    60
    61
    impl ScalarUDFImpl for VersionFunc {
    62
    0
        fn as_any(&self) -> &dyn Any {
    63
    0
            self
    64
    0
        }
    65
    66
    0
        fn name(&self) -> &str {
    67
    0
            "version"
    68
    0
        }
    69
    70
    0
        fn signature(&self) -> &Signature {
    71
    0
            &self.signature
    72
    0
        }
    73
    74
    0
        fn return_type(&self, args: &[DataType]) -> Result<DataType> {
    75
    0
            let [] = take_function_args(self.name(), args)?;
    76
    0
            Ok(DataType::Utf8)
    77
    0
        }
    78
    79
    0
        fn invoke_with_args(&self, args: ScalarFunctionArgs) -> Result<ColumnarValue> {
    80
    0
            let [] = take_function_args(self.name(), args.args)?;
    81
            // TODO it would be great to add rust version and arrow version,
    82
            // but that requires a `build.rs` script and/or adding a version const to arrow-rs
    83
    0
            let version = format!(
    84
    0
                "Apache DataFusion {}, {} on {}",
    85
                env!("CARGO_PKG_VERSION"),
    86
                std::env::consts::ARCH,
    87
                std::env::consts::OS,
    88
            );
    89
    0
            Ok(ColumnarValue::Scalar(ScalarValue::Utf8(Some(version))))
    90
    0
        }
    91
    92
    0
        fn documentation(&self) -> Option<&Documentation> {
    93
    0
            self.doc()
    94
    0
        }
    95
    }
    96
    97
    #[cfg(test)]
    98
    mod test {
    99
        use super::*;
    100
        use arrow::datatypes::Field;
    101
        use datafusion_common::config::ConfigOptions;
    102
        use datafusion_expr::ScalarUDF;
    103
        use std::sync::Arc;
    104
    105
        #[tokio::test]
    106
        async fn test_version_udf() {
    107
            let version_udf = ScalarUDF::from(VersionFunc::new());
    108
            let version = version_udf
    109
                .invoke_with_args(ScalarFunctionArgs {
    110
                    args: vec![],
    111
                    arg_fields: vec![],
    112
                    number_rows: 0,
    113
                    return_field: Field::new("f", DataType::Utf8, true).into(),
    114
                    config_options: Arc::new(ConfigOptions::default()),
    115
                })
    116
                .unwrap();
    117
    118
            if let ColumnarValue::Scalar(ScalarValue::Utf8(Some(version))) = version {
    119
                assert!(version.starts_with("Apache DataFusion"));
    120
            } else {
    121
                panic!("Expected version string");
    122
            }
    123
        }
    124
    }