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

[#3521] fix(client-python): Fix hash() function with multiple variables issue in name_identitifer #3522

Merged
merged 2 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clients/client-python/gravitino/name_identifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def __eq__(self, other):
return self._namespace == other._namespace and self._name == other._name

def __hash__(self):
return hash(self._namespace, self._name)
return hash((self._namespace, self._name))

def __str__(self):
if self.has_namespace():
Expand Down
21 changes: 21 additions & 0 deletions clients/client-python/tests/unittests/test_name_identifier.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""
Copyright 2024 Datastrato Pvt Ltd.
This software is licensed under the Apache License version 2.
"""

import unittest

from gravitino import NameIdentifier


class TestNameIdentifier(unittest.TestCase):
def test_name_identifier_hash(self):
name_identifier1: NameIdentifier = NameIdentifier.of_fileset(
"test_metalake", "test_catalog", "test_schema", "test_fileset1"
)
name_identifier2: NameIdentifier = NameIdentifier.of_fileset(
"test_metalake", "test_catalog", "test_schema", "test_fileset2"
)
identifier_dict = {name_identifier1: "test1", name_identifier2: "test2"}

self.assertEqual("test1", identifier_dict.get(name_identifier1))
Copy link
Member

@xunliu xunliu May 23, 2024

Choose a reason for hiding this comment

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

I guess we could also add a assertNotEqual("test2", identifier_dict.get(name_identifier1))) in the use case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Loading