Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The example of nebula-python client can not get the result #240

Closed
MMMMMain opened this issue Nov 15, 2022 · 2 comments
Closed

The example of nebula-python client can not get the result #240

MMMMMain opened this issue Nov 15, 2022 · 2 comments
Assignees
Labels
type/question Type: question about the product

Comments

@MMMMMain
Copy link

MMMMMain commented Nov 15, 2022

import random
import sys
import time
from nebula3.gclient.net import ConnectionPool
from nebula3.Config import Config
from nebula3.data.ResultSet import ResultSet
from nebula3.mclient import MetaCache, HostAddr
from nebula3.sclient.GraphStorageClient import GraphStorageClient
from nebula3.sclient.ScanResult import ScanResult


def prepare_data():
    config = Config()
    config.max_connection_pool_size = 1
    # init connection pool
    connection_pool = ConnectionPool()
    # the graphd server's address
    assert connection_pool.init([('192.168.1.30', 9669)], config)
    client = connection_pool.get_session('root', 'nebula')
    client.execute(
        'CREATE SPACE IF NOT EXISTS ScanSpace('
        'PARTITION_NUM=10,'
        'vid_type=FIXED_STRING(20));'
        'USE ScanSpace;'
        'CREATE TAG IF NOT EXISTS person(name string, age int);'
        'CREATE EDGE IF NOT EXISTS friend(start int, end int);'
    )
    time.sleep(5)

    for id in range(20):
        vid = 'person' + str(id)
        cmd = 'INSERT VERTEX person(name, age) ' 'VALUES \"{}\":(\"{}\", {})'.format(
            vid, vid, id
        )
        print(client.execute(cmd))
    for id in range(20):
        src_id = 'person' + str(id)
        dst_id = 'person' + str(20 - id)
        start = random.randint(2000, 2010)
        end = random.randint(2010, 2020)
        cmd = 'INSERT EDGE friend(start, end) ' 'VALUES \"{}\"->\"{}\":({}, {})'.format(
            src_id, dst_id, start, end
        )
        print(client.execute(cmd))
    client.release()
    connection_pool.close()


def scan_person_vertex(graph_storage_client):
    resp = graph_storage_client.scan_vertex(
        space_name='ScanSpace', tag_name='person', limit=1
    )
    print('======== Scan vertexes in ScanSpace ======')
    while resp.has_next():
        result = resp.next()
        for vertex_data in result:
            print(vertex_data)


def scan_person_edge(graph_storage_client):
    resp = graph_storage_client.scan_edge(
        space_name='ScanSpace', edge_name='friend', limit=100
    )
    print('======== Scan edges in ScanSpace ======')
    while resp.has_next():
        result = resp.next()
        for edge_data in result:
            print(edge_data)


if __name__ == '__main__':
    meta_cache = None
    graph_storage_client = None
    try:
        # the metad servers's address
        meta_cache = MetaCache([('192.168.1.30', 9559), ], 50000)
        graph_storage_client = GraphStorageClient(meta_cache, storage_addrs=[HostAddr(host='192.168.1.30', port=9779)])
        prepare_data()
        scan_person_vertex(graph_storage_client)
        scan_person_edge(graph_storage_client)

    except Exception as x:
        import traceback

        print(traceback.format_exc())
        if graph_storage_client is not None:
            graph_storage_client.close()
    finally:
        if graph_storage_client is not None:
            graph_storage_client.close()
        if meta_cache is not None:
            meta_cache.close()

在运行至scan_person_vertex时,程序长时间没有输出,且没有相关报错

image

@MMMMMain
Copy link
Author

相关代码与github中的例子几乎没有差异,只是调整了连接配置
vesoft-inc/nebula-python/blob/master/example/ScanVertexEdgeExample.py

@Sophie-Xie Sophie-Xie changed the title nebula-python客户端的例子在具体运行中无法获得结果 The example of nebula-python client can not get the result Nov 15, 2022
@Sophie-Xie Sophie-Xie transferred this issue from vesoft-inc/nebula Nov 17, 2022
@Sophie-Xie Sophie-Xie added the type/question Type: question about the product label Nov 30, 2022
@dutor
Copy link
Contributor

dutor commented Sep 6, 2023

Sorry for the late response.

I will close this issue for now. If the issue still remains, feel free to reopen it.

@dutor dutor closed this as completed Sep 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/question Type: question about the product
Projects
None yet
Development

No branches or pull requests

4 participants