Skip to content

[HZ-5510] Introduced number types and removed the default_int_type config - #837

Open
yuce wants to merge 4 commits into
masterfrom
number-types
Open

[HZ-5510] Introduced number types and removed the default_int_type config#837
yuce wants to merge 4 commits into
masterfrom
number-types

Conversation

@yuce

@yuce yuce commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Hazelcast has a number of default serializers for numeric types, modeled after the corresponding Java types: signed 8, 16, 32, 64 bit integers, 32 and 64 bit floating point numbers. Go, C++ and .Net clients have corresponding native types, so they are able to serialize numeric values with the intended type. Python and Node.js clients have a different story though.

Python has a single unbounded integer type, and a single floating point type. When a user saves a number using the Python client, it is not immediately apparent which data type is used for storage. Consider the following example:

client = await HazelcastClient.create_and_start( ... )
m = await client.get_map("my-map")
await m.set("key", 123)

A configuration based mechanism was used as a workaround to solve this problem, and ensure a number is stored with the intended type. Python Client has the default_int_type configuration which sets the integer type to be used when storing an integer to the cluster. It must be set during client creation, and cannot be changed later:

client = await HazelcastClient.create_and_start(default_int_type=IntType.SHORT)
m = await client.get_map("my-map")
await m.set("key", 123)

The obvious problem with this approach is, the integer/number setting is global to a client, and can be set only once. If an application uses different number types, there is no way of storing values with different types using the client.

As I’ve shown, serializing number types is problematic using the Python Client. How about deserialization? The values are deserialized to the expected type: int so there’s not a problem, unless the user wants to put the same value back to the cluster. That problem is out of scope for this proposal, and a possible solution will be explained in a future proposal.

This problem can be easily solved by introducing missing number types. For example, the hazelcast.Int16 class can be used to serialize a value as a 16 bit signed integer:

from hazelcast import Int16
m = await client.get_map("my-map")
await m.set("key", Int16(123))

That allows us to remove the default_int_type from configuration and related code. We can keep serializing integers by default as 32 bit signed integers for convenience. So if the user never sets default_int_type other than the default, their code still works as expected.

await m.set("key", 123)  # serialized as 32 bit signed integer
await m.set("key", Int16(123))  # serialized as 16 bit signed integer

This PR:

  • Removes default_int_type configuration and related code.
  • Introduces the following number classes: Int8, Int16, Int32, Int64, BigInt, Float32, Float64
  • Unwrapped integers are stored as 32 bit integers (keeps the previous behavior).
  • Unwrapped floats are stored as 64 bit floats (keeps the previous behavior).

NOTE: Do not mind the link checker failure, they are due to AI-protection mechanism.

@yuce yuce changed the title Introduced number types and removed the default_int_type config [HZ-5510] Introduced number types and removed the default_int_type config Aug 24, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.64045% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.16%. Comparing base (ba315d5) to head (9b459ed).

Files with missing lines Patch % Lines
hazelcast/number_types.py 84.05% 11 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #837      +/-   ##
==========================================
- Coverage   94.21%   94.16%   -0.05%     
==========================================
  Files         413      414       +1     
  Lines       27646    27688      +42     
==========================================
+ Hits        26046    26073      +27     
- Misses       1600     1615      +15     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@yuce
yuce requested a review from ihsandemir August 24, 2026 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants