be/src/exprs/function/cast/function_cast_bool.cpp
Line | Count | Source |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | |
18 | | #include "exprs/function/cast/cast_to_boolean.h" |
19 | | |
20 | | namespace doris::CastWrapper { |
21 | | |
22 | 32 | WrapperType create_boolean_wrapper(FunctionContext* context, const DataTypePtr& from_type) { |
23 | 32 | std::shared_ptr<CastToBase> cast_to_bool; |
24 | | |
25 | 32 | auto make_bool_wrapper = [&](const auto& types) -> bool { |
26 | 32 | using Types = std::decay_t<decltype(types)>; |
27 | 32 | using FromDataType = typename Types::LeftType; |
28 | 32 | if constexpr (CastUtil::IsBaseCastFromType<FromDataType>) { |
29 | 32 | if (context->enable_strict_mode()) { |
30 | 21 | cast_to_bool = std::make_shared< |
31 | 21 | CastToImpl<CastModeType::StrictMode, FromDataType, DataTypeBool>>(); |
32 | 21 | } else { |
33 | 11 | cast_to_bool = std::make_shared< |
34 | 11 | CastToImpl<CastModeType::NonStrictMode, FromDataType, DataTypeBool>>(); |
35 | 11 | } |
36 | 32 | return true; |
37 | 32 | } else { |
38 | 0 | return false; |
39 | 0 | } |
40 | 32 | }; Unexecuted instantiation: function_cast_bool.cpp:_ZZN5doris11CastWrapper22create_boolean_wrapperEPNS_15FunctionContextERKSt10shared_ptrIKNS_9IDataTypeEEENK3$_1clINS_8TypePairINS_14DataTypeNumberILNS_13PrimitiveTypeE2EEEvEEEEbRKT_ Unexecuted instantiation: function_cast_bool.cpp:_ZZN5doris11CastWrapper22create_boolean_wrapperEPNS_15FunctionContextERKSt10shared_ptrIKNS_9IDataTypeEEENK3$_1clINS_8TypePairINS_14DataTypeNumberILNS_13PrimitiveTypeE3EEEvEEEEbRKT_ Unexecuted instantiation: function_cast_bool.cpp:_ZZN5doris11CastWrapper22create_boolean_wrapperEPNS_15FunctionContextERKSt10shared_ptrIKNS_9IDataTypeEEENK3$_1clINS_8TypePairINS_14DataTypeNumberILNS_13PrimitiveTypeE4EEEvEEEEbRKT_ function_cast_bool.cpp:_ZZN5doris11CastWrapper22create_boolean_wrapperEPNS_15FunctionContextERKSt10shared_ptrIKNS_9IDataTypeEEENK3$_1clINS_8TypePairINS_14DataTypeNumberILNS_13PrimitiveTypeE5EEEvEEEEbRKT_ Line | Count | Source | 25 | 2 | auto make_bool_wrapper = [&](const auto& types) -> bool { | 26 | 2 | using Types = std::decay_t<decltype(types)>; | 27 | 2 | using FromDataType = typename Types::LeftType; | 28 | 2 | if constexpr (CastUtil::IsBaseCastFromType<FromDataType>) { | 29 | 2 | if (context->enable_strict_mode()) { | 30 | 1 | cast_to_bool = std::make_shared< | 31 | 1 | CastToImpl<CastModeType::StrictMode, FromDataType, DataTypeBool>>(); | 32 | 1 | } else { | 33 | 1 | cast_to_bool = std::make_shared< | 34 | 1 | CastToImpl<CastModeType::NonStrictMode, FromDataType, DataTypeBool>>(); | 35 | 1 | } | 36 | 2 | return true; | 37 | | } else { | 38 | | return false; | 39 | | } | 40 | 2 | }; |
function_cast_bool.cpp:_ZZN5doris11CastWrapper22create_boolean_wrapperEPNS_15FunctionContextERKSt10shared_ptrIKNS_9IDataTypeEEENK3$_1clINS_8TypePairINS_14DataTypeNumberILNS_13PrimitiveTypeE6EEEvEEEEbRKT_ Line | Count | Source | 25 | 2 | auto make_bool_wrapper = [&](const auto& types) -> bool { | 26 | 2 | using Types = std::decay_t<decltype(types)>; | 27 | 2 | using FromDataType = typename Types::LeftType; | 28 | 2 | if constexpr (CastUtil::IsBaseCastFromType<FromDataType>) { | 29 | 2 | if (context->enable_strict_mode()) { | 30 | 1 | cast_to_bool = std::make_shared< | 31 | 1 | CastToImpl<CastModeType::StrictMode, FromDataType, DataTypeBool>>(); | 32 | 1 | } else { | 33 | 1 | cast_to_bool = std::make_shared< | 34 | 1 | CastToImpl<CastModeType::NonStrictMode, FromDataType, DataTypeBool>>(); | 35 | 1 | } | 36 | 2 | return true; | 37 | | } else { | 38 | | return false; | 39 | | } | 40 | 2 | }; |
function_cast_bool.cpp:_ZZN5doris11CastWrapper22create_boolean_wrapperEPNS_15FunctionContextERKSt10shared_ptrIKNS_9IDataTypeEEENK3$_1clINS_8TypePairINS_14DataTypeNumberILNS_13PrimitiveTypeE7EEEvEEEEbRKT_ Line | Count | Source | 25 | 2 | auto make_bool_wrapper = [&](const auto& types) -> bool { | 26 | 2 | using Types = std::decay_t<decltype(types)>; | 27 | 2 | using FromDataType = typename Types::LeftType; | 28 | 2 | if constexpr (CastUtil::IsBaseCastFromType<FromDataType>) { | 29 | 2 | if (context->enable_strict_mode()) { | 30 | 1 | cast_to_bool = std::make_shared< | 31 | 1 | CastToImpl<CastModeType::StrictMode, FromDataType, DataTypeBool>>(); | 32 | 1 | } else { | 33 | 1 | cast_to_bool = std::make_shared< | 34 | 1 | CastToImpl<CastModeType::NonStrictMode, FromDataType, DataTypeBool>>(); | 35 | 1 | } | 36 | 2 | return true; | 37 | | } else { | 38 | | return false; | 39 | | } | 40 | 2 | }; |
function_cast_bool.cpp:_ZZN5doris11CastWrapper22create_boolean_wrapperEPNS_15FunctionContextERKSt10shared_ptrIKNS_9IDataTypeEEENK3$_1clINS_8TypePairINS_14DataTypeNumberILNS_13PrimitiveTypeE8EEEvEEEEbRKT_ Line | Count | Source | 25 | 2 | auto make_bool_wrapper = [&](const auto& types) -> bool { | 26 | 2 | using Types = std::decay_t<decltype(types)>; | 27 | 2 | using FromDataType = typename Types::LeftType; | 28 | 2 | if constexpr (CastUtil::IsBaseCastFromType<FromDataType>) { | 29 | 2 | if (context->enable_strict_mode()) { | 30 | 1 | cast_to_bool = std::make_shared< | 31 | 1 | CastToImpl<CastModeType::StrictMode, FromDataType, DataTypeBool>>(); | 32 | 1 | } else { | 33 | 1 | cast_to_bool = std::make_shared< | 34 | 1 | CastToImpl<CastModeType::NonStrictMode, FromDataType, DataTypeBool>>(); | 35 | 1 | } | 36 | 2 | return true; | 37 | | } else { | 38 | | return false; | 39 | | } | 40 | 2 | }; |
function_cast_bool.cpp:_ZZN5doris11CastWrapper22create_boolean_wrapperEPNS_15FunctionContextERKSt10shared_ptrIKNS_9IDataTypeEEENK3$_1clINS_8TypePairINS_14DataTypeNumberILNS_13PrimitiveTypeE9EEEvEEEEbRKT_ Line | Count | Source | 25 | 2 | auto make_bool_wrapper = [&](const auto& types) -> bool { | 26 | 2 | using Types = std::decay_t<decltype(types)>; | 27 | 2 | using FromDataType = typename Types::LeftType; | 28 | 2 | if constexpr (CastUtil::IsBaseCastFromType<FromDataType>) { | 29 | 2 | if (context->enable_strict_mode()) { | 30 | 1 | cast_to_bool = std::make_shared< | 31 | 1 | CastToImpl<CastModeType::StrictMode, FromDataType, DataTypeBool>>(); | 32 | 1 | } else { | 33 | 1 | cast_to_bool = std::make_shared< | 34 | 1 | CastToImpl<CastModeType::NonStrictMode, FromDataType, DataTypeBool>>(); | 35 | 1 | } | 36 | 2 | return true; | 37 | | } else { | 38 | | return false; | 39 | | } | 40 | 2 | }; |
function_cast_bool.cpp:_ZZN5doris11CastWrapper22create_boolean_wrapperEPNS_15FunctionContextERKSt10shared_ptrIKNS_9IDataTypeEEENK3$_1clINS_8TypePairINS_15DataTypeDecimalILNS_13PrimitiveTypeE28EEEvEEEEbRKT_ Line | Count | Source | 25 | 2 | auto make_bool_wrapper = [&](const auto& types) -> bool { | 26 | 2 | using Types = std::decay_t<decltype(types)>; | 27 | 2 | using FromDataType = typename Types::LeftType; | 28 | 2 | if constexpr (CastUtil::IsBaseCastFromType<FromDataType>) { | 29 | 2 | if (context->enable_strict_mode()) { | 30 | 1 | cast_to_bool = std::make_shared< | 31 | 1 | CastToImpl<CastModeType::StrictMode, FromDataType, DataTypeBool>>(); | 32 | 1 | } else { | 33 | 1 | cast_to_bool = std::make_shared< | 34 | 1 | CastToImpl<CastModeType::NonStrictMode, FromDataType, DataTypeBool>>(); | 35 | 1 | } | 36 | 2 | return true; | 37 | | } else { | 38 | | return false; | 39 | | } | 40 | 2 | }; |
function_cast_bool.cpp:_ZZN5doris11CastWrapper22create_boolean_wrapperEPNS_15FunctionContextERKSt10shared_ptrIKNS_9IDataTypeEEENK3$_1clINS_8TypePairINS_15DataTypeDecimalILNS_13PrimitiveTypeE29EEEvEEEEbRKT_ Line | Count | Source | 25 | 2 | auto make_bool_wrapper = [&](const auto& types) -> bool { | 26 | 2 | using Types = std::decay_t<decltype(types)>; | 27 | 2 | using FromDataType = typename Types::LeftType; | 28 | 2 | if constexpr (CastUtil::IsBaseCastFromType<FromDataType>) { | 29 | 2 | if (context->enable_strict_mode()) { | 30 | 1 | cast_to_bool = std::make_shared< | 31 | 1 | CastToImpl<CastModeType::StrictMode, FromDataType, DataTypeBool>>(); | 32 | 1 | } else { | 33 | 1 | cast_to_bool = std::make_shared< | 34 | 1 | CastToImpl<CastModeType::NonStrictMode, FromDataType, DataTypeBool>>(); | 35 | 1 | } | 36 | 2 | return true; | 37 | | } else { | 38 | | return false; | 39 | | } | 40 | 2 | }; |
function_cast_bool.cpp:_ZZN5doris11CastWrapper22create_boolean_wrapperEPNS_15FunctionContextERKSt10shared_ptrIKNS_9IDataTypeEEENK3$_1clINS_8TypePairINS_15DataTypeDecimalILNS_13PrimitiveTypeE20EEEvEEEEbRKT_ Line | Count | Source | 25 | 2 | auto make_bool_wrapper = [&](const auto& types) -> bool { | 26 | 2 | using Types = std::decay_t<decltype(types)>; | 27 | 2 | using FromDataType = typename Types::LeftType; | 28 | 2 | if constexpr (CastUtil::IsBaseCastFromType<FromDataType>) { | 29 | 2 | if (context->enable_strict_mode()) { | 30 | 1 | cast_to_bool = std::make_shared< | 31 | 1 | CastToImpl<CastModeType::StrictMode, FromDataType, DataTypeBool>>(); | 32 | 1 | } else { | 33 | 1 | cast_to_bool = std::make_shared< | 34 | 1 | CastToImpl<CastModeType::NonStrictMode, FromDataType, DataTypeBool>>(); | 35 | 1 | } | 36 | 2 | return true; | 37 | | } else { | 38 | | return false; | 39 | | } | 40 | 2 | }; |
function_cast_bool.cpp:_ZZN5doris11CastWrapper22create_boolean_wrapperEPNS_15FunctionContextERKSt10shared_ptrIKNS_9IDataTypeEEENK3$_1clINS_8TypePairINS_15DataTypeDecimalILNS_13PrimitiveTypeE30EEEvEEEEbRKT_ Line | Count | Source | 25 | 2 | auto make_bool_wrapper = [&](const auto& types) -> bool { | 26 | 2 | using Types = std::decay_t<decltype(types)>; | 27 | 2 | using FromDataType = typename Types::LeftType; | 28 | 2 | if constexpr (CastUtil::IsBaseCastFromType<FromDataType>) { | 29 | 2 | if (context->enable_strict_mode()) { | 30 | 1 | cast_to_bool = std::make_shared< | 31 | 1 | CastToImpl<CastModeType::StrictMode, FromDataType, DataTypeBool>>(); | 32 | 1 | } else { | 33 | 1 | cast_to_bool = std::make_shared< | 34 | 1 | CastToImpl<CastModeType::NonStrictMode, FromDataType, DataTypeBool>>(); | 35 | 1 | } | 36 | 2 | return true; | 37 | | } else { | 38 | | return false; | 39 | | } | 40 | 2 | }; |
function_cast_bool.cpp:_ZZN5doris11CastWrapper22create_boolean_wrapperEPNS_15FunctionContextERKSt10shared_ptrIKNS_9IDataTypeEEENK3$_1clINS_8TypePairINS_15DataTypeDecimalILNS_13PrimitiveTypeE35EEEvEEEEbRKT_ Line | Count | Source | 25 | 2 | auto make_bool_wrapper = [&](const auto& types) -> bool { | 26 | 2 | using Types = std::decay_t<decltype(types)>; | 27 | 2 | using FromDataType = typename Types::LeftType; | 28 | 2 | if constexpr (CastUtil::IsBaseCastFromType<FromDataType>) { | 29 | 2 | if (context->enable_strict_mode()) { | 30 | 1 | cast_to_bool = std::make_shared< | 31 | 1 | CastToImpl<CastModeType::StrictMode, FromDataType, DataTypeBool>>(); | 32 | 1 | } else { | 33 | 1 | cast_to_bool = std::make_shared< | 34 | 1 | CastToImpl<CastModeType::NonStrictMode, FromDataType, DataTypeBool>>(); | 35 | 1 | } | 36 | 2 | return true; | 37 | | } else { | 38 | | return false; | 39 | | } | 40 | 2 | }; |
Unexecuted instantiation: function_cast_bool.cpp:_ZZN5doris11CastWrapper22create_boolean_wrapperEPNS_15FunctionContextERKSt10shared_ptrIKNS_9IDataTypeEEENK3$_1clINS_8TypePairINS_12DataTypeDateEvEEEEbRKT_ Unexecuted instantiation: function_cast_bool.cpp:_ZZN5doris11CastWrapper22create_boolean_wrapperEPNS_15FunctionContextERKSt10shared_ptrIKNS_9IDataTypeEEENK3$_1clINS_8TypePairINS_14DataTypeDateV2EvEEEEbRKT_ Unexecuted instantiation: function_cast_bool.cpp:_ZZN5doris11CastWrapper22create_boolean_wrapperEPNS_15FunctionContextERKSt10shared_ptrIKNS_9IDataTypeEEENK3$_1clINS_8TypePairINS_18DataTypeDateTimeV2EvEEEEbRKT_ Unexecuted instantiation: function_cast_bool.cpp:_ZZN5doris11CastWrapper22create_boolean_wrapperEPNS_15FunctionContextERKSt10shared_ptrIKNS_9IDataTypeEEENK3$_1clINS_8TypePairINS_16DataTypeDateTimeEvEEEEbRKT_ Unexecuted instantiation: function_cast_bool.cpp:_ZZN5doris11CastWrapper22create_boolean_wrapperEPNS_15FunctionContextERKSt10shared_ptrIKNS_9IDataTypeEEENK3$_1clINS_8TypePairINS_14DataTypeTimeV2EvEEEEbRKT_ Unexecuted instantiation: function_cast_bool.cpp:_ZZN5doris11CastWrapper22create_boolean_wrapperEPNS_15FunctionContextERKSt10shared_ptrIKNS_9IDataTypeEEENK3$_1clINS_8TypePairINS_19DataTypeTimeStampTzEvEEEEbRKT_ Unexecuted instantiation: function_cast_bool.cpp:_ZZN5doris11CastWrapper22create_boolean_wrapperEPNS_15FunctionContextERKSt10shared_ptrIKNS_9IDataTypeEEENK3$_1clINS_8TypePairINS_12DataTypeIPv4EvEEEEbRKT_ Unexecuted instantiation: function_cast_bool.cpp:_ZZN5doris11CastWrapper22create_boolean_wrapperEPNS_15FunctionContextERKSt10shared_ptrIKNS_9IDataTypeEEENK3$_1clINS_8TypePairINS_12DataTypeIPv6EvEEEEbRKT_ function_cast_bool.cpp:_ZZN5doris11CastWrapper22create_boolean_wrapperEPNS_15FunctionContextERKSt10shared_ptrIKNS_9IDataTypeEEENK3$_1clINS_8TypePairINS_14DataTypeStringEvEEEEbRKT_ Line | Count | Source | 25 | 12 | auto make_bool_wrapper = [&](const auto& types) -> bool { | 26 | 12 | using Types = std::decay_t<decltype(types)>; | 27 | 12 | using FromDataType = typename Types::LeftType; | 28 | 12 | if constexpr (CastUtil::IsBaseCastFromType<FromDataType>) { | 29 | 12 | if (context->enable_strict_mode()) { | 30 | 11 | cast_to_bool = std::make_shared< | 31 | 11 | CastToImpl<CastModeType::StrictMode, FromDataType, DataTypeBool>>(); | 32 | 11 | } else { | 33 | 1 | cast_to_bool = std::make_shared< | 34 | 1 | CastToImpl<CastModeType::NonStrictMode, FromDataType, DataTypeBool>>(); | 35 | 1 | } | 36 | 12 | return true; | 37 | | } else { | 38 | | return false; | 39 | | } | 40 | 12 | }; |
|
41 | | |
42 | 32 | if (!call_on_index_and_data_type<void>(from_type->get_primitive_type(), make_bool_wrapper)) { |
43 | 0 | return create_unsupport_wrapper( |
44 | 0 | fmt::format("CAST AS bool not supported {}", from_type->get_name())); |
45 | 0 | } |
46 | | |
47 | 32 | return [cast_to_bool](FunctionContext* context, Block& block, const ColumnNumbers& arguments, |
48 | 32 | uint32_t result, size_t input_rows_count, |
49 | 32 | const NullMap::value_type* null_map = nullptr) { |
50 | 32 | return cast_to_bool->execute_impl(context, block, arguments, result, input_rows_count, |
51 | 32 | null_map); |
52 | 32 | }; |
53 | 32 | } |
54 | | |
55 | | } // namespace doris::CastWrapper |