def check(self, query, name, **kwargs): gname = "grappa_{name}".format(name=name) if kwargs.get('join_type', None) == 'symmetric_hash': kwargs['join_type'] = grappalang.GrappaSymmetricHashJoin elif kwargs.get('join_type', None) == 'shuffle_hash': kwargs['join_type'] = grappalang.GrappaShuffleHashJoin # FIXME: see issue #348; always skipping shuffle tests because it got broken raise SkipTest() kwargs['target_alg'] = GrappaAlgebra() plan = self.get_physical_plan(query, **kwargs) physical_dot = viz.operator_to_dot(plan) with open(os.path.join("c_test_environment", "{gname}.physical.dot".format(gname=gname)), 'w') as dwf: dwf.write(physical_dot) # generate code in the target language code = compile(plan) fname = os.path.join("c_test_environment", "{gname}.cpp".format(gname=gname)) if os.path.exists(fname): os.remove(fname) with open(fname, 'w') as f: f.write(code) raise_skip_test(query) with Chdir("c_test_environment") as d: checkquery(name, GrappalangRunner())
def main(): # A simple join query = "A(x,z) :- R(x,y), S(y,z)" # Triangle # query = "A(x,z) :- R(x,y),S(y,z),T(z,x)" # Two independent rules query = """A(x,z) :- R(x,y), S(y,z); B(x,z) :- S(z,x).""" # Create a cmpiler object dlog = RACompiler() # parse the query dlog.fromDatalog(query) # Print out the graph for (label, root_operator) in dlog.logicalplan: graph = root_operator.collectGraph() v1 = graph_to_dot(graph) v2 = operator_to_dot(root_operator) assert v1 == v2 # print "Dot for individual IDB %s: " % label # print v1 # print v3 = plan_to_dot(dlog.logicalplan) # print "Dot for combined IDBs:" print v3 # print if len(dlog.logicalplan) == 1: assert v1 == v3
def check(self, query, name, join_type=None, emit_print='console', **kwargs): gname = "grappa_{name}".format(name=name) plan = self._get_grappa_physical_plan(query, join_type, emit_print, **kwargs) physical_dot = viz.operator_to_dot(plan) with open(os.path.join("c_test_environment", "{gname}.physical.dot".format(gname=gname)), 'w') as dwf: dwf.write(physical_dot) # generate code in the target language # test_mode=True turns on extra checks like assign-once instance # variables for operators code = compile(plan, test_mode=True, **kwargs) fname = os.path.join("c_test_environment", "{gname}.cpp".format(gname=gname)) if os.path.exists(fname): os.remove(fname) with open(fname, 'w') as f: f.write(code) #raise Exception() raise_skip_test(query) with Chdir("c_test_environment") as d: if emit_print == 'file': checkstore(name, GrappalangRunner(binary_input=False)) else: checkquery(name, GrappalangRunner(binary_input=False))
def emitCode(query, name, algType, plan=None, emit_print=None, dir='.'): if emit_print is not None: alg = algType(emit_print) else: alg = algType() hack_plan(alg, plan) LOG.info("compiling %s: %s", name, query) # Create a compiler object dlog = RACompiler() # parse the query dlog.fromDatalog(query) # print dlog.parsed LOG.info("logical: %s", dlog.logicalplan) print dlog.logicalplan logical_dot = viz.operator_to_dot(dlog.logicalplan) with open("%s.logical.dot" % (name), 'w') as dwf: dwf.write(logical_dot) dlog.optimize(target=alg) LOG.info("physical: %s", dlog.physicalplan) print dlog.physicalplan physical_dot = viz.operator_to_dot(dlog.physicalplan) with open("%s.physical.dot" % (name), 'w') as dwf: dwf.write(physical_dot) # generate code in the target language code = "" code += comment("Query " + query) code += compile(dlog.physicalplan) fname = '{dir}/{name}.cpp'.format(dir=dir, name=name) with open(fname, 'w') as f: f.write(code) # returns name of code file return fname
def check(self, query, name, **kwargs): with Chdir("c_test_environment") as d: kwargs['target_alg'] = CCAlgebra() plan = self.get_physical_plan(query, **kwargs) physical_dot = viz.operator_to_dot(plan) with open("%s.physical.dot"%(name), 'w') as dwf: dwf.write(physical_dot) # generate code in the target language code = compile(plan) fname = "{name}.cpp".format(name=name) if os.path.exists(fname): os.remove(fname) with open(fname, 'w') as f: f.write(code) checkquery(name, ClangRunner())
def check(self, query, name, **kwargs): kwargs['target_alg'] = CCAlgebra() plan = self.get_physical_plan(query, **kwargs) physical_dot = viz.operator_to_dot(plan) with open( os.path.join("c_test_environment", "%s.physical.dot" % (name)), 'w') as dwf: dwf.write(physical_dot) # generate code in the target language code = compile(plan) fname = os.path.join("c_test_environment", "{name}.cpp".format(name=name)) if os.path.exists(fname): os.remove(fname) with open(fname, 'w') as f: f.write(code) with Chdir("c_test_environment") as d: checkquery(name, ClangRunner())
def write_if_enabled(self, plan, title): if self.enabled: with open(self.template % self.ind, "w") as dwf: dwf.write(viz.operator_to_dot(plan, title=title)) self.ind += 1
def write_if_enabled(self, plan, title): if self.enabled: with open(self.template % self.ind, 'w') as dwf: dwf.write(viz.operator_to_dot(plan, title=title)) self.ind += 1