Skip to content

Commit 604a3f6

Browse files
committed
renamed --danger to --use-existing-table
1 parent acb6e70 commit 604a3f6

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

hbase_generate_data.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
sys.exit(4)
5353

5454
__author__ = 'Hari Sekhon'
55-
__version__ = '0.3.3'
55+
__version__ = '0.3.4'
5656

5757

5858
class HBaseGenerateData(CLI):
@@ -78,8 +78,8 @@ def __init__(self):
7878
self.skew = False
7979
self.skew_pc = self.default_skew_pc
8080
self.drop_table = False
81-
self.danger = False
82-
self.cf = 'cf1'
81+
self.use_existing_table = False
82+
self.column_family = 'cf1'
8383
self.timeout_default = 6 * 3600
8484
autoflush()
8585

@@ -100,7 +100,8 @@ def add_options(self):
100100
help='Skew percentage (default: {0})'.format(self.default_skew_pc))
101101
self.add_opt('-d', '--drop-table', action='store_true', default=False,
102102
help='Drop test data table (only allowed if keeping the default table name for safety)')
103-
self.add_opt('-X', '--danger', action='store_true', help='Allows sending data to an existing table. ' +
103+
self.add_opt('-X', '--use-existing-table', action='store_true',
104+
help='Allows sending data to an existing table. ' +
104105
'Dangerous but useful to test pre-splitting schemes on test tables')
105106

106107
def process_args(self):
@@ -130,7 +131,7 @@ def process_args(self):
130131
validate_int(self.skew_pc, 'skew percentage', 0, 100)
131132
self.skew_pc = int(self.skew_pc)
132133
self.drop_table = self.get_opt('drop_table')
133-
self.danger = self.get_opt('danger')
134+
self.use_existing_table = self.get_opt('use_existing_table')
134135

135136
if self.drop_table and self.table != self.default_table_name:
136137
die("not allowed to use --drop-table if using a table name other than the default table '{0}'"\
@@ -170,19 +171,20 @@ def run(self):
170171
# break
171172
# log.debug('waiting for table to be deleted before creating new one')
172173
# time.sleep(1)
173-
elif self.danger:
174+
elif self.use_existing_table:
174175
pass
175176
else:
176177
die("WARNING: table '{0}' already exists, will not send data to a pre-existing table for safety"\
177178
.format(self.table))
178-
self.create_table()
179+
if not self.use_existing_table:
180+
self.create_table()
179181
self.populate_table()
180182
log.info('finished, closing connection')
181183
self.conn.close()
182184

183185
def create_table(self):
184186
log.info('creating table %s', self.table)
185-
self.conn.create_table(self.table, {self.cf: dict(max_versions=1)})
187+
self.conn.create_table(self.table, {self.column_family: dict(max_versions=1)})
186188

187189
def populate_table(self):
188190
table = self.table
@@ -198,9 +200,9 @@ def populate_table(self):
198200
except ThriftException as _:
199201
die('ERROR while trying to connect to table \'{0}\': {1}'.format(table, _))
200202
log.info("populating test table '%s' with random data", table)
201-
if self.danger:
202-
self.cf = sorted(table_conn.families().keys())[0]
203-
cf_col = self.cf + ':col1'
203+
if self.use_existing_table:
204+
self.column_family = sorted(table_conn.families().keys())[0]
205+
cf_col = self.column_family + ':col1'
204206
try:
205207
skew_prefix = 'A' * key_length
206208
skew_mod = max(1, 100.0 / self.skew_pc)

0 commit comments

Comments
 (0)