eldenmoon commented on code in PR #14250: URL: https://github.com/apache/doris/pull/14250#discussion_r1024759713
########## be/src/vec/functions/array/function_array_constructor.cpp: ########## @@ -0,0 +1,90 @@ +// 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. +#include <string_view> + +#include "vec/columns/column_array.h" +#include "vec/columns/column_string.h" +#include "vec/common/string_ref.h" +#include "vec/data_types/data_type_array.h" +#include "vec/data_types/data_type_number.h" +#include "vec/data_types/get_least_supertype.h" +#include "vec/functions/array/function_array_utils.h" +#include "vec/functions/function.h" +#include "vec/functions/simple_function_factory.h" + +namespace doris::vectorized { + +// construct an array +// array(col1, col2, '22') -> [col1, col2, '22'] +class FunctionArrayConstructor : public IFunction { +public: + static constexpr auto name = "array"; + static FunctionPtr create() { return std::make_shared<FunctionArrayConstructor>(); } + + /// Get function name. + String get_name() const override { return name; } + + bool is_variadic() const override { return true; } + + bool use_default_implementation_for_nulls() const override { return false; } + + size_t get_number_of_arguments() const override { return 1; } + + DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { + DCHECK(arguments.size() > 0) + << "function: " << get_name() << ", arguments should not be empty"; + return std::make_shared<DataTypeArray>(make_nullable(remove_nullable(arguments[0]))); Review Comment: `array()` function may not call analyzeArrayFunction, but it will go bellow logic and find a suitable type to cast ``` Type[] args = fn.getArgs(); if (args.length > 0) { // Implicitly cast all the children to match the function if necessary for (int i = 0; i < argTypes.length - orderByElements.size(); ++i) { // For varargs, we must compare with the last type in callArgs.argTypes. int ix = Math.min(args.length - 1, i); if (!argTypes[i].matchesType(args[ix]) && Config.enable_date_conversion && !argTypes[i].isDateType() && (args[ix].isDate() || args[ix].isDatetime())) { uncheckedCastChild(ScalarType.getDefaultDateType(args[ix]), i); } else if (!argTypes[i].matchesType(args[ix]) && Config.enable_decimalv3 && Config.enable_decimal_conversion && argTypes[i].isDecimalV3() && args[ix].isDecimalV2()) { uncheckedCastChild(ScalarType.createDecimalV3Type(argTypes[i].getPrecision(), ((ScalarType) argTypes[i]).getScalarScale()), i); } else if (!argTypes[i].matchesType(args[ix]) && !( argTypes[i].isDateType() && args[ix].isDateType())) { LOG.debug("need cast argTypes[i]:{} to args[ix]:{}", argTypes[i], args[ix]); uncheckedCastChild(args[ix], i); } } ``` -- 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: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org