Skip to content
This repository has been archived by the owner on Jan 27, 2025. It is now read-only.

Handle and access repeated fields as arrays #78

Merged
merged 7 commits into from
Nov 30, 2021
Merged

Handle and access repeated fields as arrays #78

merged 7 commits into from
Nov 30, 2021

Conversation

fsteeg
Copy link
Member

@fsteeg fsteeg commented Nov 25, 2021

Will resolve See #65.

This is far from consistent and a bit messy, but hopefully some steps in the right direction. I noted some TODOs which would result in some refactoring work (mainly around avoiding switch statements by moving functionality into enum elements; as well as consistent handling of special path segments like wildcards and indexes), but to make sure we're moving into the right direction, I'd like to focus on use cases right now.

For our OERSI use case (updated for this state in 8b27e98c), this provides some progress, but I don't think a functional review makes sense at this point. For that, I'd like to continue with the bind scope issues, which are related to #66. To avoid a larger and longer-running branch with these additional changes, I think it makes sense to review and merge the current work in progress at this point.

Copy link
Member

@blackwinter blackwinter left a comment

Choose a reason for hiding this comment

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

I agree that there's a lot left to be discussed. And I'm afraid the (lack of) test coverage isn't helping. For the time being, though, I guess I have to disagree that this "will resolve #65".

I would contend that it might be beneficial (crucial even) to collect (and discuss) an extensive number of tests illustrating the required use cases (a specification of sorts) - and then implement those, and only those.

metafix/src/main/java/org/metafacture/metafix/Value.java Outdated Show resolved Hide resolved
metafix/src/main/java/org/metafacture/metafix/Value.java Outdated Show resolved Hide resolved
metafix/src/main/java/org/metafacture/metafix/Value.java Outdated Show resolved Hide resolved
metafix/src/main/java/org/metafacture/metafix/Value.java Outdated Show resolved Hide resolved
metafix/src/main/java/org/metafacture/metafix/Value.java Outdated Show resolved Hide resolved
metafix/src/main/java/org/metafacture/metafix/Value.java Outdated Show resolved Hide resolved
case String:
append(Arrays.asList(newName).stream().collect(Collectors.joining(".")), v.asString());
break;
case Array:
Copy link
Member

Choose a reason for hiding this comment

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

Nothing to do?

metafix/src/main/java/org/metafacture/metafix/Value.java Outdated Show resolved Hide resolved
}
}
else if (fields.length >= 1 && isNumber(fields[0])) {
final int index = Integer.parseInt(fields[0]) - 1;
Copy link
Member

Choose a reason for hiding this comment

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

Isn't Catmandu zero-based?

Copy link
Member Author

Choose a reason for hiding this comment

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

result = find(tail(fields));
}
else if (isNumber(fields[0])) {
final int index = Integer.parseInt(fields[0]) - 1;
Copy link
Member

Choose a reason for hiding this comment

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

Again, zero-based.

Copy link
Member Author

Choose a reason for hiding this comment

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

@blackwinter blackwinter assigned fsteeg and unassigned blackwinter Nov 26, 2021
@fsteeg
Copy link
Member Author

fsteeg commented Nov 29, 2021

I would contend that it might be beneficial (crucial even) to collect (and discuss) an extensive number of tests illustrating the required use cases (a specification of sorts) - and then implement those, and only those.

I agree with that goal, and I was basically trying to go for that with the unit tests here. How can we better collect and discuss these use cases? Maybe something like really short fix snippets provided as use cases, also by @TobiasNx? Which we can run with Catmandu and Metafacture, and which we integrate as unit tests?

And thanks for the specific pointers here in the review, I'll work through them to clean this up some more. My main point for eventually merging this is that it fixes the current behavior of merging subsequent entities that have the same name.

@blackwinter
Copy link
Member

I was basically trying to go for that with the unit tests here.

I'm sure you were. It's just that there seems to be quite a lot of implemented behaviour that's not actually covered by any tests. Some might be edge cases (nested find in array with wildcard: a.*.c, and without wildcard: a.b.c), others probably not so much (nested remove in array: remove_field('name.*')).

As long as we're unsure about the intended behaviour, we shouldn't implement those cases. Conversely, any implemented behaviour should manifest itself somehow in the tests; so we know for sure when and how it might get changed in the future.

@blackwinter
Copy link
Member

My main point for eventually merging this is that it fixes the current behavior of merging subsequent entities that have the same name.

Would it be possible for you to reduce the pull request to the minimal requirements for your OERSI use case? Otherwise, I'll switch my vote to -0 as long as we're clear that any untested behaviour is considered experimental and subject to change (without notice).

@blackwinter
Copy link
Member

How can we better collect and discuss these use cases? Maybe something like really short fix snippets provided as use cases, also by @TobiasNx? Which we can run with Catmandu and Metafacture, and which we integrate as unit tests?

Certainly, that would be great. Ideally even accompanied by equivalent Catmandu tests (cf. hbz/Catmandu@22d7359).

The need to discuss referred to behaviour that's not as clear-cut in (or not applicable to) Catmandu. As for the process, I don't have any ideas right now other than pull requests (here and in hbz/Catmandu).

@blackwinter
Copy link
Member

It might even make sense to port the Catmandu test suite in order to ensure compatibility. The next step would be a shared collection of (generic/implementation-independent) test cases which would be executed by both (all) implementations (maybe akin to Parsing JSON is a Minefield: Testing Architecture).

@fsteeg
Copy link
Member Author

fsteeg commented Nov 30, 2021

Thanks again for your feedback, it helped me a lot, and I think this is starting to make sense. I've added TODOs / WDCDs (What Does Catmandu Do) for open questions.

any untested behaviour is considered experimental and subject to change (without notice)

+1

To approach the WDCDs, maybe we should wrap up this PR and focus on starting a setup for testing as you outlined here:

It might even make sense to port the Catmandu test suite in order to ensure compatibility. The next step would be a shared collection of (generic/implementation-independent) test cases which would be executed by both (all) implementations

I've always seen actual compatibility as a later step, but maybe it does make sense to start setting up something like that now. To get started, we could work on a modified version (with stuff like quoted variables as currently often required in Metafix etc.). It would still allow us to be guided by the Catmandu concepts, and provide a better way to work with examples (also for @TobiasNx, instead of working on full real-world examples as we currently do in OERSI).

@fsteeg fsteeg assigned blackwinter and unassigned fsteeg Nov 30, 2021
@fsteeg fsteeg requested a review from blackwinter November 30, 2021 10:52
Copy link
Member

@blackwinter blackwinter left a comment

Choose a reason for hiding this comment

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

OK, so here's my -0 for the sake of progress.

I'll intentionally leave any unresolved conversations (TODOs) open.

I still believe that #65 should not be closed as long as we're unclear about the big picture.

@blackwinter blackwinter assigned fsteeg and unassigned blackwinter Nov 30, 2021
@TobiasNx
Copy link
Collaborator

I do not know if the issue i found concerning creating arrays (with and without set_array) see #80 , is or should be part of this PR

@fsteeg
Copy link
Member Author

fsteeg commented Nov 30, 2021

I do not know if the issue i found concerning creating arrays (with and without set_array) see #80 , is or should be part of this PR

I think we should handle that separately. Merging this to avoid an even larger and longer-running branch. Expecting new pull requests after functional review of #65.

@fsteeg fsteeg merged commit c0d1ec4 into master Nov 30, 2021
@blackwinter blackwinter deleted the 65-arrays branch November 30, 2021 15:53
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants