21 from __future__ import print_function |
21 from __future__ import print_function |
22 |
22 |
23 from itertools import repeat |
23 from itertools import repeat |
24 |
24 |
25 from six import text_type, string_types, integer_types |
25 from six import text_type, string_types, integer_types |
26 from six.moves import range |
26 from six.moves import range, zip |
27 |
27 |
28 from rql import RQLSyntaxError, CoercionError |
28 from rql import RQLSyntaxError, CoercionError |
29 from rql.stmts import Union |
29 from rql.stmts import Union |
30 from rql.nodes import ETYPE_PYOBJ_MAP, etype_from_pyobj, Relation, Exists, Not |
30 from rql.nodes import ETYPE_PYOBJ_MAP, etype_from_pyobj, Relation, Exists, Not |
31 from yams import BASE_TYPES |
31 from yams import BASE_TYPES |
475 # instance schema |
475 # instance schema |
476 self.set_schema(schema) |
476 self.set_schema(schema) |
477 |
477 |
478 def set_schema(self, schema): |
478 def set_schema(self, schema): |
479 self.schema = schema |
479 self.schema = schema |
480 repo = self._repo |
480 self.clear_caches() |
481 self.rql_cache = RQLCache(repo, schema) |
481 rqlhelper = self._repo.vreg.rqlhelper |
482 rqlhelper = repo.vreg.rqlhelper |
|
483 self._annotate = rqlhelper.annotate |
482 self._annotate = rqlhelper.annotate |
484 # rql planner |
483 # rql planner |
485 self._planner = SSPlanner(schema, rqlhelper) |
484 self._planner = SSPlanner(schema, rqlhelper) |
486 # sql generation annotator |
485 # sql generation annotator |
487 self.sqlgen_annotate = SQLGenAnnotator(schema).annotate |
486 self.sqlgen_annotate = SQLGenAnnotator(schema).annotate |
|
487 |
|
488 def clear_caches(self, eids=None, etypes=None): |
|
489 if eids is None: |
|
490 self.rql_cache = RQLCache(self._repo, self.schema) |
|
491 else: |
|
492 cache = self.rql_cache |
|
493 for eid, etype in zip(eids, etypes): |
|
494 cache.pop(('Any X WHERE X eid %s' % eid,), None) |
|
495 if etype is not None: |
|
496 cache.pop(('%s X WHERE X eid %s' % (etype, eid),), None) |
488 |
497 |
489 def plan_factory(self, rqlst, args, cnx): |
498 def plan_factory(self, rqlst, args, cnx): |
490 """create an execution plan for an INSERT RQL query""" |
499 """create an execution plan for an INSERT RQL query""" |
491 if rqlst.TYPE == 'insert': |
500 if rqlst.TYPE == 'insert': |
492 return InsertPlan(self, rqlst, args, cnx) |
501 return InsertPlan(self, rqlst, args, cnx) |