You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: string_to_array_v2_udf.rs
    path of file: ./repos/openobserve/src/service/search/datafusion
    
    the code of the file until where you have to start completion: // Copyright 2023 Zinc Labs Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

use std::sync::Arc;

use arrow::array::{Array, ListBuilder, StringBuilder};
use arrow_schema::Field;
use datafusion::{
    arrow::{array::ArrayRef, datatypes::DataType},
    common::cast::as_generic_string_array,
    error::DataFusionError,
    logical_expr::{ScalarFunctionImplementation, ScalarUDF, Volatility},
    physical_plan::functions::make_scalar_function,
    prelude::create_udf,
};
use once_cell::sync::Lazy;

/// The name of the string_to_array_v2 UDF given to DataFusion.
pub const STRING_TO_ARRAY_V2_UDF_NAME: &str = "string_to_array_v2";

/// Implementation of string_to_array_v2
pub(crate) static STRING_TO_ARRAY_V2_UDF: Lazy<ScalarUDF> = Lazy::new(|| {
    create_udf(
        STRING_TO_ARRAY_V2_UDF_NAME,
        // takes two arguments: regex, pattern
        vec![DataType::Utf8, DataType::Utf8],
        Arc::new(DataType::List(Arc::new(Field::new(
            "item",
            DataType::Utf8,
            true,
        )))),
        Volatility::Immutable,
        string_to_array_v2_impl(),
    )
});

/// date_format function for datafusion
pub fn string_to_array_v2_impl() -> ScalarFunctionImplementation {
    let func = move |args: &[ArrayRef]| -> datafusion::error::Result<ArrayRef> {
        let string_array = as_generic_string_array::<i32>(&args[0])?;
        let delimiter_array = as_generic_string_array::<i32>(&args[1])?;

        
    
pub fn string_to_array_v2_impl() -> ScalarFunctionImplementation {
    let func = move |args: &[ArrayRef]| -> datafusion::error::Result<ArrayRef> {
        let string_array = as_generic_string_array::<i32>(&args[0])?;
        let delimiter_array = as_generic_string_array::<i32>(&args[1])?;

        let mut list_builder = ListBuilder::new(StringBuilder::with_capacity(
            string_array.len(),
            string_array.get_buffer_memory_size(),
        ));

        match args.len() {
            2 => {
                string_array
                    .iter()
                    .zip(delimiter_array.iter())
                    .for_each(|(string, delimiter)| {
                        match (string, delimiter) {
                            (Some(string), Some("")) => {
                                list_builder.values().append_value(string);
                                list_builder.append(true);
                            }
                            (Some(string), Some(delimiter)) => {
                                string.split(|c| delimiter.contains(c)).for_each(|s| {
                                    if !s.is_empty() {
                                        list_builder.values().append_value(s);
                                    }
                                });
                                list_builder.append(true);
                            }
                            (Some(string), None) => {
                                string.chars().map(|c| c.to_string()).for_each(|c| {
                                    list_builder.values().append_value(c);
                                });
                                list_builder.append(true);
                            }
                            _ => list_builder.append(false), // null value
                        }
                    });
            }
            _ => {
                return Err(DataFusionError::NotImplemented(
                    "Expect string_to_array_v2 function to take two or three parameters".into(),
                ));
            }
        }

        let list_array = list_builder.finish();
        Ok(Arc::new(list_array) as ArrayRef)
    };

    make_scalar_function(func)
}