risingwave_expr_impl/scalar/
lower.rs

1// Copyright 2025 RisingWave Labs
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use risingwave_expr::function;
16
17#[function("lower(varchar) -> varchar")]
18pub fn lower(s: &str, writer: &mut impl std::fmt::Write) {
19    for c in s.chars() {
20        writer.write_char(c.to_ascii_lowercase()).unwrap();
21    }
22}
23
24#[cfg(test)]
25mod tests {
26    use super::*;
27
28    #[test]
29    fn test_lower() {
30        let cases = [
31            ("HELLO WORLD", "hello world"),
32            ("hello RUST", "hello rust"),
33            ("3 PINEAPPLES", "3 pineapples"),
34        ];
35
36        for (s, expected) in cases {
37            let mut writer = String::new();
38            lower(s, &mut writer);
39            assert_eq!(writer, expected);
40        }
41    }
42}