def _validate_query_plan(self, query, container_link, top, order_by, aggregate, select_value, offset, limit, distinct): query_plan_dict = self.client.client_connection._GetQueryPlanThroughGateway(query, container_link) query_execution_info = _PartitionedQueryExecutionInfo(query_plan_dict) self.assertTrue(query_execution_info.has_rewritten_query()) self.assertEqual(query_execution_info.has_distinct_type(), distinct != "None") self.assertEqual(query_execution_info.get_distinct_type(), distinct) self.assertEqual(query_execution_info.has_top(), top is not None) self.assertEqual(query_execution_info.get_top(), top) self.assertEqual(query_execution_info.has_order_by(), len(order_by) > 0) self.assertListEqual(query_execution_info.get_order_by(), order_by) self.assertEqual(query_execution_info.has_aggregates(), len(aggregate) > 0) self.assertListEqual(query_execution_info.get_aggregates(), aggregate) self.assertEqual(query_execution_info.has_select_value(), select_value) self.assertEqual(query_execution_info.has_offset(), offset is not None) self.assertEqual(query_execution_info.get_offset(), offset) self.assertEqual(query_execution_info.has_limit(), limit is not None) self.assertEqual(query_execution_info.get_limit(), limit)
def __next__(self): """Returns the next query result. :return: The next query result. :rtype: dict :raises StopIteration: If no more result is left. """ try: return next(self._execution_context) except CosmosHttpResponseError as e: if _is_partitioned_execution_info(e): query_to_use = self._query if self._query is not None else "Select * from root r" query_execution_info = _PartitionedQueryExecutionInfo(self._client._GetQueryPlanThroughGateway (query_to_use, self._resource_link)) self._execution_context = self._create_pipelined_execution_context(query_execution_info) else: raise e return next(self._execution_context)
def fetch_next_block(self): """Returns a block of results. This method only exists for backward compatibility reasons. (Because QueryIterable has exposed fetch_next_block api). :return: List of results. :rtype: list """ try: return self._execution_context.fetch_next_block() except CosmosHttpResponseError as e: if _is_partitioned_execution_info(e): query_to_use = self._query if self._query is not None else "Select * from root r" query_execution_info = _PartitionedQueryExecutionInfo(self._client._GetQueryPlanThroughGateway (query_to_use, self._resource_link)) self._execution_context = self._create_pipelined_execution_context(query_execution_info) else: raise e return self._execution_context.fetch_next_block()
def _get_partitioned_execution_info(e): error_msg = json.loads(e.http_error_message) return _PartitionedQueryExecutionInfo(json.loads(error_msg["additionalErrorInfo"]))
def _get_partitioned_execution_info(self, e): error_msg = json.loads(e._http_error_message) return _PartitionedQueryExecutionInfo( json.loads(error_msg['additionalErrorInfo']))