Fix bug function mapContains

This commit is contained in:
Pavel Kruglov 2021-06-08 15:27:51 +03:00
parent 86759753e0
commit 7dcbf7dbcd
3 changed files with 10 additions and 4 deletions

View File

@ -182,18 +182,20 @@ public:
ColumnPtr executeImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr & result_type, size_t input_rows_count) const override ColumnPtr executeImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr & result_type, size_t input_rows_count) const override
{ {
const ColumnMap * col_map = typeid_cast<const ColumnMap *>(arguments[0].column.get()); bool is_const = isColumnConst(*arguments[0].column);
const ColumnMap * col_map = is_const ? checkAndGetColumnConstData<ColumnMap>(arguments[0].column.get()) : checkAndGetColumn<ColumnMap>(arguments[0].column.get());
if (!col_map) if (!col_map)
return nullptr; throw Exception{"First argument for function " + getName() + " must be a map", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT};
const auto & nested_column = col_map->getNestedColumn(); const auto & nested_column = col_map->getNestedColumn();
const auto & keys_data = col_map->getNestedData().getColumn(0); const auto & keys_data = col_map->getNestedData().getColumn(0);
/// Prepare arguments to call arrayIndex for check has the array element. /// Prepare arguments to call arrayIndex for check has the array element.
ColumnPtr column_array = ColumnArray::create(keys_data.getPtr(), nested_column.getOffsetsPtr());
ColumnsWithTypeAndName new_arguments = ColumnsWithTypeAndName new_arguments =
{ {
{ {
ColumnArray::create(keys_data.getPtr(), nested_column.getOffsetsPtr()), is_const ? ColumnConst::create(std::move(column_array), keys_data.size()) : std::move(column_array),
std::make_shared<DataTypeArray>(result_type), std::make_shared<DataTypeArray>(result_type),
"" ""
}, },

View File

@ -19,3 +19,5 @@
[1002] [1002]
{'aa':4,'bb':5} ['aa','bb'] [4,5] {'aa':4,'bb':5} ['aa','bb'] [4,5]
{'aa':4,'bb':5} 1 0 {'aa':4,'bb':5} 1 0
{0:0} 1
{0:0} 0

View File

@ -24,4 +24,6 @@ drop table if exists table_map;
-- Const column -- Const column
select map( 'aa', 4, 'bb' , 5) as m, mapKeys(m), mapValues(m); select map( 'aa', 4, 'bb' , 5) as m, mapKeys(m), mapValues(m);
select map( 'aa', 4, 'bb' , 5) as m, mapContains(m, 'aa'), mapContains(m, 'k'); select map( 'aa', 4, 'bb' , 5) as m, mapContains(m, 'aa'), mapContains(m, 'k');
select map(0, 0) as m, mapContains(m, number % 2) from numbers(2);