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

gh-282 ToIterable #286

Closed
wants to merge 4 commits into from
Closed

gh-282 ToIterable #286

wants to merge 4 commits into from

Conversation

GCHQDev404
Copy link
Contributor

@GCHQDev404 GCHQDev404 commented Oct 18, 2022

@codecov-commenter
Copy link

codecov-commenter commented Oct 18, 2022

Codecov Report

Merging #286 (f14bfb4) into develop (028e7bf) will increase coverage by 0.04%.
The diff coverage is 100.00%.

Impacted file tree graph

@@              Coverage Diff              @@
##             develop     #286      +/-   ##
=============================================
+ Coverage      82.08%   82.13%   +0.04%     
- Complexity      1616     1621       +5     
=============================================
  Files            194      195       +1     
  Lines           4316     4328      +12     
  Branches         435      437       +2     
=============================================
+ Hits            3543     3555      +12     
  Misses           592      592              
  Partials         181      181              
Impacted Files Coverage Δ
.../uk/gov/gchq/koryphe/impl/function/ToIterable.java 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 028e7bf...f14bfb4. Read the comment docs.

@n3101
Copy link

n3101 commented Oct 18, 2022

@GCHQDev404 @t92549 Should this PR be pointing at a 2.0 branch rather than develop?

@t92549
Copy link
Contributor

t92549 commented Oct 18, 2022

@GCHQDev404 @t92549 Should this PR be pointing at a 2.0 branch rather than develop?

Koryphe is on version 2.5.0 now so develop is tracking version 2

Copy link
Member

@GCHQDeveloper314 GCHQDeveloper314 left a comment

Choose a reason for hiding this comment

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

This new Class should be consistent with other classes of this sort.

Comment on lines +40 to +49
} else if (value.getClass().isArray()) {
try {
return Arrays.asList((Object[]) value);
} catch (final ClassCastException e) {
throw new UnsupportedOperationException("The given array is not of type Object[]", e);
}
} else {
rtn = Collections.singletonList(value);
}
return rtn;
Copy link
Member

Choose a reason for hiding this comment

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

This isn't consistent with the other Koryphe functions - see ToList.
The test should be value instanceof Object[] to see if it's an array of Object. There shouldn't be an exception because the cast won't fail. If value is an Array of primitives then it should be wrapped in the same way as happens for ToList. This is potentially unexpected behaviour, but if that is to be improved/fixed (e.g. so that primitives are supported), it should be done for all of Koryphe and in a separate issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this function not just a duplication of ToList? As it is making new Lists anyway

Copy link
Member

Choose a reason for hiding this comment

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

It returns Iterable<Object>, whereas ToList returns List<?>. I think you might be onto something here though. Instead of creating ToIterable, it might be possible to just cast or otherwise convert the result of ToList into an Iterable<Object>. If that can be done easily enough, then this class is redundant and shouldn't be merged.

Copy link
Member

Choose a reason for hiding this comment

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

See the comment in Gaffer PR #2769

@GCHQDev404
Copy link
Contributor Author

not required

@GCHQDev404 GCHQDev404 closed this Oct 25, 2022
@t92549 t92549 deleted the gh-282-ToIterable branch October 26, 2022 15:14
@GCHQDev404 GCHQDev404 restored the gh-282-ToIterable branch November 10, 2022 14:23
@GCHQDev404
Copy link
Contributor Author

This likely this is better with lazy Iterable, that ToList.

🔥 Phoenix

@GCHQDev404 GCHQDev404 reopened this Nov 10, 2022
rtn = Collections.emptyList();
} else if (value instanceof Iterable) {
//noinspection unchecked
rtn = (Iterable<Object>) value;
Copy link
Contributor

Choose a reason for hiding this comment

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

This line is key, if the input is a lazy iterable the same iterable it returned, whereas in ToList the whole iterable has to be read to make a list

Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't it be possible to change ToList to have a flag to do this instead of a duplicating class?
I know there was a reason Koryphe is being used somewhere like this, but if we know we have an Iterable, it doesn't make sense to me to be using Koryphe to turn something which is already an Iterable into itself. So while ToList is not a good solution, I'm not sure of the reason for using Koryphe at all.
It makes sense for Koryphe to accept a list and return the same thing, but I don't see why anyone would do this unless they didn't know they already had a list.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You don't know what is being returned from the individual graphs, until its returned.

3 graphs could return:
3 nulls
3 iterates of elements
3 schemas
3 strings
3 lists of strings.

@t92549
Copy link
Contributor

t92549 commented Jan 3, 2023

Closed again as not needed, superseded by gchq/Gaffer#2831

@t92549 t92549 closed this Jan 3, 2023
@t92549 t92549 deleted the gh-282-ToIterable branch January 3, 2023 15:44
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.

Add ToIterable from FederatedStore
5 participants