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

adds equals implementation for PgArray #3174

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

vishalvrv9
Copy link
Contributor

All Submissions:

  • Have you followed the guidelines in our Contributing document?

New Feature Submissions:

  1. Does your submission pass tests?
  2. Does ./gradlew styleCheck pass ?
  3. Have you added your new test classes to an existing test suite in alphabetical order?

This PR aims to add implementation of equals() for PgArray #3170

For the hashcode() implementation, I've used https://www.baeldung.com/java-objects-hash-vs-objects-hashcode as reference

I have also added a few tests.

@davecramer @vlsi @sehrope suggestions are welcome.

@davecramer
Copy link
Member

@bokken Thoughts on this ?

@bokken
Copy link
Member

bokken commented Apr 14, 2024

I still have the questions from the issue: #3170 (comment)

@vishalvrv9
Copy link
Contributor Author

Answering the questions asked in #3170 below based on my understanding and usage of pgjdbc and as mentioned in #3170

Should it mean they represent the same logical contents?
Should it mean the contain the exact same literal data?

I think both of the above constraints should be true i.e. it should have the same logical contents (fieldString/fieldBytes) as well as the same literal data to consider 2 PgArray instances equal.

If a select statement which returns an array is executed 10 times in a row, should all of the PgArray instances be considered equal?

If the oids are same (which would be if they are the same type of array), have the same logical content (i.e. the row hasn't been updated amidst execution of returning array 10 times) and the same literals, it would be safe to consider them equal? Am I missing something?

or rather, would there be a case when equality should exist even though the logical contents and literal data might differ?

@bokken
Copy link
Member

bokken commented Apr 14, 2024

The problem is that the same logical context can be represented in multiple ways. The most obvious example is string vs binary representation.

My question about executing 10 selects in a row speaks directly to this difference. By default, the first 5 will return the string representation and all subsequent will return the binary.

This pr would not consider those 2 different representations of the same logical content as equal.

@vishalvrv9
Copy link
Contributor Author

Okay. Fair. I wasn't aware of the nature of first 5 selects returning the string representation and subsequent ones returning the binary. (where can I look to understand this behaviour better?)

In order to solve this, I'm thinking the below approach could be adopted:
Always checking the equality for only one of the type - either, byte arrays or fieldStrings i.e. even if we get field strings/bytes we first convert/encode them into bytes/strings and then check for equality.

But it makes me wonder, if the first 5 selects are string and the subsequent ones are binary, is it guaranteed that the binary representation would be valid and converting them to string would yield something can would have been stored as a fieldString if it was executed earlier?

@bokken
Copy link
Member

bokken commented Apr 15, 2024 via email

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.

None yet

4 participants