## 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/math/pi.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 std::any::Any;
    19
    20
    use arrow::datatypes::DataType;
    21
    use arrow::datatypes::DataType::Float64;
    22
    use datafusion_common::{assert_or_internal_err, DataFusionError, Result, ScalarValue};
    23
    use datafusion_expr::sort_properties::{ExprProperties, SortProperties};
    24
    use datafusion_expr::{
    25
        ColumnarValue, Documentation, ScalarFunctionArgs, ScalarUDFImpl, Signature,
    26
        Volatility,
    27
    };
    28
    use datafusion_macros::user_doc;
    29
    30
    #[user_doc(
    31
        doc_section(label = "Math Functions"),
    32
        description = "Returns an approximate value of π.",
    33
        syntax_example = "pi()"
    34
    )]
    35
    #[derive(Debug, PartialEq, Eq, Hash)]
    36
    pub struct PiFunc {
    37
        signature: Signature,
    38
    }
    39
    40
    impl Default for PiFunc {
    41
    0
        fn default() -> Self {
    42
    0
            PiFunc::new()
    43
    0
        }
    44
    }
    45
    46
    impl PiFunc {
    47
    0
        pub fn new() -> Self {
    48
    0
            Self {
    49
    0
                signature: Signature::nullary(Volatility::Immutable),
    50
    0
            }
    51
    0
        }
    52
    }
    53
    54
    impl ScalarUDFImpl for PiFunc {
    55
    0
        fn as_any(&self) -> &dyn Any {
    56
    0
            self
    57
    0
        }
    58
    59
    0
        fn name(&self) -> &str {
    60
    0
            "pi"
    61
    0
        }
    62
    63
    0
        fn signature(&self) -> &Signature {
    64
    0
            &self.signature
    65
    0
        }
    66
    67
    0
        fn return_type(&self, _arg_types: &[DataType]) -> Result<DataType> {
    68
    0
            Ok(Float64)
    69
    0
        }
    70
    71
    0
        fn invoke_with_args(&self, args: ScalarFunctionArgs) -> Result<ColumnarValue> {
    72
    0
            assert_or_internal_err!(
    73
    0
                args.args.is_empty(),
    74
    0
                "{} function does not accept arguments",
    75
    0
                self.name()
    76
            );
    77
    0
            Ok(ColumnarValue::Scalar(ScalarValue::Float64(Some(
    78
    0
                std::f64::consts::PI,
    79
    0
            ))))
    80
    0
        }
    81
    82
    0
        fn output_ordering(&self, _input: &[ExprProperties]) -> Result<SortProperties> {
    83
            // This function returns a constant value.
    84
    0
            Ok(SortProperties::Singleton)
    85
    0
        }
    86
    87
    0
        fn documentation(&self) -> Option<&Documentation> {
    88
    0
            self.doc()
    89
    0
        }
    90
    }