-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmrlin_query.py
61 lines (45 loc) · 1.47 KB
/
mrlin_query.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python
"""
mrlin - query
Provides query and look-up facilities for mrlin tables.
See https://github.com/mhausenblas/mrlin/wiki/RDF-in-HBase for details.
Usage: python mrlin_query.py pattern
Examples:
python mrlin_query.py Galway
Copyright (c) 2012 The Apache Software Foundation, Licensed under the Apache License, Version 2.0.
@author: Michael Hausenblas, http://mhausenblas.info/#i
@since: 2012-10-30
@status: init
"""
import sys, os, logging, datetime, time, urllib, urllib2, json, requests, urlparse, ntriples, base64, happybase
from mrlin_utils import *
###############
# Configuration
DEBUG = False
if DEBUG:
FORMAT = '%(asctime)-0s %(levelname)s %(message)s [at line %(lineno)d]'
logging.basicConfig(level=logging.DEBUG, format=FORMAT, datefmt='%Y-%m-%dT%I:%M:%S')
else:
FORMAT = '%(asctime)-0s %(message)s'
logging.basicConfig(level=logging.INFO, format=FORMAT, datefmt='%Y-%m-%dT%I:%M:%S')
#######################
# CLI auxilary methods
def query(pattern):
"""Query via scan."""
starttime = time.time()
hbm = HBaseThriftManager(host='localhost', server_port=HBASE_THRIFT_PORT)
hbm.scan_table(HBASE_TABLE_RDF, pattern)
deltatime = time.time() - starttime
logging.info('='*12)
logging.info('Query took me %.2f seconds.' %(deltatime))
#############
# Main script
if __name__ == '__main__':
try:
if len(sys.argv) == 2:
pattern = sys.argv[1]
query(pattern)
else: print __doc__
except Exception, e:
logging.error(e)
sys.exit(2)