self.client.execute( f'DROP SPACE IF EXISTS {db_name};' )
self.client.execute( f'CREATE SPACE IF NOT EXISTS {db_name}(vid_type=FIXED_STRING({vid_length}));USE {db_name};' )
def create_tags(self, tags):
'''
# 创建TAG
'''
for tag_name, properties_dict in tags.items():
properties_lst = []
for k, v in properties_dict.items():
properties = k + ' ' + v
properties_lst.append(properties)
properties_str = ','.join(properties_lst)
self.client.execute(
f'CREATE TAG IF NOT EXISTS {tag_name}({properties_str});'
)
print(f"【Schema】创建TAG {tag_name}成功!")
def create_edges(self, edges):
'''
# 创建EDGE
'''
for edge_name, properties_dict in edges.items():
properties_lst = []
for k, v in properties_dict.items():
properties = k + ' ' + v
properties_lst.append(properties)
properties_str = ','.join(properties_lst)
self.client.execute(
f'CREATE EDGE IF NOT EXISTS {edge_name} ({properties_str});'
)
print(f"【Schema】创建EDGE {edge_name}成功!")
def insert_graph_vertex(self, tag_name, vertexs):
'''
# 插入vertexs
'''
values_str = ','.join(
[f"'{k}':{tuple(v.values())}" for k, v in vertexs.items() if not (isinstance(k, float) and np.isnan(k))])
resp = self.client.execute(
f'INSERT VERTEX IF NOT EXISTS {tag_name} VALUES {values_str}')
try:
assert resp.is_succeeded(), resp.error_msg()
except:
print(111,values_str)
print(f"【Data】插入节点{tag_name}成功!({len(vertexs.keys())})")
Traceback (most recent call last):
File "/root/jx/kgp/utils/nebula_db.py", line 370, in <module>
test()
File "/root/jx/kgp/utils/nebula_db.py", line 362, in test
conn.insert_graph_edge(relations)
File "/root/jx/kgp/utils/nebula_db.py", line 217, in insert_graph_edge
assert resp.is_succeeded(), resp.error_msg()
AssertionError: EdgeName `liveIn' is nonexistent