Skip to content

Conversation

GromNaN
Copy link
Member

@GromNaN GromNaN commented Aug 21, 2025

Q A
Type feature
BC Break no
Fixed issues #2779 (comment)

Summary

Queryable Encryption is more strict. While the PHP driver automatically switch the type of the BSON value between int (32 bits) or long (64 bits) depending on the actual value, the encrypted fields configuration requires a unique type.

This new Int64 type is only useful for very large int encrypted fields.

@GromNaN GromNaN requested a review from jmikola August 21, 2025 21:15
@GromNaN GromNaN force-pushed the int64 branch 2 times, most recently from 96265de to ef61ca3 Compare August 21, 2025 22:22
@@ -145,6 +145,7 @@ Here is a quick overview of the built-in mapping types:
- ``hash``
- ``id``
- ``int``
- ``int64``
Copy link
Member

Choose a reason for hiding this comment

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

Contrary to the PR description, int64 might have uses beyond encryption such as satisfying a general schema or improving compatibility in cross-language apps (other drivers might not play nice with interchangeable integer types).

Copy link
Member Author

@GromNaN GromNaN Aug 22, 2025

Choose a reason for hiding this comment

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

Ok, the new type can be used independently from encryption.

Note that the int type will encode to Int64 when the value exceeds 32 bits. That would be a programmer issue. I could add an Int32 type to throw an error when the value does not fit in 32 bits.

Copy link
Member

Choose a reason for hiding this comment

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

Note that the int type will encode to Int64 when the value exceeds 32 bits.

That's legacy behavior for ODM and the expected behavior for the server (e.g. incrementing an int32 BSON type server-side could yield an int64), so I'm not worried about it. And so long as ODM continues to accept int64 BSON types for int mappings I think we're OK.

I could add an Int32 type to throw an error when the value does not fit in 32 bits.

This could certainly be added down the line. I'd probably wait until it was requested, though.

@@ -10,6 +10,9 @@
<field name="intField" type="int">
<encrypt queryType="range" min="5" max="10"/>
</field>
<field name="int64Field" type="int64">
<encrypt queryType="range" min="5" max="9223372036854775802"/>
Copy link
Member

Choose a reason for hiding this comment

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

Is it even necessary to use PHP_INT_MAX for this example? Since Int64 types allow comparisons with integers, the assertion in AbstractDriverTestCase doesn't actually check that the value is converted to an Int64 object. It may make more sense to use relaxed numeric comparisons for the assertEquals and then also assert that the value is an instance of Int64. In that case you can do without the large values here.

Copy link
Member Author

Choose a reason for hiding this comment

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

I added a type assertion in TypeTest.

My idea for using a low and a high value for the min and max was to test that they are both converted to Int64. I could add a functional test for QE.

@GromNaN GromNaN requested a review from jmikola August 22, 2025 16:39
@GromNaN GromNaN merged commit b7a7409 into doctrine:feature/queryable-encryption Aug 22, 2025
21 checks passed
@GromNaN GromNaN deleted the int64 branch August 22, 2025 16:40
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