-
Notifications
You must be signed in to change notification settings - Fork 154
Resolve AttributeError: 'ScalaFunction1' object has no attribute 'hashCode'. #184
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1366,4 +1366,25 @@ def test_fail_list_of_constraints(self): | |
| .run() | ||
|
|
||
| df = VerificationResult.checkResultsAsDataFrame(self.spark, result) | ||
| self.assertEqual(df.select("constraint_status").collect(), [Row(constraint_status="Success"), Row(constraint_status="Success")]) | ||
| self.assertEqual(df.select("constraint_status").collect(), [Row(constraint_status="Success"), Row(constraint_status="Success")]) | ||
|
|
||
| def test_hash_code(self): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DESIGN: The test repeatedly calls
|
||
| """ | ||
| Lack of Exception is passing. Previously this test would fail with: | ||
| AttributeError: 'ScalaFunction1' object has no attribute 'hashCode' | ||
| """ | ||
| vrb = VerificationSuite(self.spark) \ | ||
| .onData(self.df) | ||
| check = Check(self.spark, CheckLevel.Error, "Enough checks to trigger a hashCode not an attribute of ScalaFunction1") | ||
| check.isComplete('b') | ||
| vrb.addCheck(check) | ||
| check.containsEmail('email') | ||
| vrb.addCheck(check) | ||
| check.isGreaterThanOrEqualTo("d", "b") | ||
| vrb.addCheck(check) | ||
| check.isLessThanOrEqualTo("b", "d") | ||
| vrb.addCheck(check) | ||
| check.hasDataType("d", ConstrainableDataTypes.String, lambda x: x >= 1) | ||
| vrb.addCheck(check) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need to add and verify one by one?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because that is the use case for triggering the exception. If I change the test like so, it does not use
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it only fail at the magic 5th one? It's a big strange if so.. btw CI is failing on this test
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The issue write up has more info: #91
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't replicate the error in CI but submitted an attempt to fix it. |
||
|
|
||
| result = vrb.run() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MISSING_TEST: The test never asserts anything about the result of
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EDGE_CASE: Using
hash()on a lambda function returns a value based on the lambda's identity (memory address), not its logical content. Two identical lambda expressions (e.g.,lambda x: x > 10defined twice) will produce different hash values, makinghashCode()non-deterministic across equivalent functions. More critically,hash()in Python can return negative values or values outside Java'sintrange, andInteger.hashCode(int)on the JVM expects a Java int. Ifhash(self.lambda_function)returns a Python int larger thanInteger.MAX_VALUEor smaller thanInteger.MIN_VALUE, this could cause unexpected behavior or overflow when passed through py4j.