Fix some tests.

This commit is contained in:
Nikolai Kochetov 2021-07-19 15:35:55 +03:00
parent d996d0bae9
commit 96e20e2641
9 changed files with 30 additions and 19 deletions

View File

@ -36,6 +36,7 @@ public:
bool isParametric() const override { return true; } bool isParametric() const override { return true; }
bool cannotBeStoredInTables() const override { return true; } bool cannotBeStoredInTables() const override { return true; }
bool isCategorial() const override { return false; } bool isCategorial() const override { return false; }
bool canBeInsideNullable() const override { return true; }
}; };
} }

View File

@ -18,6 +18,7 @@
#include <Parsers/ASTSubquery.h> #include <Parsers/ASTSubquery.h>
#include <Parsers/ASTTablesInSelectQuery.h> #include <Parsers/ASTTablesInSelectQuery.h>
#include <Parsers/ASTWithElement.h> #include <Parsers/ASTWithElement.h>
#include <Parsers/queryToString.h>
#include <Processors/Executors/PullingAsyncPipelineExecutor.h> #include <Processors/Executors/PullingAsyncPipelineExecutor.h>
namespace DB namespace DB
@ -136,11 +137,9 @@ void ExecuteScalarSubqueriesMatcher::visit(const ASTSubquery & subquery, ASTPtr
type = makeNullable(type); type = makeNullable(type);
} }
/// Interpret subquery with empty result as Null literal ASTPtr ast_new = std::make_shared<ASTLiteral>(Null());
auto ast_new = makeASTFunction( ast_new = addTypeConversionToAST(std::move(ast_new), type->getName());
"CAST",
std::make_unique<ASTLiteral>(Null()),
std::make_unique<ASTLiteral>(type->getName()));
ast_new->setAlias(ast->tryGetAlias()); ast_new->setAlias(ast->tryGetAlias());
ast = std::move(ast_new); ast = std::move(ast_new);
return; return;

View File

@ -39,9 +39,12 @@ static bool tryExtractConstValueFromCondition(const ASTPtr & condition, bool & v
const ASTPtr & type_ast = expr_list->children.at(1); const ASTPtr & type_ast = expr_list->children.at(1);
if (const auto * type_literal = type_ast->as<ASTLiteral>()) if (const auto * type_literal = type_ast->as<ASTLiteral>())
{ {
if (type_literal->value.getType() == Field::Types::String && if (type_literal->value.getType() == Field::Types::String)
type_literal->value.get<std::string>() == "UInt8") {
return tryExtractConstValueFromCondition(expr_list->children.at(0), value); const auto & type_str = type_literal->value.get<std::string>();
if (type_str == "UInt8" || type_str == "Nullable(UInt8)")
return tryExtractConstValueFromCondition(expr_list->children.at(0), value);
}
} }
} }
} }

View File

@ -478,6 +478,11 @@ bool KeyCondition::getConstant(const ASTPtr & expr, Block & block_with_constants
/// Simple literal /// Simple literal
out_value = lit->value; out_value = lit->value;
out_type = block_with_constants.getByName(column_name).type; out_type = block_with_constants.getByName(column_name).type;
/// If constant is not Null, we can assume it's type is not Nullable as well.
if (!out_value.isNull())
out_type = removeNullable(out_type);
return true; return true;
} }
else if (block_with_constants.has(column_name) && isColumnConst(*block_with_constants.getByName(column_name).column)) else if (block_with_constants.has(column_name) && isColumnConst(*block_with_constants.getByName(column_name).column))
@ -486,6 +491,10 @@ bool KeyCondition::getConstant(const ASTPtr & expr, Block & block_with_constants
const auto & expr_info = block_with_constants.getByName(column_name); const auto & expr_info = block_with_constants.getByName(column_name);
out_value = (*expr_info.column)[0]; out_value = (*expr_info.column)[0];
out_type = expr_info.type; out_type = expr_info.type;
if (!out_value.isNull())
out_type = removeNullable(out_type);
return true; return true;
} }
else else

View File

@ -2,7 +2,7 @@ SELECT 1
WHERE 0 WHERE 0
SELECT 1 SELECT 1
SELECT 1 SELECT 1
WHERE (1 IN (0, 2)) AND (2 = (identity(CAST(2, \'UInt8\')) AS subquery)) WHERE (1 IN (0, 2)) AND (2 = (identity(CAST(2, \'Nullable(UInt8)\')) AS subquery))
SELECT 1 SELECT 1
WHERE 1 IN (( WHERE 1 IN ((
SELECT arrayJoin([1, 2, 3]) SELECT arrayJoin([1, 2, 3])

View File

@ -5,7 +5,7 @@ SELECT (SELECT * FROM system.numbers LIMIT 1 OFFSET 1) AS n, toUInt64(10 / n) FO
1,10 1,10
EXPLAIN SYNTAX SELECT (SELECT * FROM system.numbers LIMIT 1 OFFSET 1) AS n, toUInt64(10 / n); EXPLAIN SYNTAX SELECT (SELECT * FROM system.numbers LIMIT 1 OFFSET 1) AS n, toUInt64(10 / n);
SELECT SELECT
identity(CAST(0, \'UInt64\')) AS n, identity(CAST(0, \'Nullable(UInt64)\')) AS n,
toUInt64(10 / n) toUInt64(10 / n)
SELECT * FROM (WITH (SELECT * FROM system.numbers LIMIT 1 OFFSET 1) AS n, toUInt64(10 / n) as q SELECT * FROM system.one WHERE q > 0); SELECT * FROM (WITH (SELECT * FROM system.numbers LIMIT 1 OFFSET 1) AS n, toUInt64(10 / n) as q SELECT * FROM system.one WHERE q > 0);
0 0

View File

@ -55,7 +55,7 @@ WHERE (query_id =
WHERE current_database = currentDatabase() AND (query LIKE '%test cpu time query profiler%') AND (query NOT LIKE '%system%') WHERE current_database = currentDatabase() AND (query LIKE '%test cpu time query profiler%') AND (query NOT LIKE '%system%')
ORDER BY event_time DESC ORDER BY event_time DESC
LIMIT 1 LIMIT 1
)) AND (symbol LIKE '%Source%'); )) AND (symbol LIKE '%Source%'); -- { serverError 125 }
WITH addressToSymbol(arrayJoin(trace)) AS symbol WITH addressToSymbol(arrayJoin(trace)) AS symbol
@ -70,7 +70,7 @@ WHERE greaterOrEquals(event_date, ignore(ignore(ignore(NULL, '')), 256), yesterd
WHERE current_database = currentDatabase() AND (event_date >= yesterday()) AND (query LIKE '%test memory profiler%') WHERE current_database = currentDatabase() AND (event_date >= yesterday()) AND (query LIKE '%test memory profiler%')
ORDER BY event_time DESC ORDER BY event_time DESC
LIMIT 1 LIMIT 1
)); -- { serverError 42 } )); -- { serverError 125 }
DROP TABLE IF EXISTS trace_log; DROP TABLE IF EXISTS trace_log;

View File

@ -1,17 +1,17 @@
(0, 2) (0, 2)
0 0 0 0
0 0 0 0
WITH CAST(\'default\', \'String\') AS id_no SELECT one.dummy, ignore(id_no) FROM system.one WHERE dummy IN (0, 2) WITH CAST(\'default\', \'Nullable(String)\') AS id_no SELECT one.dummy, ignore(id_no) FROM system.one WHERE dummy IN (0, 2)
WITH CAST(\'default\', \'String\') AS id_no SELECT one.dummy, ignore(id_no) FROM system.one WHERE dummy IN (0, 2) WITH CAST(\'default\', \'Nullable(String)\') AS id_no SELECT one.dummy, ignore(id_no) FROM system.one WHERE dummy IN (0, 2)
optimize_skip_unused_shards_rewrite_in(0, 2) optimize_skip_unused_shards_rewrite_in(0, 2)
0 0 0 0
WITH CAST(\'default\', \'String\') AS id_02 SELECT one.dummy, ignore(id_02) FROM system.one WHERE dummy IN tuple(0) WITH CAST(\'default\', \'Nullable(String)\') AS id_02 SELECT one.dummy, ignore(id_02) FROM system.one WHERE dummy IN tuple(0)
WITH CAST(\'default\', \'String\') AS id_02 SELECT one.dummy, ignore(id_02) FROM system.one WHERE dummy IN tuple(2) WITH CAST(\'default\', \'Nullable(String)\') AS id_02 SELECT one.dummy, ignore(id_02) FROM system.one WHERE dummy IN tuple(2)
optimize_skip_unused_shards_rewrite_in(2,) optimize_skip_unused_shards_rewrite_in(2,)
WITH CAST(\'default\', \'String\') AS id_2 SELECT one.dummy, ignore(id_2) FROM system.one WHERE dummy IN tuple(2) WITH CAST(\'default\', \'Nullable(String)\') AS id_2 SELECT one.dummy, ignore(id_2) FROM system.one WHERE dummy IN tuple(2)
optimize_skip_unused_shards_rewrite_in(0,) optimize_skip_unused_shards_rewrite_in(0,)
0 0 0 0
WITH CAST(\'default\', \'String\') AS id_0 SELECT one.dummy, ignore(id_0) FROM system.one WHERE dummy IN tuple(0) WITH CAST(\'default\', \'Nullable(String)\') AS id_0 SELECT one.dummy, ignore(id_0) FROM system.one WHERE dummy IN tuple(0)
0 0
0 0
errors errors