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

[4/6] filterx: implement merging of two iterable objects #4866

Conversation

alltilla
Copy link
Collaborator

E.g.:

    $js = json_array();
    $js << [1, 2, 3];
    $otel_arr = otel_array();
    $otel_arr << [4, 5, 6];
    $js << $otel_arr;

    $js_obj = json();
    $js_obj << {"foo": 1};
    $otel_kvl = otel_kvlist();
    $otel_kvl << {"bar": 2};
    $js_obj << $otel_kvl;

Depends on #4860, #4861 and #4862

@alltilla alltilla changed the title filterx: implement merging of two iterable objects [4/5] filterx: implement merging of two iterable objects Mar 21, 2024
@alltilla alltilla force-pushed the filterx-merge-operator-with-other-object branch 2 times, most recently from ff8c963 to 1e31c86 Compare March 25, 2024 08:39
@kira-syslogng
Copy link
Contributor

Build FAILURE

@alltilla
Copy link
Collaborator Author

@kira-syslogng retest this please

@alltilla alltilla changed the title [4/5] filterx: implement merging of two iterable objects [4/6] filterx: implement merging of two iterable objects Mar 25, 2024
Signed-off-by: Attila Szakacs <attila.szakacs@axoflow.com>
They will be useful later for the generator logic.

Signed-off-by: Attila Szakacs <attila.szakacs@axoflow.com>
We don't have generic dicts or lists in filterx. We have dict and a list
interface, which can be implemented by anyone.

Literal dicts and lists do not make sense in this case, however with
a bit of trickery we can make them "generator"s, which use the dict
and list interfaces and operate on an actual implementation.

For this we introduce the merge "<<" operator, which on the left hand
side expects an object that is a dict or list implementation, and a
"generator" on the right hand side (in the form of literal dict and
list for now, but functions will be added soon). The merge operator
passes the "fillable" to the generator, which then fills it
appropriatery.

Please note that this is a shallow merge:
  * lists are always appended
  * dict merging works like python's dict update() function

Signed-off-by: Attila Szakacs <attila.szakacs@axoflow.com>
Signed-off-by: Attila Szakacs <attila.szakacs@axoflow.com>
Signed-off-by: Attila Szakacs <attila.szakacs@axoflow.com>
We should be able to create a json_array like these:

$arr = $json_array();
$arr = $json_array("[\"foo\", \"bar\"]");
$arr = $json("[\"foo\", \"bar\"]");

Signed-off-by: Attila Szakacs <attila.szakacs@axoflow.com>
Signed-off-by: Attila Szakacs <attila.szakacs@axoflow.com>
Signed-off-by: Attila Szakacs <attila.szakacs@axoflow.com>
Signed-off-by: Attila Szakacs <attila.szakacs@axoflow.com>
Signed-off-by: Attila Szakacs <attila.szakacs@axoflow.com>
Signed-off-by: Attila Szakacs <attila.szakacs@axoflow.com>
E.g.:

    $js = json_array();
    $js << [1, 2, 3];
    $otel_arr = otel_array();
    $otel_arr << [4, 5, 6];
    $js << $otel_arr;

    $js_obj = json();
    $js_obj << {"foo": 1};
    $otel_kvl = otel_kvlist();
    $otel_kvl << {"bar": 2};
    $js_obj << $otel_kvl;

Signed-off-by: Attila Szakacs <attila.szakacs@axoflow.com>
Signed-off-by: Attila Szakacs <attila.szakacs@axoflow.com>
@alltilla alltilla force-pushed the filterx-merge-operator-with-other-object branch from 1e31c86 to edbf47d Compare March 26, 2024 08:03
@MrAnno MrAnno requested review from MrAnno and bshifter March 27, 2024 09:15
@alltilla alltilla marked this pull request as draft March 27, 2024 09:36
Copy link
Collaborator

@bshifter bshifter left a comment

Choose a reason for hiding this comment

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

lgtm

@alltilla
Copy link
Collaborator Author

alltilla commented Apr 3, 2024

Closing, as this will be implemented in a completely different way.

@alltilla alltilla closed this Apr 3, 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.

None yet

3 participants