Esempio n. 1
0
 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)())
Esempio n. 2
0
 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)())
Esempio n. 3
0
 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)())
Esempio n. 4
0
 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
Esempio n. 5
0
 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)())
Esempio n. 6
0
    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
Esempio n. 7
0
    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
Esempio n. 8
0
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
Esempio n. 9
0
    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
Esempio n. 10
0
    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
Esempio n. 11
0
    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)())
Esempio n. 12
0
 def reanalyze(self):
     optimizedalgebra = IAlgebraOptimizer(self.alg)(self.metadata)
     runnable = IAlgebraCompiler(optimizedalgebra)(self.metadata,
                                                   optimizedalgebra)
     return runnable
Esempio n. 13
0
 def __call__(self):
     if self.context.klass == set:
         return 'set([' + IAlgebraCompiler(self.context.expr)() + '])'
     elif self.context.klass == list:
         return '[' + IAlgebraCompiler(self.context.expr)() + ']'
Esempio n. 14
0
 def __call__(self):
     return '%s%s%s' % (IAlgebraCompiler(
         self.context.left)(), self.context.op.op,
                        IAlgebraCompiler(self.context.right)())
Esempio n. 15
0
 def __call__(self):
     return 'lambda %s: %s' % (self.context.var,
                               IAlgebraCompiler(self.context.expr)())
Esempio n. 16
0
 def __call__(self):
     return '((%s) and (%s) or (%s))' % (IAlgebraCompiler(
         self.context.cond)(), IAlgebraCompiler(
             self.context.expr1)(), IAlgebraCompiler(self.context.expr2)())
Esempio n. 17
0
 def __call__(self):
     return '%s(metadata.getAll("%s"))' % (
         self.context.coll1.__name__, IAlgebraCompiler(self.context.expr)())