add test case

This commit is contained in:
liuneng 2024-03-19 17:30:16 +08:00
parent a742b235a4
commit 532d72a7d8
6 changed files with 86 additions and 9 deletions

View File

@ -2,7 +2,7 @@
#include <Analyzer/ConstantNode.h>
#include <Analyzer/FunctionNode.h>
#include <Analyzer/InDepthQueryTreeVisitor.h>
#include <Analyzer/Passes/ConvertInToEqualsPass.h>
#include <Analyzer/Passes/ConvertInToEqualPass.h>
#include <Functions/FunctionsComparison.h>
#include <Functions/IFunctionAdaptors.h>
@ -11,10 +11,10 @@ namespace DB
using FunctionEquals = FunctionComparison<EqualsOp, NameEquals>;
class ConvertInToEqualsPassVisitor : public InDepthQueryTreeVisitorWithContext<ConvertInToEqualsPassVisitor>
class ConvertInToEqualPassVisitor : public InDepthQueryTreeVisitorWithContext<ConvertInToEqualPassVisitor>
{
public:
using Base = InDepthQueryTreeVisitorWithContext<ConvertInToEqualsPassVisitor>;
using Base = InDepthQueryTreeVisitorWithContext<ConvertInToEqualPassVisitor>;
using Base::Base;
FunctionOverloadResolverPtr createInternalFunctionEqualOverloadResolver()
@ -47,9 +47,9 @@ public:
}
};
void ConvertInToEqualsPass::run(QueryTreeNodePtr & query_tree_node, ContextPtr context)
void ConvertInToEqualPass::run(QueryTreeNodePtr & query_tree_node, ContextPtr context)
{
ConvertInToEqualsPassVisitor visitor(std::move(context));
ConvertInToEqualPassVisitor visitor(std::move(context));
visitor.visit(query_tree_node);
}
}

View File

@ -10,9 +10,9 @@ namespace DB {
* Result: SELECT * from test where x = 1;
*
*/
class ConvertInToEqualsPass final : public IQueryTreePass {
class ConvertInToEqualPass final : public IQueryTreePass {
public:
String getName() override { return "ConvertInToEqualsPass"; }
String getName() override { return "ConvertInToEqualPass"; }
String getDescription() override { return "Convert in to equal"; }

View File

@ -28,7 +28,7 @@
#include <Analyzer/Passes/MultiIfToIfPass.h>
#include <Analyzer/Passes/IfConstantConditionPass.h>
#include <Analyzer/Passes/IfChainToMultiIfPass.h>
#include <Analyzer/Passes/ConvertInToEqualsPass.h>
#include <Analyzer/Passes/ConvertInToEqualPass.h>
#include <Analyzer/Passes/OrderByTupleEliminationPass.h>
#include <Analyzer/Passes/NormalizeCountVariantsPass.h>
#include <Analyzer/Passes/AggregateFunctionsArithmericOperationsPass.h>
@ -264,7 +264,7 @@ void addQueryTreePasses(QueryTreePassManager & manager, bool only_analyze)
manager.addPass(std::make_unique<SumIfToCountIfPass>());
manager.addPass(std::make_unique<RewriteArrayExistsToHasPass>());
manager.addPass(std::make_unique<NormalizeCountVariantsPass>());
manager.addPass(std::make_unique<ConvertInToEqualsPass>());
manager.addPass(std::make_unique<ConvertInToEqualPass>());
/// should before AggregateFunctionsArithmericOperationsPass
manager.addPass(std::make_unique<AggregateFunctionOfGroupByKeysPass>());

View File

@ -0,0 +1,30 @@
<test>
<settings>
<max_insert_threads>8</max_insert_threads>
<max_threads>1</max_threads>
</settings>
<create_query>
CREATE TABLE t_nullable
(
key_string1 Nullable(String),
key_string2 Nullable(String),
key_string3 Nullable(String),
key_int64_1 Nullable(Int64),
key_int64_2 Nullable(Int64),
key_int64_3 Nullable(Int64),
key_int64_4 Nullable(Int64),
key_int64_5 Nullable(Int64),
m1 Int64,
m2 Int64
)
ENGINE = Memory
</create_query>
<fill_query>insert into t_nullable select ['aaaaaa','bbaaaa','ccaaaa','ddaaaa'][number % 101 + 1], ['aa','bb','cc','dd'][number % 100 + 1], ['aa','bb','cc','dd'][number % 102 + 1], number%10+1, number%10+2, number%10+3, number%10+4,number%10+5, number%6000+1, number%5000+2 from numbers_mt(30000000)</fill_query>
<query>select * from t_nullable where key_string1 in ('aaaaaa') format Null</query>
<query>select * from t_nullable where key_string1 in ('aaaaaa') format Null SETTINGS allow_experimental_analyzer=1</query>
<query>select * from t_nullable where key_string2 in ('3') format Null</query>
<query>select * from t_nullable where key_string2 in ('3') format Null SETTINGS allow_experimental_analyzer=1</query>
<drop_query>drop table if exists t_nullable</drop_query>
</test>

View File

@ -0,0 +1,37 @@
a 1
-------------------
QUERY id: 0
PROJECTION COLUMNS
x String
y Int32
PROJECTION
LIST id: 1, nodes: 2
COLUMN id: 2, column_name: x, result_type: String, source_id: 3
COLUMN id: 4, column_name: y, result_type: Int32, source_id: 3
JOIN TREE
TABLE id: 3, alias: __table1, table_name: default.test
WHERE
FUNCTION id: 5, function_name: equals, function_type: ordinary, result_type: UInt8
ARGUMENTS
LIST id: 6, nodes: 2
COLUMN id: 7, column_name: x, result_type: String, source_id: 3
CONSTANT id: 8, constant_value: \'a\', constant_value_type: String
SETTINGS allow_experimental_analyzer=1
-------------------
QUERY id: 0
PROJECTION COLUMNS
x String
y Int32
PROJECTION
LIST id: 1, nodes: 2
COLUMN id: 2, column_name: x, result_type: String, source_id: 3
COLUMN id: 4, column_name: y, result_type: Int32, source_id: 3
JOIN TREE
TABLE id: 3, alias: __table1, table_name: default.test
WHERE
FUNCTION id: 5, function_name: in, function_type: ordinary, result_type: UInt8
ARGUMENTS
LIST id: 6, nodes: 2
COLUMN id: 7, column_name: x, result_type: String, source_id: 3
CONSTANT id: 8, constant_value: Tuple_(\'a\', \'b\'), constant_value_type: Tuple(String, String)
SETTINGS allow_experimental_analyzer=1

View File

@ -0,0 +1,10 @@
DROP TABLE IF EXISTS test;
CREATE TABLE test (x String, y Int32) ENGINE = MergeTree() ORDER BY x;
INSERT INTO test VALUES ('a', 1), ('b', 2), ('c', 3), ('d', 4), ('e', 5);
select * from test where x in ('a') SETTINGS allow_experimental_analyzer = 1;
select '-------------------';
explain query tree select * from test where x in ('a') SETTINGS allow_experimental_analyzer = 1;
select '-------------------';
explain query tree select * from test where x in ('a','b') SETTINGS allow_experimental_analyzer = 1;