cubicweb/server/querier.py
changeset 12756 d91c229de97f
parent 12739 c6f8ca03718f
child 12758 db95a417a5ec
equal deleted inserted replaced
12755:7df6c6048bc8 12756:d91c229de97f
    16 # You should have received a copy of the GNU Lesser General Public License along
    16 # You should have received a copy of the GNU Lesser General Public License along
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    18 """Helper classes to execute RQL queries on a set of sources, performing
    18 """Helper classes to execute RQL queries on a set of sources, performing
    19 security checking and data aggregation.
    19 security checking and data aggregation.
    20 """
    20 """
       
    21 import uuid
    21 from itertools import repeat
    22 from itertools import repeat
    22 
    23 
    23 from rql import RQLSyntaxError, CoercionError
    24 from rql import RQLSyntaxError, CoercionError
    24 from rql.stmts import Union
    25 from rql.stmts import Union
    25 from rql.nodes import ETYPE_PYOBJ_MAP, etype_from_pyobj, Relation, Exists, Not
    26 from rql.nodes import ETYPE_PYOBJ_MAP, etype_from_pyobj, Relation, Exists, Not
   162         self.steps = []
   163         self.steps = []
   163         # various resource accesors
   164         # various resource accesors
   164         self.querier = querier
   165         self.querier = querier
   165         self.schema = querier.schema
   166         self.schema = querier.schema
   166         self.rqlhelper = cnx.vreg.rqlhelper
   167         self.rqlhelper = cnx.vreg.rqlhelper
       
   168         # tracing token for debugging
       
   169         self.rql_query_tracing_token = None
   167 
   170 
   168     def annotate_rqlst(self):
   171     def annotate_rqlst(self):
   169         if not self.rqlst.annotated:
   172         if not self.rqlst.annotated:
   170             self.rqlhelper.annotate(self.rqlst)
   173             self.rqlhelper.annotate(self.rqlst)
   171 
   174 
   177         return self.syssource.sqlexec(self.cnx, sql, args)
   180         return self.syssource.sqlexec(self.cnx, sql, args)
   178 
   181 
   179     def execute(self):
   182     def execute(self):
   180         """execute a plan and return resulting rows"""
   183         """execute a plan and return resulting rows"""
   181         for step in self.steps:
   184         for step in self.steps:
       
   185             step.rql_query_tracing_token = self.rql_query_tracing_token
   182             result = step.execute()
   186             result = step.execute()
   183         # the latest executed step contains the full query result
   187         # the latest executed step contains the full query result
   184         return result
   188         return result
   185 
   189 
   186     def preprocess(self, union, security=True):
   190     def preprocess(self, union, security=True):
   550                 cachekey += tuple(sorted([k for k, v in args.items()
   554                 cachekey += tuple(sorted([k for k, v in args.items()
   551                                           if v is None]))
   555                                           if v is None]))
   552         # make an execution plan
   556         # make an execution plan
   553         plan = self.plan_factory(rqlst, args, cnx)
   557         plan = self.plan_factory(rqlst, args, cnx)
   554         plan.cache_key = cachekey
   558         plan.cache_key = cachekey
       
   559         plan.rql_query_tracing_token = str(uuid.uuid4())
   555         self._planner.build_plan(plan)
   560         self._planner.build_plan(plan)
   556         # execute the plan
   561         # execute the plan
   557         try:
   562         try:
   558             results = plan.execute()
   563             results = plan.execute()
   559         except (Unauthorized, ValidationError):
   564         except (Unauthorized, ValidationError):