Пример #1
0
from collections import *
try:
  import instabase.notebook.ipython.utils as ib
  ib.import_pyfile('./interpretor.py', 'interpretor')
  ib.import_pyfile('./optimizer.py', 'optimizer')
except:
  pass
from interpretor import *
from optimizer import *


def cond_to_func(expr_or_func):
  """
  if expr_or_func is a string, parse as an expression
  otherwise it better be a function!
  """
  if hasattr(expr_or_func, "__call__"):
    print expr_or_func
    return expr_or_func
  if isinstance(expr_or_func, basestring):
    return parseexpr(expr_or_func)
  raise Exception("Can't interpret as expression: %s" % expr_or_func)



if __name__ == "__main__":

  def test1():
    print "test1"
    o = Print(
          Limit(
Пример #2
0
from collections import *
try:
    import instabase.notebook.ipython.utils as ib
    ib.import_pyfile('./ops.py', 'ops')
except:
    pass
from ops import *


def run_op(op, f=lambda t: t):
    """
  This function interprets the current operator and constructs an 
  appropriate callback function to send to the parent operator

  @op current operator to execute
  @f the function to call for every output tuple of this operator (op)
  """
    klass = op.__class__.__name__

    if klass == "Print":

        def print_f(tup):
            print tup

        run_op(op.p, print_f)

    elif klass == "Scan":
        for tup in op.data:
            if f(tup) == False:
                break
Пример #3
0
import csv
import math
import inspect
import pandas
import numbers
import numpy as np
from collections import defaultdict

try:
    # hack to get this code to work on Instabase
    import instabase.notebook.ipython.utils as ib

    ib.import_pyfile('./parse_expr.py', 'parser')
except:
    pass


def cond_to_func(expr_or_func):
    """
  Helper function to help automatically interpret string expressions 
  when you manually construct a query plan.
  """
    from parse_expr import parse

    # if it's a function already, then we're good
    if hasattr(expr_or_func, "__call__"):
        return expr_or_func
    # otherwise, parse it as a string
    if isinstance(expr_or_func, str):
        return parse(expr_or_func)
    raise Exception("Can't interpret as expression: %s" % expr_or_func)
Пример #4
0
from collections import *
try:
  import instabase.notebook.ipython.utils as ib
  ib.import_pyfile('./ops.py', 'ops')
  import instabase.notebook.ipython.utils as ib
  ib.import_pyfile('./parser.py', 'parser')

except:
  pass
from ops import *
from parser import parse, parseexpr

def run_op(op, f=lambda t:t):
  """
  This function interprets the current operator and constructs an 
  appropriate callback function to send to the parent operator

  @op current operator to execute
  @f the function to call for every output tuple of this operator (op)
  """
  klass = op.__class__.__name__

  if klass == "Print":
    def print_f(tup):
      print tup
    run_op(op.c, print_f)

  elif klass == "Scan":
    for tup in op.data:
      if f(tup) == False:
        break
Пример #5
0
from collections import *
try:
  import instabase.notebook.ipython.utils as ib
  ib.import_pyfile('./interpretor.py', 'interpretor')
except:
  pass
from interpretor import *

if __name__ == "__main__":
  s = Scan("./data.csv")
  f = Filter(s, "a > 3.0 and d <= 4.0")
  run_op(Print(f))

Пример #6
0
from collections import *
try:
  import instabase.notebook.ipython.utils as ib
  ib.import_pyfile('./ops.py', 'ops')
except:
  pass
from ops import *

def run_op(op, f=lambda t:t):
  """
  This function interprets the current operator and constructs an 
  appropriate callback function to send to the parent operator

  @op current operator to execute
  @f the function to call for every output tuple of this operator (op)
  """
  klass = op.__class__.__name__

  if klass == "Print":
    def print_f(tup):
      print tup
    run_op(op.p, print_f)

  elif klass == "Scan":
    for tup in op.data:
      if f(tup) == False:
        break

  elif klass == "Join":
    def outer_loop(left):
      def inner_loop(right):
Пример #7
0
from collections import *
try:
    import instabase.notebook.ipython.utils as ib
    ib.import_pyfile('./interpretor.py', 'interpretor')
    ib.import_pyfile('./optimizer.py', 'optimizer')
except:
    pass
from interpretor import *
from optimizer import *


def cond_to_func(expr_or_func):
    """
  if expr_or_func is a string, parse as an expression
  otherwise it better be a function!
  """
    if hasattr(expr_or_func, "__call__"):
        print expr_or_func
        return expr_or_func
    if isinstance(expr_or_func, basestring):
        return parseexpr(expr_or_func)
    raise Exception("Can't interpret as expression: %s" % expr_or_func)


if __name__ == "__main__":

    def test1():
        print "test1"
        o = Print(
            Limit(
                Project(
Пример #8
0
from collections import *
try:
  import instabase.notebook.ipython.utils as ib
  ib.import_pyfile('./ops.py', 'ops')
  ib.import_pyfile('./parser.py', 'parser')
except:
  pass
from ops import *
from parse_sql import parse



class PullBasedInterpretor(object):
  def __init__(self, db):
    self.db = db

  def __call__(self, op, **kwargs):
    # make sure the scan operators have access to the database
    for scanop in op.collect("Scan"):
      scanop.set_db(self.db)

    for row in op:
      yield row





class PushBasedInterpretor(object):
  def __init__(self, db):
    self.db = db
Пример #9
0
from collections import *
try:
    import instabase.notebook.ipython.utils as ib
    ib.import_pyfile('./interpretor.py', 'interpretor')
except:
    pass
from interpretor import *

if __name__ == "__main__":
    s = Scan("./data.csv")
    f = Filter(s, "a > 3.0 and d <= 4.0")
    run_op(Print(f))