Skip to content

Commit fa5e637

Browse files
authored
PYTHON-4937 - Add support for 'number' alias in $$type operator (mongodb#2223)
1 parent 296046c commit fa5e637

File tree

2 files changed

+175
-0
lines changed

2 files changed

+175
-0
lines changed
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
{
2+
"description": "operator-type-number_alias",
3+
"schemaVersion": "1.0",
4+
"createEntities": [
5+
{
6+
"client": {
7+
"id": "client0"
8+
}
9+
},
10+
{
11+
"database": {
12+
"id": "database0",
13+
"client": "client0",
14+
"databaseName": "test"
15+
}
16+
},
17+
{
18+
"collection": {
19+
"id": "collection0",
20+
"database": "database0",
21+
"collectionName": "coll0"
22+
}
23+
}
24+
],
25+
"initialData": [
26+
{
27+
"collectionName": "coll0",
28+
"databaseName": "test",
29+
"documents": []
30+
}
31+
],
32+
"tests": [
33+
{
34+
"description": "type number alias matches int32",
35+
"operations": [
36+
{
37+
"name": "insertOne",
38+
"object": "collection0",
39+
"arguments": {
40+
"document": {
41+
"_id": 1,
42+
"x": {
43+
"$numberInt": "2147483647"
44+
}
45+
}
46+
}
47+
},
48+
{
49+
"name": "find",
50+
"object": "collection0",
51+
"arguments": {
52+
"filter": {
53+
"_id": 1
54+
},
55+
"limit": 1
56+
},
57+
"expectResult": [
58+
{
59+
"_id": 1,
60+
"x": {
61+
"$$type": "number"
62+
}
63+
}
64+
]
65+
}
66+
]
67+
},
68+
{
69+
"description": "type number alias matches int64",
70+
"operations": [
71+
{
72+
"name": "insertOne",
73+
"object": "collection0",
74+
"arguments": {
75+
"document": {
76+
"_id": 1,
77+
"x": {
78+
"$numberLong": "9223372036854775807"
79+
}
80+
}
81+
}
82+
},
83+
{
84+
"name": "find",
85+
"object": "collection0",
86+
"arguments": {
87+
"filter": {
88+
"_id": 1
89+
},
90+
"limit": 1
91+
},
92+
"expectResult": [
93+
{
94+
"_id": 1,
95+
"x": {
96+
"$$type": "number"
97+
}
98+
}
99+
]
100+
}
101+
]
102+
},
103+
{
104+
"description": "type number alias matches double",
105+
"operations": [
106+
{
107+
"name": "insertOne",
108+
"object": "collection0",
109+
"arguments": {
110+
"document": {
111+
"_id": 1,
112+
"x": {
113+
"$numberDouble": "2.71828"
114+
}
115+
}
116+
}
117+
},
118+
{
119+
"name": "find",
120+
"object": "collection0",
121+
"arguments": {
122+
"filter": {
123+
"_id": 1
124+
},
125+
"limit": 1
126+
},
127+
"expectResult": [
128+
{
129+
"_id": 1,
130+
"x": {
131+
"$$type": "number"
132+
}
133+
}
134+
]
135+
}
136+
]
137+
},
138+
{
139+
"description": "type number alias matches decimal128",
140+
"operations": [
141+
{
142+
"name": "insertOne",
143+
"object": "collection0",
144+
"arguments": {
145+
"document": {
146+
"_id": 1,
147+
"x": {
148+
"$numberDecimal": "3.14159"
149+
}
150+
}
151+
}
152+
},
153+
{
154+
"name": "find",
155+
"object": "collection0",
156+
"arguments": {
157+
"filter": {
158+
"_id": 1
159+
},
160+
"limit": 1
161+
},
162+
"expectResult": [
163+
{
164+
"_id": 1,
165+
"x": {
166+
"$$type": "number"
167+
}
168+
}
169+
]
170+
}
171+
]
172+
}
173+
]
174+
}

test/unified_format_shared.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ def closed(self, event: Union[ServerClosedEvent, TopologyClosedEvent]) -> None:
363363
"decimal": (Decimal128,),
364364
"maxKey": (MaxKey,),
365365
"minKey": (MinKey,),
366+
"number": (float, int, Int64, Decimal128),
366367
}
367368

368369

0 commit comments

Comments
 (0)