goldmedal commented on code in PR #11361: URL: https://github.com/apache/datafusion/pull/11361#discussion_r1673989968
########## datafusion/functions/src/core/map.rs: ########## @@ -0,0 +1,325 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +use std::any::Any; +use std::collections::VecDeque; +use std::sync::Arc; + +use arrow::array::{new_null_array, Array, ArrayData, ArrayRef, MapArray, StructArray}; +use arrow::compute::concat; +use arrow::datatypes::{DataType, Field, SchemaBuilder}; +use arrow_buffer::{Buffer, ToByteSlice}; +use datafusion_common::Result; +use datafusion_common::{exec_err, internal_err, ScalarValue}; +use datafusion_expr::{ColumnarValue, ScalarUDFImpl, Signature, Volatility}; + +fn make_map(args: &[ColumnarValue]) -> Result<ColumnarValue> { + if args.is_empty() { + return exec_err!("map requires at least one pair of arguments, got 0 instead"); + } + + if args.len() % 2 != 0 { + return exec_err!( + "map requires an even number of arguments, got {} instead", + args.len() + ); + } + + let mut value_type = args[1].data_type(); + + let (key, value): (Vec<_>, Vec<_>) = args.chunks_exact(2) + .enumerate() + .map(|(i, chunk)| { + if chunk[0].data_type().is_null() { + return exec_err!("map key cannot be null"); + } + if !chunk[1].data_type().is_null() { Review Comment: The main purpose of this check is to decide the type of value array to create the null array in L76. If the values are ``` [null, null, 1, 2, 3] ``` We will know the value type by the third element. So, I think the null check is necessary. However, I agree the other check isn't necessary. Maybe I don't need to implement `coerce_types` since I guess `return_type` has checked them during planning, right? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org