Skip to content

Commit ec751e7

Browse files
committed
updated hbase_generate_data.py
1 parent 4c064e7 commit ec751e7

1 file changed

Lines changed: 18 additions & 14 deletions

File tree

hbase_generate_data.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,19 @@
3838
import time
3939
import traceback
4040
import socket
41-
import happybase
42-
from thriftpy.thrift import TException as ThriftException
43-
libdir = os.path.abspath(os.path.join(os.path.dirname(__file__), 'pylib'))
41+
try:
42+
# pylint: disable=wrong-import-position
43+
import happybase # pylint: disable=unused-import
44+
# weird this is only importable after happybase, must global implicit import
45+
# happybase.hbase.ttypes.IOError no longer there in Happybase 1.0
46+
from Hbase_thrift import IOError as HBaseIOError # pylint: disable=import-error
47+
from thriftpy.thrift import TException as ThriftException
48+
except ImportError as _:
49+
print('Happybase / thrift module import error - did you forget to build this project?\n\n'
50+
+ traceback.format_exc(), end='')
51+
sys.exit(4)
52+
srcdir = os.path.abspath(os.path.dirname(__file__))
53+
libdir = os.path.join(srcdir, 'pylib')
4454
sys.path.append(libdir)
4555
try:
4656
# pylint: disable=wrong-import-position
@@ -52,7 +62,7 @@
5262
sys.exit(4)
5363

5464
__author__ = 'Hari Sekhon'
55-
__version__ = '0.3.4'
65+
__version__ = '0.4'
5666

5767

5868
class HBaseGenerateData(CLI):
@@ -140,9 +150,7 @@ def process_args(self):
140150
def get_tables(self):
141151
try:
142152
return self.conn.tables()
143-
# happybase.hbase.ttypes.IOError no longer there in Happybase 1.0
144-
#except (socket.timeout, ThriftException, happybase.hbase.ttypes.IOError) as _:
145-
except (socket.timeout, ThriftException) as _:
153+
except (socket.timeout, ThriftException, HBaseIOError) as _:
146154
die('ERROR while trying to get table list: {0}'.format(_))
147155

148156
def run(self):
@@ -154,7 +162,7 @@ def run(self):
154162
self.conn = happybase.Connection(host=self.host, port=self.port, timeout=10 * 1000) # ms
155163
# happybase.hbase.ttypes.IOError no longer there in Happybase 1.0
156164
#except (socket.timeout, ThriftException, happybase.hbase.ttypes.IOError) as _:
157-
except (socket.timeout, ThriftException) as _:
165+
except (socket.timeout, ThriftException, HBaseIOError) as _:
158166
die('ERROR: {0}'.format(_))
159167
tables = self.get_tables()
160168
# of course there is a minor race condition here between getting the table list, checking and creating
@@ -195,9 +203,7 @@ def populate_table(self):
195203
#log.info("connecting to test table '%s'", table)
196204
try:
197205
table_conn = self.conn.table(table)
198-
# happybase.hbase.ttypes.IOError no longer there in Happybase 1.0
199-
#except (socket.timeout, ThriftException, happybase.hbase.ttypes.IOError) as _:
200-
except (socket.timeout, ThriftException) as _:
206+
except (socket.timeout, ThriftException, HBaseIOError) as _:
201207
die('ERROR while trying to connect to table \'{0}\': {1}'.format(table, _))
202208
log.info("populating test table '%s' with random data", table)
203209
if self.use_existing_table:
@@ -220,9 +226,7 @@ def populate_table(self):
220226
print(file=sys.stderr)
221227
time_taken = time.time() - start
222228
log.info('sent %s rows of generated data to HBase in %.2f seconds', self.num_rows, time_taken)
223-
# happybase.hbase.ttypes.IOError no longer there in Happybase 1.0
224-
#except (socket.timeout, ThriftException, happybase.hbase.ttypes.IOError) as _:
225-
except (socket.timeout, ThriftException) as _:
229+
except (socket.timeout, ThriftException, HBaseIOError) as _:
226230
exp = str(_)
227231
exp = exp.replace('\\n', '\n')
228232
exp = exp.replace('\\t', '\t')

0 commit comments

Comments
 (0)