예제 #1
0
              )  #, '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()
        q = Query('', datadir, conditions[i])
        nhits = q.rows
        if nhits != counts[i]:
            print i, 'query "%s" on %d built-in records found %d hits, but %d were expected' % (
예제 #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')

print '----[ Results'
예제 #3
0
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()
        q = Query('', datadir, conditions[i])
        nhits = q.rows
        if nhits != counts[i]:
            print i, 'query "%s" on %d built-in records found %d hits, but %d were expected' % (str(q), nvals, nhits, counts[i])