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

Preserve same entity in nested pass-through (_elseNested). #342

Merged
merged 7 commits into from
Apr 19, 2021

Conversation

blackwinter
Copy link
Member

Fixes #338 (see test shouldHandleUnmatchedLiteralsAndEntitiesInElseNestedSource; e4c6fe5).

Doesn't work with partially handled entities, though (see test shouldHandlePartiallyUnmatchedLiteralsAndEntitiesInElseNestedSource):

  • It should either coordinate with Entity w.r.t. starting/ending entities.
    • If an entity has already been started by the morph, it must not be started again by the pass-through; conversely, if an entity has already been started by the pass-through, it must not be started again by the morph.
    • Similarly, only the last one of them may end the entity.
    • This corresponds to coordinatesWithEntity set to true.
  • Or separate pass-through entities from explicitly specified entities.
    • At every morph/pass-through boundary, start/end the entity; both "modes" will be internally consistent (i.e., preserve same entity etc.).
    • This corresponds to separatesFromEntity set to true.

I'd like a review of the actual fix and also some feedback concerning the ensuing bug (which remedy would be preferrable? is this considered a blocker for the PR to move forward?).

* Fixes #338 (see test `shouldHandleUnmatchedLiteralsAndEntitiesInElseNestedSource`; e4c6fe5).
* Doesn't work with partially handled entities (see test `shouldHandlePartiallyUnmatchedLiteralsAndEntitiesInElseNestedSource`).
  * It should either coordinate with `Entity` w.r.t. starting/ending entities.
  * Or separate pass-through entities from explicitly specified entities.
@blackwinter blackwinter self-assigned this Nov 5, 2020
@blackwinter blackwinter changed the title Preserve same entity in nested pass-through (_elseNested). Preserve same entity in nested pass-through (_elseNested). Nov 5, 2020
Copy link
Member

@dr0i dr0i left a comment

Choose a reason for hiding this comment

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

Nice solution. The ensuing bug is no blocker for the PR, since the PR does fixes the issue and does not introduce new bugs (you just anticipate issues which may or may not arise in the real world) - so move forward.
Re discussing fix for the "ensuing bug": will do that later.

o.get().literal("Hawaii", "Aloha");
if (!coordinatesWithEntity) {
o.get().endEntity();
o.get().startEntity("USA2");
Copy link
Member

Choose a reason for hiding this comment

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

indentation?

Copy link
Member Author

Choose a reason for hiding this comment

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

If we decide to leave it in, yes. But for the time being it was only intended to illustrate the issue (and the different results, depending on the potential resolution).

@blackwinter
Copy link
Member Author

The ensuing bug is no blocker for the PR, since the PR does fixes the issue and does not introduce new bugs (you just anticipate issues which may or may not arise in the real world) - so move forward.

Well, if the use case is to "change some literals or entities in a record while passing the remainder of a record untouched", then it's almost useless if it can't deal with partially handled entities. And we'd almost certainly need the first solution ("coordinate with Entity"), since it wouldn't make much sense otherwise.

For the supposedly limited use case (incompletely?) presented in #338, it would probably suffice. But I'm hesitant to call this feature (_elseNested) ready for release if it contains such an obvious limitation.

@blackwinter
Copy link
Member Author

Thinking more about this, I'm not so sure there can even be any straightforward solution. Because, after all, the input entity and the output entity are totally independent from each other. So if they happen to be named differently in the morph, there's nothing for us to merge. (Not to mention how flushWith and other modifiers might play into this!)

Which is to say, I'm leaning more towards option 2 (separation) now; at least that'd be consistent. Or should it be configurable?

Anyway, maybe we should really look at the actual use case... @hagbeck: What is it you're trying to achieve here? Can you provide us with a complete example or test case?

We may have to accept the fact that this is an experimental feature and the details will have to be fleshed out in practice.

@dr0i dr0i removed the request for review from fsteeg November 6, 2020 13:33
This reimplemets commit f009e28:

 "Data which is handled by metamorph rules will NOT be passed through
 (hence the aptly named "_else"). If you want to use data in the morph
 AND pass it through, you have to add an explicit rule for this, as usual."

This behaviour is not the default, though.
It can be achieved by this morph rule:

<entity name='$name' sameEntity='true' reset='true' flushWith='$name' flushIncomplete='true'>"

where $name is the name of the entity you want to treat.

See #338.
@dr0i
Copy link
Member

dr0i commented Nov 10, 2020

@blackwinter I commited a proposal that shows my understanding of the issue. I assume that a mix of handling and dropping data is a common scenario when one wants to also pass some data untouched.

@blackwinter
Copy link
Member Author

@dr0i: As long as we're clear that this

  1. doesn't affect the issues illustrated in shouldHandlePartiallyUnmatchedLiteralsAndEntitiesInElseNestedSource (insufficient morph definition, see below);
  2. requires users to handle an entity completely themselves as soon as they handle a part of it (seems acceptable in the "handle and drop" scenario);
  3. only works with particular settings in the morph (sameEntity="true" and flushWith="<entity>").

@hagbeck, @fsteeg: Please feel free to chime in. I still think that we would benefit from an actual use case.

@hagbeck
Copy link
Contributor

hagbeck commented Nov 10, 2020

I've tried to build an example use case in https://github.com/hagbeck/metafacture-sandbox/tree/master/else-nested-entities
The main goal in this scenario is to pass most of the data untouched and modify or delete only a few values or entities.

The current branch seems to solve the issue.

@blackwinter
Copy link
Member Author

Thanks! I've turned your example into a test so we avoid future regressions. Please let us know if you encounter further issues or come up with additional and/or more complex use cases. We're going to let this sit for a while.

fsteeg added a commit to metafacture/metafacture-fix that referenced this pull request Dec 1, 2020
fsteeg added a commit to metafacture/metafacture-fix that referenced this pull request Dec 1, 2020
@blackwinter blackwinter mentioned this pull request Apr 13, 2021
@fsteeg
Copy link
Member

fsteeg commented Apr 19, 2021

We've been using this for months in OERSI without issues. I think we can merge this and release it with 5.2.0 (see #318). @blackwinter: Do you want to assign @dr0i for final review & merge?

@blackwinter
Copy link
Member Author

Great to hear, thanks.

@blackwinter blackwinter removed their assignment Apr 19, 2021
@dr0i dr0i merged commit e132278 into master Apr 19, 2021
@dr0i dr0i deleted the issue-338-else-nested-preserve-same-entity branch April 19, 2021 15:25
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.

_elseNested: Entity with more than one subfield results in multiple entities
4 participants