예제 #1
0
def test_multi_src_dst_edge_loader(graphscope_session, student_group_e,
                                   teacher_group_e, student_v, teacher_v):
    graph = Graph(graphscope_session)
    graph = graph.add_vertices(student_v, "student",
                               ["name", "lesson_nums", "avg_score"],
                               "student_id")
    graph = graph.add_vertices(teacher_v, "teacher",
                               ["student_num", "score", "email", "tel"],
                               "teacher_id")
    graph = graph.add_edges(
        student_group_e,
        "group",
        ["group_id", "member_size"],
        src_label="student",
        dst_label="student",
        src_field="leader_student_id",
        dst_field="member_student_id",
    )
    graph = graph.add_edges(
        teacher_group_e,
        "group",
        ["group_id", "member_size"],
        src_label="teacher",
        dst_label="teacher",
        src_field="leader_teacher_id",
        dst_field="member_teacher_id",
    )
    assert graph.loaded()
예제 #2
0
def test_Load_complex_graph_variants(
    graphscope_session,
    score_e,
    student_group_e_df,
    student_v_array,
    teacher_v_oss,
    lesson_v_mars,
):
    graph = Graph(graphscope_session)
    graph = graph.add_vertices(student_v_array, "student",
                               ["name", "lesson_nums", "avg_score"],
                               "student_id")
    graph = graph.add_vertices(teacher_v_oss, "teacher",
                               ["student_num", "score", "email", "tel"])
    graph = graph.add_vertices(lesson_v_mars, "lesson")
    graph = graph.add_edges(
        score_e,
        "score",
        ["score", "score_id"],
        src_label="student",
        dst_label="lesson",
        src_field="studnet_id",
        dst_field="subject",
    )
    graph = graph.add_edges(
        student_group_e_df,
        "group",
        ["member_size"],
        src_label="student",
        dst_label="student",
        src_field="leader_studnet_id",
        dst_field="member_student_id",
    )
    assert graph.schema is not None
예제 #3
0
def test_error_on_duplicate_labels(graphscope_session, student_group_e,
                                   student_v):
    graph = Graph(graphscope_session)
    graph = graph.add_vertices(student_v, "student")
    with pytest.raises(ValueError,
                       match="Label student already existed in graph"):
        graph = graph.add_vertices(student_v, "student")
    graph = graph.add_edges(student_group_e, "group")
    with pytest.raises(ValueError, match="already existed in graph"):
        graph = graph.add_edges(student_group_e, "group")
예제 #4
0
def test_error_on_non_default_and_non_existing_v_label(graphscope_session,
                                                       student_group_e,
                                                       student_v):
    graph = Graph(graphscope_session)
    graph = graph.add_vertices(student_v, "student")
    with pytest.raises(ValueError,
                       match="src label or dst_label not existed in graph"):
        graph = graph.add_edges(student_group_e,
                                "group",
                                src_label="v",
                                dst_label="v")
    with pytest.raises(ValueError,
                       match="must be both specified or either unspecified"):
        graph = graph.add_edges(student_group_e, src_label="v")
예제 #5
0
def test_error_on_src_dst_refer_to_same_col(graphscope_session,
                                            student_group_e):
    graph = Graph(graphscope_session)
    with pytest.raises(AssertionError, match="cannot refer to the same field"):
        graph = graph.add_edges(
            student_group_e,
            "group",
            src_field="leader_student_id",
            dst_field="leader_student_id",
        )
    with pytest.raises(AssertionError, match="cannot refer to the same field"):
        graph = graph.add_edges(student_group_e,
                                "group",
                                src_field=0,
                                dst_field=0)
예제 #6
0
def test_multiple_add_vertices_edges(graphscope_session):
    prefix = os.path.expandvars("${GS_TEST_DIR}/modern_graph")
    graph = Graph(graphscope_session)
    graph = graph.add_vertices(Loader(f"{prefix}/person.csv", delimiter="|"),
                               "person")
    graph = graph.add_edges(Loader(f"{prefix}/knows.csv", delimiter="|"),
                            "knows")
    graph = graph.add_vertices(Loader(f"{prefix}/software.csv", delimiter="|"),
                               "software")
    graph = graph.add_edges(
        Loader(f"{prefix}/created.csv", delimiter="|"),
        "created",
        src_label="person",
        dst_label="software",
    )

    assert graph.schema.vertex_labels == ["person", "software"]
    assert graph.schema.edge_labels == ["created", "knows"]

    graph = graph.add_vertices(Loader(f"{prefix}/person.csv", delimiter="|"),
                               "person2")
    graph = graph.add_edges(
        Loader(f"{prefix}/knows.csv", delimiter="|"),
        "knows2",
        src_label="person2",
        dst_label="person2",
    )
    graph = graph.add_vertices(Loader(f"{prefix}/software.csv", delimiter="|"),
                               "software2")
    graph = graph.add_edges(
        Loader(f"{prefix}/created.csv", delimiter="|"),
        "created2",
        src_label="person2",
        dst_label="software2",
    )

    assert sorted(graph.schema.vertex_labels) == [
        "person",
        "person2",
        "software",
        "software2",
    ]
    assert sorted(graph.schema.edge_labels) == [
        "created",
        "created2",
        "knows",
        "knows2",
    ]
예제 #7
0
def test_serialize_roundtrip(gs_session_distributed, p2p_property_dir):
    graph = Graph(gs_session_distributed, generate_eid=False)
    graph = graph.add_vertices(f"{p2p_property_dir}/p2p-31_property_v_0",
                               "person")
    graph = graph.add_edges(
        f"{p2p_property_dir}/p2p-31_property_e_0",
        label="knows",
        src_label="person",
        dst_label="person",
    )

    graph.save_to("/tmp/serialize")
    new_graph = Graph.load_from("/tmp/serialize", gs_session_distributed)
    pg = new_graph.project_to_simple(0, 0, 0, 2)
    ctx = graphscope.sssp(pg, src=6)
    ret = (ctx.to_dataframe({
        "node": "v.id",
        "r": "r"
    },
                            vertex_range={
                                "end": 6
                            }).sort_values(by=["node"]).to_numpy(dtype=float))
    expect = np.array([[1.0, 260.0], [2.0, 229.0], [3.0, 310.0], [4.0, 256.0],
                       [5.0, 303.0]])
    assert np.all(ret == expect)
예제 #8
0
def test_properties_omitted_loader(graphscope_session, student_group_e,
                                   student_v):
    graph = Graph(graphscope_session, generate_eid=False)
    graph = graph.add_vertices(student_v, "student", [], "student_id")
    graph = graph.add_edges(student_group_e, "group", [])
    assert len(graph.schema.vertex_properties[0]) == 4
    assert len(graph.schema.edge_properties[0]) == 2
예제 #9
0
def arrow_property_graph_lpa(graphscope_session):
    g = Graph(graphscope_session, generate_eid=False)
    g = g.add_vertices(f"{property_dir}/lpa_dataset/lpa_3000_v_0", "v0")
    g = g.add_vertices(f"{property_dir}/lpa_dataset/lpa_3000_v_1", "v1")
    g = g.add_edges(f"{property_dir}/lpa_dataset/lpa_3000_e_0", "e0",
                    ["weight"], "v0", "v1")
    yield g
    g.unload()
예제 #10
0
def test_error_on_ambigious_default_label(graphscope_session, student_group_e,
                                          student_v, teacher_v):
    graph = Graph(graphscope_session)
    graph = graph.add_vertices(student_v, "student")
    graph = graph.add_vertices(teacher_v, "teacher")

    with pytest.raises(AssertionError, match="ambiguous vertex label"):
        graph = graph.add_edges(student_group_e, "group")
예제 #11
0
def test_add_vertices_edges(graphscope_session):
    prefix = os.path.expandvars("${GS_TEST_DIR}/modern_graph")
    graph = Graph(graphscope_session)
    graph = graph.add_vertices(Loader(f"{prefix}/person.csv", delimiter="|"),
                               "person")
    graph = graph.add_edges(Loader(f"{prefix}/knows.csv", delimiter="|"),
                            "knows")

    assert graph.schema.vertex_labels == ["person"]
    assert graph.schema.edge_labels == ["knows"]

    with pytest.raises(ValueError,
                       match="src label and dst label cannot be None"):
        graph = graph.add_edges(Loader(f"{prefix}/knows.csv", delimiter="|"),
                                "created")
    with pytest.raises(ValueError,
                       match="src label or dst_label not existed in graph"):
        graph = graph.add_edges(
            Loader(f"{prefix}/created.csv", delimiter="|"),
            "created",
            src_label="person",
            dst_label="software",
        )

    graph = graph.add_vertices(Loader(f"{prefix}/software.csv", delimiter="|"),
                               "software")

    with pytest.raises(ValueError,
                       match="Cannot add new relation to existed graph"):
        graph = graph.add_edges(
            Loader(f"{prefix}/knows.csv", delimiter="|"),
            "knows",
            src_label="software",
            dst_label="software",
        )

    graph = graph.add_edges(
        Loader(f"{prefix}/created.csv", delimiter="|"),
        "created",
        src_label="person",
        dst_label="software",
    )

    assert graph.schema.vertex_labels == ["person", "software"]
    assert graph.schema.edge_labels == ["knows", "created"]
예제 #12
0
def test_load_complex_graph(
    graphscope_session,
    score_e,
    student_teacher_e,
    teacher_lesson_e,
    student_v,
    teacher_v,
    lesson_v,
):
    graph = Graph(graphscope_session, oid_type="string")
    graph = graph.add_vertices(student_v, "student",
                               ["name", "lesson_nums", "avg_score"],
                               "student_id")
    graph = graph.add_vertices(teacher_v, "teacher",
                               ["student_num", "score", "email", "tel"])
    graph = graph.add_vertices(lesson_v, "lesson")
    graph = graph.add_edges(
        score_e,
        "score",
        ["score", "score_id"],
        src_label="student",
        dst_label="lesson",
        src_field="student_id",
        dst_field="subject",
    )
    graph = graph.add_edges(
        student_teacher_e,
        "student_teacher",
        ["teaching_score"],
        src_label="student",
        dst_label="teacher",
        src_field="student_id",
        dst_field="teacher_id",
    )
    graph = graph.add_edges(
        teacher_lesson_e,
        "teacher_lesson",
        ["times"],
        src_label="teacher",
        dst_label="lesson",
        src_field="teacher_id",
        dst_field="lesson",
    )
    assert graph.schema is not None
예제 #13
0
def p2p_property_graph_undirected(graphscope_session):
    g = Graph(graphscope_session, directed=False, generate_eid=False)
    g = g.add_vertices(f"{property_dir}/p2p-31_property_v_0", "person")
    g = g.add_edges(
        f"{property_dir}/p2p-31_property_e_0",
        label="knows",
        src_label="person",
        dst_label="person",
    )
    yield g
    g.unload()
예제 #14
0
def test_v_property_omitted_form_loader(graphscope_session, student_group_e,
                                        student_v):
    # properties for v can be omit, all columns will be load,
    # the first one used as vid by # default. default vlabel would be '_';
    graph = Graph(graphscope_session)
    graph = graph.add_vertices(student_v, "student")
    graph = graph.add_edges(
        student_group_e,
        "group",
        ["group_id", "member_size"],
        src_field="leader_student_id",
        dst_field="member_student_id",
    )
    assert graph.loaded()
예제 #15
0
def test_error_on_remove_vertices_edges(graphscope_session):
    prefix = os.path.expandvars("${GS_TEST_DIR}/modern_graph")
    graph = Graph(graphscope_session)
    graph = graph.add_vertices(Loader(f"{prefix}/person.csv", delimiter="|"),
                               "person")
    graph = graph.add_edges(Loader(f"{prefix}/knows.csv", delimiter="|"),
                            "knows")

    graph = graph.add_vertices(Loader(f"{prefix}/software.csv", delimiter="|"),
                               "software")
    graph = graph.add_edges(
        Loader(f"{prefix}/created.csv", delimiter="|"),
        "created",
        src_label="person",
        dst_label="software",
    )

    with pytest.raises(ValueError,
                       match="Vertex software has usage in relation"):
        graph = graph.remove_vertices("software")

    with pytest.raises(ValueError, match="label xxx not in vertices"):
        graph = graph.remove_vertices("xxx")
    with pytest.raises(ValueError, match="label xxx not in edges"):
        graph = graph.remove_edges("xxx")
    with pytest.raises(ValueError, match="Cannot find edges to remove"):
        graph = graph.remove_edges("knows", src_label="xxx", dst_label="xxx")

    assert graph.loaded()
    with pytest.raises(
            ValueError,
            match="Remove vertices from a loaded graph doesn't supported yet"):
        graph = graph.remove_vertices("person")
    with pytest.raises(
            ValueError,
            match="Remove edges from a loaded graph doesn't supported yet"):
        graph = graph.remove_edges("knows")
예제 #16
0
def test_vid_omitted_form_loader(graphscope_session, student_group_e,
                                 student_v):
    # vid can be omit, the first column will be used as vid;
    graph = Graph(graphscope_session)
    graph = graph.add_vertices(student_v, "student",
                               ["name", "lesson_nums", "avg_score"])
    graph = graph.add_edges(
        student_group_e,
        "group",
        ["group_id", "member_size"],
        src_label="student",
        dst_label="student",
        src_field="leader_student_id",
        dst_field="member_student_id",
    )
    assert graph.loaded()
예제 #17
0
def test_complete_form_loader(graphscope_session, student_group_e, student_v):
    # a complete form for loading from ev files.
    # types are inferred from Loader.
    graph = Graph(graphscope_session)
    graph = graph.add_vertices(student_v, "student",
                               ["name", "lesson_nums", "avg_score"],
                               "student_id")
    graph = graph.add_edges(
        student_group_e,
        "group",
        ["group_id", "member_size"],
        src_label="student",
        dst_label="student",
        src_field="leader_student_id",
        dst_field="member_student_id",
    )
    assert graph.loaded()
예제 #18
0
def test_errors_on_files(graphscope_session, one_column_file,
                         double_type_id_file, empty_file):
    with pytest.raises(AnalyticalEngineInternalError,
                       match="Object not exists"):
        Graph(graphscope_session,
              vineyard.ObjectName("non_exist_vy_name"))._ensure_loaded()
    return
    graph = Graph(graphscope_session)
    with pytest.raises(AnalyticalEngineInternalError, match="IOError"):
        non_existing_file = "file:///abc"
        graph.add_edges(Loader(non_existing_file))._ensure_loaded()
    with pytest.raises(AnalyticalEngineInternalError,
                       match="Index out of range: 1"):
        graph.add_edges(one_column_file)._ensure_loaded()
    with pytest.raises(AnalyticalEngineInternalError,
                       match="CSV conversion error to int64"):
        graph.add_edges(double_type_id_file)._ensure_loaded()
    with pytest.raises(AnalyticalEngineInternalError, match="End Of File"):
        graph.add_edges(empty_file)._ensure_loaded()
예제 #19
0
def arrow_property_graph_only_from_efile(graphscope_session):
    g = Graph(graphscope_session, generate_eid=False)
    g = g.add_edges(f"{new_property_dir}/twitter_e_0_0_0", "e0", ["weight"],
                    "v0", "v0")
    g = g.add_edges(f"{new_property_dir}/twitter_e_0_1_0", "e0", ["weight"],
                    "v0", "v1")
    g = g.add_edges(f"{new_property_dir}/twitter_e_1_0_0", "e0", ["weight"],
                    "v1", "v0")
    g = g.add_edges(f"{new_property_dir}/twitter_e_1_1_0", "e0", ["weight"],
                    "v1", "v1")
    g = g.add_edges(f"{new_property_dir}/twitter_e_0_0_1", "e1", ["weight"],
                    "v0", "v0")
    g = g.add_edges(f"{new_property_dir}/twitter_e_0_1_1", "e1", ["weight"],
                    "v0", "v1")
    g = g.add_edges(f"{new_property_dir}/twitter_e_1_0_1", "e1", ["weight"],
                    "v1", "v0")
    g = g.add_edges(f"{new_property_dir}/twitter_e_1_1_1", "e1", ["weight"],
                    "v1", "v1")

    yield g
    g.unload()
예제 #20
0
def test_loader_with_specified_data_type(graphscope_session, student_group_e,
                                         student_v):
    graph = Graph(graphscope_session, oid_type="string", generate_eid=False)
    graph = graph.add_vertices(
        student_v,
        "student",
        ["name", ("lesson_nums", "int"), ("avg_score", "float")],
        "student_id",
    )
    graph = graph.add_edges(student_group_e, "group",
                            ["group_id", ("member_size", "int")])
    assert graph.schema.vertex_properties == [{
        "name": 21,
        "lesson_nums": 11,
        "avg_score": 18,
        "student_id": 21
    }]
    assert graph.schema.edge_properties == [{
        "group_id": 21,
        "member_size": 11
    }]
예제 #21
0
def arrow_property_graph_undirected(graphscope_session):
    g = Graph(graphscope_session, directed=False, generate_eid=False)
    g = g.add_vertices(f"{new_property_dir}/twitter_v_0", "v0")
    g = g.add_vertices(f"{new_property_dir}/twitter_v_1", "v1")
    g = g.add_edges(f"{new_property_dir}/twitter_e_0_0_0", "e0", ["weight"],
                    "v0", "v0")
    g = g.add_edges(f"{new_property_dir}/twitter_e_0_1_0", "e0", ["weight"],
                    "v0", "v1")
    g = g.add_edges(f"{new_property_dir}/twitter_e_1_0_0", "e0", ["weight"],
                    "v1", "v0")
    g = g.add_edges(f"{new_property_dir}/twitter_e_1_1_0", "e0", ["weight"],
                    "v1", "v1")
    g = g.add_edges(f"{new_property_dir}/twitter_e_0_0_1", "e1", ["weight"],
                    "v0", "v0")
    g = g.add_edges(f"{new_property_dir}/twitter_e_0_1_1", "e1", ["weight"],
                    "v0", "v1")
    g = g.add_edges(f"{new_property_dir}/twitter_e_1_0_1", "e1", ["weight"],
                    "v1", "v0")
    g = g.add_edges(f"{new_property_dir}/twitter_e_1_1_1", "e1", ["weight"],
                    "v1", "v1")

    yield g
    g.unload()
예제 #22
0
def test_load_from_numpy(graphscope_session, student_group_e_array,
                         student_v_array):
    graph = Graph(graphscope_session)
    graph = graph.add_vertices(student_v_array)
    graph = graph.add_edges(student_group_e_array)
    assert graph.loaded()
예제 #23
0
def test_vertices_omitted_form_loader(graphscope_session, student_group_e):
    # vertices can be omit.
    graph = Graph(graphscope_session)
    graph = graph.add_edges(student_group_e)
    assert graph.loaded()
예제 #24
0
def test_multiple_e_all_omitted_form_loader(graphscope_session,
                                            student_group_e, friend_e):
    graph = Graph(graphscope_session)
    graph = graph.add_edges(student_group_e, "group")
    graph = graph.add_edges(friend_e, "friend")
    assert graph.loaded()
예제 #25
0
def test_load_from_pandas(graphscope_session, student_group_e_df,
                          student_v_df):
    graph = Graph(graphscope_session)
    graph = graph.add_vertices(student_v_df)
    graph = graph.add_edges(student_group_e_df)
    assert graph.loaded()