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

filterx: rework of unset_empties #275

Merged
merged 6 commits into from
Sep 24, 2024

Conversation

bshifter
Copy link
Member

@bshifter bshifter commented Sep 5, 2024

  • Default empty set: "", null, [], {}.
    - Optional named arguments:
    • recursive: Enables recursive processing of nested dictionaries.
    • ignorecase: Enables case-insensitive matching.
    • replacement: Specifies a filterxobject to replace target elements instead of removing them.
    • targets: A list of elements to identify for removal or replacement, clearing the default empty set.
      - UTF-8 support.
      - ignorecase and recursive args are defaults to TRUE
This change removes elements from the given dictionary or list that match
the empty set. If the recursive argument is provided, the function will
process nested dictionaries as well. The replacement argument allows
replacing target elements with a specified object, and the targets
argument customizes which elements are removed or replaced, overriding
the default empty set.
Usage: unset_empties(object, recursive=bool, ignorecase=bool, targets=[objects...], replacement=str);

example:

unset_empties(js1, targets=["foo", "bar", null, "", [], {}], ignorecase=false, replacement="N/A", recursive=false);

lib/filterx/func-unset-empties.c Outdated Show resolved Hide resolved
lib/filterx/func-unset-empties.c Show resolved Hide resolved
Comment on lines 60 to 67
gsize str_len;
const gchar *str;
if (filterx_object_extract_string(obj, &str, &str_len) && str_len == 0)
return TRUE;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this above the dict and list handling part, but the processing of it is below that?

lib/filterx/func-unset-empties.c Outdated Show resolved Hide resolved
const gchar *str;
if (filterx_object_extract_string(obj, &str, &str_len) && str_len == 0)
return TRUE;

if (filterx_object_is_type(obj, &FILTERX_TYPE_NAME(dict)) ||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit strange for me that the user cannot change the behavior of handling lists, dicts and nulls.
I don't know if they want to do it, but this seems asymmetric. If as a user I were to set the target strings, and nulls and empty dicts were getting removed, I would be surprised.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what would be the proper way to handle that case?

@bshifter bshifter force-pushed the unset-empties-rework branch 3 times, most recently from 8b47daa to ece5629 Compare September 16, 2024 23:31
@bshifter bshifter changed the title Unset empties rework: remove fields with empty values filterx: rework of unset_empties Sep 16, 2024
@bshifter bshifter requested a review from alltilla September 17, 2024 06:38
lib/filterx/func-unset-empties.c Outdated Show resolved Hide resolved
lib/filterx/func-unset-empties.c Show resolved Hide resolved
lib/filterx/func-unset-empties.c Outdated Show resolved Hide resolved
lib/filterx/func-unset-empties.c Outdated Show resolved Hide resolved
lib/filterx/func-unset-empties.c Show resolved Hide resolved
@bshifter bshifter force-pushed the unset-empties-rework branch 7 times, most recently from 9d7ebfa to 6942182 Compare September 18, 2024 12:28
@bshifter bshifter requested a review from MrAnno September 19, 2024 09:54
lib/filterx/func-flags.h Outdated Show resolved Hide resolved
lib/filterx/expr-literal-generator.c Show resolved Hide resolved
lib/filterx/func-unset-empties.c Outdated Show resolved Hide resolved
@bshifter bshifter force-pushed the unset-empties-rework branch from 6942182 to a5683a9 Compare September 23, 2024 14:17
…ardize function flag handling

Signed-off-by: shifter <shifter@axoflow.com>
Signed-off-by: shifter <shifter@axoflow.com>
- filterx_expr_is_literal_generator function added
- proper inner_dict_generator handling in filterx_expr_is_literal_dict_generator
- proper inner_list_generator handling in filterx_expr_is_literal_list_generator

Signed-off-by: shifter <shifter@axoflow.com>
- Default empty set: "", null, [], {}.
- Optional named arguments:
  - recursive: Enables recursive processing of nested dictionaries.
  - ignorecase: Enables case-insensitive matching.
  - replacement: Specifies a filterxobject to replace target elements instead of removing them.
  - targets: A list of elements to identify for removal or replacement, clearing the default empty set.
- UTF-8 support.
- ignorecase and recursive args are defaults to TRUE

This change removes elements from the given dictionary or list that match
the empty set. If the recursive argument is provided, the function will
process nested dictionaries as well. The replacement argument allows
replacing target elements with a specified object, and the targets
argument customizes which elements are removed or replaced, overriding
the default empty set.

Signed-off-by: shifter <shifter@axoflow.com>
Signed-off-by: shifter <shifter@axoflow.com>
Signed-off-by: shifter <shifter@axoflow.com>
Copy link
Member

@alltilla alltilla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool feature :)

@alltilla alltilla merged commit 1433ee6 into axoflow:main Sep 24, 2024
22 checks passed
fekete-robert pushed a commit to axoflow/axosyslog-core-docs that referenced this pull request Nov 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants