ClickHouse/src/Functions/transform.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

1266 lines
58 KiB
C++
Raw Normal View History

#include <mutex>
2021-10-02 07:13:14 +00:00
#include <base/bit_cast.h>
2022-09-18 07:20:48 +00:00
#include <Common/FieldVisitorDump.h>
2021-06-14 04:13:35 +00:00
#include <Common/FieldVisitorConvertToNumber.h>
#include <DataTypes/DataTypeArray.h>
#include <Columns/ColumnString.h>
ColumnConst unification (#1011) * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * Fixed error in ColumnArray::replicateGeneric [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150].
2017-07-21 06:35:58 +00:00
#include <Columns/ColumnArray.h>
#include <Columns/ColumnConst.h>
#include <Columns/ColumnsNumber.h>
2021-11-26 02:05:31 +00:00
#include <Columns/ColumnDecimal.h>
#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>
ColumnConst unification (#1011) * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * Fixed error in ColumnArray::replicateGeneric [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150].
2017-07-21 06:35:58 +00:00
#include <Functions/FunctionHelpers.h>
#include <Functions/FunctionFactory.h>
#include <DataTypes/getLeastSupertype.h>
#include <Interpreters/convertFieldToType.h>
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.
*/
/** transform(x, [from...], [to...], default)
2017-05-27 15:45:25 +00:00
* - converts the values according to the explicitly specified mapping.
*
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.
*
2017-05-27 15:45:25 +00:00
* Types:
* 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.
*
2017-05-27 15:45:25 +00:00
* Types:
* transform(T, Array(T), Array(T)) -> T
*
2017-05-27 15:45:25 +00:00
* Note: the implementation is rather cumbersome.
*/
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>(); }
2016-05-03 23:19:14 +00:00
String getName() const override
{
return name;
2016-05-03 23:19:14 +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; }
bool useDefaultImplementationForConstants() const override { return true; }
ColumnNumbers getArgumentsThatAreAlwaysConstant() const override { return {1, 2}; }
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override
{
const auto args_size = arguments.size();
if (args_size != 3 && args_size != 4)
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);
const DataTypePtr & type_x = arguments[0];
if (!type_x->isValueRepresentedByNumber() && !isString(type_x))
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());
ColumnConst unification (#1011) * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * Fixed error in ColumnArray::replicateGeneric [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150].
2017-07-21 06:35:58 +00:00
const DataTypeArray * type_arr_from = checkAndGetDataType<DataTypeArray>(arguments[1].get());
if (!type_arr_from)
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT,
"Second argument of function {}, must be array of source values to transform from.",
getName());
const auto type_arr_from_nested = type_arr_from->getNestedType();
if ((type_x->isValueRepresentedByNumber() != type_arr_from_nested->isValueRepresentedByNumber())
|| (isString(type_x) != isString(type_arr_from_nested)))
2016-05-03 23:19:14 +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
}
ColumnConst unification (#1011) * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * Fixed error in ColumnArray::replicateGeneric [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150].
2017-07-21 06:35:58 +00:00
const DataTypeArray * type_arr_to = checkAndGetDataType<DataTypeArray>(arguments[2].get());
if (!type_arr_to)
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT,
"Third argument of function {}, must be array of destination values to transform to.",
getName());
const DataTypePtr & type_arr_to_nested = type_arr_to->getNestedType();
if (args_size == 3)
{
if ((type_x->isValueRepresentedByNumber() != type_arr_to_nested->isValueRepresentedByNumber())
|| (isString(type_x) != isString(type_arr_to_nested)))
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());
2021-12-13 11:37:23 +00:00
return getLeastSupertype(DataTypes{type_x, type_arr_to_nested});
}
else
{
const DataTypePtr & type_default = arguments[3];
if (!type_default->isValueRepresentedByNumber() && !isString(type_default))
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());
bool default_is_string = WhichDataType(type_default).isString();
bool nested_is_string = WhichDataType(type_arr_to_nested).isString();
if ((type_default->isValueRepresentedByNumber() != type_arr_to_nested->isValueRepresentedByNumber())
|| (default_is_string != nested_is_string))
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());
if (type_arr_to_nested->isValueRepresentedByNumber() && type_default->isValueRepresentedByNumber())
{
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`.
return getLeastSupertype(DataTypes{type_arr_to_nested, type_default});
}
2017-05-27 15:45:25 +00:00
/// TODO More checks.
return type_arr_to_nested;
}
}
ColumnPtr executeImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr & result_type, size_t input_rows_count) const override
{
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());
if (!array_from || !array_to)
throw Exception(ErrorCodes::ILLEGAL_COLUMN, "Second and third arguments of function {} must be constant arrays.", getName());
2020-10-19 15:27:41 +00:00
initialize(array_from->getValue<Array>(), array_to->getValue<Array>(), arguments);
2020-10-19 15:27:41 +00:00
const auto * in = arguments.front().column.get();
if (isColumnConst(*in))
2020-10-19 15:27:41 +00:00
return executeConst(arguments, result_type, input_rows_count);
const IColumn * default_column = nullptr;
if (arguments.size() == 4)
2020-10-19 15:27:41 +00:00
default_column = arguments[3].column.get();
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();
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)
&& !executeString(in, out, default_column))
2016-05-03 23:19:14 +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
}
2020-10-19 15:27:41 +00:00
return column_result;
}
private:
static ColumnPtr executeConst(const ColumnsWithTypeAndName & arguments, const DataTypePtr & result_type, size_t input_rows_count)
{
/// Materialize the input column and compute the function as usual.
2020-10-19 15:27:41 +00:00
ColumnsWithTypeAndName args = arguments;
args[0].column = args[0].column->cloneResized(input_rows_count)->convertToFullColumnIfConst();
2021-05-15 17:33:15 +00:00
auto impl = FunctionToOverloadResolverAdaptor(std::make_shared<FunctionTransform>()).build(args);
2020-10-19 15:27:41 +00:00
return impl->execute(args, result_type, input_rows_count);
}
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
{
ColumnConst unification (#1011) * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * Fixed error in ColumnArray::replicateGeneric [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150].
2017-07-21 06:35:58 +00:00
if (const auto in = checkAndGetColumn<ColumnVector<T>>(in_untyped))
{
if (!default_untyped)
{
auto out = typeid_cast<ColumnVector<T> *>(out_untyped);
if (!out)
2016-05-03 23:19:14 +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
}
executeImplNumToNum<T>(in->getData(), out->getData());
}
else if (isColumnConst(*default_untyped))
{
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)
&& !executeNumToStringWithConstDefault<T>(in, out_untyped))
2016-05-03 23:19:14 +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
}
}
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)
&& !executeNumToStringWithNonConstDefault<T>(in, out_untyped, default_untyped))
2016-05-03 23:19:14 +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
}
}
return true;
}
return false;
}
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)
{
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))
{
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))
{
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
{
2020-04-22 08:45:14 +00:00
if (const auto * in = checkAndGetColumn<ColumnString>(in_untyped))
{
if (!default_untyped)
{
if (!executeStringToString(in, out_untyped))
throw Exception(ErrorCodes::ILLEGAL_COLUMN, "Illegal column {} of elements of array of second argument of function {}",
in->getName(), getName());
}
else if (isColumnConst(*default_untyped))
{
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)
&& !executeStringToStringWithConstDefault(in, out_untyped))
2016-05-03 23:19:14 +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
}
}
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)
&& !executeStringToStringWithNonConstDefault(in, out_untyped, default_untyped))
2016-05-03 23:19:14 +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
}
}
return true;
}
return false;
}
template <typename T, typename U>
2020-07-21 13:58:07 +00:00
bool executeNumToNumWithConstDefault(const ColumnVector<T> * in, IColumn * out_untyped) const
{
auto out = typeid_cast<ColumnVector<U> *>(out_untyped);
if (!out)
return false;
2022-09-11 02:49:43 +00:00
executeImplNumToNumWithConstDefault<T, U>(in->getData(), out->getData(), static_cast<U>(cache.const_default_value.get<U>()));
return true;
}
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;
}
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
{
auto out = typeid_cast<ColumnVector<U> *>(out_untyped);
if (!out)
return false;
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
{
throw Exception(ErrorCodes::ILLEGAL_COLUMN, "Illegal column {} of fourth argument of function {}",
default_untyped->getName(), getName());
2016-05-03 23:19:14 +00:00
}
return true;
}
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))
{
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))
{
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))
{
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, typename V>
2020-07-21 13:58:07 +00:00
bool executeNumToNumWithNonConstDefault2(const ColumnVector<T> * in, ColumnVector<U> * out, const IColumn * default_untyped) const
{
ColumnConst unification (#1011) * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * Fixed error in ColumnArray::replicateGeneric [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150].
2017-07-21 06:35:58 +00:00
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;
}
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;
}
template <typename T>
2020-07-21 13:58:07 +00:00
bool executeNumToStringWithConstDefault(const ColumnVector<T> * in, IColumn * out_untyped) const
{
2020-04-22 08:45:14 +00:00
auto * out = typeid_cast<ColumnString *>(out_untyped);
if (!out)
return false;
2020-07-21 13:58:07 +00:00
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;
}
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;
}
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
{
2020-04-22 08:45:14 +00:00
auto * out = typeid_cast<ColumnString *>(out_untyped);
if (!out)
return false;
2020-04-22 08:45:14 +00:00
const auto * default_col = checkAndGetColumn<ColumnString>(default_untyped);
if (!default_col)
2016-05-03 23:19:14 +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
}
executeImplNumToStringWithNonConstDefault<T>(
in->getData(),
out->getChars(), out->getOffsets(),
default_col->getChars(), default_col->getOffsets());
return true;
}
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)
{
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;
}
template <typename U>
2020-07-21 13:58:07 +00:00
bool executeStringToNumWithConstDefault(const ColumnString * 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
executeImplStringToNumWithConstDefault<U>(
in->getChars(), in->getOffsets(), out->getData(), static_cast<U>(cache.const_default_value.get<U>()));
return true;
}
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;
}
template <typename U>
2020-07-21 13:58:07 +00:00
bool executeStringToNumWithNonConstDefault(const ColumnString * in, IColumn * out_untyped, const IColumn * default_untyped) const
{
auto out = typeid_cast<ColumnVector<U> *>(out_untyped);
if (!out)
return false;
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
{
throw Exception(ErrorCodes::ILLEGAL_COLUMN, "Illegal column {} of fourth argument of function {}",
default_untyped->getName(), getName());
2016-05-03 23:19:14 +00:00
}
return true;
}
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))
{
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 U, typename V>
2020-07-21 13:58:07 +00:00
bool executeStringToNumWithNonConstDefault2(const ColumnString * in, ColumnVector<U> * out, const IColumn * default_untyped) const
{
ColumnConst unification (#1011) * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * Fixed error in ColumnArray::replicateGeneric [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150].
2017-07-21 06:35:58 +00:00
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;
}
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
{
2020-04-22 08:45:14 +00:00
auto * out = typeid_cast<ColumnString *>(out_untyped);
if (!out)
return false;
executeImplStringToString(in->getChars(), in->getOffsets(), out->getChars(), out->getOffsets());
return true;
}
2020-07-21 13:58:07 +00:00
bool executeStringToStringWithConstDefault(const ColumnString * in, IColumn * out_untyped) const
{
2020-04-22 08:45:14 +00:00
auto * out = typeid_cast<ColumnString *>(out_untyped);
if (!out)
return false;
2020-07-21 13:58:07 +00:00
const String & default_str = cache.const_default_value.get<const String &>();
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;
}
2020-07-21 13:58:07 +00:00
bool executeStringToStringWithNonConstDefault(const ColumnString * in, IColumn * out_untyped, const IColumn * default_untyped) const
{
2020-04-22 08:45:14 +00:00
auto * out = typeid_cast<ColumnString *>(out_untyped);
if (!out)
return false;
2020-04-22 08:45:14 +00:00
const auto * default_col = checkAndGetColumn<ColumnString>(default_untyped);
if (!default_col)
2016-05-03 23:19:14 +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
}
executeImplStringToStringWithNonConstDefault(
in->getChars(), in->getOffsets(),
out->getChars(), out->getOffsets(),
default_col->getChars(), default_col->getOffsets());
return true;
}
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
{
2020-07-21 13:58:07 +00:00
const auto & table = *cache.table_num_to_num;
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]));
if (it)
{
2023-04-23 04:01:39 +00:00
if constexpr (std::endian::native == std::endian::little)
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]));
}
else
dst[i] = dst_default;
}
}
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
{
2020-07-21 13:58:07 +00:00
const auto & table = *cache.table_num_to_num;
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]));
if (it)
{
2023-04-23 04:01:39 +00:00
if constexpr (std::endian::native == std::endian::little)
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]);
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)
}
}
template <typename T>
2020-07-21 13:58:07 +00:00
void executeImplNumToNum(const PaddedPODArray<T> & src, PaddedPODArray<T> & dst) const
{
2020-07-21 13:58:07 +00:00
const auto & table = *cache.table_num_to_num;
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]));
if (it)
{
2023-04-23 04:01:39 +00:00
if constexpr (std::endian::native == std::endian::little)
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]));
}
else
dst[i] = src[i];
}
}
template <typename T>
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
{
2020-07-21 13:58:07 +00:00
const auto & table = *cache.table_num_to_string;
size_t size = src.size();
dst_offsets.resize(size);
ColumnString::Offset current_dst_offset = 0;
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;
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;
}
}
template <typename T>
void executeImplNumToStringWithNonConstDefault(const PaddedPODArray<T> & src,
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
{
2020-07-21 13:58:07 +00:00
const auto & table = *cache.table_num_to_string;
size_t size = src.size();
dst_offsets.resize(size);
ColumnString::Offset current_dst_offset = 0;
ColumnString::Offset current_dst_default_offset = 0;
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]));
StringRef ref;
if (it)
2019-10-29 15:16:51 +00:00
ref = it->getMapped();
else
{
ref.data = reinterpret_cast<const char *>(&dst_default_data[current_dst_default_offset]);
ref.size = dst_default_offsets[i] - current_dst_default_offset;
}
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;
}
}
template <typename U>
void executeImplStringToNumWithConstDefault(
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
{
2020-07-21 13:58:07 +00:00
const auto & table = *cache.table_string_to_num;
size_t size = src_offsets.size();
dst.resize(size);
ColumnString::Offset current_src_offset = 0;
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);
if (it)
{
2023-04-23 04:01:39 +00:00
if constexpr (std::endian::native == std::endian::little)
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]));
}
else
dst[i] = dst_default;
}
}
template <typename U, typename V>
void executeImplStringToNumWithNonConstDefault(
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
{
2020-07-21 13:58:07 +00:00
const auto & table = *cache.table_string_to_num;
size_t size = src_offsets.size();
dst.resize(size);
ColumnString::Offset current_src_offset = 0;
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);
if (it)
{
2023-04-23 04:01:39 +00:00
if constexpr (std::endian::native == std::endian::little)
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]);
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)
}
}
template <bool with_default>
void executeImplStringToStringWithOrWithoutConstDefault(
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
{
2020-07-21 13:58:07 +00:00
const auto & table = *cache.table_string_to_string;
size_t size = src_offsets.size();
dst_offsets.resize(size);
ColumnString::Offset current_src_offset = 0;
ColumnString::Offset current_dst_offset = 0;
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];
2020-04-22 08:45:14 +00:00
const auto * it = table.find(src_ref);
2019-10-29 15:16:51 +00:00
StringRef dst_ref = it ? it->getMapped() : (with_default ? dst_default : src_ref);
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;
}
}
void executeImplStringToString(
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
{
executeImplStringToStringWithOrWithoutConstDefault<false>(src_data, src_offsets, dst_data, dst_offsets, {});
}
void executeImplStringToStringWithConstDefault(
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
{
executeImplStringToStringWithOrWithoutConstDefault<true>(src_data, src_offsets, dst_data, dst_offsets, dst_default);
}
void executeImplStringToStringWithNonConstDefault(
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
{
2020-07-21 13:58:07 +00:00
const auto & table = *cache.table_string_to_string;
size_t size = src_offsets.size();
dst_offsets.resize(size);
ColumnString::Offset current_src_offset = 0;
ColumnString::Offset current_dst_offset = 0;
ColumnString::Offset current_dst_default_offset = 0;
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];
2020-04-22 08:45:14 +00:00
const auto * it = table.find(src_ref);
StringRef dst_ref;
if (it)
2019-10-29 15:16:51 +00:00
dst_ref = it->getMapped();
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;
}
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-05-27 15:45:25 +00:00
/// Different versions of the hash tables to implement the mapping.
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;
2020-07-21 13:58:07 +00:00
Arena string_pool;
2020-07-21 13:58:07 +00:00
Field const_default_value; /// Null, if not specified.
2020-07-21 13:58:07 +00:00
std::atomic<bool> initialized{false};
std::mutex mutex;
};
2020-07-21 13:58:07 +00:00
mutable Cache cache;
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:
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.
void initialize(const Array & from, const Array & to, const ColumnsWithTypeAndName & arguments) const
{
2020-07-21 13:58:07 +00:00
if (cache.initialized)
return;
const size_t size = from.size();
if (0 == size)
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Empty arrays are illegal in function {}", getName());
2020-07-21 13:58:07 +00:00
std::lock_guard lock(cache.mutex);
2020-07-21 13:58:07 +00:00
if (cache.initialized)
return;
2018-08-27 16:31:45 +00:00
if (size != to.size())
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Second and third arguments of function {} must be arrays of same size", getName());
Array converted_to;
const Array * used_to = &to;
2017-05-27 15:45:25 +00:00
/// Whether the default value is set.
if (arguments.size() == 4)
{
2020-10-19 15:27:41 +00:00
const IColumn * default_col = arguments[3].column.get();
ColumnConst unification (#1011) * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * Fixed error in ColumnArray::replicateGeneric [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150].
2017-07-21 06:35:58 +00:00
const ColumnConst * const_default_col = typeid_cast<const ColumnConst *>(default_col);
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];
ColumnConst unification (#1011) * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * Fixed error in ColumnArray::replicateGeneric [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150].
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 =
ColumnConst unification (#1011) * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * Fixed error in ColumnArray::replicateGeneric [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150].
2017-07-21 06:35:58 +00:00
checkColumn<ColumnFloat32>(default_col)
|| checkColumn<ColumnFloat64>(default_col)
|| checkColumnConst<ColumnFloat32>(default_col)
|| checkColumnConst<ColumnFloat64>(default_col);
2015-06-03 03:55:29 +00:00
bool to_is_float = to[0].getType() == Field::Types::Float64;
2015-06-03 03:55:29 +00:00
if (default_col_is_float && !to_is_float)
{
2018-08-27 16:31:45 +00:00
converted_to.resize(size);
for (size_t i = 0; i < size; ++i)
Squashed commit of the following: commit c567d4e1fe8d54e6363e47548f1e3927cc5ee78f Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Fri Jan 6 20:35:01 2017 +0300 Style [#METR-2944]. commit 26bf3e1228e03f46c29b13edb0e3770bd453e3f1 Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Fri Jan 6 20:33:11 2017 +0300 Miscellaneous [#METR-2944]. commit eb946f4c6fd4bb0e9e5c7fb1468d36be3dfca5a5 Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Fri Jan 6 20:30:19 2017 +0300 Miscellaneous [#METR-2944]. commit 78c867a14744b5af2db8d37caf7804fc2057ea51 Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Fri Jan 6 20:11:41 2017 +0300 Miscellaneous [#METR-2944]. commit 6604c5c83cfcedc81c8da4da026711920d5963b4 Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Fri Jan 6 19:56:15 2017 +0300 Miscellaneous [#METR-2944]. commit 23fbf05c1d4bead636458ec21b05a101b1152e33 Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Fri Jan 6 19:47:52 2017 +0300 Miscellaneous [#METR-2944]. commit 98772faf11a7d450d473f7fa84f8a9ae24f7b59b Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Fri Jan 6 19:46:05 2017 +0300 Miscellaneous [#METR-2944]. commit 3dc636ab9f9359dbeac2e8d997ae563d4ca147e2 Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Fri Jan 6 19:39:46 2017 +0300 Miscellaneous [#METR-2944]. commit 3e16aee95482f374ee3eda1a4dbe9ba5cdce02e8 Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Fri Jan 6 19:38:03 2017 +0300 Miscellaneous [#METR-2944]. commit ae7e7e90eb1f82bd0fe0f887708d08b9e7755612 Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Fri Jan 6 19:34:15 2017 +0300 Miscellaneous [#METR-2944].
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);
}
}
ColumnConst unification (#1011) * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * Fixed error in ColumnArray::replicateGeneric [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150].
2017-07-21 06:35:58 +00:00
/// Note: Doesn't check the duplicates in the `from` array.
const IDataType & from_type = *arguments[0].type;
if (from[0].getType() != Field::Types::String)
{
if (to[0].getType() != Field::Types::String)
2019-12-17 10:19:21 +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]);
}
2019-12-17 10:19:21 +00:00
}
else
{
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;
}
}
}
else
{
if (to[0].getType() != Field::Types::String)
{
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]);
}
}
else
{
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;
}
}
}
2020-07-21 13:58:07 +00:00
cache.initialized = true;
}
};
2020-09-07 18:00:37 +00:00
}
REGISTER_FUNCTION(Transform)
{
factory.registerFunction<FunctionTransform>();
}
}