@@ -948,17 +948,19 @@ class Query:
948948 filters (Union[Node, tuple]): Node representing a filter expression
949949 tree. Property filters applied by this query. The sequence
950950 is ``(property_name, operator, value)``.
951- order_by (Union[tuple, list ]): The field names used to
951+ order_by (Union[list, tuple ]): The field names used to
952952 order query results. Renamed `order` in google.cloud.datastore.
953+ orders (Union[list, tuple]): Deprecated. Synonym for order_by.
953954 app (str): The app to restrict results. If not passed, uses the
954955 client's value. Renamed `project` in google.cloud.datastore.
955956 namespace (str): The namespace to which to restrict results.
956957 If not passed, uses the client's value.
957958 default_options (QueryOptions): QueryOptions object.
958959 projection (Union[list, tuple]): The fields returned as part of the
959960 query results.
960- group_by (Union[list, tuple]): The field names used to group query
961+ distinct_on (Union[list, tuple]): The field names used to group query
961962 results. Renamed distinct_on in google.cloud.datastore.
963+ group_by (Union[list, tuple]): Deprecated. Synonym for distinct_on.
962964
963965 Raises: TypeError if any of the arguments are invalid.
964966 """
@@ -974,6 +976,7 @@ def __init__(
974976 namespace = None ,
975977 default_options = None ,
976978 projection = None ,
979+ distinct_on = None ,
977980 group_by = None ,
978981 ):
979982 if ancestor is not None :
@@ -1054,17 +1057,24 @@ def __init__(
10541057 self ._check_properties (self ._to_property_names (projection ))
10551058 self .projection = tuple (projection )
10561059
1057- self .group_by = None
1058- if group_by is not None :
1059- if not group_by :
1060- raise TypeError ("group_by argument cannot be empty" )
1061- if not isinstance (group_by , (tuple , list )):
1060+ if distinct_on is not None and group_by is not None :
1061+ raise TypeError (
1062+ "Cannot use both group_by and distinct_on, they are synonyms"
1063+ "(group_by is deprecated now)"
1064+ )
1065+ if distinct_on is None :
1066+ distinct_on = group_by
1067+ self .distinct_on = None
1068+ if distinct_on is not None :
1069+ if not distinct_on :
1070+ raise TypeError ("distinct_on argument cannot be empty" )
1071+ if not isinstance (distinct_on , (tuple , list )):
10621072 raise TypeError (
1063- "group_by must be a tuple, list or None; "
1064- "received {}" .format (group_by )
1073+ "distinct_on must be a tuple, list or None; "
1074+ "received {}" .format (distinct_on )
10651075 )
1066- self ._check_properties (self ._to_property_names (group_by ))
1067- self .group_by = tuple (group_by )
1076+ self ._check_properties (self ._to_property_names (distinct_on ))
1077+ self .distinct_on = tuple (distinct_on )
10681078
10691079 def __repr__ (self ):
10701080 args = []
@@ -1084,9 +1094,9 @@ def __repr__(self):
10841094 args .append (
10851095 "projection=%r" % (self ._to_property_names (self .projection ))
10861096 )
1087- if self .group_by :
1097+ if self .distinct_on :
10881098 args .append (
1089- "group_by =%r" % (self ._to_property_names (self .group_by ))
1099+ "distinct_on =%r" % (self ._to_property_names (self .distinct_on ))
10901100 )
10911101 if self .default_options is not None :
10921102 args .append ("default_options=%r" % self .default_options )
@@ -1097,11 +1107,11 @@ def is_distinct(self):
10971107 """True if results are guaranteed to contain a unique set of property
10981108 values.
10991109
1100- This happens when every property in the group_by is also in the projection.
1110+ This happens when every property in distinct_on is also in projection.
11011111 """
11021112 return bool (
1103- self .group_by
1104- and set (self ._to_property_names (self .group_by ))
1113+ self .distinct_on
1114+ and set (self ._to_property_names (self .distinct_on ))
11051115 <= set (self ._to_property_names (self .projection ))
11061116 )
11071117
@@ -1141,7 +1151,7 @@ def filter(self, *filters):
11411151 namespace = self .namespace ,
11421152 default_options = self .default_options ,
11431153 projection = self .projection ,
1144- group_by = self .group_by ,
1154+ distinct_on = self .distinct_on ,
11451155 )
11461156
11471157 def order (self , * names ):
@@ -1170,7 +1180,7 @@ def order(self, *names):
11701180 namespace = self .namespace ,
11711181 default_options = self .default_options ,
11721182 projection = self .projection ,
1173- group_by = self .group_by ,
1183+ distinct_on = self .distinct_on ,
11741184 )
11751185
11761186 def analyze (self ):
@@ -1248,7 +1258,7 @@ def bind(self, *positional, **keyword):
12481258 namespace = self .namespace ,
12491259 default_options = self .default_options ,
12501260 projection = self .projection ,
1251- group_by = self .group_by ,
1261+ distinct_on = self .distinct_on ,
12521262 )
12531263
12541264 def _to_property_names (self , properties ):
0 commit comments