def __call__(self): if self.context.klass == set: return 'set.union(%s, %s)' % (IAlgebraCompiler( self.context.coll1)(), IAlgebraCompiler(self.context.coll2)()) elif self.context.klass == list: return '(%s)+(%s)' % (IAlgebraCompiler( self.context.coll1)(), IAlgebraCompiler(self.context.coll2)())
def __call__(self): if self.context.klass == set: return 'set(filter(%s, %s))' % (IAlgebraCompiler( self.context.func)(), IAlgebraCompiler(self.context.call)()) if self.context.klass == list: return 'filter()%s, %s' % (IAlgebraCompiler( self.context.func)(), IAlgebraCompiler(self.context.call)())
def __call__(self): if self.context.klass == set: return 'set(range(%s,%s))' % (IAlgebraCompiler( self.context.start)(), IAlgebraCompiler(self.context.end)()) elif self.context.klass == list: return 'range(%s,%s)' % (IAlgebraCompiler( self.context.start)(), IAlgebraCompiler(self.context.end)())
def __call__(self, metadata, algebra): algebra = self.context.tree #code = algebra.compile() adapter = IAlgebraCompiler(algebra) code = adapter() run = RunnableQuery(metadata, self.context, code) return run
def __call__(self): if self.context.klass == set: return 'reduce(%s, map(%s, %s), %s)' % (IAlgebraCompiler( self.context.aggreg)(), IAlgebraCompiler( self.context.func)(), IAlgebraCompiler(self.context.coll)( ), IAlgebraCompiler(self.context.expr)()) elif self.context.klass == list: return 'reduce(%s, map(%s, %s), %s)' % (IAlgebraCompiler( self.context.aggreg)(), IAlgebraCompiler( self.context.func)(), IAlgebraCompiler(self.context.coll)( ), IAlgebraCompiler(self.context.expr)())
def reanalyze(self): optimizedalgebra = IAlgebraOptimizer(self.alg)(self.metadata) runnable = IAlgebraCompiler(optimizedalgebra)(self.metadata, optimizedalgebra) self.metadata = runnable.metadata self.alg = runnable.alg self.code = runnable.code return self
def compile(self, query): #TODO: later use maybe named adapters metadata = IDB(None) objectquery = IQueryParser(query)(metadata) optimizedoq = IQueryOptimizer(objectquery)() algebra = IRewriter(optimizedoq)() optimizedalgebra = IAlgebraOptimizer(algebra)() runnable = IAlgebraCompiler(optimizedalgebra)(metadata, algebra) return runnable
def compile(expr): #nasty?? thing to allow compilation of not fully compliant algebra tree #mostly required for demonstration purposes try: code = IAlgebraCompiler(expr)() except TypeError: if RELAX_COMPILE: if isinstance(expr, basestring): return expr return unicode(expr) else: raise return code
def compile(self, query): #TODO: later use maybe named adapters metadata = IDB(None) if IObjectQueryHead.providedBy(query): objectquery = query else: objectquery = IQueryParser(query)(metadata) optimizedoq = IQueryOptimizer(objectquery)() algebra = IRewriter(optimizedoq)() optimizedalgebra = IAlgebraOptimizer(algebra)(metadata) runnable = IAlgebraCompiler(optimizedalgebra)(metadata, optimizedalgebra) return runnable
def compile(self, query): #TODO: later use maybe named adapters metadata = IDB(None) if IObjectQueryHead.providedBy(query): objectquery = query else: objectquery = IQueryParser(query)(metadata) optimizedoq = IQueryOptimizer(objectquery)() algebra = IRewriter(optimizedoq)() optimizedalgebra = IAlgebraOptimizer(algebra)(metadata) #algebra is passed here to keep track of the original one, not the optimized runnable = IAlgebraCompiler(optimizedalgebra)(metadata, algebra) return runnable
def __call__(self): if self.context.func is LambdaCompiler and \ self.context.call is set and \ self.context.expr is IfCompiler: if self.context.klass == set: return 'reduce(set.union, map(%s,%s), set())' % ( IAlgebraCompiler(self.context.func)(), IAlgebraCompiler(self.context.coll)()) if self.context.klass == list: return 'reduce(operator.add, map(%s, %s), [])' % ( IAlgebraCompiler(self.context.func)(), IAlgebraCompiler(self.context.coll)()) else: if self.context.klass == set: return 'reduce(set.union, map(%s,%s), set())' % ( IAlgebraCompiler(self.context.func)(), IAlgebraCompiler(self.context.coll)()) if self.context.klass == list: return 'reduce(operator.add, map(%s, %s), [])' % ( IAlgebraCompiler(self.context.func)(), IAlgebraCompiler(self.context.coll)())
def reanalyze(self): optimizedalgebra = IAlgebraOptimizer(self.alg)(self.metadata) runnable = IAlgebraCompiler(optimizedalgebra)(self.metadata, optimizedalgebra) return runnable
def __call__(self): if self.context.klass == set: return 'set([' + IAlgebraCompiler(self.context.expr)() + '])' elif self.context.klass == list: return '[' + IAlgebraCompiler(self.context.expr)() + ']'
def __call__(self): return '%s%s%s' % (IAlgebraCompiler( self.context.left)(), self.context.op.op, IAlgebraCompiler(self.context.right)())
def __call__(self): return 'lambda %s: %s' % (self.context.var, IAlgebraCompiler(self.context.expr)())
def __call__(self): return '((%s) and (%s) or (%s))' % (IAlgebraCompiler( self.context.cond)(), IAlgebraCompiler( self.context.expr1)(), IAlgebraCompiler(self.context.expr2)())
def __call__(self): return '%s(metadata.getAll("%s"))' % ( self.context.coll1.__name__, IAlgebraCompiler(self.context.expr)())