@@ -1285,6 +1285,33 @@ def map_get(self, key: str | Constant[str]) -> "Expression":
12851285 "map_get" , [self , self ._cast_to_expr_or_convert_to_constant (key )]
12861286 )
12871287
1288+ def map_set (self , key : str | Constant [str ], value : Any ) -> "Expression" :
1289+ """Creates an expression that returns a new map with the specified entries added or
1290+ updated.
1291+
1292+ Note:
1293+ `map_set` only performs shallow updates to the map. Setting a value to `None`
1294+ will retain the key with a `None` value. To remove a key entirely, use
1295+ `map_remove`.
1296+
1297+ Example:
1298+ >>> Map({"city": "London"}).map_set("city", "New York")
1299+ >>> Field.of("address").map_set("city", "Seattle")
1300+
1301+ Args:
1302+ key: The key to set in the map.
1303+ value: The value to associate with the key.
1304+
1305+ Returns:
1306+ A new `Expression` representing the map_set operation.
1307+ """
1308+ args = [
1309+ self ,
1310+ self ._cast_to_expr_or_convert_to_constant (key ),
1311+ self ._cast_to_expr_or_convert_to_constant (value ),
1312+ ]
1313+ return FunctionExpression ("map_set" , args )
1314+
12881315 @expose_as_static
12891316 def map_remove (self , key : str | Constant [str ]) -> "Expression" :
12901317 """Remove a key from a the map produced by evaluating this expression.
@@ -1328,6 +1355,58 @@ def map_merge(
13281355 )
13291356
13301357 @expose_as_static
1358+ def map_keys (self ) -> "Expression" :
1359+ """Creates an expression that returns the keys of a map.
1360+
1361+ Note:
1362+ While the backend generally preserves insertion order, relying on the
1363+ order of the output array is not guaranteed and should be avoided.
1364+
1365+ Example:
1366+ >>> Map({"city": "London", "country": "UK"}).map_keys()
1367+ >>> Field.of("address").map_keys()
1368+
1369+ Returns:
1370+ A new `Expression` representing the keys of the map.
1371+ """
1372+ return FunctionExpression ("map_keys" , [self ])
1373+
1374+ @expose_as_static
1375+ def map_values (self ) -> "Expression" :
1376+ """Creates an expression that returns the values of a map.
1377+
1378+ Note:
1379+ While the backend generally preserves insertion order, relying on the
1380+ order of the output array is not guaranteed and should be avoided.
1381+
1382+ Example:
1383+ >>> Map({"city": "London", "country": "UK"}).map_values()
1384+ >>> Field.of("address").map_values()
1385+
1386+ Returns:
1387+ A new `Expression` representing the values of the map.
1388+ """
1389+ return FunctionExpression ("map_values" , [self ])
1390+
1391+ @expose_as_static
1392+ def map_entries (self ) -> "Expression" :
1393+ """Creates an expression that returns the entries of a map as an array of maps,
1394+ where each map contains a `"k"` property for the key and a `"v"` property for the value.
1395+ For example: `[{ "k": "key1", "v": "value1" }, ...]`.
1396+
1397+ Note:
1398+ While the backend generally preserves insertion order, relying on the
1399+ order of the output array is not guaranteed and should be avoided.
1400+
1401+ Example:
1402+ >>> Map({"city": "London", "country": "UK"}).map_entries()
1403+ >>> Field.of("address").map_entries()
1404+
1405+ Returns:
1406+ A new `Expression` representing the entries of the map.
1407+ """
1408+ return FunctionExpression ("map_entries" , [self ])
1409+
13311410 def regex_find (self , pattern : str | Constant [str ] | Expression ) -> "Expression" :
13321411 """Creates an expression that returns the first substring of a string expression that
13331412 matches a specified regular expression.
0 commit comments