@@ -273,25 +273,22 @@ def find_nearest(
273273 stages .FindNearest (field , vector , distance_measure , options )
274274 )
275275
276- def literals (
277- self ,
278- * documents : Selectable ,
279- ) -> "_BasePipeline" :
276+ def literals (self , * documents : str | Selectable ) -> "_BasePipeline" :
280277 """
281278 Returns documents from a fixed set of predefined document objects.
282279
283280 This stage is commonly used for testing other stages in isolation, though it can
284281 also be used as inputs to join conditions.
285282
286283 Example:
284+ >>> from google.cloud.firestore_v1.pipeline_expressions import Constant
285+ >>> documents = [
286+ ... {"name": "joe", "age": 10},
287+ ... {"name": "bob", "age": 30},
288+ ... {"name": "alice", "age": 40}
289+ ... ]
287290 >>> pipeline = client.pipeline()
288- ... .literals(
289- ... [
290- ... {"name": "joe", "age": 10},
291- ... {"name": "bob", "age": 30},
292- ... {"name": "alice", "age": 40}
293- ... ]
294- ... )
291+ ... .literals(Constant.of(documents))
295292 ... .where(field("age").lessThan(35))
296293
297294 Output documents:
@@ -317,13 +314,11 @@ def literals(
317314
318315 Example:
319316 >>> from google.cloud.firestore_v1.pipeline_expressions import Constant
320- >>> pipeline = client.pipeline()
321- ... .literals(
322- ... [
323- ... {"x": Constant.of("foo-bar-baz").char_length()},
324- ... {"x": Constant.of("bar").char_length()}
325- ... ]
326- ... )
317+ >>> documents = [
318+ ... {"x": Constant.of("foo-bar-baz").char_length()},
319+ ... {"x": Constant.of("bar").char_length()}
320+ ... ]
321+ >>> pipeline = client.pipeline().literals(Constant.of(documents))
327322
328323 Output documents:
329324 ```json
@@ -334,9 +329,12 @@ def literals(
334329 ```
335330
336331 Args:
337- documents: A fixed set of predefined document objects.
332+ documents: A `str` or `Selectable` expression. If a `str`, it's
333+ treated as a field path to an array of documents.
334+ If a `Selectable`, it's usually a `Constant`
335+ containing an array of documents (as dictionaries).
338336 Returns:
339- A new Pipeline object with this stage appended to the stage list
337+ A new Pipeline object with this stage appended to the stage list.
340338 """
341339 return self ._append (stages .Literals (* documents ))
342340
0 commit comments