vesoft-inc / nebula

A distributed, fast open-source graph database featuring horizontal scalability and high availability
https://nebula-graph.io
Apache License 2.0
10.89k stars 1.21k forks source link

Using with connection_pool.session_context('root', 'nebula') as session, the data cannot be written to the database #5823

Open guiniao opened 9 months ago

guiniao commented 9 months ago
config = Config() # 定义一个配置
config.max_connection_pool_size = 10 # 设置最大连接数
connection_pool = ConnectionPool() # 初始化连接池
ok = connection_pool.init([('1.16.1.37', 9669)], config)

with connection_pool.session_context('root', 'nebula') as session:
    # 创建图空间
    session.execute('CREATE SPACE IF NOT EXISTS ttt (vid_type = FIXED_STRING(32))')

    # 使用nba空间
    session.execute('USE ttt')

    session.execute('CREATE TAG IF NOT EXISTS player(name string, age int)') # 创建player标签
    session.execute('CREATE TAG IF NOT EXISTS team(name string)') # 创建team标签
    session.execute('CREATE TAG IF NOT EXISTS bachelor(name string,speciality string)') # 创建bachelor标签

    session.execute('CREATE EDGE IF NOT EXISTS like(likeness int)') # 创建like边
    session.execute('CREATE EDGE IF NOT EXISTS serve(start_year int, end_year int)') # 创建serve边
    session.execute('CREATE EDGE IF NOT EXISTS teammate(start_year int, end_year int)') # 创建teammate边

    从CSV文件中读取数据,插入到player标签中
    try:
        for index, row in df_player.iterrows():
            session.execute('INSERT VERTEX IF NOT EXISTS player(name, age) VALUES "{}":("{}", {})'.format(row['player_id'],row['name'],np.int64(row['age'])))

        # 从CSV文件中读取数据,插入到team标签中
        for index, row in df_team.iterrows():
            session.execute('INSERT VERTEX IF NOT EXISTS team(name) VALUES "{}":("{}")'.format(row['teamid'],row['name']))

        # 从csv文件中读取数据,插入到bachelor标签中
        for index,row in df_bachelor.iterrows():
            session.execute('INSERT VERTEX if not exist bachelor(name,speciality) VALUES "{}":("{}","{}")'.format(row['player_id1'],row['player_id2'],row['speciality']))

        # 从CSV文件中读取数据,插入到like边中
        for index, row in df_like.iterrows():
            session.execute('INSERT EDGE IF NOT EXISTS like(likeness) VALUES "{}"->"{}":({})'.format(row['player_id1'], row['player_id2'], np.int64(row['likeness'])))

        # 从CSV文件中读取数据,插入到serve边中
        for index, row in df_serve.iterrows():
            session.execute('INSERT EDGE IF NOT EXISTS serve(start_year, end_year) VALUES "{}"->"{}":({}, {})'.format(row['player_id1'], row['player_id2'], np.int64(row['start_year']), np.int64(row['end_year'])))

        # 从CSV文件中读取数据,插入到teammate边中
        for index,row in df_teammate.iterrows():
            session.execute('INSERT EDGE IF NOT EXISTS teammate(start_year, end_year) VALUES "{}"->"{}":({},{})'.format(row['player_id1'], row['player_id2'], np.int64(row['start_year']), np.int64(row['end_year'])))
    except Exception as e:
        print(e) 

#关闭连接池
connection_pool.close()

使用上述方法,创建写入数据,程序没有报错,但数据就是写不进去,create tag都不成功,是代码的问题吗,这种方式不是官方给的例子吗

johnny-smitherson commented 9 months ago

here are the problems i see:

so the errors are returned, but you're not checking for them like above.

in the future, you might want to open python issues in the python repo linked above

QingZ11 commented 9 months ago

有报错信息么?

Are there any error messages?