44import click
55import redis
66
7- from .config import Config
8- from .label import Label
9- from .query_buffer import QueryBuffer
10- from .relation_type import RelationType
7+ try :
8+ from .config import Config
9+ from .label import Label
10+ from .query_buffer import QueryBuffer
11+ from .relation_type import RelationType
12+ except :
13+ from config import Config
14+ from label import Label
15+ from query_buffer import QueryBuffer
16+ from relation_type import RelationType
1117
12-
13- def parse_schemas (cls , query_buf , path_to_csv , csv_tuples , config ):
18+ def parse_schemas (cls , query_buf , path_to_csv , csv_tuples , config , label_column ):
1419 schemas = [None ] * (len (path_to_csv ) + len (csv_tuples ))
1520 for idx , in_csv in enumerate (path_to_csv ):
1621 # Build entity descriptor from input CSV
17- schemas [idx ] = cls (query_buf , in_csv , None , config )
22+ schemas [idx ] = cls (query_buf , in_csv , None , config , label_column )
1823
1924 offset = len (path_to_csv )
2025 for idx , csv_tuple in enumerate (csv_tuples ):
2126 # Build entity descriptor from input CSV
22- schemas [idx + offset ] = cls (query_buf , csv_tuple [1 ], csv_tuple [0 ], config )
27+ schemas [idx + offset ] = cls (query_buf , csv_tuple [1 ], csv_tuple [0 ], config , label_column )
2328 return schemas
2429
2530
@@ -54,6 +59,7 @@ def process_entities(entities):
5459 "--redis-url" , "-u" , default = "redis://127.0.0.1:6379" , help = "Redis connection url"
5560)
5661@click .option ("--nodes" , "-n" , multiple = True , help = "Path to node csv file" )
62+ @click .option ("--node-label-column" , "-L" , default = None , nargs = 2 , help = "Import based on <column> having <value>" )
5763@click .option (
5864 "--nodes-with-label" ,
5965 "-N" ,
@@ -62,6 +68,7 @@ def process_entities(entities):
6268 help = "Label string followed by path to node csv file" ,
6369)
6470@click .option ("--relations" , "-r" , multiple = True , help = "Path to relation csv file" )
71+ @click .option ("--relation-type-column" , "-T" , default = None , nargs = 2 , help = "Import based on <column> having <value>" )
6572@click .option (
6673 "--relations-with-type" ,
6774 "-R" ,
@@ -144,8 +151,10 @@ def bulk_insert(
144151 graph ,
145152 redis_url ,
146153 nodes ,
154+ node_label_column ,
147155 nodes_with_label ,
148156 relations ,
157+ relation_type_column ,
149158 relations_with_type ,
150159 separator ,
151160 enforce_schema ,
@@ -160,9 +169,7 @@ def bulk_insert(
160169 index ,
161170 full_text_index ,
162171):
163- if sys .version_info .major < 3 or sys .version_info .minor < 6 :
164- raise Exception ("Python >= 3.6 is required for the RedisGraph bulk loader." )
165-
172+
166173 if not (any (nodes ) or any (nodes_with_label )):
167174 raise Exception ("At least one node file must be specified." )
168175
@@ -216,9 +223,9 @@ def bulk_insert(
216223 query_buf = QueryBuffer (graph , client , config )
217224
218225 # Read the header rows of each input CSV and save its schema.
219- labels = parse_schemas (Label , query_buf , nodes , nodes_with_label , config )
226+ labels = parse_schemas (Label , query_buf , nodes , nodes_with_label , config , node_label_column )
220227 reltypes = parse_schemas (
221- RelationType , query_buf , relations , relations_with_type , config
228+ RelationType , query_buf , relations , relations_with_type , config , relation_type_column ,
222229 )
223230
224231 process_entities (labels )
0 commit comments