未验证 提交 6d2dca32 编写于 作者: A alexey-milovidov 提交者: GitHub

Merge pull request #6705 from 4ertus2/bugs

JOINs with not nullable types and join_use_nulls=1
......@@ -81,6 +81,16 @@ MutableColumnPtr ColumnTuple::cloneEmpty() const
return ColumnTuple::create(std::move(new_columns));
}
MutableColumnPtr ColumnTuple::cloneResized(size_t new_size) const
{
const size_t tuple_size = columns.size();
MutableColumns new_columns(tuple_size);
for (size_t i = 0; i < tuple_size; ++i)
new_columns[i] = columns[i]->cloneResized(new_size);
return ColumnTuple::create(std::move(new_columns));
}
Field ColumnTuple::operator[](size_t n) const
{
return Tuple{ext::map<TupleBackend>(columns, [n] (const auto & column) { return (*column)[n]; })};
......
......@@ -42,6 +42,7 @@ public:
const char * getFamilyName() const override { return "Tuple"; }
MutableColumnPtr cloneEmpty() const override;
MutableColumnPtr cloneResized(size_t size) const override;
size_t size() const override
{
......
......@@ -291,8 +291,8 @@ void ExpressionAction::prepare(Block & sample_block, const Settings & settings,
bool make_nullable = is_null_used_as_default && right_or_full_join;
if (make_nullable && !col.type->isNullable())
col.type = std::make_shared<DataTypeNullable>(col.type);
if (make_nullable && col.type->canBeInsideNullable())
col.type = makeNullable(col.type);
}
for (const auto & col : columns_added_by_join)
......@@ -316,8 +316,8 @@ void ExpressionAction::prepare(Block & sample_block, const Settings & settings,
}
}
if (make_nullable && !res_type->isNullable())
res_type = std::make_shared<DataTypeNullable>(res_type);
if (make_nullable && res_type->canBeInsideNullable())
res_type = makeNullable(res_type);
sample_block.insert(ColumnWithTypeAndName(nullptr, res_type, col.name));
}
......
......@@ -50,7 +50,7 @@ static std::unordered_map<String, DataTypePtr> requiredRightKeys(const Names & k
static void convertColumnToNullable(ColumnWithTypeAndName & column)
{
if (column.type->isNullable())
if (column.type->isNullable() || !column.type->canBeInsideNullable())
return;
column.type = makeNullable(column.type);
......@@ -71,7 +71,7 @@ static ColumnWithTypeAndName correctNullability(ColumnWithTypeAndName && column,
if (nullable)
{
convertColumnToNullable(column);
if (negative_null_map.size())
if (column.type->isNullable() && negative_null_map.size())
{
MutableColumnPtr mutable_column = (*std::move(column.column)).mutate();
assert_cast<ColumnNullable &>(*mutable_column).applyNegatedNullMap(negative_null_map);
......
0 ['left'] 0 ['left'] \N
1 ['left'] 1 ['left'] 1
2 [] \N [] 2
['left'] 0 ['left'] \N
['left'] 1 ['left'] 1
[] \N [] 2
['left'] 42 \N
['right'] \N 42
SET join_use_nulls = 1;
SELECT * FROM
(
SELECT number, ['left'] as ar, number AS left_number FROM system.numbers LIMIT 2
)
FULL JOIN
(
SELECT number, ['right'] as ar, number AS right_number FROM system.numbers LIMIT 1, 2
)
USING (number)
ORDER BY number;
SELECT * FROM
(
SELECT ['left'] as ar, number AS left_number FROM system.numbers LIMIT 2
)
FULL JOIN
(
SELECT ['right'] as ar, number AS right_number FROM system.numbers LIMIT 1, 2
)
ON left_number = right_number
ORDER BY left_number;
SELECT * FROM
(
SELECT ['left'] as ar, 42 AS left_number
)
FULL JOIN
(
SELECT ['right'] as ar, 42 AS right_number
)
USING(ar)
ORDER BY left_number;
a ('b','c') ('b','c')
d ('e','f') ('','')
a
x
a ('b','c') ('b','c')
x ('','') ('y','z')
a
d
a
x
a ('b','c') ('b','c')
d ('e','f') ('','')
a ('b','c') ('b','c')
x ('','') ('y','z')
a b ['b','c']
d e []
a b ['b','c']
x ['y','z']
a
d
a
x
a b ['b','c']
d e []
a b ['b','c']
x \N ['y','z']
DROP TABLE IF EXISTS l;
DROP TABLE IF EXISTS r;
CREATE TABLE l (a String, b Tuple(String, String)) ENGINE = Memory();
CREATE TABLE r (a String, c Tuple(String, String)) ENGINE = Memory();
INSERT INTO l (a, b) VALUES ('a', ('b', 'c')), ('d', ('e', 'f'));
INSERT INTO r (a, c) VALUES ('a', ('b', 'c')), ('x', ('y', 'z'));
SET join_use_nulls = 0;
SELECT * from l LEFT JOIN r USING a ORDER BY a;
SELECT a from l RIGHT JOIN r USING a ORDER BY a;
SELECT * from l RIGHT JOIN r USING a ORDER BY a;
SET join_use_nulls = 1;
SELECT a from l LEFT JOIN r USING a ORDER BY a;
SELECT a from l RIGHT JOIN r USING a ORDER BY a;
SELECT * from l LEFT JOIN r USING a ORDER BY a;
SELECT * from l RIGHT JOIN r USING a ORDER BY a;
DROP TABLE l;
DROP TABLE r;
CREATE TABLE l (a String, b String) ENGINE = Memory();
CREATE TABLE r (a String, c Array(String)) ENGINE = Memory();
INSERT INTO l (a, b) VALUES ('a', 'b'), ('d', 'e');
INSERT INTO r (a, c) VALUES ('a', ['b', 'c']), ('x', ['y', 'z']);
SET join_use_nulls = 0;
SELECT * from l LEFT JOIN r USING a ORDER BY a;
SELECT * from l RIGHT JOIN r USING a ORDER BY a;
SET join_use_nulls = 1;
SELECT a from l LEFT JOIN r USING a ORDER BY a;
SELECT a from l RIGHT JOIN r USING a ORDER BY a;
SELECT * from l LEFT JOIN r USING a ORDER BY a;
SELECT * from l RIGHT JOIN r USING a ORDER BY a;
DROP TABLE l;
DROP TABLE r;
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册