mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-23 16:12:01 +00:00
fixed tests and dealt with nulls
This commit is contained in:
parent
ba5e26aebf
commit
966f07bd8e
@ -565,10 +565,9 @@ ColumnPtr FunctionArrayIntersect::execute(const UnpackedArrays & arrays, Mutable
|
||||
all_has_nullable = false;
|
||||
}
|
||||
|
||||
for (size_t arg_num = 0; arg_num < 1; ++arg_num)
|
||||
{
|
||||
all_has_nullable = all_nullable;
|
||||
const auto & arg = arrays.args[arg_num];
|
||||
// We have NULL in output only once if it should be there
|
||||
bool null_added = false;
|
||||
const auto & arg = arrays.args[0];
|
||||
size_t off;
|
||||
// const array has only one row
|
||||
if (arg.is_const)
|
||||
@ -576,26 +575,32 @@ ColumnPtr FunctionArrayIntersect::execute(const UnpackedArrays & arrays, Mutable
|
||||
else
|
||||
off = (*arg.offsets)[row];
|
||||
|
||||
for (auto i : collections::range(prev_off[arg_num], off))
|
||||
for (auto i : collections::range(prev_off[0], off))
|
||||
{
|
||||
all_has_nullable = all_nullable;
|
||||
current_has_nullable = false;
|
||||
typename Map::LookupResult pair = nullptr;
|
||||
|
||||
if (arg.null_map && (*arg.null_map)[i])
|
||||
{
|
||||
current_has_nullable = true;
|
||||
if (null_added)
|
||||
continue;
|
||||
}
|
||||
else if constexpr (is_numeric_column)
|
||||
{
|
||||
pair = map.find(columns[arg_num]->getElement(i));
|
||||
pair = map.find(columns[0]->getElement(i));
|
||||
}
|
||||
else if constexpr (std::is_same_v<ColumnType, ColumnString> || std::is_same_v<ColumnType, ColumnFixedString>)
|
||||
pair = map.find(columns[arg_num]->getDataAt(i));
|
||||
pair = map.find(columns[0]->getDataAt(i));
|
||||
else
|
||||
{
|
||||
const char * data = nullptr;
|
||||
pair = map.find(columns[arg_num]->serializeValueIntoArena(i, arena, data));
|
||||
pair = map.find(columns[0]->serializeValueIntoArena(i, arena, data));
|
||||
}
|
||||
|
||||
prev_off[arg_num] = off;
|
||||
prev_off[0] = off;
|
||||
if (arg.is_const)
|
||||
prev_off[arg_num] = 0;
|
||||
prev_off[0] = 0;
|
||||
|
||||
if (!current_has_nullable)
|
||||
all_has_nullable = false;
|
||||
@ -606,14 +611,14 @@ ColumnPtr FunctionArrayIntersect::execute(const UnpackedArrays & arrays, Mutable
|
||||
++result_offset;
|
||||
if constexpr (is_numeric_column)
|
||||
{
|
||||
if (pair->getKey() == columns[arg_num]->getElement(i))
|
||||
if (pair->getKey() == columns[0]->getElement(i))
|
||||
{
|
||||
result_data.insertValue(pair->getKey());
|
||||
}
|
||||
}
|
||||
else if constexpr (std::is_same_v<ColumnType, ColumnString> || std::is_same_v<ColumnType, ColumnFixedString>)
|
||||
{
|
||||
if (pair->getKey() == columns[arg_num]->getDataAt(i))
|
||||
if (pair->getKey() == columns[0]->getDataAt(i))
|
||||
{
|
||||
result_data.insertData(pair->getKey().data, pair->getKey().size);
|
||||
}
|
||||
@ -621,32 +626,30 @@ ColumnPtr FunctionArrayIntersect::execute(const UnpackedArrays & arrays, Mutable
|
||||
else
|
||||
{
|
||||
const char * data = nullptr;
|
||||
if (pair->getKey() == columns[arg_num]->serializeValueIntoArena(i, arena, data))
|
||||
if (pair->getKey() == columns[0]->serializeValueIntoArena(i, arena, data))
|
||||
{
|
||||
result_data.deserializeAndInsertFromArena(pair->getKey().data);
|
||||
}
|
||||
}
|
||||
if (all_nullable)
|
||||
null_map.push_back(0);
|
||||
// std::cerr << "========== " << current_has_nullable << std::endl;
|
||||
}
|
||||
if (all_has_nullable)
|
||||
if (all_has_nullable && !null_added)
|
||||
{
|
||||
++result_offset;
|
||||
result_data.insertDefault();
|
||||
null_map.push_back(1);
|
||||
null_added = true;
|
||||
}
|
||||
}
|
||||
result_offsets.getElement(row) = result_offset;
|
||||
|
||||
}
|
||||
}
|
||||
ColumnPtr result_column = std::move(result_data_ptr);
|
||||
if (all_nullable)
|
||||
result_column = ColumnNullable::create(result_column, std::move(null_map_column));
|
||||
return ColumnArray::create(result_column, std::move(result_offsets_ptr));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
[1]
|
||||
[1]
|
||||
[1]
|
||||
[NULL,1]
|
||||
[1,NULL]
|
||||
[1]
|
||||
[1]
|
||||
[[1,1]]
|
||||
|
Loading…
Reference in New Issue
Block a user