2015-06-03 03:29:28 +00:00
|
|
|
#include <mutex>
|
2021-10-02 07:13:14 +00:00
|
|
|
#include <base/bit_cast.h>
|
2021-02-14 16:07:20 +00:00
|
|
|
|
2022-09-18 07:20:48 +00:00
|
|
|
#include <Common/FieldVisitorDump.h>
|
2021-06-14 04:13:35 +00:00
|
|
|
#include <Common/FieldVisitorConvertToNumber.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <DataTypes/DataTypeArray.h>
|
|
|
|
#include <Columns/ColumnString.h>
|
2017-07-21 06:35:58 +00:00
|
|
|
#include <Columns/ColumnArray.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Columns/ColumnConst.h>
|
|
|
|
#include <Columns/ColumnsNumber.h>
|
2021-11-26 02:05:31 +00:00
|
|
|
#include <Columns/ColumnDecimal.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Common/Arena.h>
|
|
|
|
#include <Common/HashTable/HashMap.h>
|
2017-07-13 20:58:19 +00:00
|
|
|
#include <Common/typeid_cast.h>
|
2021-10-02 07:13:14 +00:00
|
|
|
#include <base/StringRef.h>
|
2021-05-17 07:30:42 +00:00
|
|
|
#include <Functions/IFunction.h>
|
2017-07-21 06:35:58 +00:00
|
|
|
#include <Functions/FunctionHelpers.h>
|
2018-12-02 02:52:49 +00:00
|
|
|
#include <Functions/FunctionFactory.h>
|
2018-01-11 18:37:11 +00:00
|
|
|
#include <DataTypes/getLeastSupertype.h>
|
2021-02-14 16:07:20 +00:00
|
|
|
#include <Interpreters/convertFieldToType.h>
|
2015-06-03 03:29:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2017-04-08 01:32:05 +00:00
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
2020-02-25 18:02:41 +00:00
|
|
|
extern const int ILLEGAL_TYPE_OF_ARGUMENT;
|
2017-04-08 01:32:05 +00:00
|
|
|
extern const int BAD_ARGUMENTS;
|
2017-06-13 02:06:53 +00:00
|
|
|
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
|
|
|
|
extern const int ILLEGAL_COLUMN;
|
2017-04-08 01:32:05 +00:00
|
|
|
}
|
|
|
|
|
2020-09-07 18:00:37 +00:00
|
|
|
namespace
|
|
|
|
{
|
2017-04-08 01:32:05 +00:00
|
|
|
|
2017-05-27 15:45:25 +00:00
|
|
|
/** transform(x, from_array, to_array[, default]) - convert x according to an explicitly passed match.
|
2015-06-03 03:29:28 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/** transform(x, [from...], [to...], default)
|
2017-05-27 15:45:25 +00:00
|
|
|
* - converts the values according to the explicitly specified mapping.
|
2015-06-03 03:29:28 +00:00
|
|
|
*
|
2017-05-27 15:45:25 +00:00
|
|
|
* x - what to transform.
|
|
|
|
* from - a constant array of values for the transformation.
|
|
|
|
* to - a constant array of values into which values from `from` must be transformed.
|
|
|
|
* default - what value to use if x is not equal to any of the values in `from`.
|
|
|
|
* `from` and `to` - arrays of the same size.
|
2015-06-03 03:29:28 +00:00
|
|
|
*
|
2017-05-27 15:45:25 +00:00
|
|
|
* Types:
|
2015-06-03 03:29:28 +00:00
|
|
|
* transform(T, Array(T), Array(U), U) -> U
|
|
|
|
*
|
|
|
|
* transform(x, [from...], [to...])
|
2017-05-27 15:45:25 +00:00
|
|
|
* - if `default` is not specified, then for values of `x` for which there is no corresponding element in `from`, the unchanged value of `x` is returned.
|
2015-06-03 03:29:28 +00:00
|
|
|
*
|
2017-05-27 15:45:25 +00:00
|
|
|
* Types:
|
2015-06-03 03:29:28 +00:00
|
|
|
* transform(T, Array(T), Array(T)) -> T
|
|
|
|
*
|
2017-05-27 15:45:25 +00:00
|
|
|
* Note: the implementation is rather cumbersome.
|
2015-06-03 03:29:28 +00:00
|
|
|
*/
|
|
|
|
class FunctionTransform : public IFunction
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static constexpr auto name = "transform";
|
2021-06-01 12:20:52 +00:00
|
|
|
static FunctionPtr create(ContextPtr) { return std::make_shared<FunctionTransform>(); }
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2016-05-03 23:19:14 +00:00
|
|
|
String getName() const override
|
|
|
|
{
|
2016-12-10 04:51:36 +00:00
|
|
|
return name;
|
2016-05-03 23:19:14 +00:00
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2016-12-29 19:38:10 +00:00
|
|
|
bool isVariadic() const override { return true; }
|
2021-06-22 16:21:23 +00:00
|
|
|
bool isSuitableForShortCircuitArgumentsExecution(const DataTypesWithConstInfo & /*arguments*/) const override { return true; }
|
2016-12-29 19:38:10 +00:00
|
|
|
size_t getNumberOfArguments() const override { return 0; }
|
2018-02-17 03:06:01 +00:00
|
|
|
bool useDefaultImplementationForConstants() const override { return true; }
|
|
|
|
ColumnNumbers getArgumentsThatAreAlwaysConstant() const override { return {1, 2}; }
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2016-07-06 09:47:55 +00:00
|
|
|
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override
|
2015-06-03 03:29:28 +00:00
|
|
|
{
|
|
|
|
const auto args_size = arguments.size();
|
|
|
|
if (args_size != 3 && args_size != 4)
|
2023-01-23 21:13:58 +00:00
|
|
|
throw Exception(ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH, "Number of arguments for function {} doesn't match: "
|
|
|
|
"passed {}, should be 3 or 4", getName(), args_size);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-12-18 01:11:48 +00:00
|
|
|
const DataTypePtr & type_x = arguments[0];
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2018-09-07 14:37:26 +00:00
|
|
|
if (!type_x->isValueRepresentedByNumber() && !isString(type_x))
|
2023-01-23 21:13:58 +00:00
|
|
|
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT,
|
|
|
|
"Unsupported type {} of first argument "
|
|
|
|
"of function {}, must be numeric type or Date/DateTime or String",
|
|
|
|
type_x->getName(), getName());
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-07-21 06:35:58 +00:00
|
|
|
const DataTypeArray * type_arr_from = checkAndGetDataType<DataTypeArray>(arguments[1].get());
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2015-06-03 03:29:28 +00:00
|
|
|
if (!type_arr_from)
|
2023-01-23 21:13:58 +00:00
|
|
|
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT,
|
|
|
|
"Second argument of function {}, must be array of source values to transform from.",
|
|
|
|
getName());
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2015-06-03 03:29:28 +00:00
|
|
|
const auto type_arr_from_nested = type_arr_from->getNestedType();
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-12-09 06:32:22 +00:00
|
|
|
if ((type_x->isValueRepresentedByNumber() != type_arr_from_nested->isValueRepresentedByNumber())
|
2018-09-07 14:37:26 +00:00
|
|
|
|| (isString(type_x) != isString(type_arr_from_nested)))
|
2016-05-03 23:19:14 +00:00
|
|
|
{
|
2023-01-23 21:13:58 +00:00
|
|
|
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT,
|
|
|
|
"First argument and elements of array "
|
|
|
|
"of second argument of function {} must have compatible types: "
|
|
|
|
"both numeric or both strings.", getName());
|
2016-05-03 23:19:14 +00:00
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-07-21 06:35:58 +00:00
|
|
|
const DataTypeArray * type_arr_to = checkAndGetDataType<DataTypeArray>(arguments[2].get());
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2015-06-03 03:29:28 +00:00
|
|
|
if (!type_arr_to)
|
2023-01-23 21:13:58 +00:00
|
|
|
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT,
|
|
|
|
"Third argument of function {}, must be array of destination values to transform to.",
|
|
|
|
getName());
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-12-07 00:31:46 +00:00
|
|
|
const DataTypePtr & type_arr_to_nested = type_arr_to->getNestedType();
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2015-06-03 03:29:28 +00:00
|
|
|
if (args_size == 3)
|
|
|
|
{
|
2017-12-09 06:32:22 +00:00
|
|
|
if ((type_x->isValueRepresentedByNumber() != type_arr_to_nested->isValueRepresentedByNumber())
|
2018-09-07 14:37:26 +00:00
|
|
|
|| (isString(type_x) != isString(type_arr_to_nested)))
|
2023-01-23 21:13:58 +00:00
|
|
|
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Function {} has signature: "
|
|
|
|
"transform(T, Array(T), Array(U), U) -> U; "
|
|
|
|
"or transform(T, Array(T), Array(T)) -> T; where T and U are types.", getName());
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2021-12-13 11:37:23 +00:00
|
|
|
return getLeastSupertype(DataTypes{type_x, type_arr_to_nested});
|
2015-06-03 03:29:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-12-07 01:43:06 +00:00
|
|
|
const DataTypePtr & type_default = arguments[3];
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2018-09-07 14:37:26 +00:00
|
|
|
if (!type_default->isValueRepresentedByNumber() && !isString(type_default))
|
2023-01-23 21:13:58 +00:00
|
|
|
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT,
|
|
|
|
"Unsupported type {} of fourth argument (default value) "
|
|
|
|
"of function {}, must be numeric type or Date/DateTime or String",
|
|
|
|
type_default->getName(), getName());
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2018-09-07 14:37:26 +00:00
|
|
|
bool default_is_string = WhichDataType(type_default).isString();
|
|
|
|
bool nested_is_string = WhichDataType(type_arr_to_nested).isString();
|
|
|
|
|
2017-12-09 06:32:22 +00:00
|
|
|
if ((type_default->isValueRepresentedByNumber() != type_arr_to_nested->isValueRepresentedByNumber())
|
2018-09-07 14:37:26 +00:00
|
|
|
|| (default_is_string != nested_is_string))
|
2023-01-23 21:13:58 +00:00
|
|
|
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Function {} have signature: "
|
|
|
|
"transform(T, Array(T), Array(U), U) -> U; "
|
|
|
|
"or transform(T, Array(T), Array(T)) -> T; where T and U are types.", getName());
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-12-09 06:32:22 +00:00
|
|
|
if (type_arr_to_nested->isValueRepresentedByNumber() && type_default->isValueRepresentedByNumber())
|
2015-06-03 03:29:28 +00:00
|
|
|
{
|
2017-05-27 15:45:25 +00:00
|
|
|
/// We take the smallest common type for the elements of the array of values `to` and for `default`.
|
2021-06-12 15:10:25 +00:00
|
|
|
return getLeastSupertype(DataTypes{type_arr_to_nested, type_default});
|
2015-06-03 03:29:28 +00:00
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-05-27 15:45:25 +00:00
|
|
|
/// TODO More checks.
|
2017-12-18 01:11:48 +00:00
|
|
|
return type_arr_to_nested;
|
2015-06-03 03:29:28 +00:00
|
|
|
}
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2020-11-17 13:24:45 +00:00
|
|
|
ColumnPtr executeImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr & result_type, size_t input_rows_count) const override
|
2015-06-03 03:29:28 +00:00
|
|
|
{
|
2020-10-19 15:27:41 +00:00
|
|
|
const ColumnConst * array_from = checkAndGetColumnConst<ColumnArray>(arguments[1].column.get());
|
|
|
|
const ColumnConst * array_to = checkAndGetColumnConst<ColumnArray>(arguments[2].column.get());
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2015-12-08 09:16:09 +00:00
|
|
|
if (!array_from || !array_to)
|
2023-01-23 21:13:58 +00:00
|
|
|
throw Exception(ErrorCodes::ILLEGAL_COLUMN, "Second and third arguments of function {} must be constant arrays.", getName());
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2020-10-19 15:27:41 +00:00
|
|
|
initialize(array_from->getValue<Array>(), array_to->getValue<Array>(), arguments);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2020-10-19 15:27:41 +00:00
|
|
|
const auto * in = arguments.front().column.get();
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2019-06-27 19:28:52 +00:00
|
|
|
if (isColumnConst(*in))
|
2020-10-19 15:27:41 +00:00
|
|
|
return executeConst(arguments, result_type, input_rows_count);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2015-06-03 03:29:28 +00:00
|
|
|
const IColumn * default_column = nullptr;
|
|
|
|
if (arguments.size() == 4)
|
2020-10-19 15:27:41 +00:00
|
|
|
default_column = arguments[3].column.get();
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2020-10-19 15:27:41 +00:00
|
|
|
auto column_result = result_type->createColumn();
|
2020-04-22 08:45:14 +00:00
|
|
|
auto * out = column_result.get();
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2015-06-03 03:29:28 +00:00
|
|
|
if (!executeNum<UInt8>(in, out, default_column)
|
|
|
|
&& !executeNum<UInt16>(in, out, default_column)
|
|
|
|
&& !executeNum<UInt32>(in, out, default_column)
|
|
|
|
&& !executeNum<UInt64>(in, out, default_column)
|
|
|
|
&& !executeNum<Int8>(in, out, default_column)
|
|
|
|
&& !executeNum<Int16>(in, out, default_column)
|
|
|
|
&& !executeNum<Int32>(in, out, default_column)
|
|
|
|
&& !executeNum<Int64>(in, out, default_column)
|
|
|
|
&& !executeNum<Float32>(in, out, default_column)
|
|
|
|
&& !executeNum<Float64>(in, out, default_column)
|
2021-11-26 02:05:31 +00:00
|
|
|
&& !executeDecimal<Decimal32>(in, out, default_column)
|
|
|
|
&& !executeDecimal<Decimal64>(in, out, default_column)
|
2015-06-03 03:29:28 +00:00
|
|
|
&& !executeString(in, out, default_column))
|
2016-05-03 23:19:14 +00:00
|
|
|
{
|
2023-01-23 21:13:58 +00:00
|
|
|
throw Exception(ErrorCodes::ILLEGAL_COLUMN, "Illegal column {} of first argument of function {}", in->getName(), getName());
|
2016-05-03 23:19:14 +00:00
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2020-10-19 15:27:41 +00:00
|
|
|
return column_result;
|
2015-06-03 03:29:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2020-11-17 13:24:45 +00:00
|
|
|
static ColumnPtr executeConst(const ColumnsWithTypeAndName & arguments, const DataTypePtr & result_type, size_t input_rows_count)
|
2015-06-03 03:29:28 +00:00
|
|
|
{
|
2018-02-17 03:06:01 +00:00
|
|
|
/// Materialize the input column and compute the function as usual.
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2020-10-19 15:27:41 +00:00
|
|
|
ColumnsWithTypeAndName args = arguments;
|
|
|
|
args[0].column = args[0].column->cloneResized(input_rows_count)->convertToFullColumnIfConst();
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2021-05-15 17:33:15 +00:00
|
|
|
auto impl = FunctionToOverloadResolverAdaptor(std::make_shared<FunctionTransform>()).build(args);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2020-10-19 15:27:41 +00:00
|
|
|
return impl->execute(args, result_type, input_rows_count);
|
2015-06-03 03:29:28 +00:00
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2015-06-03 03:29:28 +00:00
|
|
|
template <typename T>
|
2020-07-21 13:58:07 +00:00
|
|
|
bool executeNum(const IColumn * in_untyped, IColumn * out_untyped, const IColumn * default_untyped) const
|
2015-06-03 03:29:28 +00:00
|
|
|
{
|
2017-07-21 06:35:58 +00:00
|
|
|
if (const auto in = checkAndGetColumn<ColumnVector<T>>(in_untyped))
|
2015-06-03 03:29:28 +00:00
|
|
|
{
|
|
|
|
if (!default_untyped)
|
|
|
|
{
|
|
|
|
auto out = typeid_cast<ColumnVector<T> *>(out_untyped);
|
|
|
|
if (!out)
|
2016-05-03 23:19:14 +00:00
|
|
|
{
|
2023-01-23 21:13:58 +00:00
|
|
|
throw Exception(ErrorCodes::ILLEGAL_COLUMN,
|
|
|
|
"Illegal column {} of elements "
|
|
|
|
"of array of third argument of function {}, must be {}",
|
|
|
|
out_untyped->getName(), getName(), in->getName());
|
2016-05-03 23:19:14 +00:00
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2015-06-03 03:29:28 +00:00
|
|
|
executeImplNumToNum<T>(in->getData(), out->getData());
|
|
|
|
}
|
2019-06-27 19:28:52 +00:00
|
|
|
else if (isColumnConst(*default_untyped))
|
2015-06-03 03:29:28 +00:00
|
|
|
{
|
|
|
|
if (!executeNumToNumWithConstDefault<T, UInt8>(in, out_untyped)
|
|
|
|
&& !executeNumToNumWithConstDefault<T, UInt16>(in, out_untyped)
|
|
|
|
&& !executeNumToNumWithConstDefault<T, UInt32>(in, out_untyped)
|
|
|
|
&& !executeNumToNumWithConstDefault<T, UInt64>(in, out_untyped)
|
|
|
|
&& !executeNumToNumWithConstDefault<T, Int8>(in, out_untyped)
|
|
|
|
&& !executeNumToNumWithConstDefault<T, Int16>(in, out_untyped)
|
|
|
|
&& !executeNumToNumWithConstDefault<T, Int32>(in, out_untyped)
|
|
|
|
&& !executeNumToNumWithConstDefault<T, Int64>(in, out_untyped)
|
|
|
|
&& !executeNumToNumWithConstDefault<T, Float32>(in, out_untyped)
|
|
|
|
&& !executeNumToNumWithConstDefault<T, Float64>(in, out_untyped)
|
2021-11-26 02:05:31 +00:00
|
|
|
&& !executeNumToDecimalWithConstDefault<T, Decimal32>(in, out_untyped)
|
|
|
|
&& !executeNumToDecimalWithConstDefault<T, Decimal64>(in, out_untyped)
|
2015-06-03 03:29:28 +00:00
|
|
|
&& !executeNumToStringWithConstDefault<T>(in, out_untyped))
|
2016-05-03 23:19:14 +00:00
|
|
|
{
|
2023-01-23 21:13:58 +00:00
|
|
|
throw Exception(ErrorCodes::ILLEGAL_COLUMN, "Illegal column {} of elements of array of second argument of function {}",
|
|
|
|
in->getName(), getName());
|
2016-05-03 23:19:14 +00:00
|
|
|
}
|
2015-06-03 03:29:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!executeNumToNumWithNonConstDefault<T, UInt8>(in, out_untyped, default_untyped)
|
|
|
|
&& !executeNumToNumWithNonConstDefault<T, UInt16>(in, out_untyped, default_untyped)
|
|
|
|
&& !executeNumToNumWithNonConstDefault<T, UInt32>(in, out_untyped, default_untyped)
|
|
|
|
&& !executeNumToNumWithNonConstDefault<T, UInt64>(in, out_untyped, default_untyped)
|
|
|
|
&& !executeNumToNumWithNonConstDefault<T, Int8>(in, out_untyped, default_untyped)
|
|
|
|
&& !executeNumToNumWithNonConstDefault<T, Int16>(in, out_untyped, default_untyped)
|
|
|
|
&& !executeNumToNumWithNonConstDefault<T, Int32>(in, out_untyped, default_untyped)
|
|
|
|
&& !executeNumToNumWithNonConstDefault<T, Int64>(in, out_untyped, default_untyped)
|
|
|
|
&& !executeNumToNumWithNonConstDefault<T, Float32>(in, out_untyped, default_untyped)
|
|
|
|
&& !executeNumToNumWithNonConstDefault<T, Float64>(in, out_untyped, default_untyped)
|
2021-11-26 02:05:31 +00:00
|
|
|
&& !executeNumToDecimalWithNonConstDefault<T, Decimal32>(in, out_untyped, default_untyped)
|
|
|
|
&& !executeNumToDecimalWithNonConstDefault<T, Decimal64>(in, out_untyped, default_untyped)
|
2015-06-03 03:29:28 +00:00
|
|
|
&& !executeNumToStringWithNonConstDefault<T>(in, out_untyped, default_untyped))
|
2016-05-03 23:19:14 +00:00
|
|
|
{
|
2023-01-23 21:13:58 +00:00
|
|
|
throw Exception(ErrorCodes::ILLEGAL_COLUMN, "Illegal column {} of elements of array of second argument of function {}",
|
|
|
|
in->getName(), getName());
|
2016-05-03 23:19:14 +00:00
|
|
|
}
|
2015-06-03 03:29:28 +00:00
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2015-06-03 03:29:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2015-06-03 03:29:28 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2021-11-26 02:05:31 +00:00
|
|
|
template <typename T>
|
|
|
|
bool executeDecimal(const IColumn * in_untyped, IColumn * out_untyped, const IColumn * default_untyped) const
|
|
|
|
{
|
|
|
|
if (const auto in = checkAndGetColumn<ColumnDecimal<T>>(in_untyped))
|
|
|
|
{
|
|
|
|
if (!default_untyped)
|
|
|
|
{
|
|
|
|
auto out = typeid_cast<ColumnDecimal<T> *>(out_untyped);
|
|
|
|
if (!out)
|
|
|
|
{
|
2023-01-23 21:13:58 +00:00
|
|
|
throw Exception(ErrorCodes::ILLEGAL_COLUMN,
|
|
|
|
"Illegal column {} of elements "
|
|
|
|
"of array of third argument of function {}, must be {}",
|
|
|
|
out_untyped->getName(), getName(), in->getName());
|
2021-11-26 02:05:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
executeImplNumToNum<T>(in->getData(), out->getData());
|
|
|
|
}
|
|
|
|
else if (isColumnConst(*default_untyped))
|
|
|
|
{
|
|
|
|
if (!executeDecimalToNumWithConstDefault<T, UInt8>(in, out_untyped)
|
|
|
|
&& !executeDecimalToNumWithConstDefault<T, UInt16>(in, out_untyped)
|
|
|
|
&& !executeDecimalToNumWithConstDefault<T, UInt32>(in, out_untyped)
|
|
|
|
&& !executeDecimalToNumWithConstDefault<T, UInt64>(in, out_untyped)
|
|
|
|
&& !executeDecimalToNumWithConstDefault<T, Int8>(in, out_untyped)
|
|
|
|
&& !executeDecimalToNumWithConstDefault<T, Int16>(in, out_untyped)
|
|
|
|
&& !executeDecimalToNumWithConstDefault<T, Int32>(in, out_untyped)
|
|
|
|
&& !executeDecimalToNumWithConstDefault<T, Int64>(in, out_untyped)
|
|
|
|
&& !executeDecimalToNumWithConstDefault<T, Float32>(in, out_untyped)
|
|
|
|
&& !executeDecimalToNumWithConstDefault<T, Float64>(in, out_untyped)
|
|
|
|
&& !executeDecimalToDecimalWithConstDefault<T, Decimal32>(in, out_untyped)
|
|
|
|
&& !executeDecimalToDecimalWithConstDefault<T, Decimal64>(in, out_untyped)
|
|
|
|
&& !executeDecimalToStringWithConstDefault<T>(in, out_untyped))
|
|
|
|
{
|
2023-01-23 21:13:58 +00:00
|
|
|
throw Exception(ErrorCodes::ILLEGAL_COLUMN, "Illegal column {} of elements of array of second argument of function {}",
|
|
|
|
in->getName(), getName());
|
2021-11-26 02:05:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!executeDecimalToNumWithNonConstDefault<T, UInt8>(in, out_untyped, default_untyped)
|
|
|
|
&& !executeDecimalToNumWithNonConstDefault<T, UInt16>(in, out_untyped, default_untyped)
|
|
|
|
&& !executeDecimalToNumWithNonConstDefault<T, UInt32>(in, out_untyped, default_untyped)
|
|
|
|
&& !executeDecimalToNumWithNonConstDefault<T, UInt64>(in, out_untyped, default_untyped)
|
|
|
|
&& !executeDecimalToNumWithNonConstDefault<T, Int8>(in, out_untyped, default_untyped)
|
|
|
|
&& !executeDecimalToNumWithNonConstDefault<T, Int16>(in, out_untyped, default_untyped)
|
|
|
|
&& !executeDecimalToNumWithNonConstDefault<T, Int32>(in, out_untyped, default_untyped)
|
|
|
|
&& !executeDecimalToNumWithNonConstDefault<T, Int64>(in, out_untyped, default_untyped)
|
|
|
|
&& !executeDecimalToNumWithNonConstDefault<T, Float32>(in, out_untyped, default_untyped)
|
|
|
|
&& !executeDecimalToNumWithNonConstDefault<T, Float64>(in, out_untyped, default_untyped)
|
|
|
|
&& !executeDecimalToDecimalWithNonConstDefault<T, Decimal32>(in, out_untyped, default_untyped)
|
|
|
|
&& !executeDecimalToDecimalWithNonConstDefault<T, Decimal64>(in, out_untyped, default_untyped)
|
|
|
|
&& !executeDecimalToStringWithNonConstDefault<T>(in, out_untyped, default_untyped))
|
|
|
|
{
|
2023-01-23 21:13:58 +00:00
|
|
|
throw Exception(ErrorCodes::ILLEGAL_COLUMN, "Illegal column {} of elements of array of second argument of function {}",
|
|
|
|
in->getName(), getName());
|
2021-11-26 02:05:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-07-21 13:58:07 +00:00
|
|
|
bool executeString(const IColumn * in_untyped, IColumn * out_untyped, const IColumn * default_untyped) const
|
2015-06-03 03:29:28 +00:00
|
|
|
{
|
2020-04-22 08:45:14 +00:00
|
|
|
if (const auto * in = checkAndGetColumn<ColumnString>(in_untyped))
|
2015-06-03 03:29:28 +00:00
|
|
|
{
|
|
|
|
if (!default_untyped)
|
|
|
|
{
|
|
|
|
if (!executeStringToString(in, out_untyped))
|
2023-01-23 21:13:58 +00:00
|
|
|
throw Exception(ErrorCodes::ILLEGAL_COLUMN, "Illegal column {} of elements of array of second argument of function {}",
|
|
|
|
in->getName(), getName());
|
2015-06-03 03:29:28 +00:00
|
|
|
}
|
2019-06-27 19:28:52 +00:00
|
|
|
else if (isColumnConst(*default_untyped))
|
2015-06-03 03:29:28 +00:00
|
|
|
{
|
|
|
|
if (!executeStringToNumWithConstDefault<UInt8>(in, out_untyped)
|
|
|
|
&& !executeStringToNumWithConstDefault<UInt16>(in, out_untyped)
|
|
|
|
&& !executeStringToNumWithConstDefault<UInt32>(in, out_untyped)
|
|
|
|
&& !executeStringToNumWithConstDefault<UInt64>(in, out_untyped)
|
|
|
|
&& !executeStringToNumWithConstDefault<Int8>(in, out_untyped)
|
|
|
|
&& !executeStringToNumWithConstDefault<Int16>(in, out_untyped)
|
|
|
|
&& !executeStringToNumWithConstDefault<Int32>(in, out_untyped)
|
|
|
|
&& !executeStringToNumWithConstDefault<Int64>(in, out_untyped)
|
|
|
|
&& !executeStringToNumWithConstDefault<Float32>(in, out_untyped)
|
|
|
|
&& !executeStringToNumWithConstDefault<Float64>(in, out_untyped)
|
2021-11-26 02:05:31 +00:00
|
|
|
&& !executeStringToDecimalWithConstDefault<Decimal32>(in, out_untyped)
|
|
|
|
&& !executeStringToDecimalWithConstDefault<Decimal64>(in, out_untyped)
|
2015-06-03 03:29:28 +00:00
|
|
|
&& !executeStringToStringWithConstDefault(in, out_untyped))
|
2016-05-03 23:19:14 +00:00
|
|
|
{
|
2023-01-23 21:13:58 +00:00
|
|
|
throw Exception(ErrorCodes::ILLEGAL_COLUMN, "Illegal column {} of elements of array of second argument of function {}",
|
|
|
|
in->getName(), getName());
|
2016-05-03 23:19:14 +00:00
|
|
|
}
|
2015-06-03 03:29:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!executeStringToNumWithNonConstDefault<UInt8>(in, out_untyped, default_untyped)
|
|
|
|
&& !executeStringToNumWithNonConstDefault<UInt16>(in, out_untyped, default_untyped)
|
|
|
|
&& !executeStringToNumWithNonConstDefault<UInt32>(in, out_untyped, default_untyped)
|
|
|
|
&& !executeStringToNumWithNonConstDefault<UInt64>(in, out_untyped, default_untyped)
|
|
|
|
&& !executeStringToNumWithNonConstDefault<Int8>(in, out_untyped, default_untyped)
|
|
|
|
&& !executeStringToNumWithNonConstDefault<Int16>(in, out_untyped, default_untyped)
|
|
|
|
&& !executeStringToNumWithNonConstDefault<Int32>(in, out_untyped, default_untyped)
|
|
|
|
&& !executeStringToNumWithNonConstDefault<Int64>(in, out_untyped, default_untyped)
|
|
|
|
&& !executeStringToNumWithNonConstDefault<Float32>(in, out_untyped, default_untyped)
|
|
|
|
&& !executeStringToNumWithNonConstDefault<Float64>(in, out_untyped, default_untyped)
|
2021-11-26 02:05:31 +00:00
|
|
|
&& !executeStringToDecimalWithNonConstDefault<Decimal32>(in, out_untyped, default_untyped)
|
|
|
|
&& !executeStringToDecimalWithNonConstDefault<Decimal64>(in, out_untyped, default_untyped)
|
|
|
|
|
2015-06-03 03:29:28 +00:00
|
|
|
&& !executeStringToStringWithNonConstDefault(in, out_untyped, default_untyped))
|
2016-05-03 23:19:14 +00:00
|
|
|
{
|
2023-01-23 21:13:58 +00:00
|
|
|
throw Exception(ErrorCodes::ILLEGAL_COLUMN, "Illegal column {} of elements of array of second argument of function {}",
|
|
|
|
in->getName(), getName());
|
2016-05-03 23:19:14 +00:00
|
|
|
}
|
2015-06-03 03:29:28 +00:00
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2015-06-03 03:29:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2015-06-03 03:29:28 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2015-06-03 03:29:28 +00:00
|
|
|
template <typename T, typename U>
|
2020-07-21 13:58:07 +00:00
|
|
|
bool executeNumToNumWithConstDefault(const ColumnVector<T> * in, IColumn * out_untyped) const
|
2015-06-03 03:29:28 +00:00
|
|
|
{
|
|
|
|
auto out = typeid_cast<ColumnVector<U> *>(out_untyped);
|
|
|
|
if (!out)
|
|
|
|
return false;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2022-09-11 02:49:43 +00:00
|
|
|
executeImplNumToNumWithConstDefault<T, U>(in->getData(), out->getData(), static_cast<U>(cache.const_default_value.get<U>()));
|
2015-06-03 03:29:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2021-11-26 02:05:31 +00:00
|
|
|
template <typename T, typename U>
|
|
|
|
bool executeNumToDecimalWithConstDefault(const ColumnVector<T> * in, IColumn * out_untyped) const
|
|
|
|
{
|
|
|
|
auto out = typeid_cast<ColumnDecimal<U> *>(out_untyped);
|
|
|
|
if (!out)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
executeImplNumToNumWithConstDefault<T, U>(in->getData(), out->getData(), cache.const_default_value.get<U>());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T, typename U>
|
|
|
|
bool executeDecimalToNumWithConstDefault(const ColumnDecimal<T> * in, IColumn * out_untyped) const
|
|
|
|
{
|
|
|
|
auto out = typeid_cast<ColumnVector<U> *>(out_untyped);
|
|
|
|
if (!out)
|
|
|
|
return false;
|
|
|
|
|
2022-09-11 03:38:59 +00:00
|
|
|
executeImplNumToNumWithConstDefault<T, U>(in->getData(), out->getData(), static_cast<U>(cache.const_default_value.get<U>()));
|
2021-11-26 02:05:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, typename U>
|
|
|
|
bool executeDecimalToDecimalWithConstDefault(const ColumnDecimal<T> * in, IColumn * out_untyped) const
|
|
|
|
{
|
|
|
|
auto out = typeid_cast<ColumnDecimal<U> *>(out_untyped);
|
|
|
|
if (!out)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
executeImplNumToNumWithConstDefault<T, U>(in->getData(), out->getData(), cache.const_default_value.get<U>());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-03 03:29:28 +00:00
|
|
|
template <typename T, typename U>
|
2020-07-21 13:58:07 +00:00
|
|
|
bool executeNumToNumWithNonConstDefault(const ColumnVector<T> * in, IColumn * out_untyped, const IColumn * default_untyped) const
|
2015-06-03 03:29:28 +00:00
|
|
|
{
|
|
|
|
auto out = typeid_cast<ColumnVector<U> *>(out_untyped);
|
|
|
|
if (!out)
|
|
|
|
return false;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2015-06-03 03:29:28 +00:00
|
|
|
if (!executeNumToNumWithNonConstDefault2<T, U, UInt8>(in, out, default_untyped)
|
|
|
|
&& !executeNumToNumWithNonConstDefault2<T, U, UInt16>(in, out, default_untyped)
|
|
|
|
&& !executeNumToNumWithNonConstDefault2<T, U, UInt32>(in, out, default_untyped)
|
|
|
|
&& !executeNumToNumWithNonConstDefault2<T, U, UInt64>(in, out, default_untyped)
|
|
|
|
&& !executeNumToNumWithNonConstDefault2<T, U, Int8>(in, out, default_untyped)
|
|
|
|
&& !executeNumToNumWithNonConstDefault2<T, U, Int16>(in, out, default_untyped)
|
|
|
|
&& !executeNumToNumWithNonConstDefault2<T, U, Int32>(in, out, default_untyped)
|
|
|
|
&& !executeNumToNumWithNonConstDefault2<T, U, Int64>(in, out, default_untyped)
|
|
|
|
&& !executeNumToNumWithNonConstDefault2<T, U, Float32>(in, out, default_untyped)
|
|
|
|
&& !executeNumToNumWithNonConstDefault2<T, U, Float64>(in, out, default_untyped))
|
2016-05-03 23:19:14 +00:00
|
|
|
{
|
2023-01-23 21:13:58 +00:00
|
|
|
throw Exception(ErrorCodes::ILLEGAL_COLUMN, "Illegal column {} of fourth argument of function {}",
|
|
|
|
default_untyped->getName(), getName());
|
2016-05-03 23:19:14 +00:00
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2015-06-03 03:29:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2021-11-26 02:05:31 +00:00
|
|
|
template <typename T, typename U>
|
|
|
|
bool executeNumToDecimalWithNonConstDefault(const ColumnVector<T> * in, IColumn * out_untyped, const IColumn * default_untyped) const
|
|
|
|
{
|
|
|
|
auto out = typeid_cast<ColumnDecimal<U> *>(out_untyped);
|
|
|
|
if (!out)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!executeNumToDecimalWithNonConstDefault2<T, U, UInt8>(in, out, default_untyped)
|
|
|
|
&& !executeNumToDecimalWithNonConstDefault2<T, U, UInt16>(in, out, default_untyped)
|
|
|
|
&& !executeNumToDecimalWithNonConstDefault2<T, U, UInt32>(in, out, default_untyped)
|
|
|
|
&& !executeNumToDecimalWithNonConstDefault2<T, U, UInt64>(in, out, default_untyped)
|
|
|
|
&& !executeNumToDecimalWithNonConstDefault2<T, U, Int8>(in, out, default_untyped)
|
|
|
|
&& !executeNumToDecimalWithNonConstDefault2<T, U, Int16>(in, out, default_untyped)
|
|
|
|
&& !executeNumToDecimalWithNonConstDefault2<T, U, Int32>(in, out, default_untyped)
|
|
|
|
&& !executeNumToDecimalWithNonConstDefault2<T, U, Int64>(in, out, default_untyped)
|
|
|
|
&& !executeNumToDecimalWithNonConstDefault2<T, U, Float32>(in, out, default_untyped)
|
|
|
|
&& !executeNumToDecimalWithNonConstDefault2<T, U, Float64>(in, out, default_untyped)
|
|
|
|
&& !executeNumToDecimalWithNonConstDefaultDecimal2<T, U, Decimal32>(in, out, default_untyped)
|
|
|
|
&& !executeNumToDecimalWithNonConstDefaultDecimal2<T, U, Decimal64>(in, out, default_untyped))
|
|
|
|
{
|
2023-01-23 21:13:58 +00:00
|
|
|
throw Exception(ErrorCodes::ILLEGAL_COLUMN, "Illegal column {} of fourth argument of function {}",
|
|
|
|
default_untyped->getName(), getName());
|
2021-11-26 02:05:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, typename U>
|
|
|
|
bool executeDecimalToNumWithNonConstDefault(const ColumnDecimal<T> * in, IColumn * out_untyped, const IColumn * default_untyped) const
|
|
|
|
{
|
|
|
|
auto out = typeid_cast<ColumnVector<U> *>(out_untyped);
|
|
|
|
if (!out)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!executeDecimalToNumWithNonConstDefault2<T, U, UInt8>(in, out, default_untyped)
|
|
|
|
&& !executeDecimalToNumWithNonConstDefault2<T, U, UInt16>(in, out, default_untyped)
|
|
|
|
&& !executeDecimalToNumWithNonConstDefault2<T, U, UInt32>(in, out, default_untyped)
|
|
|
|
&& !executeDecimalToNumWithNonConstDefault2<T, U, UInt64>(in, out, default_untyped)
|
|
|
|
&& !executeDecimalToNumWithNonConstDefault2<T, U, Int8>(in, out, default_untyped)
|
|
|
|
&& !executeDecimalToNumWithNonConstDefault2<T, U, Int16>(in, out, default_untyped)
|
|
|
|
&& !executeDecimalToNumWithNonConstDefault2<T, U, Int32>(in, out, default_untyped)
|
|
|
|
&& !executeDecimalToNumWithNonConstDefault2<T, U, Int64>(in, out, default_untyped)
|
|
|
|
&& !executeDecimalToNumWithNonConstDefault2<T, U, Float32>(in, out, default_untyped)
|
|
|
|
&& !executeDecimalToNumWithNonConstDefault2<T, U, Float64>(in, out, default_untyped)
|
|
|
|
&& !executeDecimalToNumWithNonConstDefaultDecimal2<T, U, Decimal32>(in, out, default_untyped)
|
|
|
|
&& !executeDecimalToNumWithNonConstDefaultDecimal2<T, U, Decimal64>(in, out, default_untyped))
|
|
|
|
{
|
2023-01-23 21:13:58 +00:00
|
|
|
throw Exception(ErrorCodes::ILLEGAL_COLUMN, "Illegal column {} of fourth argument of function {}",
|
|
|
|
default_untyped->getName(), getName());
|
2021-11-26 02:05:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, typename U>
|
|
|
|
bool executeDecimalToDecimalWithNonConstDefault(const ColumnDecimal<T> * in, IColumn * out_untyped, const IColumn * default_untyped) const
|
|
|
|
{
|
|
|
|
auto out = typeid_cast<ColumnDecimal<U> *>(out_untyped);
|
|
|
|
if (!out)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!executeDecimalToDecimalWithNonConstDefault2<T, U, UInt8>(in, out, default_untyped)
|
|
|
|
&& !executeDecimalToDecimalWithNonConstDefault2<T, U, UInt16>(in, out, default_untyped)
|
|
|
|
&& !executeDecimalToDecimalWithNonConstDefault2<T, U, UInt32>(in, out, default_untyped)
|
|
|
|
&& !executeDecimalToDecimalWithNonConstDefault2<T, U, UInt64>(in, out, default_untyped)
|
|
|
|
&& !executeDecimalToDecimalWithNonConstDefault2<T, U, Int8>(in, out, default_untyped)
|
|
|
|
&& !executeDecimalToDecimalWithNonConstDefault2<T, U, Int16>(in, out, default_untyped)
|
|
|
|
&& !executeDecimalToDecimalWithNonConstDefault2<T, U, Int32>(in, out, default_untyped)
|
|
|
|
&& !executeDecimalToDecimalWithNonConstDefault2<T, U, Int64>(in, out, default_untyped)
|
|
|
|
&& !executeDecimalToDecimalWithNonConstDefault2<T, U, Float32>(in, out, default_untyped)
|
|
|
|
&& !executeDecimalToDecimalWithNonConstDefault2<T, U, Float64>(in, out, default_untyped)
|
|
|
|
&& !executeDecimalToDecimalWithNonConstDefaultDecimal2<T, U, Decimal32>(in, out, default_untyped)
|
|
|
|
&& !executeDecimalToDecimalWithNonConstDefaultDecimal2<T, U, Decimal64>(in, out, default_untyped))
|
|
|
|
{
|
2023-01-23 21:13:58 +00:00
|
|
|
throw Exception(ErrorCodes::ILLEGAL_COLUMN, "Illegal column {} of fourth argument of function {}",
|
|
|
|
default_untyped->getName(), getName());
|
2021-11-26 02:05:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-03 03:29:28 +00:00
|
|
|
template <typename T, typename U, typename V>
|
2020-07-21 13:58:07 +00:00
|
|
|
bool executeNumToNumWithNonConstDefault2(const ColumnVector<T> * in, ColumnVector<U> * out, const IColumn * default_untyped) const
|
2015-06-03 03:29:28 +00:00
|
|
|
{
|
2017-07-21 06:35:58 +00:00
|
|
|
auto col_default = checkAndGetColumn<ColumnVector<V>>(default_untyped);
|
2015-06-03 03:29:28 +00:00
|
|
|
if (!col_default)
|
|
|
|
return false;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2015-06-03 03:29:28 +00:00
|
|
|
executeImplNumToNumWithNonConstDefault<T, U, V>(in->getData(), out->getData(), col_default->getData());
|
|
|
|
return true;
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2021-11-26 02:05:31 +00:00
|
|
|
template <typename T, typename U, typename V>
|
|
|
|
bool executeNumToDecimalWithNonConstDefault2(const ColumnVector<T> * in, ColumnDecimal<U> * out, const IColumn * default_untyped) const
|
|
|
|
{
|
|
|
|
auto col_default = checkAndGetColumn<ColumnVector<V>>(default_untyped);
|
|
|
|
if (!col_default)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
executeImplNumToNumWithNonConstDefault<T, U, V>(in->getData(), out->getData(), col_default->getData());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, typename U, typename V>
|
|
|
|
bool executeNumToDecimalWithNonConstDefaultDecimal2(const ColumnVector<T> * in, ColumnDecimal<U> * out, const IColumn * default_untyped) const
|
|
|
|
{
|
|
|
|
auto col_default = checkAndGetColumn<ColumnDecimal<V>>(default_untyped);
|
|
|
|
if (!col_default)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
executeImplNumToNumWithNonConstDefault<T, U, V>(in->getData(), out->getData(), col_default->getData());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, typename U, typename V>
|
|
|
|
bool executeDecimalToNumWithNonConstDefault2(const ColumnDecimal<T> * in, ColumnVector<U> * out, const IColumn * default_untyped) const
|
|
|
|
{
|
|
|
|
auto col_default = checkAndGetColumn<ColumnVector<V>>(default_untyped);
|
|
|
|
if (!col_default)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
executeImplNumToNumWithNonConstDefault<T, U, V>(in->getData(), out->getData(), col_default->getData());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, typename U, typename V>
|
|
|
|
bool executeDecimalToDecimalWithNonConstDefault2(const ColumnDecimal<T> * in, ColumnDecimal<U> * out, const IColumn * default_untyped) const
|
|
|
|
{
|
|
|
|
auto col_default = checkAndGetColumn<ColumnVector<V>>(default_untyped);
|
|
|
|
if (!col_default)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
executeImplNumToNumWithNonConstDefault<T, U, V>(in->getData(), out->getData(), col_default->getData());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, typename U, typename V>
|
|
|
|
bool executeDecimalToNumWithNonConstDefaultDecimal2(const ColumnDecimal<T> * in, ColumnVector<U> * out, const IColumn * default_untyped) const
|
|
|
|
{
|
|
|
|
auto col_default = checkAndGetColumn<ColumnDecimal<V>>(default_untyped);
|
|
|
|
if (!col_default)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
executeImplNumToNumWithNonConstDefault<T, U, V>(in->getData(), out->getData(), col_default->getData());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, typename U, typename V>
|
|
|
|
bool executeDecimalToDecimalWithNonConstDefaultDecimal2(const ColumnDecimal<T> * in, ColumnDecimal<U> * out, const IColumn * default_untyped) const
|
|
|
|
{
|
|
|
|
auto col_default = checkAndGetColumn<ColumnDecimal<V>>(default_untyped);
|
|
|
|
if (!col_default)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
executeImplNumToNumWithNonConstDefault<T, U, V>(in->getData(), out->getData(), col_default->getData());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-03 03:29:28 +00:00
|
|
|
template <typename T>
|
2020-07-21 13:58:07 +00:00
|
|
|
bool executeNumToStringWithConstDefault(const ColumnVector<T> * in, IColumn * out_untyped) const
|
2015-06-03 03:29:28 +00:00
|
|
|
{
|
2020-04-22 08:45:14 +00:00
|
|
|
auto * out = typeid_cast<ColumnString *>(out_untyped);
|
2015-06-03 03:29:28 +00:00
|
|
|
if (!out)
|
|
|
|
return false;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2020-07-21 13:58:07 +00:00
|
|
|
const String & default_str = cache.const_default_value.get<const String &>();
|
2015-06-03 03:29:28 +00:00
|
|
|
StringRef default_string_ref{default_str.data(), default_str.size() + 1};
|
|
|
|
executeImplNumToStringWithConstDefault<T>(in->getData(), out->getChars(), out->getOffsets(), default_string_ref);
|
|
|
|
return true;
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2021-11-26 02:05:31 +00:00
|
|
|
template <typename T>
|
|
|
|
bool executeDecimalToStringWithConstDefault(const ColumnDecimal<T> * in, IColumn * out_untyped) const
|
|
|
|
{
|
|
|
|
auto * out = typeid_cast<ColumnString *>(out_untyped);
|
|
|
|
if (!out)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const String & default_str = cache.const_default_value.get<const String &>();
|
|
|
|
StringRef default_string_ref{default_str.data(), default_str.size() + 1};
|
|
|
|
executeImplNumToStringWithConstDefault<T>(in->getData(), out->getChars(), out->getOffsets(), default_string_ref);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-03 03:29:28 +00:00
|
|
|
template <typename T>
|
2020-07-21 13:58:07 +00:00
|
|
|
bool executeNumToStringWithNonConstDefault(const ColumnVector<T> * in, IColumn * out_untyped, const IColumn * default_untyped) const
|
2015-06-03 03:29:28 +00:00
|
|
|
{
|
2020-04-22 08:45:14 +00:00
|
|
|
auto * out = typeid_cast<ColumnString *>(out_untyped);
|
2015-06-03 03:29:28 +00:00
|
|
|
if (!out)
|
|
|
|
return false;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2020-04-22 08:45:14 +00:00
|
|
|
const auto * default_col = checkAndGetColumn<ColumnString>(default_untyped);
|
2015-06-03 03:29:28 +00:00
|
|
|
if (!default_col)
|
2016-05-03 23:19:14 +00:00
|
|
|
{
|
2023-01-23 21:13:58 +00:00
|
|
|
throw Exception(ErrorCodes::ILLEGAL_COLUMN, "Illegal column {} of fourth argument of function {}",
|
|
|
|
default_untyped->getName(), getName());
|
2016-05-03 23:19:14 +00:00
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2015-06-03 03:29:28 +00:00
|
|
|
executeImplNumToStringWithNonConstDefault<T>(
|
|
|
|
in->getData(),
|
|
|
|
out->getChars(), out->getOffsets(),
|
|
|
|
default_col->getChars(), default_col->getOffsets());
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2015-06-03 03:29:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2021-11-26 02:05:31 +00:00
|
|
|
template <typename T>
|
|
|
|
bool executeDecimalToStringWithNonConstDefault(const ColumnDecimal<T> * in, IColumn * out_untyped, const IColumn * default_untyped) const
|
|
|
|
{
|
|
|
|
auto * out = typeid_cast<ColumnString *>(out_untyped);
|
|
|
|
if (!out)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const auto * default_col = checkAndGetColumn<ColumnString>(default_untyped);
|
|
|
|
if (!default_col)
|
|
|
|
{
|
2023-01-23 21:13:58 +00:00
|
|
|
throw Exception(ErrorCodes::ILLEGAL_COLUMN, "Illegal column {} of fourth argument of function {}",
|
|
|
|
default_untyped->getName(), getName());
|
2021-11-26 02:05:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
executeImplNumToStringWithNonConstDefault<T>(
|
|
|
|
in->getData(),
|
|
|
|
out->getChars(), out->getOffsets(),
|
|
|
|
default_col->getChars(), default_col->getOffsets());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-03 03:29:28 +00:00
|
|
|
template <typename U>
|
2020-07-21 13:58:07 +00:00
|
|
|
bool executeStringToNumWithConstDefault(const ColumnString * in, IColumn * out_untyped) const
|
2015-06-03 03:29:28 +00:00
|
|
|
{
|
|
|
|
auto out = typeid_cast<ColumnVector<U> *>(out_untyped);
|
|
|
|
if (!out)
|
|
|
|
return false;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2022-09-11 03:38:59 +00:00
|
|
|
executeImplStringToNumWithConstDefault<U>(
|
|
|
|
in->getChars(), in->getOffsets(), out->getData(), static_cast<U>(cache.const_default_value.get<U>()));
|
2015-06-03 03:29:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2021-11-26 02:05:31 +00:00
|
|
|
template <typename U>
|
|
|
|
bool executeStringToDecimalWithConstDefault(const ColumnString * in, IColumn * out_untyped) const
|
|
|
|
{
|
|
|
|
auto out = typeid_cast<ColumnDecimal<U> *>(out_untyped);
|
|
|
|
if (!out)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
executeImplStringToNumWithConstDefault<U>(in->getChars(), in->getOffsets(), out->getData(), cache.const_default_value.get<U>());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-03 03:29:28 +00:00
|
|
|
template <typename U>
|
2020-07-21 13:58:07 +00:00
|
|
|
bool executeStringToNumWithNonConstDefault(const ColumnString * in, IColumn * out_untyped, const IColumn * default_untyped) const
|
2015-06-03 03:29:28 +00:00
|
|
|
{
|
|
|
|
auto out = typeid_cast<ColumnVector<U> *>(out_untyped);
|
|
|
|
if (!out)
|
|
|
|
return false;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2015-06-03 03:29:28 +00:00
|
|
|
if (!executeStringToNumWithNonConstDefault2<U, UInt8>(in, out, default_untyped)
|
|
|
|
&& !executeStringToNumWithNonConstDefault2<U, UInt16>(in, out, default_untyped)
|
|
|
|
&& !executeStringToNumWithNonConstDefault2<U, UInt32>(in, out, default_untyped)
|
|
|
|
&& !executeStringToNumWithNonConstDefault2<U, UInt64>(in, out, default_untyped)
|
|
|
|
&& !executeStringToNumWithNonConstDefault2<U, Int8>(in, out, default_untyped)
|
|
|
|
&& !executeStringToNumWithNonConstDefault2<U, Int16>(in, out, default_untyped)
|
|
|
|
&& !executeStringToNumWithNonConstDefault2<U, Int32>(in, out, default_untyped)
|
|
|
|
&& !executeStringToNumWithNonConstDefault2<U, Int64>(in, out, default_untyped)
|
|
|
|
&& !executeStringToNumWithNonConstDefault2<U, Float32>(in, out, default_untyped)
|
|
|
|
&& !executeStringToNumWithNonConstDefault2<U, Float64>(in, out, default_untyped))
|
2016-05-03 23:19:14 +00:00
|
|
|
{
|
2023-01-23 21:13:58 +00:00
|
|
|
throw Exception(ErrorCodes::ILLEGAL_COLUMN, "Illegal column {} of fourth argument of function {}",
|
|
|
|
default_untyped->getName(), getName());
|
2016-05-03 23:19:14 +00:00
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2015-06-03 03:29:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2021-11-26 02:05:31 +00:00
|
|
|
template <typename U>
|
|
|
|
bool executeStringToDecimalWithNonConstDefault(const ColumnString * in, IColumn * out_untyped, const IColumn * default_untyped) const
|
|
|
|
{
|
|
|
|
auto out = typeid_cast<ColumnDecimal<U> *>(out_untyped);
|
|
|
|
if (!out)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!executeStringToDecimalWithNonConstDefault2<U, UInt8>(in, out, default_untyped)
|
|
|
|
&& !executeStringToDecimalWithNonConstDefault2<U, UInt16>(in, out, default_untyped)
|
|
|
|
&& !executeStringToDecimalWithNonConstDefault2<U, UInt32>(in, out, default_untyped)
|
|
|
|
&& !executeStringToDecimalWithNonConstDefault2<U, UInt64>(in, out, default_untyped)
|
|
|
|
&& !executeStringToDecimalWithNonConstDefault2<U, Int8>(in, out, default_untyped)
|
|
|
|
&& !executeStringToDecimalWithNonConstDefault2<U, Int16>(in, out, default_untyped)
|
|
|
|
&& !executeStringToDecimalWithNonConstDefault2<U, Int32>(in, out, default_untyped)
|
|
|
|
&& !executeStringToDecimalWithNonConstDefault2<U, Int64>(in, out, default_untyped)
|
|
|
|
&& !executeStringToDecimalWithNonConstDefault2<U, Float32>(in, out, default_untyped)
|
|
|
|
&& !executeStringToDecimalWithNonConstDefault2<U, Float64>(in, out, default_untyped)
|
|
|
|
&& !executeStringToDecimalWithNonConstDefaultDecimal2<U, Decimal32>(in, out, default_untyped)
|
|
|
|
&& !executeStringToDecimalWithNonConstDefaultDecimal2<U, Decimal64>(in, out, default_untyped))
|
|
|
|
{
|
2023-01-23 21:13:58 +00:00
|
|
|
throw Exception(ErrorCodes::ILLEGAL_COLUMN, "Illegal column {} of fourth argument of function {}",
|
|
|
|
default_untyped->getName(), getName());
|
2021-11-26 02:05:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-03 03:29:28 +00:00
|
|
|
template <typename U, typename V>
|
2020-07-21 13:58:07 +00:00
|
|
|
bool executeStringToNumWithNonConstDefault2(const ColumnString * in, ColumnVector<U> * out, const IColumn * default_untyped) const
|
2015-06-03 03:29:28 +00:00
|
|
|
{
|
2017-07-21 06:35:58 +00:00
|
|
|
auto col_default = checkAndGetColumn<ColumnVector<V>>(default_untyped);
|
2015-06-03 03:29:28 +00:00
|
|
|
if (!col_default)
|
|
|
|
return false;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2015-06-03 03:29:28 +00:00
|
|
|
executeImplStringToNumWithNonConstDefault<U, V>(in->getChars(), in->getOffsets(), out->getData(), col_default->getData());
|
|
|
|
return true;
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2021-11-26 02:05:31 +00:00
|
|
|
template <typename U, typename V>
|
|
|
|
bool executeStringToDecimalWithNonConstDefault2(const ColumnString * in, ColumnDecimal<U> * out, const IColumn * default_untyped) const
|
|
|
|
{
|
|
|
|
auto col_default = checkAndGetColumn<ColumnVector<V>>(default_untyped);
|
|
|
|
if (!col_default)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
executeImplStringToNumWithNonConstDefault<U, V>(in->getChars(), in->getOffsets(), out->getData(), col_default->getData());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename U, typename V>
|
|
|
|
bool executeStringToDecimalWithNonConstDefaultDecimal2(const ColumnString * in, ColumnDecimal<U> * out, const IColumn * default_untyped) const
|
|
|
|
{
|
|
|
|
auto col_default = checkAndGetColumn<ColumnDecimal<V>>(default_untyped);
|
|
|
|
if (!col_default)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
executeImplStringToNumWithNonConstDefault<U, V>(in->getChars(), in->getOffsets(), out->getData(), col_default->getData());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-07-21 13:58:07 +00:00
|
|
|
bool executeStringToString(const ColumnString * in, IColumn * out_untyped) const
|
2015-06-03 03:29:28 +00:00
|
|
|
{
|
2020-04-22 08:45:14 +00:00
|
|
|
auto * out = typeid_cast<ColumnString *>(out_untyped);
|
2015-06-03 03:29:28 +00:00
|
|
|
if (!out)
|
|
|
|
return false;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2015-06-03 03:29:28 +00:00
|
|
|
executeImplStringToString(in->getChars(), in->getOffsets(), out->getChars(), out->getOffsets());
|
|
|
|
return true;
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2020-07-21 13:58:07 +00:00
|
|
|
bool executeStringToStringWithConstDefault(const ColumnString * in, IColumn * out_untyped) const
|
2015-06-03 03:29:28 +00:00
|
|
|
{
|
2020-04-22 08:45:14 +00:00
|
|
|
auto * out = typeid_cast<ColumnString *>(out_untyped);
|
2015-06-03 03:29:28 +00:00
|
|
|
if (!out)
|
|
|
|
return false;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2020-07-21 13:58:07 +00:00
|
|
|
const String & default_str = cache.const_default_value.get<const String &>();
|
2015-06-03 03:29:28 +00:00
|
|
|
StringRef default_string_ref{default_str.data(), default_str.size() + 1};
|
|
|
|
executeImplStringToStringWithConstDefault(in->getChars(), in->getOffsets(), out->getChars(), out->getOffsets(), default_string_ref);
|
|
|
|
return true;
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2020-07-21 13:58:07 +00:00
|
|
|
bool executeStringToStringWithNonConstDefault(const ColumnString * in, IColumn * out_untyped, const IColumn * default_untyped) const
|
2015-06-03 03:29:28 +00:00
|
|
|
{
|
2020-04-22 08:45:14 +00:00
|
|
|
auto * out = typeid_cast<ColumnString *>(out_untyped);
|
2015-06-03 03:29:28 +00:00
|
|
|
if (!out)
|
|
|
|
return false;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2020-04-22 08:45:14 +00:00
|
|
|
const auto * default_col = checkAndGetColumn<ColumnString>(default_untyped);
|
2015-06-03 03:29:28 +00:00
|
|
|
if (!default_col)
|
2016-05-03 23:19:14 +00:00
|
|
|
{
|
2023-01-23 21:13:58 +00:00
|
|
|
throw Exception(ErrorCodes::ILLEGAL_COLUMN, "Illegal column {} of fourth argument of function {}",
|
|
|
|
default_untyped->getName(), getName());
|
2016-05-03 23:19:14 +00:00
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2015-06-03 03:29:28 +00:00
|
|
|
executeImplStringToStringWithNonConstDefault(
|
|
|
|
in->getChars(), in->getOffsets(),
|
|
|
|
out->getChars(), out->getOffsets(),
|
|
|
|
default_col->getChars(), default_col->getOffsets());
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2015-06-03 03:29:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
|
2015-06-03 03:29:28 +00:00
|
|
|
template <typename T, typename U>
|
2020-07-21 13:58:07 +00:00
|
|
|
void executeImplNumToNumWithConstDefault(const PaddedPODArray<T> & src, PaddedPODArray<U> & dst, U dst_default) const
|
2015-06-03 03:29:28 +00:00
|
|
|
{
|
2020-07-21 13:58:07 +00:00
|
|
|
const auto & table = *cache.table_num_to_num;
|
2015-06-03 03:29:28 +00:00
|
|
|
size_t size = src.size();
|
|
|
|
dst.resize(size);
|
|
|
|
for (size_t i = 0; i < size; ++i)
|
|
|
|
{
|
2021-06-15 19:55:21 +00:00
|
|
|
const auto * it = table.find(bit_cast<UInt64>(src[i]));
|
2019-08-20 09:58:44 +00:00
|
|
|
if (it)
|
2023-01-23 19:54:35 +00:00
|
|
|
{
|
2023-04-23 04:01:39 +00:00
|
|
|
if constexpr (std::endian::native == std::endian::little)
|
2023-01-23 19:54:35 +00:00
|
|
|
memcpy(&dst[i], &it->getMapped(), sizeof(dst[i]));
|
|
|
|
else
|
|
|
|
memcpy(&dst[i], reinterpret_cast<const char *>(&it->getMapped()) + sizeof(UInt64) - sizeof(dst[i]), sizeof(dst[i]));
|
|
|
|
}
|
2015-06-03 03:29:28 +00:00
|
|
|
else
|
|
|
|
dst[i] = dst_default;
|
|
|
|
}
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2015-06-03 03:29:28 +00:00
|
|
|
template <typename T, typename U, typename V>
|
2020-07-21 13:58:07 +00:00
|
|
|
void executeImplNumToNumWithNonConstDefault(const PaddedPODArray<T> & src, PaddedPODArray<U> & dst, const PaddedPODArray<V> & dst_default) const
|
2015-06-03 03:29:28 +00:00
|
|
|
{
|
2020-07-21 13:58:07 +00:00
|
|
|
const auto & table = *cache.table_num_to_num;
|
2015-06-03 03:29:28 +00:00
|
|
|
size_t size = src.size();
|
|
|
|
dst.resize(size);
|
|
|
|
for (size_t i = 0; i < size; ++i)
|
|
|
|
{
|
2021-06-15 19:55:21 +00:00
|
|
|
const auto * it = table.find(bit_cast<UInt64>(src[i]));
|
2019-08-20 09:58:44 +00:00
|
|
|
if (it)
|
2023-01-23 19:54:35 +00:00
|
|
|
{
|
2023-04-23 04:01:39 +00:00
|
|
|
if constexpr (std::endian::native == std::endian::little)
|
2023-01-23 19:54:35 +00:00
|
|
|
memcpy(&dst[i], &it->getMapped(), sizeof(dst[i]));
|
|
|
|
else
|
|
|
|
memcpy(&dst[i], reinterpret_cast<const char *>(&it->getMapped()) + sizeof(UInt64) - sizeof(dst[i]), sizeof(dst[i]));
|
|
|
|
}
|
2022-09-11 03:38:59 +00:00
|
|
|
else if constexpr (is_decimal<U>)
|
|
|
|
dst[i] = static_cast<typename U::NativeType>(dst_default[i]);
|
2015-06-03 03:29:28 +00:00
|
|
|
else
|
2022-09-21 00:16:47 +00:00
|
|
|
dst[i] = static_cast<U>(dst_default[i]); // NOLINT(bugprone-signed-char-misuse,cert-str34-c)
|
2015-06-03 03:29:28 +00:00
|
|
|
}
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2015-06-03 03:29:28 +00:00
|
|
|
template <typename T>
|
2020-07-21 13:58:07 +00:00
|
|
|
void executeImplNumToNum(const PaddedPODArray<T> & src, PaddedPODArray<T> & dst) const
|
2015-06-03 03:29:28 +00:00
|
|
|
{
|
2020-07-21 13:58:07 +00:00
|
|
|
const auto & table = *cache.table_num_to_num;
|
2015-06-03 03:29:28 +00:00
|
|
|
size_t size = src.size();
|
|
|
|
dst.resize(size);
|
|
|
|
for (size_t i = 0; i < size; ++i)
|
|
|
|
{
|
2021-06-15 19:55:21 +00:00
|
|
|
const auto * it = table.find(bit_cast<UInt64>(src[i]));
|
2019-08-20 09:58:44 +00:00
|
|
|
if (it)
|
2023-01-23 19:54:35 +00:00
|
|
|
{
|
2023-04-23 04:01:39 +00:00
|
|
|
if constexpr (std::endian::native == std::endian::little)
|
2023-01-23 19:54:35 +00:00
|
|
|
memcpy(&dst[i], &it->getMapped(), sizeof(dst[i]));
|
|
|
|
else
|
|
|
|
memcpy(&dst[i], reinterpret_cast<const char *>(&it->getMapped()) + sizeof(UInt64) - sizeof(dst[i]), sizeof(dst[i]));
|
|
|
|
}
|
2015-06-03 03:29:28 +00:00
|
|
|
else
|
|
|
|
dst[i] = src[i];
|
|
|
|
}
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2015-06-03 03:29:28 +00:00
|
|
|
template <typename T>
|
2016-04-15 00:33:21 +00:00
|
|
|
void executeImplNumToStringWithConstDefault(const PaddedPODArray<T> & src,
|
2020-07-21 13:58:07 +00:00
|
|
|
ColumnString::Chars & dst_data, ColumnString::Offsets & dst_offsets, StringRef dst_default) const
|
2015-06-03 03:29:28 +00:00
|
|
|
{
|
2020-07-21 13:58:07 +00:00
|
|
|
const auto & table = *cache.table_num_to_string;
|
2015-06-03 03:29:28 +00:00
|
|
|
size_t size = src.size();
|
|
|
|
dst_offsets.resize(size);
|
2017-12-15 21:32:25 +00:00
|
|
|
ColumnString::Offset current_dst_offset = 0;
|
2015-06-03 03:29:28 +00:00
|
|
|
for (size_t i = 0; i < size; ++i)
|
|
|
|
{
|
2021-06-15 19:55:21 +00:00
|
|
|
const auto * it = table.find(bit_cast<UInt64>(src[i]));
|
2019-10-29 15:16:51 +00:00
|
|
|
StringRef ref = it ? it->getMapped() : dst_default;
|
2015-06-03 03:29:28 +00:00
|
|
|
dst_data.resize(current_dst_offset + ref.size);
|
|
|
|
memcpy(&dst_data[current_dst_offset], ref.data, ref.size);
|
|
|
|
current_dst_offset += ref.size;
|
|
|
|
dst_offsets[i] = current_dst_offset;
|
|
|
|
}
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2015-06-03 03:29:28 +00:00
|
|
|
template <typename T>
|
2016-04-15 00:33:21 +00:00
|
|
|
void executeImplNumToStringWithNonConstDefault(const PaddedPODArray<T> & src,
|
2018-11-25 00:08:50 +00:00
|
|
|
ColumnString::Chars & dst_data, ColumnString::Offsets & dst_offsets,
|
2020-07-21 13:58:07 +00:00
|
|
|
const ColumnString::Chars & dst_default_data, const ColumnString::Offsets & dst_default_offsets) const
|
2015-06-03 03:29:28 +00:00
|
|
|
{
|
2020-07-21 13:58:07 +00:00
|
|
|
const auto & table = *cache.table_num_to_string;
|
2015-06-03 03:29:28 +00:00
|
|
|
size_t size = src.size();
|
|
|
|
dst_offsets.resize(size);
|
2017-12-15 21:32:25 +00:00
|
|
|
ColumnString::Offset current_dst_offset = 0;
|
|
|
|
ColumnString::Offset current_dst_default_offset = 0;
|
2015-06-03 03:29:28 +00:00
|
|
|
for (size_t i = 0; i < size; ++i)
|
|
|
|
{
|
2022-09-18 07:20:48 +00:00
|
|
|
const auto * it = table.find(bit_cast<UInt64>(src[i]));
|
2015-06-03 03:29:28 +00:00
|
|
|
StringRef ref;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2019-08-20 09:58:44 +00:00
|
|
|
if (it)
|
2019-10-29 15:16:51 +00:00
|
|
|
ref = it->getMapped();
|
2015-06-03 03:29:28 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
ref.data = reinterpret_cast<const char *>(&dst_default_data[current_dst_default_offset]);
|
|
|
|
ref.size = dst_default_offsets[i] - current_dst_default_offset;
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2015-06-03 03:29:28 +00:00
|
|
|
dst_data.resize(current_dst_offset + ref.size);
|
|
|
|
memcpy(&dst_data[current_dst_offset], ref.data, ref.size);
|
|
|
|
current_dst_offset += ref.size;
|
|
|
|
current_dst_default_offset = dst_default_offsets[i];
|
|
|
|
dst_offsets[i] = current_dst_offset;
|
|
|
|
}
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2015-06-03 03:29:28 +00:00
|
|
|
template <typename U>
|
|
|
|
void executeImplStringToNumWithConstDefault(
|
2018-11-25 00:08:50 +00:00
|
|
|
const ColumnString::Chars & src_data, const ColumnString::Offsets & src_offsets,
|
2020-07-21 13:58:07 +00:00
|
|
|
PaddedPODArray<U> & dst, U dst_default) const
|
2015-06-03 03:29:28 +00:00
|
|
|
{
|
2020-07-21 13:58:07 +00:00
|
|
|
const auto & table = *cache.table_string_to_num;
|
2015-06-03 03:29:28 +00:00
|
|
|
size_t size = src_offsets.size();
|
|
|
|
dst.resize(size);
|
2017-12-15 21:32:25 +00:00
|
|
|
ColumnString::Offset current_src_offset = 0;
|
2015-06-03 03:29:28 +00:00
|
|
|
for (size_t i = 0; i < size; ++i)
|
|
|
|
{
|
|
|
|
StringRef ref{&src_data[current_src_offset], src_offsets[i] - current_src_offset};
|
|
|
|
current_src_offset = src_offsets[i];
|
2020-04-22 08:45:14 +00:00
|
|
|
const auto * it = table.find(ref);
|
2019-08-20 09:58:44 +00:00
|
|
|
if (it)
|
2023-01-23 19:54:35 +00:00
|
|
|
{
|
2023-04-23 04:01:39 +00:00
|
|
|
if constexpr (std::endian::native == std::endian::little)
|
2023-01-23 19:54:35 +00:00
|
|
|
memcpy(&dst[i], &it->getMapped(), sizeof(dst[i]));
|
|
|
|
else
|
|
|
|
memcpy(&dst[i], reinterpret_cast<const char *>(&it->getMapped()) + sizeof(UInt64) - sizeof(dst[i]), sizeof(dst[i]));
|
|
|
|
}
|
2015-06-03 03:29:28 +00:00
|
|
|
else
|
|
|
|
dst[i] = dst_default;
|
|
|
|
}
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2015-06-03 03:29:28 +00:00
|
|
|
template <typename U, typename V>
|
|
|
|
void executeImplStringToNumWithNonConstDefault(
|
2018-11-25 00:08:50 +00:00
|
|
|
const ColumnString::Chars & src_data, const ColumnString::Offsets & src_offsets,
|
2020-07-21 13:58:07 +00:00
|
|
|
PaddedPODArray<U> & dst, const PaddedPODArray<V> & dst_default) const
|
2015-06-03 03:29:28 +00:00
|
|
|
{
|
2020-07-21 13:58:07 +00:00
|
|
|
const auto & table = *cache.table_string_to_num;
|
2015-06-03 03:29:28 +00:00
|
|
|
size_t size = src_offsets.size();
|
|
|
|
dst.resize(size);
|
2017-12-15 21:32:25 +00:00
|
|
|
ColumnString::Offset current_src_offset = 0;
|
2015-06-03 03:29:28 +00:00
|
|
|
for (size_t i = 0; i < size; ++i)
|
|
|
|
{
|
|
|
|
StringRef ref{&src_data[current_src_offset], src_offsets[i] - current_src_offset};
|
|
|
|
current_src_offset = src_offsets[i];
|
2020-04-22 08:45:14 +00:00
|
|
|
const auto * it = table.find(ref);
|
2019-08-20 09:58:44 +00:00
|
|
|
if (it)
|
2023-01-23 19:54:35 +00:00
|
|
|
{
|
2023-04-23 04:01:39 +00:00
|
|
|
if constexpr (std::endian::native == std::endian::little)
|
2023-01-23 19:54:35 +00:00
|
|
|
memcpy(&dst[i], &it->getMapped(), sizeof(dst[i]));
|
|
|
|
else
|
|
|
|
memcpy(&dst[i], reinterpret_cast<const char *>(&it->getMapped()) + sizeof(UInt64) - sizeof(dst[i]), sizeof(dst[i]));
|
|
|
|
}
|
2022-09-11 03:38:59 +00:00
|
|
|
else if constexpr (is_decimal<U>)
|
|
|
|
dst[i] = static_cast<typename U::NativeType>(dst_default[i]);
|
2015-06-03 03:29:28 +00:00
|
|
|
else
|
2022-09-21 12:35:24 +00:00
|
|
|
dst[i] = static_cast<U>(dst_default[i]); // NOLINT(bugprone-signed-char-misuse,cert-str34-c)
|
2015-06-03 03:29:28 +00:00
|
|
|
}
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2015-06-03 03:29:28 +00:00
|
|
|
template <bool with_default>
|
|
|
|
void executeImplStringToStringWithOrWithoutConstDefault(
|
2018-11-25 00:08:50 +00:00
|
|
|
const ColumnString::Chars & src_data, const ColumnString::Offsets & src_offsets,
|
2020-07-21 13:58:07 +00:00
|
|
|
ColumnString::Chars & dst_data, ColumnString::Offsets & dst_offsets, StringRef dst_default) const
|
2015-06-03 03:29:28 +00:00
|
|
|
{
|
2020-07-21 13:58:07 +00:00
|
|
|
const auto & table = *cache.table_string_to_string;
|
2015-06-03 03:29:28 +00:00
|
|
|
size_t size = src_offsets.size();
|
|
|
|
dst_offsets.resize(size);
|
2017-12-15 21:32:25 +00:00
|
|
|
ColumnString::Offset current_src_offset = 0;
|
|
|
|
ColumnString::Offset current_dst_offset = 0;
|
2015-06-03 03:29:28 +00:00
|
|
|
for (size_t i = 0; i < size; ++i)
|
|
|
|
{
|
|
|
|
StringRef src_ref{&src_data[current_src_offset], src_offsets[i] - current_src_offset};
|
|
|
|
current_src_offset = src_offsets[i];
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2020-04-22 08:45:14 +00:00
|
|
|
const auto * it = table.find(src_ref);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2019-10-29 15:16:51 +00:00
|
|
|
StringRef dst_ref = it ? it->getMapped() : (with_default ? dst_default : src_ref);
|
2015-06-03 03:29:28 +00:00
|
|
|
dst_data.resize(current_dst_offset + dst_ref.size);
|
|
|
|
memcpy(&dst_data[current_dst_offset], dst_ref.data, dst_ref.size);
|
|
|
|
current_dst_offset += dst_ref.size;
|
|
|
|
dst_offsets[i] = current_dst_offset;
|
|
|
|
}
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2015-06-03 03:29:28 +00:00
|
|
|
void executeImplStringToString(
|
2018-11-25 00:08:50 +00:00
|
|
|
const ColumnString::Chars & src_data, const ColumnString::Offsets & src_offsets,
|
2020-07-21 13:58:07 +00:00
|
|
|
ColumnString::Chars & dst_data, ColumnString::Offsets & dst_offsets) const
|
2015-06-03 03:29:28 +00:00
|
|
|
{
|
|
|
|
executeImplStringToStringWithOrWithoutConstDefault<false>(src_data, src_offsets, dst_data, dst_offsets, {});
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2015-06-03 03:29:28 +00:00
|
|
|
void executeImplStringToStringWithConstDefault(
|
2018-11-25 00:08:50 +00:00
|
|
|
const ColumnString::Chars & src_data, const ColumnString::Offsets & src_offsets,
|
2020-07-21 13:58:07 +00:00
|
|
|
ColumnString::Chars & dst_data, ColumnString::Offsets & dst_offsets, StringRef dst_default) const
|
2015-06-03 03:29:28 +00:00
|
|
|
{
|
|
|
|
executeImplStringToStringWithOrWithoutConstDefault<true>(src_data, src_offsets, dst_data, dst_offsets, dst_default);
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2015-06-03 03:29:28 +00:00
|
|
|
void executeImplStringToStringWithNonConstDefault(
|
2018-11-25 00:08:50 +00:00
|
|
|
const ColumnString::Chars & src_data, const ColumnString::Offsets & src_offsets,
|
|
|
|
ColumnString::Chars & dst_data, ColumnString::Offsets & dst_offsets,
|
2020-07-21 13:58:07 +00:00
|
|
|
const ColumnString::Chars & dst_default_data, const ColumnString::Offsets & dst_default_offsets) const
|
2015-06-03 03:29:28 +00:00
|
|
|
{
|
2020-07-21 13:58:07 +00:00
|
|
|
const auto & table = *cache.table_string_to_string;
|
2015-06-03 03:29:28 +00:00
|
|
|
size_t size = src_offsets.size();
|
|
|
|
dst_offsets.resize(size);
|
2017-12-15 21:32:25 +00:00
|
|
|
ColumnString::Offset current_src_offset = 0;
|
|
|
|
ColumnString::Offset current_dst_offset = 0;
|
|
|
|
ColumnString::Offset current_dst_default_offset = 0;
|
2015-06-03 03:29:28 +00:00
|
|
|
for (size_t i = 0; i < size; ++i)
|
|
|
|
{
|
|
|
|
StringRef src_ref{&src_data[current_src_offset], src_offsets[i] - current_src_offset};
|
|
|
|
current_src_offset = src_offsets[i];
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2020-04-22 08:45:14 +00:00
|
|
|
const auto * it = table.find(src_ref);
|
2015-06-03 03:29:28 +00:00
|
|
|
StringRef dst_ref;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2019-08-20 09:58:44 +00:00
|
|
|
if (it)
|
2019-10-29 15:16:51 +00:00
|
|
|
dst_ref = it->getMapped();
|
2015-06-03 03:29:28 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
dst_ref.data = reinterpret_cast<const char *>(&dst_default_data[current_dst_default_offset]);
|
|
|
|
dst_ref.size = dst_default_offsets[i] - current_dst_default_offset;
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2015-06-03 03:29:28 +00:00
|
|
|
dst_data.resize(current_dst_offset + dst_ref.size);
|
|
|
|
memcpy(&dst_data[current_dst_offset], dst_ref.data, dst_ref.size);
|
|
|
|
current_dst_offset += dst_ref.size;
|
|
|
|
current_dst_default_offset = dst_default_offsets[i];
|
|
|
|
dst_offsets[i] = current_dst_offset;
|
|
|
|
}
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
|
2017-05-27 15:45:25 +00:00
|
|
|
/// Different versions of the hash tables to implement the mapping.
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2020-07-21 13:58:07 +00:00
|
|
|
struct Cache
|
|
|
|
{
|
|
|
|
using NumToNum = HashMap<UInt64, UInt64, HashCRC32<UInt64>>;
|
|
|
|
using NumToString = HashMap<UInt64, StringRef, HashCRC32<UInt64>>; /// Everywhere StringRef's with trailing zero.
|
|
|
|
using StringToNum = HashMap<StringRef, UInt64, StringRefHash>;
|
|
|
|
using StringToString = HashMap<StringRef, StringRef, StringRefHash>;
|
|
|
|
|
|
|
|
std::unique_ptr<NumToNum> table_num_to_num;
|
|
|
|
std::unique_ptr<NumToString> table_num_to_string;
|
|
|
|
std::unique_ptr<StringToNum> table_string_to_num;
|
|
|
|
std::unique_ptr<StringToString> table_string_to_string;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2020-07-21 13:58:07 +00:00
|
|
|
Arena string_pool;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2020-07-21 13:58:07 +00:00
|
|
|
Field const_default_value; /// Null, if not specified.
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2020-07-21 13:58:07 +00:00
|
|
|
std::atomic<bool> initialized{false};
|
|
|
|
std::mutex mutex;
|
|
|
|
};
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2020-07-21 13:58:07 +00:00
|
|
|
mutable Cache cache;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2022-09-18 03:16:08 +00:00
|
|
|
|
|
|
|
static UInt64 bitCastToUInt64(const Field & x)
|
|
|
|
{
|
|
|
|
switch (x.getType())
|
|
|
|
{
|
|
|
|
case Field::Types::UInt64: return x.get<UInt64>();
|
|
|
|
case Field::Types::Int64: return x.get<Int64>();
|
|
|
|
case Field::Types::Float64: return std::bit_cast<UInt64>(x.get<Float64>());
|
|
|
|
case Field::Types::Bool: return x.get<bool>();
|
|
|
|
case Field::Types::Decimal32: return x.get<DecimalField<Decimal32>>().getValue();
|
|
|
|
case Field::Types::Decimal64: return x.get<DecimalField<Decimal64>>().getValue();
|
|
|
|
default:
|
2023-01-23 21:13:58 +00:00
|
|
|
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Unexpected type in function 'transform'");
|
2022-09-18 03:16:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-27 15:45:25 +00:00
|
|
|
/// Can be called from different threads. It works only on the first call.
|
2020-11-17 13:24:45 +00:00
|
|
|
void initialize(const Array & from, const Array & to, const ColumnsWithTypeAndName & arguments) const
|
2015-06-03 03:29:28 +00:00
|
|
|
{
|
2020-07-21 13:58:07 +00:00
|
|
|
if (cache.initialized)
|
2015-06-03 03:29:28 +00:00
|
|
|
return;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2015-06-03 03:29:28 +00:00
|
|
|
const size_t size = from.size();
|
|
|
|
if (0 == size)
|
2023-01-23 21:13:58 +00:00
|
|
|
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Empty arrays are illegal in function {}", getName());
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2020-07-21 13:58:07 +00:00
|
|
|
std::lock_guard lock(cache.mutex);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2020-07-21 13:58:07 +00:00
|
|
|
if (cache.initialized)
|
2015-06-03 03:29:28 +00:00
|
|
|
return;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2018-08-27 16:31:45 +00:00
|
|
|
if (size != to.size())
|
2023-01-23 21:13:58 +00:00
|
|
|
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Second and third arguments of function {} must be arrays of same size", getName());
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2015-06-03 03:29:28 +00:00
|
|
|
Array converted_to;
|
|
|
|
const Array * used_to = &to;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-05-27 15:45:25 +00:00
|
|
|
/// Whether the default value is set.
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2015-06-03 03:29:28 +00:00
|
|
|
if (arguments.size() == 4)
|
|
|
|
{
|
2020-10-19 15:27:41 +00:00
|
|
|
const IColumn * default_col = arguments[3].column.get();
|
2017-07-21 06:35:58 +00:00
|
|
|
const ColumnConst * const_default_col = typeid_cast<const ColumnConst *>(default_col);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2015-06-03 03:55:29 +00:00
|
|
|
if (const_default_col)
|
2020-07-21 13:58:07 +00:00
|
|
|
cache.const_default_value = (*const_default_col)[0];
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-07-21 06:35:58 +00:00
|
|
|
/// Do we need to convert the elements `to` and `default_value` to the smallest common type that is Float64?
|
2015-06-03 03:55:29 +00:00
|
|
|
bool default_col_is_float =
|
2017-07-21 06:35:58 +00:00
|
|
|
checkColumn<ColumnFloat32>(default_col)
|
|
|
|
|| checkColumn<ColumnFloat64>(default_col)
|
|
|
|
|| checkColumnConst<ColumnFloat32>(default_col)
|
|
|
|
|| checkColumnConst<ColumnFloat64>(default_col);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2015-06-03 03:55:29 +00:00
|
|
|
bool to_is_float = to[0].getType() == Field::Types::Float64;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2015-06-03 03:55:29 +00:00
|
|
|
if (default_col_is_float && !to_is_float)
|
2015-06-03 03:29:28 +00:00
|
|
|
{
|
2018-08-27 16:31:45 +00:00
|
|
|
converted_to.resize(size);
|
|
|
|
for (size_t i = 0; i < size; ++i)
|
2017-01-06 17:41:19 +00:00
|
|
|
converted_to[i] = applyVisitor(FieldVisitorConvertToNumber<Float64>(), to[i]);
|
2015-06-03 03:55:29 +00:00
|
|
|
used_to = &converted_to;
|
|
|
|
}
|
|
|
|
else if (!default_col_is_float && to_is_float)
|
|
|
|
{
|
|
|
|
if (const_default_col)
|
2020-07-21 13:58:07 +00:00
|
|
|
cache.const_default_value = applyVisitor(FieldVisitorConvertToNumber<Float64>(), cache.const_default_value);
|
2015-06-03 03:29:28 +00:00
|
|
|
}
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-07-21 06:35:58 +00:00
|
|
|
/// Note: Doesn't check the duplicates in the `from` array.
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2021-02-14 16:07:20 +00:00
|
|
|
const IDataType & from_type = *arguments[0].type;
|
|
|
|
|
|
|
|
if (from[0].getType() != Field::Types::String)
|
2015-06-03 03:29:28 +00:00
|
|
|
{
|
2021-02-14 16:07:20 +00:00
|
|
|
if (to[0].getType() != Field::Types::String)
|
2019-12-17 10:19:21 +00:00
|
|
|
{
|
2021-02-14 16:07:20 +00:00
|
|
|
cache.table_num_to_num = std::make_unique<Cache::NumToNum>();
|
|
|
|
auto & table = *cache.table_num_to_num;
|
|
|
|
for (size_t i = 0; i < size; ++i)
|
|
|
|
{
|
|
|
|
Field key = convertFieldToType(from[i], from_type);
|
|
|
|
if (key.isNull())
|
|
|
|
continue;
|
|
|
|
|
2022-09-18 06:58:32 +00:00
|
|
|
/// Field may be of Float type, but for the purpose of bitwise equality we can treat them as UInt64
|
|
|
|
table[bitCastToUInt64(key)] = bitCastToUInt64((*used_to)[i]);
|
2021-02-14 16:07:20 +00:00
|
|
|
}
|
2019-12-17 10:19:21 +00:00
|
|
|
}
|
2021-02-14 16:07:20 +00:00
|
|
|
else
|
2015-06-03 03:29:28 +00:00
|
|
|
{
|
2021-02-14 16:07:20 +00:00
|
|
|
cache.table_num_to_string = std::make_unique<Cache::NumToString>();
|
|
|
|
auto & table = *cache.table_num_to_string;
|
|
|
|
for (size_t i = 0; i < size; ++i)
|
|
|
|
{
|
|
|
|
Field key = convertFieldToType(from[i], from_type);
|
|
|
|
if (key.isNull())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
const String & str_to = to[i].get<const String &>();
|
|
|
|
StringRef ref{cache.string_pool.insert(str_to.data(), str_to.size() + 1), str_to.size() + 1};
|
2022-09-18 03:16:08 +00:00
|
|
|
table[bitCastToUInt64(key)] = ref;
|
2021-02-14 16:07:20 +00:00
|
|
|
}
|
2015-06-03 03:29:28 +00:00
|
|
|
}
|
|
|
|
}
|
2021-02-14 16:07:20 +00:00
|
|
|
else
|
2015-06-03 03:29:28 +00:00
|
|
|
{
|
2021-02-14 16:07:20 +00:00
|
|
|
if (to[0].getType() != Field::Types::String)
|
2015-06-03 03:29:28 +00:00
|
|
|
{
|
2021-02-14 16:07:20 +00:00
|
|
|
cache.table_string_to_num = std::make_unique<Cache::StringToNum>();
|
|
|
|
auto & table = *cache.table_string_to_num;
|
|
|
|
for (size_t i = 0; i < size; ++i)
|
|
|
|
{
|
|
|
|
const String & str_from = from[i].get<const String &>();
|
|
|
|
StringRef ref{cache.string_pool.insert(str_from.data(), str_from.size() + 1), str_from.size() + 1};
|
2022-09-18 03:16:08 +00:00
|
|
|
table[ref] = bitCastToUInt64((*used_to)[i]);
|
2021-02-14 16:07:20 +00:00
|
|
|
}
|
2015-06-03 03:29:28 +00:00
|
|
|
}
|
2021-02-14 16:07:20 +00:00
|
|
|
else
|
2015-06-03 03:29:28 +00:00
|
|
|
{
|
2021-02-14 16:07:20 +00:00
|
|
|
cache.table_string_to_string = std::make_unique<Cache::StringToString>();
|
|
|
|
auto & table = *cache.table_string_to_string;
|
|
|
|
for (size_t i = 0; i < size; ++i)
|
|
|
|
{
|
|
|
|
const String & str_from = from[i].get<const String &>();
|
|
|
|
const String & str_to = to[i].get<const String &>();
|
|
|
|
StringRef ref_from{cache.string_pool.insert(str_from.data(), str_from.size() + 1), str_from.size() + 1};
|
|
|
|
StringRef ref_to{cache.string_pool.insert(str_to.data(), str_to.size() + 1), str_to.size() + 1};
|
|
|
|
table[ref_from] = ref_to;
|
|
|
|
}
|
2015-06-03 03:29:28 +00:00
|
|
|
}
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2020-07-21 13:58:07 +00:00
|
|
|
cache.initialized = true;
|
2015-06-03 03:29:28 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-09-07 18:00:37 +00:00
|
|
|
}
|
|
|
|
|
2022-07-04 07:01:39 +00:00
|
|
|
REGISTER_FUNCTION(Transform)
|
2018-12-02 02:52:49 +00:00
|
|
|
{
|
|
|
|
factory.registerFunction<FunctionTransform>();
|
|
|
|
}
|
|
|
|
|
2015-06-03 03:29:28 +00:00
|
|
|
}
|