| 879 | } |
| 880 | |
| 881 | ColumnPtr executeForNullThenElse(const ColumnsWithTypeAndName & arguments, const DataTypePtr & result_type, size_t input_rows_count) const |
| 882 | { |
| 883 | const ColumnWithTypeAndName & arg_cond = arguments[0]; |
| 884 | const ColumnWithTypeAndName & arg_then = arguments[1]; |
| 885 | const ColumnWithTypeAndName & arg_else = arguments[2]; |
| 886 | |
| 887 | bool then_is_null = arg_then.column->onlyNull(); |
| 888 | bool else_is_null = arg_else.column->onlyNull(); |
| 889 | |
| 890 | if (!then_is_null && !else_is_null) |
| 891 | return nullptr; |
| 892 | |
| 893 | if (then_is_null && else_is_null) |
| 894 | return result_type->createColumnConstWithDefaultValue(input_rows_count); |
| 895 | |
| 896 | bool then_is_short = arg_then.column->size() < arg_cond.column->size(); |
| 897 | bool else_is_short = arg_else.column->size() < arg_cond.column->size(); |
| 898 | |
| 899 | const ColumnUInt8 * cond_col = typeid_cast<const ColumnUInt8 *>(arg_cond.column.get()); |
| 900 | const ColumnConst * cond_const_col = checkAndGetColumnConst<ColumnVector<UInt8>>(arg_cond.column.get()); |
| 901 | |
| 902 | /// If then is NULL, we create Nullable column with null mask OR-ed with condition. |
| 903 | if (then_is_null) |
| 904 | { |
| 905 | if (cond_col) |
| 906 | { |
| 907 | auto arg_else_column = arg_else.column; |
| 908 | auto result_column = IColumn::mutate(std::move(arg_else_column)); |
| 909 | if (else_is_short) |
| 910 | result_column->expand(cond_col->getData(), true); |
| 911 | if (isColumnNullable(*arg_else.column)) |
| 912 | { |
| 913 | assert_cast<ColumnNullable &>(*result_column).applyNullMap(assert_cast<const ColumnUInt8 &>(*arg_cond.column)); |
| 914 | return result_column; |
| 915 | } |
| 916 | else |
| 917 | return ColumnNullable::create(materializeColumnIfConst(result_column), arg_cond.column); |
| 918 | } |
| 919 | else if (cond_const_col) |
| 920 | { |
| 921 | if (cond_const_col->getValue<UInt8>()) |
| 922 | return result_type->createColumn()->cloneResized(input_rows_count); |
| 923 | else |
| 924 | return makeNullableColumnIfNot(arg_else.column); |
| 925 | } |
| 926 | else |
| 927 | throw Exception("Illegal column " + arg_cond.column->getName() + " of first argument of function " + getName() |
| 928 | + ". Must be ColumnUInt8 or ColumnConstUInt8.", |
| 929 | ErrorCodes::ILLEGAL_COLUMN); |
| 930 | } |
| 931 | |
| 932 | /// If else is NULL, we create Nullable column with null mask OR-ed with negated condition. |
| 933 | if (else_is_null) |
| 934 | { |
| 935 | if (cond_col) |
| 936 | { |
| 937 | auto arg_then_column = arg_then.column; |
| 938 | auto result_column = IColumn::mutate(std::move(arg_then_column)); |
nothing calls this directly
no test coverage detected