Skip to content

Commit 6a826ff

Browse files
Merge pull request ClickHouse#57380 from evillique/fix-parameterized-view-except-query
Fix parameterized view with SELECT EXCEPT query
2 parents f2378d1 + 3973b7f commit 6a826ff

File tree

3 files changed

+89
-3
lines changed

3 files changed

+89
-3
lines changed

src/Interpreters/InterpreterSelectIntersectExceptQuery.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,13 @@ std::unique_ptr<IInterpreterUnionOrSelectQuery>
108108
InterpreterSelectIntersectExceptQuery::buildCurrentChildInterpreter(const ASTPtr & ast_ptr_)
109109
{
110110
if (ast_ptr_->as<ASTSelectWithUnionQuery>())
111-
return std::make_unique<InterpreterSelectWithUnionQuery>(ast_ptr_, context, SelectQueryOptions());
111+
return std::make_unique<InterpreterSelectWithUnionQuery>(ast_ptr_, context, options);
112112

113113
if (ast_ptr_->as<ASTSelectQuery>())
114-
return std::make_unique<InterpreterSelectQuery>(ast_ptr_, context, SelectQueryOptions());
114+
return std::make_unique<InterpreterSelectQuery>(ast_ptr_, context, options);
115115

116116
if (ast_ptr_->as<ASTSelectIntersectExceptQuery>())
117-
return std::make_unique<InterpreterSelectIntersectExceptQuery>(ast_ptr_, context, SelectQueryOptions());
117+
return std::make_unique<InterpreterSelectIntersectExceptQuery>(ast_ptr_, context, options);
118118

119119
throw Exception(ErrorCodes::LOGICAL_ERROR, "Unexpected query: {}", ast_ptr_->getID());
120120
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--- Data ---
2+
1231 John 33
3+
6666 Ksenia 48
4+
8888 Alice 50
5+
--- Params ---
6+
10 50 10 40
7+
--- First view ---
8+
1231
9+
6666
10+
8888
11+
--- Second query result ---
12+
6666
13+
8888
14+
--- Second view result ---
15+
6666
16+
8888
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
select '--- Data ---';
2+
3+
DROP VIEW IF EXISTS V_DELTA;
4+
DROP TABLE IF EXISTS users;
5+
6+
CREATE TABLE users (uid Int16, name String, age Int16) ENGINE=Memory;
7+
8+
INSERT INTO users VALUES (1231, 'John', 33);
9+
INSERT INTO users VALUES (6666, 'Ksenia', 48);
10+
INSERT INTO users VALUES (8888, 'Alice', 50);
11+
12+
SELECT * FROM users order by uid;
13+
14+
select '--- Params ---';
15+
16+
-- set params
17+
set param_a1 = '10';
18+
set param_a2 = '50';
19+
set param_a3 = '10';
20+
set param_a4 = '40';
21+
--check
22+
select {a1: Int32}, {a2: Int32}, {a3: Int32}, {a4: Int32};
23+
24+
select '--- First view ---';
25+
-- using 4 param in the select of the view work here.
26+
CREATE OR REPLACE VIEW V_DELTA AS
27+
select distinct uid from
28+
(
29+
select uid, name, age from users
30+
where age >= {a1: Int32}
31+
OR age >= {a2: Int32}
32+
OR age >= {a3: Int32}
33+
OR age >= {a4: Int32}
34+
)
35+
order by uid;
36+
37+
SELECT * FROM V_DELTA(a1=10, a2=50, a3=10, a4=40);
38+
39+
40+
select '--- Second query result ---';
41+
42+
-- check individual query before the next part
43+
select distinct uid from
44+
(
45+
select uid, name, age from users
46+
where age >= {a1: Int32} AND age <= {a2: Int32}
47+
EXCEPT
48+
select uid, name, age from users
49+
where age >= {a3: Int32} AND age <= {a4: Int32}
50+
)
51+
order by uid;
52+
53+
select '--- Second view result ---';
54+
55+
-- using 4 param in the select of the view do not work here.
56+
CREATE OR REPLACE VIEW V_DELTA AS
57+
select distinct uid from
58+
(
59+
select uid, name, age from users
60+
where age >= {a1: Int32} AND age <= {a2: Int32}
61+
EXCEPT
62+
select uid, name, age from users
63+
where age >= {a3: Int32} AND age <= {a4: Int32}
64+
)
65+
order by uid;
66+
67+
SELECT * FROM V_DELTA(a1=10, a2=50, a3=10, a4=40);
68+
69+
DROP VIEW V_DELTA;
70+
DROP TABLE users;

0 commit comments

Comments
 (0)