Skip to content

Commit fe3c238

Browse files
author
Taylor A Murphy
committed
change nsj to ndjson
1 parent aa116d5 commit fe3c238

2 files changed

Lines changed: 16 additions & 13 deletions

File tree

rethinkdb/_export.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
info = "'rethinkdb export` exports data from a RethinkDB cluster into a directory"
3030
usage = "\
3131
rethinkdb export [-c HOST:PORT] [-a AUTH_KEY] [-d DIR] [-e (DB | DB.TABLE)]...\n\
32-
[--format (csv | json | nsj)] [--fields FIELD,FIELD...] [--delimiter CHARACTER]\n\
32+
[--format (csv | json | ndjson)] [--fields FIELD,FIELD...] [--delimiter CHARACTER]\n\
3333
[--clients NUM]"
3434

3535
def print_export_help():
@@ -42,8 +42,8 @@ def print_export_help():
4242
print(" -a [ --auth ] AUTH_KEY authorization key for rethinkdb clients")
4343
print(" -d [ --directory ] DIR directory to output to (defaults to")
4444
print(" rethinkdb_export_DATE_TIME)")
45-
print(" --format (csv | json | nsj) format to write (defaults to json.")
46-
print(" nsj is newline separated json.)")
45+
print(" --format (csv | json | ndjson) format to write (defaults to json.")
46+
print(" ndjson is newline delimited json.)")
4747
print(" --fields FIELD,FIELD... limit the exported fields to those specified")
4848
print(" (required for CSV format)")
4949
print(" -e [ --export ] (DB | DB.TABLE) limit dump to the given database or table (may")
@@ -75,7 +75,7 @@ def parse_options():
7575
parser = OptionParser(add_help_option=False, usage=usage)
7676
parser.add_option("-c", "--connect", dest="host", metavar="HOST:PORT", default="localhost:28015", type="string")
7777
parser.add_option("-a", "--auth", dest="auth_key", metavar="AUTHKEY", default="", type="string")
78-
parser.add_option("--format", dest="format", metavar="json | csv | nsj", default="json", type="string")
78+
parser.add_option("--format", dest="format", metavar="json | csv | ndjson", default="json", type="string")
7979
parser.add_option("-d", "--directory", dest="directory", metavar="DIRECTORY", default=None, type="string")
8080
parser.add_option("-e", "--export", dest="tables", metavar="DB | DB.TABLE", default=[], action="append", type="string")
8181
parser.add_option("--fields", dest="fields", metavar="<FIELD>,<FIELD>...", default=None, type="string")
@@ -99,8 +99,8 @@ def parse_options():
9999
(res["host"], res["port"]) = parse_connect_option(options.host)
100100

101101
# Verify valid --format option
102-
if options.format not in ["csv", "json", "nsj"]:
103-
raise RuntimeError("Error: Unknown format '%s', valid options are 'csv', 'json', and 'nsj'" % options.format)
102+
if options.format not in ["csv", "json", "ndjson"]:
103+
raise RuntimeError("Error: Unknown format '%s', valid options are 'csv', 'json', and 'ndjson'" % options.format)
104104
res["format"] = options.format
105105

106106
# Verify valid directory option
@@ -242,7 +242,7 @@ def json_writer(filename, fields, task_queue, error_queue, format):
242242
try:
243243
with open(filename, "w") as out:
244244
first = True
245-
if format != "nsj":
245+
if format != "ndjson":
246246
out.write("[")
247247
item = task_queue.get()
248248
while not isinstance(item, StopIteration):
@@ -252,18 +252,18 @@ def json_writer(filename, fields, task_queue, error_queue, format):
252252
if item not in fields:
253253
del row[item]
254254
if first:
255-
if format == "nsj":
255+
if format == "ndjson":
256256
out.write(json.dumps(row))
257257
else:
258258
out.write("\n" + json.dumps(row))
259259
first = False
260-
elif format == "nsj":
260+
elif format == "ndjson":
261261
out.write("\n" + json.dumps(row))
262262
else:
263263
out.write(",\n" + json.dumps(row))
264264

265265
item = task_queue.get()
266-
if format != "nsj":
266+
if format != "ndjson":
267267
out.write("\n]\n")
268268
except:
269269
ex_type, ex_class, tb = sys.exc_info()
@@ -306,15 +306,18 @@ def csv_writer(filename, fields, delimiter, task_queue, error_queue):
306306
pass
307307

308308
def launch_writer(format, directory, db, table, fields, delimiter, task_queue, error_queue):
309-
if format == "json" or format == "nsj":
309+
if format == "json":
310310
filename = directory + "/%s/%s.json" % (db, table)
311311
return multiprocessing.Process(target=json_writer,
312312
args=(filename, fields, task_queue, error_queue, format))
313313
elif format == "csv":
314314
filename = directory + "/%s/%s.csv" % (db, table)
315315
return multiprocessing.Process(target=csv_writer,
316316
args=(filename, fields, delimiter, task_queue, error_queue))
317-
317+
elif format == "ndjson":
318+
filename = directory + "/%s/%s.ndjson" % (db, table)
319+
return multiprocessing.Process(target=json_writer,
320+
args=(filename, fields, task_queue, error_queue, format))
318321
else:
319322
raise RuntimeError("unknown format type: %s" % format)
320323

rethinkdb/_import.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def print_import_help():
6767
print(" -f [ --file ] FILE the file to import data from")
6868
print(" --table DB.TABLE the table to import the data into")
6969
print(" --format (csv | json) the format of the file (defaults to json and accepts")
70-
print(" newline separated json)")
70+
print(" newline delimited json)")
7171
print(" --pkey PRIMARY_KEY the field to use as the primary key in the table")
7272
print("")
7373
print("Import CSV format:")

0 commit comments

Comments
 (0)