ip = [ int(x) for x in ip.split('.') ] return (ip[0] * 2**24) + (ip[1] * 2**16) + (ip[2] * 2**8) + (ip[3] * 2**0) from fastbit import FastBit, Query, ResultSet fast = FastBit() print 'set_logfile', fast.set_logfile('testlog') print 'set_verbose_level', fast.set_verbose_level(10) print 'get_logfile', fast.get_logfile() ips = ['24.126.104.55', '63.254.155.34', '64.189.104.238', '69.232.196.114', '71.17.178.96', '76.176.158.239', '81.222.80.217', '98.230.97.172', '157.252.179.242', '208.102.79.212'] print 'add', fast.add_values('ip', 'uI', [ ip2dec(x) for x in ips], 0) print 'add', fast.add_values('host', 't', ips, 0) print 'flush', fast.flush_buffer('foodir') print 'cols', fast.columns_in_partition('foodir') print 'rows', fast.rows_in_partition('foodir') print 'build_index', fast.build_index('foodir', 'ip', '') print 'build_index', fast.build_index('foodir', 'host', '') print 'build_indexes', fast.build_indexes('foodir', '') print '----[ Query' qh = Query('ip, host', 'foodir', 'ip < %d' % ip2dec('127.0.0.0')) print 'build_query\n', qh print 'from clause', qh.get_from_clause() print 'select clause', qh.get_select_clause() print 'n_rows', qh.get_result_rows() print 'len', len(qh) print 'qualified doubles', qh.get_qualified_doubles('ip') print 'qualified longs', qh.get_qualified_longs('ip')
shutil.rmtree(datadir) nvals = int(1e6) conditions = ("a<5", "a+a>150", "a < 60 and c < 60", "c > 90", "c > a") #, 'd = "asdf"') counts = (5, nvals - 76, 19, 10, 50) #, nvals) import time t = time.time() fb = FastBit() fb.add_values('a', 'int', range(nvals)) fb.add_values('b', 'short', [x % 128 for x in range(nvals)]) fb.add_values('c', 'float', [float(1e2 -i) for i in xrange(nvals)]) fb.add_values('d', 'ub', ["asdf" for i in xrange(nvals)]) fb.flush_buffer(datadir) print "time to add %iK values (* 3): %.3f" % (nvals / 1000., time.time() - t) mult = fb.rows_in_partition(datadir) if mult != nvals: print 'Directory %d contains %d rows, expected %i' % (datadir, mult, nvals) sys.exit(1) nerrors = 0 # NOTE runs faster second time. for rep in range(2): if rep == 1: print "\nafter indexes (automatically) created...\n" for i in xrange(len(conditions)): t = time.time()
nvals = int(1e6) conditions = ("a<5", "a+a>150", "a < 60 and c < 60", "c > 90", "c > a" ) #, 'd = "asdf"') counts = (5, nvals - 76, 19, 10, 50) #, nvals) import time t = time.time() fb = FastBit() fb.add_values('a', 'int', range(nvals)) fb.add_values('b', 'short', [x % 128 for x in range(nvals)]) fb.add_values('c', 'float', [float(1e2 - i) for i in xrange(nvals)]) fb.add_values('d', 'ub', ["asdf" for i in xrange(nvals)]) fb.flush_buffer(datadir) print "time to add %iK values (* 3): %.3f" % (nvals / 1000., time.time() - t) mult = fb.rows_in_partition(datadir) if mult != nvals: print 'Directory %d contains %d rows, expected %i' % (datadir, mult, nvals) sys.exit(1) nerrors = 0 # NOTE runs faster second time. for rep in range(2): if rep == 1: print "\nafter indexes (automatically) created...\n" for i in xrange(len(conditions)): t = time.time()
import shutil shutil.rmtree('arr', True) fast = FastBit('arr') fast.logfile = 'test.log' fast.verbosity = 10 fast.add_array(np.arange(10, dtype='f'), 'arr') fast.add_array(np.arange(10, dtype='i'), 'brr') #fast.add_array(np.array(['asdf', 'jkll'], dtype='c'), 'srr') print "added" fast.flush_buffer() print fast.guess_col_types() print "flushed" del fast f = FastBit('arr') #q = f.query('brr > 0', 'brr', 'arr') #, 'srr') q = f.query('brr > 0') print q.rows, q.columns, len(q) #print q.brr for i in range(4): print q.arr#, q.brr