Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14234] Add support for hexadecimal values to DDSSQLFilter (backport #2598) #2602

Merged
merged 1 commit into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ using selector = parse_tree::selector <
literal_value_processor::on<
true_value,
false_value,
hex_value,
integer_value,
float_value,
char_value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ struct literal_value_processor
n->value->kind = DDSFilterValue::ValueKind::BOOLEAN;
n->value->boolean_value = false;
}
else if (n->is<integer_value>())
else if (n->is<integer_value>() || n->is<hex_value>())
{
if (n->m_begin.data[0] == '-')
{
n->value->kind = DDSFilterValue::ValueKind::SIGNED_INTEGER;
n->value->signed_integer_value = std::stoll(n->content());
n->value->signed_integer_value = std::stoll(n->content(), nullptr, 0);
}
else
{
n->value->kind = DDSFilterValue::ValueKind::UNSIGNED_INTEGER;
n->value->unsigned_integer_value = std::stoull(n->content());
n->value->unsigned_integer_value = std::stoull(n->content(), nullptr, 0);
}
}
else if (n->is<float_value>())
Expand Down
3 changes: 2 additions & 1 deletion src/cpp/fastdds/topic/DDSSQLFilter/DDSFilterGrammar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ struct integer_value : seq< opt< sign >, integer > {};
struct fractional : seq< dot_op, integer > {};
struct exponent : seq< one< 'e', 'E' >, integer_value > {};
struct float_value : seq < opt< sign >, integer, sor < exponent, seq< fractional, opt< exponent > > > > {};
struct hex_value : seq< opt< sign >, one< '0' >, one< 'x', 'X' >, plus< xdigit > > {};

// PARAMETER
struct parameter_value : seq< one< '%' >, digit, opt< digit > > {};
Expand All @@ -80,7 +81,7 @@ struct match_op : pad< sor< TAO_PEGTL_KEYWORD("MATCH"), TAO_PEGTL_KEYWORD("match
struct rel_op : sor< match_op, like_op, ne_op, le_op, ge_op, lt_op, gt_op, eq_op > {};

// Parameter, Range
struct Literal : sor< boolean_value, float_value, integer_value, char_value, string_value > {};
struct Literal : sor< boolean_value, float_value, hex_value, integer_value, char_value, string_value > {};
struct Parameter : sor< Literal, parameter_value > {};
struct Range : seq< Parameter, and_op, Parameter > {};

Expand Down
40 changes: 38 additions & 2 deletions test/unittest/dds/topic/DDSSQLFilter/DDSSQLFilterTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ TEST_F(DDSSQLFilterTests, type_compatibility_like)
// Integer values
{"1", bad_code},
{"-1", bad_code},
{"0x1F", bad_code},
{"-0x1f", bad_code},
// Floating point values
{"1.0", bad_code},
{"-1.0", bad_code},
Expand Down Expand Up @@ -351,6 +353,8 @@ TEST_F(DDSSQLFilterTests, type_compatibility_match)
// Integer values
{"1", bad_code},
{"-1", bad_code},
{"0xab", bad_code},
{"-0xCd", bad_code},
// Floating point values
{"1.0", bad_code},
{"-1.0", bad_code},
Expand Down Expand Up @@ -450,6 +454,8 @@ TEST_F(DDSSQLFilterTests, type_compatibility_compare)
// Integer values
{"1", "INT"},
{"-1", "INT"},
{"0xabcdef", "INT"},
{"-0xFEEDBAC0", "INT"},
// Floating point values
{"1.0", "FLOAT"},
{"-1.0", "FLOAT"},
Expand Down Expand Up @@ -1608,6 +1614,11 @@ static std::vector<DDSSQLFilterValueParams> get_test_filtered_value_promotion_in
input.samples_filtered.assign({true, true, true, true, true});
inputs.push_back(input);

input.test_case_name = "bool_field_signed_hex_constant";
input.expression = "bool_field > -0x1";
input.samples_filtered.assign({true, true, true, true, true});
inputs.push_back(input);

input.test_case_name = "bool_field_uint8_field";
input.expression = "bool_field < uint8_field";
input.samples_filtered.assign({false, true, true, true, true});
Expand All @@ -1633,6 +1644,11 @@ static std::vector<DDSSQLFilterValueParams> get_test_filtered_value_promotion_in
input.samples_filtered.assign({true, true, false, false, false});
inputs.push_back(input);

input.test_case_name = "bool_field_unsigned_hex_constant";
input.expression = "bool_field < 0x1";
input.samples_filtered.assign({true, true, false, false, false});
inputs.push_back(input);

// INT - INT promotions
input.test_case_name = "int16_field_int32_field";
input.expression = "int16_field > int32_field";
Expand Down Expand Up @@ -1715,8 +1731,13 @@ static std::vector<DDSSQLFilterValueParams> get_test_filtered_value_promotion_in
input.samples_filtered.assign({true, true, true, false, false});
inputs.push_back(input);

input.test_case_name = "int32_field_unsigned_int_constant";
input.expression = "int32_field < 1";
input.test_case_name = "int16_field_unsigned_hex_constant";
input.expression = "int16_field < 0x1";
input.samples_filtered.assign({true, true, true, false, false});
inputs.push_back(input);

input.test_case_name = "int32_field_unsigned_hex_constant";
input.expression = "int32_field < 0x1";
input.samples_filtered.assign({true, true, true, false, false});
inputs.push_back(input);

Expand All @@ -1725,6 +1746,11 @@ static std::vector<DDSSQLFilterValueParams> get_test_filtered_value_promotion_in
input.samples_filtered.assign({true, true, true, false, false});
inputs.push_back(input);

input.test_case_name = "int64_field_unsigned_hex_constant";
input.expression = "int64_field < 0x1";
input.samples_filtered.assign({true, true, true, false, false});
inputs.push_back(input);

// INT - FLOAT promotions
input.test_case_name = "int16_field_float_field";
input.expression = "int16_field < float_field";
Expand Down Expand Up @@ -1873,6 +1899,11 @@ static std::vector<DDSSQLFilterValueParams> get_test_filtered_value_promotion_in
input.samples_filtered.assign({true, true, true, true, true});
inputs.push_back(input);

input.test_case_name = "enum_field_signed_hex_constant";
input.expression = "enum_field > -0x1";
input.samples_filtered.assign({true, true, true, true, true});
inputs.push_back(input);

// ENUM - UINT promotions
input.test_case_name = "enum_field_uint8_field";
input.expression = "enum_field >= uint8_field";
Expand All @@ -1899,6 +1930,11 @@ static std::vector<DDSSQLFilterValueParams> get_test_filtered_value_promotion_in
input.samples_filtered.assign({false, false, true, true, true});
inputs.push_back(input);

input.test_case_name = "enum_field_unsigned_hex_constant";
input.expression = "enum_field > 0x1";
input.samples_filtered.assign({false, false, true, true, true});
inputs.push_back(input);

// CHAR - STRING promotions
input.test_case_name = "char_field_string_field";
input.expression = "string_field < char_field";
Expand Down