|
8 | 8 | import click |
9 | 9 |
|
10 | 10 | # Global variables |
11 | | -CONFIGS = None # thresholds for batching Redis queries |
12 | | -NODE_DICT = {} # global node dictionary |
13 | | -TOP_NODE_ID = 0 # next ID to assign to a node |
14 | | -QUERY_BUF = None # Buffer for query being constructed |
| 11 | +CONFIGS = None # thresholds for batching Redis queries |
| 12 | +NODE_DICT = {} # global node dictionary |
| 13 | +TOP_NODE_ID = 0 # next ID to assign to a node |
| 14 | +QUERY_BUF = None # Buffer for query being constructed |
15 | 15 |
|
16 | 16 | # Custom error class for invalid inputs |
17 | 17 | class CSVError(Exception): |
@@ -104,7 +104,7 @@ def __init__(self, filename): |
104 | 104 | self.infile = io.open(filename, 'rt') |
105 | 105 | # Initialize CSV reader that ignores leading whitespace in each field |
106 | 106 | # and does not modify input quote characters |
107 | | - self.reader = csv.reader(self.infile, skipinitialspace=True, quoting=csv.QUOTE_NONE) |
| 107 | + self.reader = csv.reader(self.infile, skipinitialspace=True, quoting=QUOTING) |
108 | 108 |
|
109 | 109 | self.prop_offset = 0 # Starting index of properties in row |
110 | 110 | self.prop_count = 0 # Number of properties per entity |
@@ -328,16 +328,23 @@ def process_entity_csvs(cls, csvs): |
328 | 328 | @click.option('--max-token-count', '-c', default=1024, help='max number of processed CSVs to send per query (default 1024)') |
329 | 329 | @click.option('--max-buffer-size', '-b', default=2048, help='max buffer size in megabytes (default 2048)') |
330 | 330 | @click.option('--max-token-size', '-t', default=500, help='max size of each token in megabytes (default 500, max 512)') |
| 331 | +@click.option('--quote-minimal/--no-quote-minimal', '-q/-d', default=False, help='only quote those fields which contain special characters such as delimiter, quotechar or any of the characters in lineterminator') |
331 | 332 |
|
332 | | -def bulk_insert(graph, host, port, password, nodes, relations, max_token_count, max_buffer_size, max_token_size): |
| 333 | +def bulk_insert(graph, host, port, password, nodes, relations, max_token_count, max_buffer_size, max_token_size, quote_minimal): |
333 | 334 | global CONFIGS |
334 | 335 | global NODE_DICT |
335 | 336 | global TOP_NODE_ID |
336 | 337 | global QUERY_BUF |
| 338 | + global QUOTING |
337 | 339 |
|
338 | 340 | if sys.version_info[0] < 3: |
339 | 341 | raise Exception("Python 3 is required for the RedisGraph bulk loader.") |
340 | 342 |
|
| 343 | + if quote_minimal: |
| 344 | + QUOTING=csv.QUOTE_MINIMAL |
| 345 | + else: |
| 346 | + QUOTING=csv.QUOTE_NONE |
| 347 | + |
341 | 348 | TOP_NODE_ID = 0 # reset global ID variable (in case we are calling bulk_insert from unit tests) |
342 | 349 | CONFIGS = Configs(max_token_count, max_buffer_size, max_token_size) |
343 | 350 |
|
|
0 commit comments