Skip to content

World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.

[#3769] fix(client-python): fix invalid-field-call issue (#3809)

Liang Chun29bf1225f286
diff --git a/clients/client-python/gravitino/api/fileset_change.py b/clients/client-python/gravitino/api/fileset_change.py
index 6e70eb0321..74473e1996 100644
--- a/clients/client-python/gravitino/api/fileset_change.py
+++ b/clients/client-python/gravitino/api/fileset_change.py
@@ -4,7 +4,7 @@ This software is licensed under the Apache License version 2.
"""
from abc import ABC
-from dataclasses import field
+from dataclasses import dataclass, field
from dataclasses_json import config
@@ -63,14 +63,12 @@ class FilesetChange(ABC):
"""
return FilesetChange.RemoveProperty(fileset_property)
+ @dataclass
class RenameFileset:
"""A fileset change to rename the fileset."""
_new_name: str = field(metadata=config(field_name="new_name"))
- def __init__(self, new_name):
- self._new_name = new_name
-
def new_name(self):
"""Retrieves the new name set for the fileset.
@@ -111,14 +109,12 @@ class FilesetChange(ABC):
"""
return f"RENAMEFILESET {self._new_name}"
+ @dataclass
class UpdateFilesetComment:
"""A fileset change to update the fileset comment."""
_new_comment: str = field(metadata=config(field_name="new_comment"))
- def __init__(self, new_comment):
- self._new_comment = new_comment
-
def new_comment(self):
"""Retrieves the new comment intended for the fileset.
@@ -159,16 +155,13 @@ class FilesetChange(ABC):
"""
return f"UPDATEFILESETCOMMENT {self._new_comment}"
+ @dataclass
class SetProperty:
"""A fileset change to set the property and value for the fileset."""
_property: str = field(metadata=config(field_name="property"))
_value: str = field(metadata=config(field_name="value"))
- def __init__(self, fileset_property: str, value: str):
- self._property = fileset_property
- self._value = value
-
def property(self):
"""Retrieves the name of the property being set in the fileset.
@@ -217,14 +210,12 @@ class FilesetChange(ABC):
"""
return f"SETPROPERTY {self._property} {self._value}"
+ @dataclass
class RemoveProperty:
"""A fileset change to remove a property from the fileset."""
_property: str = field(metadata=config(field_name="property"))
- def __init__(self, fileset_property: str):
- self._property = fileset_property
-
def property(self):
"""Retrieves the name of the property to be removed from the fileset.
diff --git a/clients/client-python/gravitino/api/schema_change.py b/clients/client-python/gravitino/api/schema_change.py
index 3dd0580303..7b56b265af 100644
--- a/clients/client-python/gravitino/api/schema_change.py
+++ b/clients/client-python/gravitino/api/schema_change.py
@@ -4,7 +4,7 @@ This software is licensed under the Apache License version 2.
"""
from abc import ABC
-from dataclasses import field
+from dataclasses import dataclass, field
from dataclasses_json import config
@@ -37,16 +37,13 @@ class SchemaChange(ABC):
"""
return SchemaChange.RemoveProperty(schema_property)
+ @dataclass
class SetProperty:
"""SchemaChange class to set the property and value pairs for the schema."""
_property: str = field(metadata=config(field_name="property"))
_value: str = field(metadata=config(field_name="value"))
- def __init__(self, schema_property: str, value: str):
- self._property = schema_property
- self._value = value
-
def property(self):
"""Retrieves the name of the property to be set.
@@ -95,14 +92,12 @@ class SchemaChange(ABC):
"""
return f"SETPROPERTY {self._property} {self._value}"
+ @dataclass
class RemoveProperty:
"""SchemaChange class to remove a property from the schema."""
_property: str = field(metadata=config(field_name="property"))
- def __init__(self, schema_property: str):
- self._property = schema_property
-
def property(self):
"""Retrieves the name of the property to be removed.
diff --git a/clients/client-python/gravitino/dto/dto_converters.py b/clients/client-python/gravitino/dto/dto_converters.py
index 294c0aa430..061948166e 100644
--- a/clients/client-python/gravitino/dto/dto_converters.py
+++ b/clients/client-python/gravitino/dto/dto_converters.py
@@ -54,9 +54,11 @@ class DTOConverters:
@staticmethod
def to_catalog_update_request(change: CatalogChange):
if isinstance(change, CatalogChange.RenameCatalog):
- return CatalogUpdateRequest.RenameCatalogRequest(change.new_name)
+ return CatalogUpdateRequest.RenameCatalogRequest(change.new_name())
if isinstance(change, CatalogChange.UpdateCatalogComment):
- return CatalogUpdateRequest.UpdateCatalogCommentRequest(change.new_comment)
+ return CatalogUpdateRequest.UpdateCatalogCommentRequest(
+ change.new_comment()
+ )
if isinstance(change, CatalogChange.SetProperty):
# TODO
# pylint: disable=too-many-function-args
diff --git a/clients/client-python/gravitino/dto/requests/catalog_update_request.py b/clients/client-python/gravitino/dto/requests/catalog_update_request.py
index c8dc720015..9db2be5888 100644
--- a/clients/client-python/gravitino/dto/requests/catalog_update_request.py
+++ b/clients/client-python/gravitino/dto/requests/catalog_update_request.py
@@ -28,11 +28,19 @@ class CatalogUpdateRequestBase(RESTRequest):
class CatalogUpdateRequest:
"""Represents an interface for catalog update requests."""
+ @dataclass
class RenameCatalogRequest(CatalogUpdateRequestBase):
- new_name: Optional[str] = field(metadata=config(field_name="newName"))
+ """Represents a request to rename a catalog."""
+
+ _new_name: Optional[str] = field(metadata=config(field_name="newName"))
+ """The new name for the catalog."""
+
+ def __init__(self, new_name: str):
+ super().__init__("rename")
+ self._new_name = new_name
def catalog_change(self):
- return CatalogChange.rename(self.new_name)
+ return CatalogChange.rename(self._new_name)
def validate(self):
"""Validates the fields of the request.
@@ -41,46 +49,66 @@ class CatalogUpdateRequest:
IllegalArgumentException if the new name is not set.
"""
assert (
- self.new_name is None
+ self._new_name is None
), '"newName" field is required and cannot be empty'
+ @dataclass
class UpdateCatalogCommentRequest(CatalogUpdateRequestBase):
"""Request to update the comment of a catalog."""
- new_comment: Optional[str] = field(metadata=config(field_name="newComment"))
+ _new_comment: Optional[str] = field(metadata=config(field_name="newComment"))
+ """The new comment for the catalog."""
+
+ def __init__(self, new_comment: str):
+ super().__init__("updateComment")
+ self._new_comment = new_comment
def catalog_change(self):
- return CatalogChange.update_comment(self.new_comment)
+ return CatalogChange.update_comment(self._new_comment)
def validate(self):
assert (
- self.new_comment is None
+ self._new_comment is None
), '"newComment" field is required and cannot be empty'
+ @dataclass
class SetCatalogPropertyRequest(CatalogUpdateRequestBase):
"""Request to set a property on a catalog."""
- property: Optional[str] = None
- value: Optional[str] = None
+ _property: Optional[str] = field(metadata=config(field_name="property"))
+ """The property to set."""
+
+ _value: Optional[str] = field(metadata=config(field_name="value"))
+ """The value of the property."""
+
+ def __init__(self, catalog_property: str, value: str):
+ super().__init__("setProperty")
+ self._property = catalog_property
+ self._value = value
def catalog_change(self):
- return CatalogChange.set_property(self.property, self.value)
+ return CatalogChange.set_property(self._property, self._value)
def validate(self):
assert (
- self.property is None
+ self._property is None
), '"property" field is required and cannot be empty'
- assert self.value is None, '"value" field is required and cannot be empty'
+ assert self._value is None, '"value" field is required and cannot be empty'
class RemoveCatalogPropertyRequest(CatalogUpdateRequestBase):
"""Request to remove a property from a catalog."""
property: Optional[str] = None
+ """The property to remove."""
+
+ def __init__(self, catalog_property: str):
+ super().__init__("removeProperty")
+ self._property = catalog_property
def catalog_change(self):
- return CatalogChange.remove_property(self.property)
+ return CatalogChange.remove_property(self._property)
def validate(self):
assert (
- self.property is None
+ self._property is None
), '"property" field is required and cannot be empty'
diff --git a/clients/client-python/pylintrc b/clients/client-python/pylintrc
index 431bd64675..e2e398e93c 100644
--- a/clients/client-python/pylintrc
+++ b/clients/client-python/pylintrc
@@ -25,7 +25,6 @@ disable=missing-class-docstring,
missing-timeout, #TODO-fix
broad-exception-caught, #TODO-fix
duplicate-code, #TODO-fix
- invalid-field-call, #TODO-fix
too-many-arguments, #TODO-fix
[LOGGING]