Skip to content

Commit 9313978

Browse files
committed
Update to use latest proto
1 parent 3cd7698 commit 9313978

File tree

11 files changed

+165
-148
lines changed

11 files changed

+165
-148
lines changed

weaviate/collections/aggregations/aggregate.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,17 @@ def _to_aggregate_result(
9090
)
9191

9292
def _to_result(
93-
self, response: aggregate_pb2.AggregateReply, is_group_by: bool
93+
self, response: aggregate_pb2.AggregateReply
9494
) -> Union[AggregateReturn, AggregateGroupByReturn]:
95-
if len(response.result.groups) == 0:
96-
raise WeaviateQueryError("No results found in the aggregation query!", "gRPC")
97-
if is_group_by:
95+
if response.HasField("single_result"):
96+
return AggregateReturn(
97+
properties={
98+
aggregation.property: self.__parse_property_grpc(aggregation)
99+
for aggregation in response.single_result.aggregations.aggregations
100+
},
101+
total_count=response.single_result.objects_count,
102+
)
103+
if response.HasField("grouped_results"):
98104
return AggregateGroupByReturn(
99105
groups=[
100106
AggregateGroup(
@@ -105,21 +111,15 @@ def _to_result(
105111
},
106112
total_count=group.objects_count,
107113
)
108-
for group in response.result.groups
114+
for group in response.grouped_results.groups
109115
]
110116
)
111117
else:
112-
result = response.result.groups[0]
113-
return AggregateReturn(
114-
properties={
115-
aggregation.property: self.__parse_property_grpc(aggregation)
116-
for aggregation in result.aggregations.aggregations
117-
},
118-
total_count=result.objects_count,
119-
)
118+
_Warnings.unknown_type_encountered(response.WhichOneof("result"))
119+
return AggregateReturn(properties={}, total_count=None)
120120

121121
def __parse_grouped_by_value(
122-
self, grouped_by: aggregate_pb2.AggregateGroup.GroupedBy
122+
self, grouped_by: aggregate_pb2.AggregateReply.Group.GroupedBy
123123
) -> GroupedBy:
124124
value: Union[
125125
str,
@@ -157,7 +157,7 @@ def __parse_grouped_by_value(
157157
)
158158
else:
159159
value = None
160-
_Warnings.unknown_type_encountered(grouped_by.WhichOneof("GroupedBy"))
160+
_Warnings.unknown_type_encountered(grouped_by.WhichOneof("value"))
161161
return GroupedBy(prop=grouped_by.path[0], value=value)
162162

163163
def _to_group_by_result(
@@ -254,7 +254,7 @@ def __parse_property_gql(property_: dict, metric: _Metrics) -> AggregateResult:
254254

255255
@staticmethod
256256
def __parse_property_grpc(
257-
aggregation: aggregate_pb2.AggregateGroup.Aggregations.Aggregation,
257+
aggregation: aggregate_pb2.AggregateReply.Aggregations.Aggregation,
258258
) -> AggregateResult:
259259
if aggregation.HasField("text"):
260260
return AggregateText(

weaviate/collections/aggregations/hybrid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ async def hybrid(
115115
limit=group_by.limit if group_by is not None else None,
116116
objects_count=total_count,
117117
)
118-
return self._to_result(reply, group_by is not None)
118+
return self._to_result(reply)
119119

120120

121121
@syncify.convert

weaviate/collections/aggregations/near_image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ async def near_image(
104104
objects_count=total_count,
105105
object_limit=object_limit,
106106
)
107-
return self._to_result(reply, group_by is not None)
107+
return self._to_result(reply)
108108

109109

110110
@syncify.convert

weaviate/collections/aggregations/near_object.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ async def near_object(
101101
objects_count=total_count,
102102
object_limit=object_limit,
103103
)
104-
return self._to_result(reply, group_by is not None)
104+
return self._to_result(reply)
105105

106106

107107
@syncify.convert

weaviate/collections/aggregations/near_text.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ async def near_text(
117117
objects_count=total_count,
118118
object_limit=object_limit,
119119
)
120-
return self._to_result(reply, group_by is not None)
120+
return self._to_result(reply)
121121

122122

123123
@syncify.convert

weaviate/collections/aggregations/near_vector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ async def near_vector(
121121
objects_count=total_count,
122122
object_limit=object_limit,
123123
)
124-
return self._to_result(reply, group_by is not None)
124+
return self._to_result(reply)
125125

126126

127127
@syncify.convert

weaviate/collections/aggregations/over_all.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ async def over_all(
7373
limit=group_by.limit if group_by is not None else None,
7474
objects_count=total_count,
7575
)
76-
return self._to_result(reply, group_by is not None)
76+
return self._to_result(reply)
7777

7878

7979
@syncify.convert

weaviate/collections/grpc/aggregate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def __init__(
3737

3838
async def objects_count(self) -> int:
3939
res = await self.__call(self.__create_request(objects_count=True))
40-
return res.result.groups[0].objects_count
40+
return res.single_result.objects_count
4141

4242
def hybrid(
4343
self,

weaviate/collections/queries/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def __deserialize_list_value_prop_125(
192192
return [
193193
self.__parse_nonref_properties_result(val) for val in value.object_values.values
194194
]
195-
_Warnings.unknown_type_encountered(value.WhichOneof("Value"))
195+
_Warnings.unknown_type_encountered(value.WhichOneof("value"))
196196
return None
197197

198198
def __deserialize_list_value_prop_123(self, value: properties_pb2.ListValue) -> List[Any]:
@@ -248,7 +248,7 @@ def __deserialize_non_ref_prop(self, value: properties_pb2.Value) -> Any:
248248
if value.HasField("null_value"):
249249
return None
250250

251-
_Warnings.unknown_type_encountered(value.WhichOneof("Value"))
251+
_Warnings.unknown_type_encountered(value.WhichOneof("value"))
252252
return None
253253

254254
def __parse_nonref_properties_result(

weaviate/proto/v1/aggregate_pb2.py

Lines changed: 33 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)