1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15- # from google.cloud.firestore import Query
16- # from google.cloud.firestore_v1.pipeline import Pipeline
17- # from google.cloud.firestore_v1.pipeline_source import PipelineSource
18- # from google.cloud.firestore_v1.pipeline_expressions import (
19- # AggregateFunction,
20- # Constant,
21- # Expression,
22- # Field,
23- # Count,
24- # )
25- # from google.cloud.firestore_v1.pipeline_expressions import (
26- # And,
27- # Conditional,
28- # Or,
29- # Not,
30- # Xor,
31- # )
32- # from google.cloud.firestore_v1.pipeline_stages import (
33- # Aggregate,
34- # FindNearestOptions,
35- # SampleOptions,
36- # UnnestOptions,
37- # )
38- # from google.cloud.firestore_v1.base_vector_query import DistanceMeasure
39- # from google.cloud.firestore_v1.vector import Vector
40- # from google.cloud.firestore_v1.client import Client
41-
4215import firebase_admin
4316from firebase_admin import firestore
4417
4720
4821
4922# pylint: disable=invalid-name
23+
24+ def query_explain ():
25+ # [START query_explain]
26+ from google .cloud .firestore import Query , FieldFilter , ExplainOptions
27+
28+ results = client .collection ("cities" ) \
29+ .where (filter = FieldFilter ("capital" , "==" , True )) \
30+ .execute (explain_options = ExplainOptions (analyze = False ))
31+ metrics = results .explain_metrics ()
32+ summary = metrics .plan_summary ()
33+ # [END query_explain]
34+
35+
5036def pipeline_concepts ():
5137 # [START pipeline_concepts]
5238 from google .cloud .firestore_v1 .pipeline_expressions import Field
@@ -1764,7 +1750,7 @@ def vector_length_function():
17641750def stages_expressions_example ():
17651751 # [START stages_expressions_example]
17661752 from google .cloud .firestore_v1 .pipeline_expressions import Field , Constant
1767- from firebase_admin import firestore
1753+ from google . cloud import firestore
17681754
17691755 trailing_30_days = (
17701756 Constant .of (firestore .SERVER_TIMESTAMP )
@@ -1995,9 +1981,10 @@ def unnest_empty_array_example():
19951981def unnest_preserve_empty_array_example ():
19961982 # [START unnest_preserve_empty_array]
19971983 from google .cloud .firestore_v1 .pipeline_expressions import (
1998- Field ,
1984+ Array ,
19991985 Conditional ,
20001986 Expression ,
1987+ Field ,
20011988 )
20021989 from google .cloud .firestore_v1 .pipeline_stages import UnnestOptions
20031990
@@ -2006,8 +1993,8 @@ def unnest_preserve_empty_array_example():
20061993 .collection ("users" )
20071994 .unnest (
20081995 Conditional (
2009- Field .of ("scores" ).equal (Expression . array ([])),
2010- Expression . array ([Field .of ("scores" )]),
1996+ Field .of ("scores" ).equal (Array ([])),
1997+ Array ([Field .of ("scores" )]),
20111998 Field .of ("scores" ),
20121999 ).as_ ("userScore" ),
20132000 options = UnnestOptions (index_field = "attempt" ),
0 commit comments