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
Rewrite chart
and set-attributes
operators
#3866
Conversation
85fe548
to
99e4383
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
99e4383
to
0d0001e
Compare
I, too, was curious. You need this patch for it to work. diff --git a/libtenzir/builtins/operators/chart.cpp b/libtenzir/builtins/operators/chart.cpp
index dac05635e9..0b05b45771 100644
--- a/libtenzir/builtins/operators/chart.cpp
+++ b/libtenzir/builtins/operators/chart.cpp
@@ -261,7 +261,7 @@ struct chart_definition {
= build_argument_list<std::optional<std::string>>(parser, optional_flags);
parser.parse(p);
configuration result;
- result.emplace_back("type", attribute_value{std::string{type}});
+ result.emplace_back("chart", attribute_value{std::string{type}});
// Go through the arguments,
// and populate `result` with the specified attributes
for (auto&& [attr, arg] : required_arguments) {
@@ -322,23 +322,23 @@ chart_definition chart_definitions[] = {
{.type = "line",
.required_flags = {},
.optional_flags
- = {{.attr = "x-axis", .flag = "-x,--x-axis", .type = flag_type::field_name, .default_ = nth_field{0}},
- {.attr = "y-axis", .flag = "-y,--y-axis", .type = flag_type::field_name, .default_ = nth_field{1}},
+ = {{.attr = "x", .flag = "-x,--x-axis", .type = flag_type::field_name, .default_ = nth_field{0}},
+ {.attr = "y", .flag = "-y,--y-axis", .type = flag_type::field_name, .default_ = nth_field{1}},
{.attr = "title", .flag = "--title", .type = flag_type::attribute_value, .default_ = schema_name{}},}},
// `bar` is equivalent to `line`
{.type = "bar",
.required_flags = {},
.optional_flags
- = {{.attr = "x-axis", .flag = "-x,--x-axis", .type = flag_type::field_name, .default_ = nth_field{0}},
- {.attr = "y-axis", .flag = "-y,--y-axis", .type = flag_type::field_name, .default_ = nth_field{1}},
+ = {{.attr = "x", .flag = "-x,--x-axis", .type = flag_type::field_name, .default_ = nth_field{0}},
+ {.attr = "y", .flag = "-y,--y-axis", .type = flag_type::field_name, .default_ = nth_field{1}},
{.attr = "title", .flag = "--title", .type = flag_type::attribute_value, .default_ = schema_name{}},}},
// `donut` chart is equivalent to `line` and `bar`, except
// --x-axis is called --name, and --y-axis is called --value
{.type = "donut",
.required_flags = {},
.optional_flags
- = {{.attr = "name", .flag = "--name", .type = flag_type::field_name, .default_ = nth_field{0}},
- {.attr = "value", .flag = "--value", .type = flag_type::field_name, .default_ = nth_field{1}},
+ = {{.attr = "x", .flag = "--name", .type = flag_type::field_name, .default_ = nth_field{0}},
+ {.attr = "y", .flag = "--value", .type = flag_type::field_name, .default_ = nth_field{1}},
{.attr = "title", .flag = "--title", .type = flag_type::attribute_value, .default_ = schema_name{}},}},
}; Thanks @eliaskosunen for the argument DSL, that made it really easy to modify this. Really good engineering as it'll also allow the app folks to modify the arguments without knowing any C++ at all. |
0d0001e
to
84e9853
Compare
Just realized the awesomeness of positional arguments as dimensions, nice! |
396c836
to
7c13f53
Compare
7c13f53
to
7fd5171
Compare
Closes https://github.com/tenzir/issues/issues/1153
This PR brings the
chart
andset-attributes
up to the spec described in the issue. Due to differences in the design, the common denominator between the implementations of these two operators is now VASTly reduced. Thus,set_attributes_operator_helper
is removed.key=value
to--key value
/--key=value
argument_parser
is used for parsing the command line (inchart
). This leads to (arguably) improved error messages (see alsostep_03.ref
in the diff), but also means that there's no longer any common parsing logic betweenchart
andset-attributes
:chart
operator now have default values.--x-axis
/--name
defaults to the first field of the schema,--y-axis
/--value
to the second, and--title
to the schema name. Due to this additional logic,set-attributes
can't be used for the implementation ofchart
.chart.cpp
.chart
is added to the documentation, and a changelog entry for it is added.set-attributes
is kept as undocumented."chart_operator"
is added as a new feature flag