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

RFC: define a single otk.op.join #8

Merged
merged 2 commits into from
May 8, 2024

Conversation

mvo5
Copy link
Contributor

@mvo5 mvo5 commented Apr 10, 2024

I wonder if we can simply avoid having the user care about the type when doing a join operation. It seems mostly a burden to the user and we need to check during compilation of the otk file anyway so maybe we can just leave it out?

P.S. Having an example use-case for both would be really good, I'm wonder if we only should add things to the spec once we actually use it in the example/* tree ?

@kingsleyzissou
Copy link

Having an example use-case for both would be really good

This was a question I've been asking and was going to put it down, but it seems you have beaten me to asking it :)

@supakeen
Copy link
Member

My reasoning for this was that having separate operations per type allows us to have separate arguments per type. For a map erroring on duplicates (or overwriting them) makes sense. For a sequence less so.

@mvo5
Copy link
Contributor Author

mvo5 commented Apr 11, 2024

My reasoning for this was that having separate operations per type allows us to have separate arguments per type. For a map erroring on duplicates (or overwriting them) makes sense. For a sequence less so.

Thanks! I'm not sure I follow - if otk.op.join would be used on two maps with duplicates it would still error. If it is used on two sequences with duplicates it would not. Mixing the two is not allowed. What am I missing?

@supakeen
Copy link
Member

supakeen commented Apr 11, 2024

My reasoning for this was that having separate operations per type allows us to have separate arguments per type. For a map erroring on duplicates (or overwriting them) makes sense. For a sequence less so.

Thanks! I'm not sure I follow - if otk.op.join would be used on two maps with duplicates it would still error. If it is used on two sequences with duplicates it would not. Mixing the two is not allowed. What am I missing?

Wanting to define the behavior, for example (don't pin me on this one ;)).

otk.op.map.join:
  duplicates: overwrite
  values:
    - key:
        one
    - key:
        two

The duplicates key would not do anything on the otk.op.seq.join I feel?

@mvo5
Copy link
Contributor Author

mvo5 commented Apr 11, 2024

My reasoning for this was that having separate operations per type allows us to have separate arguments per type. For a map erroring on duplicates (or overwriting them) makes sense. For a sequence less so.

Thanks! I'm not sure I follow - if otk.op.join would be used on two maps with duplicates it would still error. If it is used on two sequences with duplicates it would not. Mixing the two is not allowed. What am I missing?

Wanting to define the behavior, for example (don't pin me on this one ;)).

otk.op.map.join:
  duplicates: overwrite
  values:
    - key:
        one
    - key:
        two

The duplicates key would not do anything on the otk.op.seq.join I feel?

Thank you! That is interesting (and the context I was looking for!). We could start with what popular languages like python are doing:

  1. duplicated keys in a map get replaced by "later" joins (essentially meaning overwrite)
  2. seq are just joined

I like the idea of the users having a say here though, so once the above is not good enough anymore, we could add rules like

duplicates: [error, overwrite]

and then we could decide to error if "overwrite" is used on sequences. Or we could also "bend" the definition and "de-duplicate/replace/overwrite" keys in a seqence if later sequences also define it (not sure I like it or not but it's an option :)

@mvo5 mvo5 force-pushed the one-join-to-rule-them-all branch from bf8327d to 1e25c66 Compare April 18, 2024 14:28
@mvo5
Copy link
Contributor Author

mvo5 commented Apr 18, 2024

I fixed the conflicts, sorry that this took me a bit

doc/directives.md Outdated Show resolved Hide resolved
@mvo5 mvo5 force-pushed the one-join-to-rule-them-all branch from 1e25c66 to b2e0ed6 Compare April 24, 2024 09:45
@mvo5 mvo5 force-pushed the one-join-to-rule-them-all branch from b2e0ed6 to 37115c7 Compare May 7, 2024 08:07
@mvo5 mvo5 requested a review from supakeen May 7, 2024 08:07
@mvo5 mvo5 force-pushed the one-join-to-rule-them-all branch from 37115c7 to dd9c6e3 Compare May 7, 2024 08:08
@supakeen supakeen force-pushed the one-join-to-rule-them-all branch from dd9c6e3 to 6349403 Compare May 7, 2024 08:22
@supakeen
Copy link
Member

supakeen commented May 7, 2024

@mvo5 mvo5 force-pushed the one-join-to-rule-them-all branch from 6349403 to 73775a9 Compare May 7, 2024 10:29
Copy link

@kingsleyzissou kingsleyzissou left a comment

Choose a reason for hiding this comment

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

Duplicate keys in maps are considered an error.

It might be nice to have a test for this (unless there is one already and I missed it)

I wonder if we can simply avoid having the user care about the type when
doing a join operation. It seems mostly a burden to the user and we need
to check during compilation of the otk file anyway so maybe we can just
leave it out?

P.S. Having an example use-case for both would be really good, I'm wonder
if we only should add things to the spec once we actually use it in the
example/* tree ?
@supakeen supakeen force-pushed the one-join-to-rule-them-all branch from 73775a9 to 9ead440 Compare May 7, 2024 12:25
@tree.must_pass(tree.has_keys(["values"]))
def op_map_merge(ctx: Context, tree: dict[str, Any]) -> Any:
"""Merge two dictionaries. Keys from the second dictionary overwrite keys
def _op_map_join(ctx: Context, values: List[dict]) -> Any:
Copy link
Member

Choose a reason for hiding this comment

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

List wasn't imported from typing.

@supakeen
Copy link
Member

supakeen commented May 7, 2024

Duplicate keys in maps are considered an error.

It might be nice to have a test for this (unless there is one already and I missed it)

There's no test for it (yet) and the code doesn't actually check this:

for value in values:

It should straightforward to add, or reconsider if it should be an error.

@kingsleyzissou
Copy link

It should straightforward to add, or reconsider if it should be an error.

Yeah doesn't have to be for this PR :)

@mvo5 mvo5 force-pushed the one-join-to-rule-them-all branch from 9ead440 to befed85 Compare May 7, 2024 13:23
@supakeen
Copy link
Member

supakeen commented May 8, 2024

@mvo5 you imported List in the wrong module ;)

Following the recent spec update the code is now updated as well
to have a single `otk.op.join` instead of the previous:
- otk.op.map.merge
- otk.op.seq.merge
@mvo5 mvo5 force-pushed the one-join-to-rule-them-all branch from befed85 to 1bc69c5 Compare May 8, 2024 09:06
@mvo5
Copy link
Contributor Author

mvo5 commented May 8, 2024

@mvo5 you imported List in the wrong module ;)

Silly me, sorry for that! Fwiw, make type gives me a bunch of errors so I did not see this one but it's not really important at this point (the wrong List import is hopefully fixed now).

@supakeen supakeen added this pull request to the merge queue May 8, 2024
Merged via the queue into osbuild:main with commit 4fdff6e May 8, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants