diff --git a/hazelcast/proxy/map.py b/hazelcast/proxy/map.py index 05c892b4cc..fb2aceac5e 100644 --- a/hazelcast/proxy/map.py +++ b/hazelcast/proxy/map.py @@ -187,7 +187,7 @@ def add_entry_listener( LOADED=loaded_func, ) - if key is not None and predicate: + if key is not None and predicate is not None: try: key_data = self._to_data(key) predicate_data = self._to_data(predicate) @@ -215,7 +215,7 @@ def add_entry_listener( ) response_decoder = with_key_and_predicate_codec.decode_response event_message_handler = with_key_and_predicate_codec.handle - elif key is not None and not predicate: + elif key is not None and predicate is None: try: key_data = self._to_data(key) except SchemaNotReplicatedError as e: @@ -242,7 +242,7 @@ def add_entry_listener( ) response_decoder = with_key_codec.decode_response event_message_handler = with_key_codec.handle - elif key is None and predicate: + elif key is None and predicate is not None: try: predicate = self._to_data(predicate) except SchemaNotReplicatedError as e: diff --git a/hazelcast/proxy/replicated_map.py b/hazelcast/proxy/replicated_map.py index bf21174867..657a5d9dc5 100644 --- a/hazelcast/proxy/replicated_map.py +++ b/hazelcast/proxy/replicated_map.py @@ -78,7 +78,7 @@ def add_entry_listener( Returns: A registration id which is used as a key to remove the listener. """ - if key is not None and predicate: + if key is not None and predicate is not None: try: key_data = self._to_data(key) predicate_data = self._to_data(predicate) @@ -103,7 +103,7 @@ def add_entry_listener( ) response_decoder = with_key_and_predicate_codec.decode_response event_message_handler = with_key_and_predicate_codec.handle - elif key is not None and not predicate: + elif key is not None and predicate is None: try: key_data = self._to_data(key) except SchemaNotReplicatedError as e: @@ -123,7 +123,7 @@ def add_entry_listener( request = with_key_codec.encode_request(self.name, key_data, self._is_smart) response_decoder = with_key_codec.decode_response event_message_handler = with_key_codec.handle - elif key is None and predicate: + elif key is None and predicate is not None: try: predicate = self._to_data(predicate) except SchemaNotReplicatedError as e: diff --git a/hazelcast/serialization/api.py b/hazelcast/serialization/api.py index 1b0ec738f1..e492251727 100644 --- a/hazelcast/serialization/api.py +++ b/hazelcast/serialization/api.py @@ -1175,33 +1175,30 @@ class CompactReader(abc.ABC): """ @abc.abstractmethod - def read_boolean(self, field_name: str) -> bool: - """Reads a boolean. + def get_field_kind(self, field_name): + """Returns the FieldKind for the given field. Args: field_name: Name of the field. Returns: - The value of the field. - - Raises: - HazelcastSerializationError: If the field does not exist in the - schema or the type of the field does not match with the one - defined in the schema. + Field kind for the given field. or FieldKind.NOT_AVAILABLE if the field does not exist. """ @abc.abstractmethod - def read_boolean_or_default(self, field_name: str, default: bool) -> bool: - """Reads a boolean or returns the default value. + def read_boolean(self, field_name: str) -> bool: + """Reads a boolean. Args: field_name: Name of the field. - default: Default value to return if the field with the given name - does not exist in the schema or the type of the field does not - match with the one defined in the schema. Returns: - The value or the default value of the field. + The value of the field. + + Raises: + HazelcastSerializationError: If the field does not exist in the + schema or the type of the field does not match with the one + defined in the schema. """ @abc.abstractmethod @@ -1220,22 +1217,6 @@ def read_nullable_boolean(self, field_name: str) -> typing.Optional[bool]: defined in the schema. """ - @abc.abstractmethod - def read_nullable_boolean_or_default( - self, field_name: str, default: typing.Optional[bool] - ) -> typing.Optional[bool]: - """Reads a nullable boolean or returns the default value. - - Args: - field_name: Name of the field. - default: Default value to return if the field with the given name - does not exist in the schema or the type of the field does not - match with the one defined in the schema. - - Returns: - The value or the default value of the field. - """ - @abc.abstractmethod def read_int8(self, field_name: str) -> int: """Reads an 8-bit two's complement signed integer. @@ -1252,21 +1233,6 @@ def read_int8(self, field_name: str) -> int: defined in the schema. """ - @abc.abstractmethod - def read_int8_or_default(self, field_name: str, default: int) -> int: - """Reads an 8-bit two's complement signed integer or returns the - default value. - - Args: - field_name: Name of the field. - default: Default value to return if the field with the given name - does not exist in the schema or the type of the field does not - match with the one defined in the schema. - - Returns: - The value or the default value of the field. - """ - @abc.abstractmethod def read_nullable_int8(self, field_name: str) -> typing.Optional[int]: """Reads a nullable 8-bit two's complement signed integer. @@ -1283,23 +1249,6 @@ def read_nullable_int8(self, field_name: str) -> typing.Optional[int]: defined in the schema. """ - @abc.abstractmethod - def read_nullable_int8_or_default( - self, field_name: str, default: typing.Optional[int] - ) -> typing.Optional[int]: - """Reads a nullable 8-bit two's complement signed integer or returns - the default value. - - Args: - field_name: Name of the field. - default: Default value to return if the field with the given name - does not exist in the schema or the type of the field does not - match with the one defined in the schema. - - Returns: - The value or the default value of the field. - """ - @abc.abstractmethod def read_int16(self, field_name: str) -> int: """Reads a 16-bit two's complement signed integer. @@ -1316,21 +1265,6 @@ def read_int16(self, field_name: str) -> int: defined in the schema. """ - @abc.abstractmethod - def read_int16_or_default(self, field_name: str, default: int) -> int: - """Reads a 16-bit two's complement signed integer or returns the - default value. - - Args: - field_name: Name of the field. - default: Default value to return if the field with the given name - does not exist in the schema or the type of the field does not - match with the one defined in the schema. - - Returns: - The value or the default value of the field. - """ - @abc.abstractmethod def read_nullable_int16(self, field_name: str) -> typing.Optional[int]: """Reads a nullable 16-bit two's complement signed integer. @@ -1347,23 +1281,6 @@ def read_nullable_int16(self, field_name: str) -> typing.Optional[int]: defined in the schema. """ - @abc.abstractmethod - def read_nullable_int16_or_default( - self, field_name: str, default: typing.Optional[int] - ) -> typing.Optional[int]: - """Reads a nullable 16-bit two's complement signed integer or returns - the default value. - - Args: - field_name: Name of the field. - default: Default value to return if the field with the given name - does not exist in the schema or the type of the field does not - match with the one defined in the schema. - - Returns: - The value or the default value of the field. - """ - @abc.abstractmethod def read_int32(self, field_name: str) -> int: """Reads a 32-bit two's complement signed integer. @@ -1380,21 +1297,6 @@ def read_int32(self, field_name: str) -> int: defined in the schema. """ - @abc.abstractmethod - def read_int32_or_default(self, field_name: str, default: int) -> int: - """Reads a 32-bit two's complement signed integer or returns the - default value. - - Args: - field_name: Name of the field. - default: Default value to return if the field with the given name - does not exist in the schema or the type of the field does not - match with the one defined in the schema. - - Returns: - The value or the default value of the field. - """ - @abc.abstractmethod def read_nullable_int32(self, field_name: str) -> typing.Optional[int]: """Reads a nullable 32-bit two's complement signed integer. @@ -1411,23 +1313,6 @@ def read_nullable_int32(self, field_name: str) -> typing.Optional[int]: defined in the schema. """ - @abc.abstractmethod - def read_nullable_int32_or_default( - self, field_name: str, default: typing.Optional[int] - ) -> typing.Optional[int]: - """Reads a nullable 32-bit two's complement signed integer or returns - the default value. - - Args: - field_name: Name of the field. - default: Default value to return if the field with the given name - does not exist in the schema or the type of the field does not - match with the one defined in the schema. - - Returns: - The value or the default value of the field. - """ - @abc.abstractmethod def read_int64(self, field_name: str) -> int: """Reads a 64-bit two's complement signed integer. @@ -1444,21 +1329,6 @@ def read_int64(self, field_name: str) -> int: defined in the schema. """ - @abc.abstractmethod - def read_int64_or_default(self, field_name: str, default: int) -> int: - """Reads a 64-bit two's complement signed integer or returns the - default value. - - Args: - field_name: Name of the field. - default: Default value to return if the field with the given name - does not exist in the schema or the type of the field does not - match with the one defined in the schema. - - Returns: - The value or the default value of the field. - """ - @abc.abstractmethod def read_nullable_int64(self, field_name: str) -> typing.Optional[int]: """Reads a nullable 64-bit two's complement signed integer. @@ -1475,23 +1345,6 @@ def read_nullable_int64(self, field_name: str) -> typing.Optional[int]: defined in the schema. """ - @abc.abstractmethod - def read_nullable_int64_or_default( - self, field_name: str, default: typing.Optional[int] - ) -> typing.Optional[int]: - """Reads a nullable 64-bit two's complement signed integer or returns - the default value. - - Args: - field_name: Name of the field. - default: Default value to return if the field with the given name - does not exist in the schema or the type of the field does not - match with the one defined in the schema. - - Returns: - The value or the default value of the field. - """ - @abc.abstractmethod def read_float32(self, field_name: str) -> float: """Reads a 32-bit IEEE 754 floating point number. @@ -1508,21 +1361,6 @@ def read_float32(self, field_name: str) -> float: defined in the schema. """ - @abc.abstractmethod - def read_float32_or_default(self, field_name: str, default: float) -> float: - """Reads a 32-bit IEEE 754 floating point number or returns the - default value. - - Args: - field_name: Name of the field. - default: Default value to return if the field with the given name - does not exist in the schema or the type of the field does not - match with the one defined in the schema. - - Returns: - The value or the default value of the field. - """ - @abc.abstractmethod def read_nullable_float32(self, field_name: str) -> typing.Optional[float]: """Reads a nullable 32-bit IEEE 754 floating point number. @@ -1539,23 +1377,6 @@ def read_nullable_float32(self, field_name: str) -> typing.Optional[float]: defined in the schema. """ - @abc.abstractmethod - def read_nullable_float32_or_default( - self, field_name: str, default: typing.Optional[float] - ) -> typing.Optional[float]: - """Reads a nullable 32-bit IEEE 754 floating point number or returns - the default value. - - Args: - field_name: Name of the field. - default: Default value to return if the field with the given name - does not exist in the schema or the type of the field does not - match with the one defined in the schema. - - Returns: - The value or the default value of the field. - """ - @abc.abstractmethod def read_float64(self, field_name: str) -> float: """Reads a 64-bit IEEE 754 floating point number. @@ -1572,21 +1393,6 @@ def read_float64(self, field_name: str) -> float: defined in the schema. """ - @abc.abstractmethod - def read_float64_or_default(self, field_name: str, default: float) -> float: - """Reads a 64-bit IEEE 754 floating point number or returns the - default value. - - Args: - field_name: Name of the field. - default: Default value to return if the field with the given name - does not exist in the schema or the type of the field does not - match with the one defined in the schema. - - Returns: - The value or the default value of the field. - """ - @abc.abstractmethod def read_nullable_float64(self, field_name: str) -> typing.Optional[float]: """Reads a nullable 64-bit IEEE 754 floating point number. @@ -1603,23 +1409,6 @@ def read_nullable_float64(self, field_name: str) -> typing.Optional[float]: defined in the schema. """ - @abc.abstractmethod - def read_nullable_float64_or_default( - self, field_name: str, default: typing.Optional[float] - ) -> typing.Optional[float]: - """Reads a nullable 64-bit IEEE 754 floating point number or returns - the default value. - - Args: - field_name: Name of the field. - default: Default value to return if the field with the given name - does not exist in the schema or the type of the field does not - match with the one defined in the schema. - - Returns: - The value or the default value of the field. - """ - @abc.abstractmethod def read_string(self, field_name: str) -> typing.Optional[str]: """Reads an UTF-8 encoded string. @@ -1636,22 +1425,6 @@ def read_string(self, field_name: str) -> typing.Optional[str]: defined in the schema. """ - @abc.abstractmethod - def read_string_or_default( - self, field_name: str, default: typing.Optional[str] - ) -> typing.Optional[str]: - """Reads an UTF-8 encoded string or returns the default value. - - Args: - field_name: Name of the field. - default: Default value to return if the field with the given name - does not exist in the schema or the type of the field does not - match with the one defined in the schema. - - Returns: - The value or the default value of the field. - """ - @abc.abstractmethod def read_decimal(self, field_name: str) -> typing.Optional[decimal.Decimal]: """Reads an arbitrary precision and scale floating point number. @@ -1668,23 +1441,6 @@ def read_decimal(self, field_name: str) -> typing.Optional[decimal.Decimal]: defined in the schema. """ - @abc.abstractmethod - def read_decimal_or_default( - self, field_name: str, default: typing.Optional[decimal.Decimal] - ) -> typing.Optional[decimal.Decimal]: - """Reads an arbitrary precision and scale floating point number or - returns the default value. - - Args: - field_name: Name of the field. - default: Default value to return if the field with the given name - does not exist in the schema or the type of the field does not - match with the one defined in the schema. - - Returns: - The value or the default value of the field. - """ - @abc.abstractmethod def read_time(self, field_name: str) -> typing.Optional[datetime.time]: """Reads a time consisting of hour, minute, second, and nanoseconds. @@ -1701,23 +1457,6 @@ def read_time(self, field_name: str) -> typing.Optional[datetime.time]: defined in the schema. """ - @abc.abstractmethod - def read_time_or_default( - self, field_name: str, default: typing.Optional[datetime.time] - ) -> typing.Optional[datetime.time]: - """Reads a time consisting of hour, minute, second, and nanoseconds or - returns the default value. - - Args: - field_name: Name of the field. - default: Default value to return if the field with the given name - does not exist in the schema or the type of the field does not - match with the one defined in the schema. - - Returns: - The value or the default value of the field. - """ - @abc.abstractmethod def read_date(self, field_name: str) -> typing.Optional[datetime.date]: """Reads a date consisting of year, month, and day. @@ -1734,23 +1473,6 @@ def read_date(self, field_name: str) -> typing.Optional[datetime.date]: defined in the schema. """ - @abc.abstractmethod - def read_date_or_default( - self, field_name: str, default: typing.Optional[datetime.date] - ) -> typing.Optional[datetime.date]: - """Reads a date consisting of year, month, and day or returns the - default value. - - Args: - field_name: Name of the field. - default: Default value to return if the field with the given name - does not exist in the schema or the type of the field does not - match with the one defined in the schema. - - Returns: - The value or the default value of the field. - """ - @abc.abstractmethod def read_timestamp(self, field_name: str) -> typing.Optional[datetime.datetime]: """Reads a timestamp consisting of date and time. @@ -1767,23 +1489,6 @@ def read_timestamp(self, field_name: str) -> typing.Optional[datetime.datetime]: defined in the schema. """ - @abc.abstractmethod - def read_timestamp_or_default( - self, field_name: str, default: typing.Optional[datetime.datetime] - ) -> typing.Optional[datetime.datetime]: - """Reads a timestamp consisting of date and time or returns the - default value. - - Args: - field_name: Name of the field. - default: Default value to return if the field with the given name - does not exist in the schema or the type of the field does not - match with the one defined in the schema. - - Returns: - The value or the default value of the field. - """ - @abc.abstractmethod def read_timestamp_with_timezone(self, field_name: str) -> typing.Optional[datetime.datetime]: """Reads a timestamp with timezone consisting of date, time and @@ -1801,23 +1506,6 @@ def read_timestamp_with_timezone(self, field_name: str) -> typing.Optional[datet defined in the schema. """ - @abc.abstractmethod - def read_timestamp_with_timezone_or_default( - self, field_name: str, default: typing.Optional[datetime.datetime] - ) -> typing.Optional[datetime.datetime]: - """Reads a timestamp with timezone consisting of date, time and - timezone offset or returns the default value. - - Args: - field_name: Name of the field. - default: Default value to return if the field with the given name - does not exist in the schema or the type of the field does not - match with the one defined in the schema. - - Returns: - The value or the default value of the field. - """ - @abc.abstractmethod def read_compact(self, field_name: str) -> typing.Optional[typing.Any]: """Reads a compact object. @@ -1834,22 +1522,6 @@ def read_compact(self, field_name: str) -> typing.Optional[typing.Any]: defined in the schema. """ - @abc.abstractmethod - def read_compact_or_default( - self, field_name: str, default: typing.Optional[typing.Any] - ) -> typing.Optional[typing.Any]: - """Reads a compact object or returns the default value. - - Args: - field_name: Name of the field. - default: Default value to return if the field with the given name - does not exist in the schema or the type of the field does not - match with the one defined in the schema. - - Returns: - The value or the default value of the field. - """ - @abc.abstractmethod def read_array_of_boolean(self, field_name: str) -> typing.Optional[typing.List[bool]]: """Reads an array of booleans. @@ -1866,22 +1538,6 @@ def read_array_of_boolean(self, field_name: str) -> typing.Optional[typing.List[ defined in the schema. """ - @abc.abstractmethod - def read_array_of_boolean_or_default( - self, field_name: str, default: typing.Optional[typing.List[bool]] - ) -> typing.Optional[typing.List[bool]]: - """Reads an array of booleans or returns the default value. - - Args: - field_name: Name of the field. - default: Default value to return if the field with the given name - does not exist in the schema or the type of the field does not - match with the one defined in the schema. - - Returns: - The value or the default value of the field. - """ - @abc.abstractmethod def read_array_of_nullable_boolean( self, field_name: str @@ -1900,22 +1556,6 @@ def read_array_of_nullable_boolean( defined in the schema. """ - @abc.abstractmethod - def read_array_of_nullable_boolean_or_default( - self, field_name: str, default: typing.Optional[typing.List[typing.Optional[bool]]] - ) -> typing.Optional[typing.List[typing.Optional[bool]]]: - """Reads an array of nullable booleans or returns the default value. - - Args: - field_name: Name of the field. - default: Default value to return if the field with the given name - does not exist in the schema or the type of the field does not - match with the one defined in the schema. - - Returns: - The value or the default value of the field. - """ - @abc.abstractmethod def read_array_of_int8(self, field_name: str) -> typing.Optional[typing.List[int]]: """Reads an array of 8-bit two's complement signed integers. @@ -1932,23 +1572,6 @@ def read_array_of_int8(self, field_name: str) -> typing.Optional[typing.List[int defined in the schema. """ - @abc.abstractmethod - def read_array_of_int8_or_default( - self, field_name: str, default: typing.Optional[typing.List[int]] - ) -> typing.Optional[typing.List[int]]: - """Reads an array of 8-bit two's complement signed integers or returns - the default value. - - Args: - field_name: Name of the field. - default: Default value to return if the field with the given name - does not exist in the schema or the type of the field does not - match with the one defined in the schema. - - Returns: - The value or the default value of the field. - """ - @abc.abstractmethod def read_array_of_nullable_int8( self, field_name: str @@ -1967,23 +1590,6 @@ def read_array_of_nullable_int8( defined in the schema. """ - @abc.abstractmethod - def read_array_of_nullable_int8_or_default( - self, field_name: str, default: typing.Optional[typing.List[typing.Optional[int]]] - ) -> typing.Optional[typing.List[typing.Optional[int]]]: - """Reads an array of nullable 8-bit two's complement signed integers - or returns the default value. - - Args: - field_name: Name of the field. - default: Default value to return if the field with the given name - does not exist in the schema or the type of the field does not - match with the one defined in the schema. - - Returns: - The value or the default value of the field. - """ - @abc.abstractmethod def read_array_of_int16(self, field_name: str) -> typing.Optional[typing.List[int]]: """Reads an array of 16-bit two's complement signed integers. @@ -2000,23 +1606,6 @@ def read_array_of_int16(self, field_name: str) -> typing.Optional[typing.List[in defined in the schema. """ - @abc.abstractmethod - def read_array_of_int16_or_default( - self, field_name: str, default: typing.Optional[typing.List[int]] - ) -> typing.Optional[typing.List[int]]: - """Reads an array of 16-bit two's complement signed integers or - returns the default value. - - Args: - field_name: Name of the field. - default: Default value to return if the field with the given name - does not exist in the schema or the type of the field does not - match with the one defined in the schema. - - Returns: - The value or the default value of the field. - """ - @abc.abstractmethod def read_array_of_nullable_int16( self, field_name: str @@ -2035,23 +1624,6 @@ def read_array_of_nullable_int16( defined in the schema. """ - @abc.abstractmethod - def read_array_of_nullable_int16_or_default( - self, field_name: str, default: typing.Optional[typing.List[typing.Optional[int]]] - ) -> typing.Optional[typing.List[typing.Optional[int]]]: - """Reads an array of nullable 16-bit two's complement signed integers - or returns the default value. - - Args: - field_name: Name of the field. - default: Default value to return if the field with the given name - does not exist in the schema or the type of the field does not - match with the one defined in the schema. - - Returns: - The value or the default value of the field. - """ - @abc.abstractmethod def read_array_of_int32(self, field_name: str) -> typing.Optional[typing.List[int]]: """Reads an array of 32-bit two's complement signed integers. @@ -2068,23 +1640,6 @@ def read_array_of_int32(self, field_name: str) -> typing.Optional[typing.List[in defined in the schema. """ - @abc.abstractmethod - def read_array_of_int32_or_default( - self, field_name: str, default: typing.Optional[typing.List[int]] - ) -> typing.Optional[typing.List[int]]: - """Reads an array of 32-bit two's complement signed integers or - returns the default value. - - Args: - field_name: Name of the field. - default: Default value to return if the field with the given name - does not exist in the schema or the type of the field does not - match with the one defined in the schema. - - Returns: - The value or the default value of the field. - """ - @abc.abstractmethod def read_array_of_nullable_int32( self, field_name: str @@ -2103,23 +1658,6 @@ def read_array_of_nullable_int32( defined in the schema. """ - @abc.abstractmethod - def read_array_of_nullable_int32_or_default( - self, field_name: str, default: typing.Optional[typing.List[typing.Optional[int]]] - ) -> typing.Optional[typing.List[typing.Optional[int]]]: - """Reads an array of nullable 32-bit two's complement signed integers - or returns the default value. - - Args: - field_name: Name of the field. - default: Default value to return if the field with the given name - does not exist in the schema or the type of the field does not - match with the one defined in the schema. - - Returns: - The value or the default value of the field. - """ - @abc.abstractmethod def read_array_of_int64(self, field_name: str) -> typing.Optional[typing.List[int]]: """Reads an array of 64-bit two's complement signed integers. @@ -2136,23 +1674,6 @@ def read_array_of_int64(self, field_name: str) -> typing.Optional[typing.List[in defined in the schema. """ - @abc.abstractmethod - def read_array_of_int64_or_default( - self, field_name: str, default: typing.Optional[typing.List[int]] - ) -> typing.Optional[typing.List[int]]: - """Reads an array of 64-bit two's complement signed integers or - returns the default value. - - Args: - field_name: Name of the field. - default: Default value to return if the field with the given name - does not exist in the schema or the type of the field does not - match with the one defined in the schema. - - Returns: - The value or the default value of the field. - """ - @abc.abstractmethod def read_array_of_nullable_int64( self, field_name: str @@ -2171,23 +1692,6 @@ def read_array_of_nullable_int64( defined in the schema. """ - @abc.abstractmethod - def read_array_of_nullable_int64_or_default( - self, field_name: str, default: typing.Optional[typing.List[typing.Optional[int]]] - ) -> typing.Optional[typing.List[typing.Optional[int]]]: - """Reads an array of nullable 64-bit two's complement signed integers - or returns the default value. - - Args: - field_name: Name of the field. - default: Default value to return if the field with the given name - does not exist in the schema or the type of the field does not - match with the one defined in the schema. - - Returns: - The value or the default value of the field. - """ - @abc.abstractmethod def read_array_of_float32(self, field_name: str) -> typing.Optional[typing.List[float]]: """Reads an array of 32-bit IEEE 754 floating point numbers. @@ -2204,23 +1708,6 @@ def read_array_of_float32(self, field_name: str) -> typing.Optional[typing.List[ defined in the schema. """ - @abc.abstractmethod - def read_array_of_float32_or_default( - self, field_name: str, default: typing.Optional[typing.List[float]] - ) -> typing.Optional[typing.List[float]]: - """Reads an array of 32-bit IEEE 754 floating point numbers or returns - the default value. - - Args: - field_name: Name of the field. - default: Default value to return if the field with the given name - does not exist in the schema or the type of the field does not - match with the one defined in the schema. - - Returns: - The value or the default value of the field. - """ - @abc.abstractmethod def read_array_of_nullable_float32( self, field_name: str @@ -2239,23 +1726,6 @@ def read_array_of_nullable_float32( defined in the schema. """ - @abc.abstractmethod - def read_array_of_nullable_float32_or_default( - self, field_name: str, default: typing.Optional[typing.List[typing.Optional[float]]] - ) -> typing.Optional[typing.List[typing.Optional[float]]]: - """Reads an array of nullable 32-bit IEEE 754 floating point numbers - or returns the default value. - - Args: - field_name: Name of the field. - default: Default value to return if the field with the given name - does not exist in the schema or the type of the field does not - match with the one defined in the schema. - - Returns: - The value or the default value of the field. - """ - @abc.abstractmethod def read_array_of_float64(self, field_name: str) -> typing.Optional[typing.List[float]]: """Reads an array of 64-bit IEEE 754 floating point numbers. @@ -2272,23 +1742,6 @@ def read_array_of_float64(self, field_name: str) -> typing.Optional[typing.List[ defined in the schema. """ - @abc.abstractmethod - def read_array_of_float64_or_default( - self, field_name: str, default: typing.Optional[typing.List[float]] - ) -> typing.Optional[typing.List[float]]: - """Reads an array of 64-bit IEEE 754 floating point numbers or returns - the default value. - - Args: - field_name: Name of the field. - default: Default value to return if the field with the given name - does not exist in the schema or the type of the field does not - match with the one defined in the schema. - - Returns: - The value or the default value of the field. - """ - @abc.abstractmethod def read_array_of_nullable_float64( self, field_name: str @@ -2307,23 +1760,6 @@ def read_array_of_nullable_float64( defined in the schema. """ - @abc.abstractmethod - def read_array_of_nullable_float64_or_default( - self, field_name: str, default: typing.Optional[typing.List[typing.Optional[float]]] - ) -> typing.Optional[typing.List[typing.Optional[float]]]: - """Reads an array of nullable 64-bit IEEE 754 floating point numbers - or returns the default value. - - Args: - field_name: Name of the field. - default: Default value to return if the field with the given name - does not exist in the schema or the type of the field does not - match with the one defined in the schema. - - Returns: - The value or the default value of the field. - """ - @abc.abstractmethod def read_array_of_string( self, field_name: str @@ -2342,23 +1778,6 @@ def read_array_of_string( defined in the schema. """ - @abc.abstractmethod - def read_array_of_string_or_default( - self, field_name: str, default: typing.Optional[typing.List[typing.Optional[str]]] - ) -> typing.Optional[typing.List[typing.Optional[str]]]: - """Reads an array of UTF-8 encoded strings or returns the default - value. - - Args: - field_name: Name of the field. - default: Default value to return if the field with the given name - does not exist in the schema or the type of the field does not - match with the one defined in the schema. - - Returns: - The value or the default value of the field. - """ - @abc.abstractmethod def read_array_of_decimal( self, field_name: str @@ -2378,25 +1797,6 @@ def read_array_of_decimal( defined in the schema. """ - @abc.abstractmethod - def read_array_of_decimal_or_default( - self, - field_name: str, - default: typing.Optional[typing.List[typing.Optional[decimal.Decimal]]], - ) -> typing.Optional[typing.List[typing.Optional[decimal.Decimal]]]: - """Reads an array of arbitrary precision and scale floating point - numbers or returns the default value. - - Args: - field_name: Name of the field. - default: Default value to return if the field with the given name - does not exist in the schema or the type of the field does not - match with the one defined in the schema. - - Returns: - The value or the default value of the field. - """ - @abc.abstractmethod def read_array_of_time( self, field_name: str @@ -2416,23 +1816,6 @@ def read_array_of_time( defined in the schema. """ - @abc.abstractmethod - def read_array_of_time_or_default( - self, field_name: str, default: typing.Optional[typing.List[typing.Optional[datetime.time]]] - ) -> typing.Optional[typing.List[typing.Optional[datetime.time]]]: - """Reads an array of times consisting of hour, minute, second, and - nanoseconds or returns the default value. - - Args: - field_name: Name of the field. - default: Default value to return if the field with the given name - does not exist in the schema or the type of the field does not - match with the one defined in the schema. - - Returns: - The value or the default value of the field. - """ - @abc.abstractmethod def read_array_of_date( self, field_name: str @@ -2451,23 +1834,6 @@ def read_array_of_date( defined in the schema. """ - @abc.abstractmethod - def read_array_of_date_or_default( - self, field_name: str, default: typing.Optional[typing.List[typing.Optional[datetime.date]]] - ) -> typing.Optional[typing.List[typing.Optional[datetime.date]]]: - """Reads an array of dates consisting of year, month, and day or - returns the default value. - - Args: - field_name: Name of the field. - default: Default value to return if the field with the given name - does not exist in the schema or the type of the field does not - match with the one defined in the schema. - - Returns: - The value or the default value of the field. - """ - @abc.abstractmethod def read_array_of_timestamp( self, field_name: str @@ -2486,25 +1852,6 @@ def read_array_of_timestamp( defined in the schema. """ - @abc.abstractmethod - def read_array_of_timestamp_or_default( - self, - field_name: str, - default: typing.Optional[typing.List[typing.Optional[datetime.datetime]]], - ) -> typing.Optional[typing.List[typing.Optional[datetime.datetime]]]: - """Reads an array of timestamps consisting of date and time or returns - the default value. - - Args: - field_name: Name of the field. - default: Default value to return if the field with the given name - does not exist in the schema or the type of the field does not - match with the one defined in the schema. - - Returns: - The value or the default value of the field. - """ - @abc.abstractmethod def read_array_of_timestamp_with_timezone( self, field_name: str @@ -2524,25 +1871,6 @@ def read_array_of_timestamp_with_timezone( defined in the schema. """ - @abc.abstractmethod - def read_array_of_timestamp_with_timezone_or_default( - self, - field_name: str, - default: typing.Optional[typing.List[typing.Optional[datetime.datetime]]], - ) -> typing.Optional[typing.List[typing.Optional[datetime.datetime]]]: - """Reads an array of timestamp with timezones consisting of date, time - and timezone offset or returns the default value. - - Args: - field_name: Name of the field. - default: Default value to return if the field with the given name - does not exist in the schema or the type of the field does not - match with the one defined in the schema. - - Returns: - The value or the default value of the field. - """ - @abc.abstractmethod def read_array_of_compact( self, field_name: str @@ -2561,22 +1889,6 @@ def read_array_of_compact( defined in the schema. """ - @abc.abstractmethod - def read_array_of_compact_or_default( - self, field_name: str, default: typing.Optional[typing.List[typing.Optional[typing.Any]]] - ) -> typing.Optional[typing.List[typing.Optional[typing.Any]]]: - """Reads an array of compact objects or returns the default value. - - Args: - field_name: Name of the field. - default: Default value to return if the field with the given name - does not exist in the schema or the type of the field does not - match with the one defined in the schema. - - Returns: - The value or the default value of the field. - """ - class CompactWriter(abc.ABC): """Provides means of writing compact serialized fields to the binary diff --git a/hazelcast/serialization/compact.py b/hazelcast/serialization/compact.py index 01e06dc2bf..64cee7b405 100644 --- a/hazelcast/serialization/compact.py +++ b/hazelcast/serialization/compact.py @@ -611,6 +611,12 @@ def __init__( # from inp can start from the correct position inp.set_position(end_position) + def get_field_kind(self, field_name) -> "FieldKind": + field = self._schema.fields.get(field_name) + if not field: + return FieldKind.NOT_AVAILABLE + return field.kind + def read_boolean(self, field_name: str) -> bool: field = self._get_field(field_name) kind = field.kind @@ -1754,13 +1760,14 @@ def _init(self): for field in self.fields_list: kind = field.kind - if FIELD_OPERATIONS[kind].is_var_sized(): + if kind < 0 or kind >= FieldKind.NOT_AVAILABLE: + raise HazelcastSerializationError(f"Invalid field kind: {kind}") + if FIELD_OPERATIONS[field.kind].is_var_sized(): var_sized_fields.append(field) + elif FieldKind.BOOLEAN == kind: + bool_fields.append(field) else: - if FieldKind.BOOLEAN == kind: - bool_fields.append(field) - else: - fix_sized_fields.append(field) + fix_sized_fields.append(field) fix_sized_fields.sort( key=lambda f: FIELD_OPERATIONS[f.kind].size_in_bytes(), @@ -2038,6 +2045,7 @@ class FieldKind(enum.IntEnum): ARRAY_OF_NULLABLE_FLOAT32 = 43 NULLABLE_FLOAT64 = 44 ARRAY_OF_NULLABLE_FLOAT64 = 45 + NOT_AVAILABLE = 46 class FieldKindOperations(abc.ABC): @@ -2272,4 +2280,5 @@ class ArrayOfNullableFloat64Operations(FieldKindOperations): ArrayOfNullableFloat32Operations(), NullableFloat64Operations(), ArrayOfNullableFloat64Operations(), + None, ] diff --git a/tests/integration/backward_compatible/serialization/compact_test.py b/tests/integration/backward_compatible/serialization/compact_test.py index 325b25a863..20842dcecd 100644 --- a/tests/integration/backward_compatible/serialization/compact_test.py +++ b/tests/integration/backward_compatible/serialization/compact_test.py @@ -50,7 +50,7 @@ class FieldKind(enum.Enum): if _COMPACT_AVAILABLE: - FIELD_KINDS = [kind for kind in FieldKind] + FIELD_KINDS = [kind for kind in FieldKind if FIELD_OPERATIONS[kind] is not None] FIX_SIZED_FIELD_KINDS = [ kind for kind in FIELD_KINDS if not FIELD_OPERATIONS[kind].is_var_sized() ] diff --git a/tests/unit/serialization/compact_test.py b/tests/unit/serialization/compact_test.py index 593d224e5d..27b47c6300 100644 --- a/tests/unit/serialization/compact_test.py +++ b/tests/unit/serialization/compact_test.py @@ -5,6 +5,7 @@ from parameterized import parameterized +from hazelcast.errors import HazelcastSerializationError from hazelcast.serialization.compact import ( RabinFingerprint, SchemaWriter, @@ -80,10 +81,20 @@ def test_schema(self): class SchemaTest(unittest.TestCase): def test_constructor(self): - fields = [FieldDescriptor(kind.name, kind) for kind in FieldKind] + fields = [ + FieldDescriptor(kind.name, kind) + for kind in FieldKind + if kind is not FieldKind.NOT_AVAILABLE + ] schema = Schema("something", fields) self._verify_schema(schema, fields) + def test_constructor_with_invalid_field_kind(self): + fd = FieldDescriptor("foo", FieldKind.NOT_AVAILABLE) + self.assertRaises(HazelcastSerializationError, lambda: Schema("foo", [fd])) + fd.kind = -1 + self.assertRaises(HazelcastSerializationError, lambda: Schema("foo", [fd])) + def test_with_no_fields(self): schema = Schema("something", []) self.assertEqual({}, schema.fields) @@ -132,7 +143,10 @@ def _verify_schema(self, schema: Schema, fields: typing.List[FieldDescriptor]): var_sized_fields = [] fix_sized_fields = [] for field in fields: - if FIELD_OPERATIONS[field.kind].is_var_sized(): + op = FIELD_OPERATIONS[field.kind] + if op is None: + continue + if op.is_var_sized(): var_sized_fields.append(field) else: fix_sized_fields.append(field) @@ -176,7 +190,10 @@ def test_schema_writer(self): fields = [] for kind in FieldKind: name = str(uuid.uuid4()) - getattr(writer, f"write_{kind.name.lower()}")(name, None) + fun = getattr(writer, f"write_{kind.name.lower()}", None) + if fun is None: + continue + fun(name, None) fields.append((name, kind)) schema = writer.build()