mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 00:22:29 +00:00
Fix bug function mapContains
This commit is contained in:
parent
86759753e0
commit
7dcbf7dbcd
@ -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),
|
||||||
""
|
""
|
||||||
},
|
},
|
||||||
|
@ -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
|
||||||
|
@ -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);
|
||||||
|
Loading…
Reference in New Issue
Block a user