import json
from fabric.api import env, run, parallel, task

# -T c   -- generate cutomers ONLY
# -T l   -- generate nation/region ONLY
# -T L   -- generate lineitem ONLY
# -T n   -- generate nation ONLY
# -T o   -- generate orders/lineitem ONLY
# -T O   -- generate orders ONLY
# -T p   -- generate parts/partsupp ONLY
# -T P   -- generate parts ONLY
# -T r   -- generate region ONLY
# -T s   -- generate suppliers ONLY
# -T S   -- generate partsupp ONLY

tables_options = {
    'lineitem' : 'L',
    'customers' : 'c',
    'nation' : 'n',
    'orders' : 'O',
    'parts' : 'P',
    'region' : 'r',
    'suppliers' : 's',
    'partsupp' : 'S'
}

def dbgen(sf=1, table=""):
    if not table:
       table = tables_options[table]
    chunks = len(env.hosts)
    if chunks > 0:
        chunk = env.hosts.index(env.host)
    else: chunk = 0
    print "Scale Factor = ", sf
    print "Chunks = ", chunks
    print "Chunk = ", chunk
    print "Table = ", table



import json
from fabric.api import env, run, path

tables_options = {
    'lineitem' : 'L',
    'customers' : 'c',
    'nation' : 'n',
    'orders' : 'O',
    'parts' : 'P',
    'region' : 'r',
    'suppliers' : 's',
    'partsupp' : 'S'
}

def dbgen(sf, table):
    if not table:
       table = tables_options[table]
    chunks = len(env.hosts)
    if chunks > 0:
        chunk = env.hosts.index(env.host)
    else: chunk = 0
    print "Scale Factor = ", sf
    print "Chunks = ", chunks
    print "Chunk = ", chunk
    print "Table = ", table
    with path("~/tpch-kit/tpch/tpch_2_17_0/dbgen"):
        dbgen_cmd = "./dbgen -f -s % -C % -S % -T %" % (sf, chunks, chunk, table)
        run("dbgen -h")


def install():
    with path(" cd ~/"):
        run("git clone https://github.com/alexpap/tpch-kit.git")


update fabfile