From 9eb6746a67928e7075bfaa16443a635abda4e09a Mon Sep 17 00:00:00 2001 From: Jan Ciolek Date: Wed, 1 Feb 2023 16:00:42 +0100 Subject: [PATCH] test/expr_test: test IN (123, ?, 456) Add tests which test evaluating the IN restriction with a list which contains a bind variable. Signed-off-by: Jan Ciolek --- test/boost/expr_test.cc | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/boost/expr_test.cc b/test/boost/expr_test.cc index ab4b91e3b2..2950cf1af4 100644 --- a/test/boost/expr_test.cc +++ b/test/boost/expr_test.cc @@ -2525,6 +2525,29 @@ BOOST_AUTO_TEST_CASE(evaluate_binary_operator_in) { test_evaluate_binop_null(oper_t::IN, make_int_const(5), in_list); } +// Tests ` IN (123, ?, 789)` where the bind variable has value 456 +BOOST_AUTO_TEST_CASE(evaluate_binary_operator_in_list_with_bind_variable) { + schema_ptr table_schema = + schema_builder("test_ks", "test_cf").with_column("pk", int32_type, column_kind::partition_key).build(); + + expression in_list = collection_constructor{ + .style = collection_constructor::style_type::list, + .elements = {make_int_const(123), bind_variable{.bind_index = 0, .receiver = make_receiver(int32_type)}, + make_int_const(789)}, + .type = list_type_impl::get_instance(int32_type, true)}; + + auto [inputs, inputs_data] = make_evaluation_inputs(table_schema, {{"pk", make_int_raw(111)}}, {make_int_raw(456)}); + + expression true_in_binop = binary_operator(make_int_const(456), oper_t::IN, in_list); + BOOST_REQUIRE_EQUAL(evaluate(true_in_binop, inputs), make_bool_raw(true)); + + expression false_in_binop = binary_operator(make_int_const(-100), oper_t::IN, in_list); + BOOST_REQUIRE_EQUAL(evaluate(false_in_binop, inputs), make_bool_raw(false)); + + expression empty_in_list = binary_operator(make_empty_const(int32_type), oper_t::IN, in_list); + BOOST_REQUIRE_EQUAL(evaluate(empty_in_list, inputs), make_bool_raw(false)); +} + BOOST_AUTO_TEST_CASE(evaluate_binary_operator_list_contains) { expression list_val = make_int_list_const({1, 3, 5});