Example #1
0
def main():
    import optparse
    op = optparse.OptionParser()
    op.add_option('-m','--meta',help='Load splits from a meta-table')
    op.add_option('-f','--file',help='Load splits from a file')
    op.add_option('-s','--splits',action='store_true',help='Dump split points')
    op.add_option('-n','--num',type='int',default=1,help='Number of partitions to use')
    op.add_option('-i','--index',type='int',help='Emit row predicate for single partition')
    op.add_option('-r','--rows',action='store_true',help='Dump row predicates for all partitions')
    op.add_option('-b','--binary',action='store_true',help='Generate splits for binary strings')
    opt,args = op.parse_args()

    from util.string_interpolate import Alphabet,chr_range
    if opt.binary:
        alpha = Alphabet(chr_range('\x00', '\xff'))
    else:
        alpha = Alphabet(chr_range(' ', '~'))

    pts = []
    if opt.meta:
        pts = loadSplitPointsFromMeta(opt.meta)
    if opt.file:
        pts = loadSplitPointsFromFile(opt.file)
    if opt.splits:
        for t,s in pts:
            print t,s
    rows = list(iterRowPredicates(opt.num, pts, alpha))
    if opt.rows:
        for r in rows:
            print r
    if opt.index is not None:
        print rows[opt.index]
Example #2
0
def main():
    import optparse
    op = optparse.OptionParser()
    op.add_option('-m','--meta',help='location of metatable')
    op.add_option('-t','--table',help='name of table to insert')
    op.add_option('-k','--count',type='int',help='number of partitions to make')
    op.add_option('-p','--partitions',help='file of partition information')
    op.add_option('-s','--servers',help='comma-separated tablet servers')
    op.add_option('-f','--format',help='tablet URI format (def=%default)',
                  default='kdi://%(server)s/%(table)s/%(partition)s')
    op.add_option('-n','--dryrun',action='store_true',
                  help='print meta table cells without loading them')
    op.add_option('-b','--binary',action='store_true',
                  help='use binary string interpolation')
    
    opt,arg = op.parse_args()

    if not opt.table:
        op.error('need --table')
    if not opt.count or opt.count < 1:
        op.error('need --count')

    if opt.binary:
        alphabet = Alphabet(chr_range('\x00', '\xff'))
    else:
        alphabet = Alphabet(chr_range(' ', '~'))
    
    if opt.partitions:
        pts = loadSplitPointsFromFile(opt.partitions)
    else:
        pts = []

    if not opt.servers:
        op.error('need --servers')
    servers = opt.servers.split(',')
    if not servers:
        op.error('need --servers')

    if opt.dryrun:
        def emit(r,c,t,v):
            print '(%r,%r,%r,%r)' % (r,c,t,v)
        metaTable = None
    else:
        if not opt.meta:
            op.error('need --meta')
        metaTable = pykdi.Table(opt.meta)
        def emit(r,c,t,v):
            metaTable.set(r,c,t,v)

    #for split in iterSplits(opt.count, pts, alphabet):
    #    print split
    #return

    for r,c,t,v in iterMetaCells(opt.table, opt.count, pts, servers, opt.format, alphabet):
        emit(r,c,t,v)

    if metaTable:
        metaTable.sync()
Example #3
0
File: splits.py Project: crnt/kdi
def main():
    import optparse
    op = optparse.OptionParser()
    op.add_option('-m', '--meta', help='Load splits from a meta-table')
    op.add_option('-f', '--file', help='Load splits from a file')
    op.add_option('-s',
                  '--splits',
                  action='store_true',
                  help='Dump split points')
    op.add_option('-n',
                  '--num',
                  type='int',
                  default=1,
                  help='Number of partitions to use')
    op.add_option('-i',
                  '--index',
                  type='int',
                  help='Emit row predicate for single partition')
    op.add_option('-r',
                  '--rows',
                  action='store_true',
                  help='Dump row predicates for all partitions')
    op.add_option('-b',
                  '--binary',
                  action='store_true',
                  help='Generate splits for binary strings')
    opt, args = op.parse_args()

    from util.string_interpolate import Alphabet, chr_range
    if opt.binary:
        alpha = Alphabet(chr_range('\x00', '\xff'))
    else:
        alpha = Alphabet(chr_range(' ', '~'))

    pts = []
    if opt.meta:
        pts = loadSplitPointsFromMeta(opt.meta)
    if opt.file:
        pts = loadSplitPointsFromFile(opt.file)
    if opt.splits:
        for t, s in pts:
            print t, s
    rows = list(iterRowPredicates(opt.num, pts, alpha))
    if opt.rows:
        for r in rows:
            print r
    if opt.index is not None:
        print rows[opt.index]
Example #4
0
def main():
    import optparse
    op = optparse.OptionParser()
    op.add_option('-m', '--meta', help='location of metatable')
    op.add_option('-t', '--table', help='name of table to insert')
    op.add_option('-k',
                  '--count',
                  type='int',
                  help='number of partitions to make')
    op.add_option('-p', '--partitions', help='file of partition information')
    op.add_option('-s', '--servers', help='comma-separated tablet servers')
    op.add_option('-f',
                  '--format',
                  help='tablet URI format (def=%default)',
                  default='kdi://%(server)s/%(table)s/%(partition)s')
    op.add_option('-n',
                  '--dryrun',
                  action='store_true',
                  help='print meta table cells without loading them')
    op.add_option('-b',
                  '--binary',
                  action='store_true',
                  help='use binary string interpolation')

    opt, arg = op.parse_args()

    if not opt.table:
        op.error('need --table')
    if not opt.count or opt.count < 1:
        op.error('need --count')

    if opt.binary:
        alphabet = Alphabet(chr_range('\x00', '\xff'))
    else:
        alphabet = Alphabet(chr_range(' ', '~'))

    if opt.partitions:
        pts = loadSplitPointsFromFile(opt.partitions)
    else:
        pts = []

    if not opt.servers:
        op.error('need --servers')
    servers = opt.servers.split(',')
    if not servers:
        op.error('need --servers')

    if opt.dryrun:

        def emit(r, c, t, v):
            print '(%r,%r,%r,%r)' % (r, c, t, v)

        metaTable = None
    else:
        if not opt.meta:
            op.error('need --meta')
        metaTable = pykdi.Table(opt.meta)

        def emit(r, c, t, v):
            metaTable.set(r, c, t, v)

    #for split in iterSplits(opt.count, pts, alphabet):
    #    print split
    #return

    for r, c, t, v in iterMetaCells(opt.table, opt.count, pts, servers,
                                    opt.format, alphabet):
        emit(r, c, t, v)

    if metaTable:
        metaTable.sync()