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

Add support for orderBy in multiple tables #149

Closed
cphillipszg opened this issue Aug 22, 2019 · 8 comments
Closed

Add support for orderBy in multiple tables #149

cphillipszg opened this issue Aug 22, 2019 · 8 comments
Milestone

Comments

@cphillipszg
Copy link

cphillipszg commented Aug 22, 2019

orderBy as written compares every orderBy against every table in the expected data set. If the orderBy column doesn't exist in one of the provided tables it will NPE.

For example:

# expected.yml
foo:
  - id: 1
  - id: 2
bar:
   - uuid: "uuid'3e6a4f38-f9b3-4697-bf9c-f9e957af2fdb'"
@ExpectedDataSet(value = "expected.yml", orderBy = "id")

The implementation of orderBy is critically flawed. Which tables should orderBy apply to? Should users be forced to supply one file per table and each array index mapped to an orderBy index? In that case, how would you handle ordering multiple columns for multiple tables?

DbUnit had DatabaseAssertionMode.NON_STRICT_UNORDERED which worked exactly as expected: it compares records without respect to ordering. Can't we please just have that? 😭

@rmpestano
Copy link
Member

rmpestano commented Aug 23, 2019

If the orderBy column doesn't exist in one of the provided tables it will NPE.

We can fix that, thanks for the feedback

The implementation of orderBy is critically flawed. Which tables should orderBy apply to?

All tables, so you must use a common column to all tables involved in expected dataset, otherwise how would order by work for different columns? which one takes priority on the ordering when more than one column is present on a table? do you have a better solution for that?

DbUnit had DatabaseAssertionMode.NON_STRICT_UNORDERED which worked exactly as expected: it compares records without respect to ordering. Can't we please just have that?

I think that is the default when orderBy attribute is not used, isn't it?

@rmpestano
Copy link
Member

I agree that would be better if we could specify table and column in order by I'm just not sure if there is a simple way to do that without polluting/making the API harder to use

@jenskreidler
Copy link
Collaborator

jenskreidler commented Aug 23, 2019 via email

@rmpestano
Copy link
Member

rmpestano commented Aug 23, 2019

Hi @jenskreidler, thank you again for the helpful insight!

I think it is definitely doable and also backward compatible which is great.

Anyone else agree/disagree?

@rmpestano rmpestano changed the title major issue with orderBy Add support for orderBy in multiple tables Aug 23, 2019
@rmpestano rmpestano added this to the 1.8.0 milestone Aug 23, 2019
@cphillipszg
Copy link
Author

DbUnit had DatabaseAssertionMode.NON_STRICT_UNORDERED which worked exactly as expected: it compares records without respect to ordering. Can't we please just have that?

I think that is the default when orderBy attribute is not used, isn't it?

No that's not the default. #76 highlights the original problem.

Here's the docs on spring-test-dbunit NON_STRICT_UNORDERED, and the original PR that spawned it for more insight into the problem and the solution it provides.

I would like to object to the renaming of this issue as well, because I'd much rather have unordered comparisons than to support multiple orderBy.

@cphillipszg
Copy link
Author

I agree that would be better if we could specify table and column in order by I'm just not sure if there is a simple way to do that without polluting/making the API harder to use

This is why the existing implementation is critically flawed. I'd much rather see a compareOperation = CompareOperation.NON_STRICT_UNORDERED solution.

@rmpestano
Copy link
Member

Hi @cphillipszg,

I would like to object to the renaming of this issue as well, because I'd much rather have unordered comparisons than to support multiple orderBy.

so please, state what you need because "major issue with orderBy" also doesn't say much.

This is why the existing implementation is critically flawed

Well I think "critically flawed" is a bit harsh, it works for most case, actually it would be nice to have a failing test where currentorder by doesn't work (not the NPE which can be fixed by ignoring unknow columns)

@rmpestano rmpestano modified the milestones: 1.8.0, 1.7.3 Sep 8, 2019
@rmpestano
Copy link
Member

Fixed according to @jenskreidler comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants