Skip to content

Commit

Permalink
csvparser/filterx: change default delimiter to a comma
Browse files Browse the repository at this point in the history
Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
  • Loading branch information
bazsi committed Jun 7, 2024
1 parent 216714f commit 330d70d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion modules/csvparser/filterx-func-format-csv.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ filterx_function_format_csv_new(const gchar *function_name, FilterXFunctionArgs

self->super.super.eval = _eval;
self->super.super.free_fn = _free;
self->delimiter = ' ';
self->delimiter = ',';

if (!_extract_arguments(self, args, error))
goto error;
Expand Down
2 changes: 1 addition & 1 deletion modules/csvparser/filterx-func-parse-csv.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ filterx_function_parse_csv_new(const gchar *function_name, FilterXFunctionArgs *
filterx_function_init_instance(&self->super, function_name);
self->super.super.eval = _eval;
self->super.super.free_fn = _free;
csv_scanner_options_set_delimiters(&self->options, " ");
csv_scanner_options_set_delimiters(&self->options, ",");
csv_scanner_options_set_quote_pairs(&self->options, "\"\"''");
csv_scanner_options_set_flags(&self->options, CSV_SCANNER_STRIP_WHITESPACE);
csv_scanner_options_set_dialect(&self->options, CSV_SCANNER_ESCAPE_NONE);
Expand Down
8 changes: 4 additions & 4 deletions modules/csvparser/tests/test_filterx_func_format_csv.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Test(filterx_func_format_csv, test_array_mode_with_default_delimiter)
GList *args = NULL;
args = g_list_append(args, filterx_function_arg_new(NULL, csv_data));

_assert_format_csv(args, "foo bar baz");
_assert_format_csv(args, "foo,bar,baz");
}

Test(filterx_func_format_csv, test_array_mode_with_custom_delimiter)
Expand All @@ -124,7 +124,7 @@ Test(filterx_func_format_csv, test_array_mode_skip_column_names)
args = g_list_append(args, filterx_function_arg_new(FILTERX_FUNC_FORMAT_CSV_ARG_NAME_COLUMNS,
filterx_non_literal_new(filterx_json_array_new_from_repr("[\"col1\",\"col2\"]", -1))));

_assert_format_csv(args, "foo bar baz");
_assert_format_csv(args, "foo,bar,baz");
}

Test(filterx_func_format_csv, test_dict_mode_without_column_names_with_default_delimiter)
Expand All @@ -134,7 +134,7 @@ Test(filterx_func_format_csv, test_dict_mode_without_column_names_with_default_d
GList *args = NULL;
args = g_list_append(args, filterx_function_arg_new(NULL, csv_data));

_assert_format_csv(args, "foo bar baz");
_assert_format_csv(args, "foo,bar,baz");
}

Test(filterx_func_format_csv, test_dict_mode_without_column_names_with_custom_delimiter)
Expand All @@ -158,7 +158,7 @@ Test(filterx_func_format_csv, test_dict_mode_with_column_names_with_default_deli
args = g_list_append(args, filterx_function_arg_new(FILTERX_FUNC_FORMAT_CSV_ARG_NAME_COLUMNS,
filterx_non_literal_new(filterx_json_array_new_from_repr("[\"col2\",\"col1\"]", -1))));

_assert_format_csv(args, "bar foo");
_assert_format_csv(args, "bar,foo");
}

Test(filterx_func_format_csv, test_dict_mode_with_column_names_with_custom_delimiter)
Expand Down
12 changes: 6 additions & 6 deletions modules/csvparser/tests/test_filterx_func_parse_csv.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ Test(filterx_func_parse_csv, test_skipped_opts_causes_default_behaviour)
{
GList *args = NULL;
args = g_list_append(args, filterx_function_arg_new(NULL,
filterx_literal_new(filterx_string_new("foo bar baz tik tak toe", -1))));
filterx_literal_new(filterx_string_new("foo,bar,baz,tik,tak,toe", -1))));

GError *err = NULL;
GError *args_err = NULL;
Expand All @@ -140,7 +140,7 @@ Test(filterx_func_parse_csv, test_skipped_opts_causes_default_behaviour)
Test(filterx_func_parse_csv, test_set_optional_first_argument_column_names)
{
GList *args = NULL;
args = g_list_append(args, filterx_function_arg_new(NULL, filterx_literal_new(filterx_string_new("foo bar baz", -1))));
args = g_list_append(args, filterx_function_arg_new(NULL, filterx_literal_new(filterx_string_new("foo,bar,baz", -1))));
FilterXObject *col_names = _generate_column_list("1st", "2nd", "3rd", NULL);
args = g_list_append(args, filterx_function_arg_new(FILTERX_FUNC_PARSE_CSV_ARG_NAME_COLUMNS,
filterx_literal_new(col_names)));
Expand Down Expand Up @@ -171,7 +171,7 @@ Test(filterx_func_parse_csv, test_column_names_sets_expected_column_size_additio
{
GList *args = NULL;
args = g_list_append(args, filterx_function_arg_new(NULL,
filterx_literal_new(filterx_string_new("foo bar baz more columns we did not expect", -1))));
filterx_literal_new(filterx_string_new("foo,bar,baz,more,columns,we,did,not,expect", -1))));
FilterXObject *col_names = _generate_column_list("1st", "2nd", "3rd", NULL); // sets expected column size 3
args = g_list_append(args, filterx_function_arg_new(FILTERX_FUNC_PARSE_CSV_ARG_NAME_COLUMNS,
filterx_literal_new(col_names)));
Expand Down Expand Up @@ -262,7 +262,7 @@ Test(filterx_func_parse_csv, test_optional_argument_flag_greedy)
{
GList *args = NULL;
args = g_list_append(args, filterx_function_arg_new(NULL,
filterx_literal_new(filterx_string_new("foo bar baz tik tak toe", -1))));
filterx_literal_new(filterx_string_new("foo,bar,baz,tik,tak,toe", -1))));
args = g_list_append(args, filterx_function_arg_new(FILTERX_FUNC_PARSE_CSV_ARG_NAME_COLUMNS,
filterx_literal_new(_generate_column_list("1st", "2nd",
"3rd", "rest", NULL)))); // columns
Expand All @@ -285,7 +285,7 @@ Test(filterx_func_parse_csv, test_optional_argument_flag_greedy)
LogMessageValueType lmvt;
cr_assert(filterx_object_marshal(obj, repr, &lmvt));

cr_assert_str_eq(repr->str, "{\"1st\":\"foo\",\"2nd\":\"bar\",\"3rd\":\"baz\",\"rest\":\"tik tak toe\"}");
cr_assert_str_eq(repr->str, "{\"1st\":\"foo\",\"2nd\":\"bar\",\"3rd\":\"baz\",\"rest\":\"tik,tak,toe\"}");
filterx_expr_unref(func);
filterx_object_unref(obj);
g_error_free(err);
Expand All @@ -295,7 +295,7 @@ Test(filterx_func_parse_csv, test_optional_argument_flag_non_greedy)
{
GList *args = NULL;
args = g_list_append(args, filterx_function_arg_new(NULL,
filterx_literal_new(filterx_string_new("foo bar baz tik tak toe", -1))));
filterx_literal_new(filterx_string_new("foo,bar,baz,tik,tak,toe", -1))));
args = g_list_append(args, filterx_function_arg_new(FILTERX_FUNC_PARSE_CSV_ARG_NAME_COLUMNS,
filterx_literal_new(_generate_column_list("1st", "2nd",
"3rd", "rest", NULL)))); // columns
Expand Down

0 comments on commit 330d70d

Please sign in to comment.