Skip to content

Commit 2da705d

Browse files
committed
1 parent 47b7ea5 commit 2da705d

File tree

5 files changed

+285
-257
lines changed

5 files changed

+285
-257
lines changed

deps/rabbit/src/rabbit_amqp_filter_sql.erl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@ eval0({unary_minus, Expr}, Msg) ->
159159
end;
160160

161161
%% Special operators
162-
eval0({'in', Expr, ValueList}, Msg) ->
162+
eval0({'in', Expr, ExprList}, Msg) ->
163163
Value = eval0(Expr, Msg),
164-
is_in(Value, ValueList);
164+
is_in(Value, ExprList, Msg);
165165

166166
eval0({'is_null', Expr}, Msg) ->
167167
eval0(Expr, Msg) =:= undefined;
@@ -218,12 +218,13 @@ arithmetic('%', Left, Right) when is_integer(Left) andalso is_integer(Right) and
218218
arithmetic(_, _, _) ->
219219
undefined.
220220

221-
is_in(undefined, _) ->
221+
is_in(undefined, _, _) ->
222222
%% "If identifier of an IN or NOT IN operation is NULL,
223223
%% the value of the operation is unknown."
224224
undefined;
225-
is_in(Value, List) ->
226-
lists:member(Value, List).
225+
is_in(Value, ExprList, Msg) ->
226+
IsEqual = fun(Expr) -> eval0(Expr, Msg) == Value end,
227+
lists:any(IsEqual, ExprList).
227228

228229
like(Subject, {exact, Pattern}) ->
229230
Subject =:= Pattern;

deps/rabbit/src/rabbit_amqp_sql_ast.erl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ search(Pred, Node) ->
2323
case Node of
2424
{Op, Arg} when is_atom(Op) ->
2525
search(Pred, Arg);
26+
{in, Arg, List} ->
27+
search(Pred, Arg) orelse
28+
lists:any(fun(N) -> search(Pred, N) end, List);
2629
{Op, Arg1, Arg2} when is_atom(Op) ->
2730
search(Pred, Arg1) orelse
2831
search(Pred, Arg2);
@@ -49,6 +52,8 @@ map_1(Other, _Fun) ->
4952

5053
map_2({Op, Arg1}, Fun) ->
5154
{Op, map_1(Arg1, Fun)};
55+
map_2({in, Arg1, List}, Fun) ->
56+
{in, map_1(Arg1, Fun), lists:map(fun(N) -> map_1(N, Fun) end, List)};
5257
map_2({Op, Arg1, Arg2}, Fun) ->
5358
{Op, map_1(Arg1, Fun), map_1(Arg2, Fun)};
5459
map_2({Op, Arg1, Arg2, Arg3}, Fun) ->
@@ -79,8 +84,11 @@ has_binary_identifier_test() ->
7984
false = has_binary_identifier("properties.group-id LIKE 'group_%' ESCAPE '!'"),
8085
true = has_binary_identifier("user_tag LIKE 'group_%' ESCAPE '!'"),
8186

82-
false = has_binary_identifier("properties.group-id IN ('g1', 'g2', 'g3')"),
8387
true = has_binary_identifier("user_category IN ('g1', 'g2', 'g3')"),
88+
true = has_binary_identifier("p.group-id IN ('g1', user_key, 'g3')"),
89+
true = has_binary_identifier("p.group-id IN ('g1', 'g2', a.user_key)"),
90+
false = has_binary_identifier("p.group-id IN (p.reply-to-group-id, 'g2', 'g3')"),
91+
false = has_binary_identifier("properties.group-id IN ('g1', 'g2', 'g3')"),
8492

8593
false = has_binary_identifier(
8694
"(properties.group-sequence + 1) * 2 <= 100 AND " ++

0 commit comments

Comments
 (0)