Fixed "join_use_nulls" mode #1544

This commit is contained in:
Alexey Milovidov 2017-12-25 03:38:45 +03:00
parent 671b731c90
commit a71b04e377
4 changed files with 36 additions and 2 deletions

View File

@ -51,7 +51,6 @@ public:
*/
ARRAY_JOIN,
/// INNER|LEFT JOIN.
JOIN,
/// Reorder and rename the columns, delete the extra ones. The same column names are allowed in the result.

View File

@ -15,6 +15,7 @@
#include <DataTypes/DataTypeSet.h>
#include <DataTypes/DataTypeArray.h>
#include <DataTypes/DataTypeNullable.h>
#include <DataTypes/DataTypeTuple.h>
#include <DataTypes/DataTypeExpression.h>
#include <DataTypes/DataTypeNested.h>
@ -2838,7 +2839,9 @@ void ExpressionAnalyzer::collectJoinedColumns(NameSet & joined_columns, NamesAnd
&& !joined_columns.count(col.name)) /// Duplicate columns in the subquery for JOIN do not make sense.
{
joined_columns.insert(col.name);
joined_columns_name_type.emplace_back(col.name, col.type);
bool make_nullable = settings.join_use_nulls && (table_join.kind == ASTTableJoin::Kind::Left || table_join.kind == ASTTableJoin::Kind::Full);
joined_columns_name_type.emplace_back(col.name, make_nullable ? makeNullable(col.type) : col.type);
}
}
}

View File

@ -0,0 +1,2 @@
0 0 \N
1 1 1

View File

@ -0,0 +1,30 @@
SET join_use_nulls = 1;
DROP TABLE IF EXISTS test.null;
CREATE TABLE test.null (k UInt64, a String, b Nullable(String)) ENGINE = Log;
INSERT INTO test.null SELECT
k,
a,
b
FROM
(
SELECT
number AS k,
toString(number) AS a
FROM system.numbers
LIMIT 2
)
ANY LEFT JOIN
(
SELECT
number AS k,
toString(number) AS b
FROM system.numbers
LIMIT 1, 2
) USING (k)
ORDER BY k ASC;
SELECT * FROM test.null ORDER BY k, a, b;
DROP TABLE test.null;