Skip to content

Commit

Permalink
[#3521] fix(client-python): Fix hash() function with multiple varia…
Browse files Browse the repository at this point in the history
…bles issue in `name_identitifer` (#3532)

### What changes were proposed in this pull request?

Fix `hash()` function in `name_identifier`.

### Why are the changes needed?

Fix: #3521 

### How was this patch tested?

Add a ut.

Co-authored-by: xloya <982052490@qq.com>
Co-authored-by: xiaojiebao <xiaojiebao@xiaomi.com>
  • Loading branch information
3 people authored May 23, 2024
1 parent da62f1d commit 587be02
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
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
22 changes: 22 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,22 @@
"""
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))
self.assertNotEqual("test2", identifier_dict.get(name_identifier1))

0 comments on commit 587be02

Please sign in to comment.