add tests and fix build

This commit is contained in:
Ruslan 2019-12-29 01:08:18 +03:00
parent bd01bdad97
commit af2b17fbcb
5 changed files with 2008 additions and 7 deletions

View File

@ -48,7 +48,7 @@ ASTs OptimizeIfChainsVisitor::IfChain(ASTPtr & child)
throw Exception("Wrong number of arguments for function 'if' (" + toString(args->children.size()) + " instead of 3)",
ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
if (args->children[2]->as<ASTFunction>() && args->children[2]->as<ASTFunction>()->name == "if" )
if (args->children[2]->as<ASTFunction>() && args->children[2]->as<ASTFunction>()->name == "if")
{
auto cur = IfChain(function_node->arguments->children[2]);
cur.push_back(function_node->arguments->children[1]);

View File

@ -9,16 +9,12 @@ namespace DB
class OptimizeIfChainsVisitor
{
public:
OptimizeIfChainsVisitor(Aliases & aliases_)
: aliases(aliases_)
{}
OptimizeIfChainsVisitor() = default;
void visit(ASTPtr & ast);
ASTs IfChain(ASTPtr & child);
private:
Aliases & aliases;
};
}

View File

@ -915,7 +915,7 @@ SyntaxAnalyzerResultPtr SyntaxAnalyzer::analyze(
/// Optimize if with constant condition after constants was substituted instead of scalar subqueries.
OptimizeIfWithConstantConditionVisitor(result.aliases).visit(query);
OptimizeIfChainsVisitor(result.aliases).visit(query);
OptimizeIfChainsVisitor().visit(query);
if (select_query)
{

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,3 @@
SELECT x FROM (SELECT number % 16 = 0 ? nan : (number % 24 = 0 ? NULL : (number % 37 = 0 ? nan : (number % 34 = 0 ? nan : (number % 3 = 0 ? NULL : (number % 68 = 0 ? 42 : (number % 28 = 0 ? nan : (number % 46 = 0 ? nan : (number % 13 = 0 ? nan : (number % 27 = 0 ? NULL : (number % 39 = 0 ? NULL : (number % 27 = 0 ? NULL : (number % 30 = 0 ? NULL : (number % 72 = 0 ? NULL : (number % 36 = 0 ? NULL : (number % 51 = 0 ? NULL : (number % 58 = 0 ? nan : (number % 26 = 0 ? 42 : (number % 13 = 0 ? nan : (number % 12 = 0 ? NULL : (number % 22 = 0 ? nan : (number % 36 = 0 ? NULL : (number % 63 = 0 ? NULL : (number % 27 = 0 ? NULL : (number % 18 = 0 ? NULL : (number % 69 = 0 ? NULL : (number % 76 = 0 ? nan : (number % 42 = 0 ? NULL : (number % 9 = 0 ? NULL : (toFloat64(number)))))))))))))))))))))))))))))) AS x FROM system.numbers LIMIT 1001) ORDER BY x ASC NULLS FIRST;
SELECT x FROM (SELECT number % 22 = 0 ? nan : (number % 56 = 0 ? 42 : (number % 45 = 0 ? NULL : (number % 47 = 0 ? 42 : (number % 39 = 0 ? NULL : (number % 1 = 0 ? nan : (number % 43 = 0 ? nan : (number % 40 = 0 ? nan : (number % 42 = 0 ? NULL : (number % 26 = 0 ? 42 : (number % 41 = 0 ? 42 : (number % 6 = 0 ? NULL : (number % 39 = 0 ? NULL : (number % 34 = 0 ? nan : (number % 74 = 0 ? 42 : (number % 40 = 0 ? nan : (number % 37 = 0 ? nan : (number % 51 = 0 ? NULL : (number % 46 = 0 ? nan : (toFloat64(number)))))))))))))))))))) AS x FROM system.numbers LIMIT 1001) ORDER BY x ASC NULLS FIRST;