Skip to content

Commit

Permalink
impl for value/original_id update
Browse files Browse the repository at this point in the history
  • Loading branch information
andydiwenzhu committed May 14, 2023
1 parent c5779c1 commit fa39361
Show file tree
Hide file tree
Showing 12 changed files with 327 additions and 597 deletions.
78 changes: 39 additions & 39 deletions modules/graph/grin/c/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "../include/common/error.h"
#include "../include/index/label.h"
#include "../include/index/order.h"
#include "../include/index/original_id.h"
#include "../include/partition/partition.h"
#include "../include/partition/reference.h"
#include "../include/partition/topology.h"
Expand All @@ -25,6 +26,9 @@ GRIN_GRAPH get_graph(int argc, char** argv) {
GRIN_PARTITION partition =
grin_get_partition_from_list(pg, local_partitions, 0);
GRIN_GRAPH g = grin_get_local_graph_by_partition(pg, partition);
grin_destroy_partition(pg, partition);
grin_destroy_partition_list(pg, local_partitions);
grin_destroy_partitioned_graph(pg);
#else
GRIN_GRAPH g = grin_get_graph_from_storage(argc - 1, &(argv[1]));
#endif
Expand Down Expand Up @@ -99,7 +103,7 @@ void test_property_type(int argc, char** argv) {
const char* vt_name = grin_get_vertex_type_name(g, vt);
printf("vertex type name: %s\n", vt_name);
GRIN_VERTEX_TYPE vt0 = grin_get_vertex_type_by_name(g, vt_name);
grin_destroy_name(g, vt_name);
//grin_destroy_name(g, vt_name);
if (!grin_equal_vertex_type(g, vt, vt0)) {
printf("vertex type name not match\n");
}
Expand Down Expand Up @@ -132,7 +136,7 @@ void test_property_type(int argc, char** argv) {
} else {
const char* vt2_name = grin_get_vertex_type_name(g, vt2);
printf("vertex type name: %s\n", vt2_name);
grin_destroy_name(g, vt2_name);
//grin_destroy_name(g, vt2_name);
}
#else
GRIN_VERTEX_TYPE vt2 = get_one_vertex_type(g);
Expand Down Expand Up @@ -161,7 +165,7 @@ void test_property_type(int argc, char** argv) {
const char* et_name = grin_get_edge_type_name(g, et);
printf("edge type name: %s\n", et_name);
GRIN_EDGE_TYPE et0 = grin_get_edge_type_by_name(g, et_name);
grin_destroy_name(g, et_name);
//grin_destroy_name(g, et_name);
if (!grin_equal_edge_type(g, et, et0)) {
printf("edge type name not match\n");
}
Expand Down Expand Up @@ -195,9 +199,9 @@ void test_property_type(int argc, char** argv) {
const char* dst_vt_name = grin_get_vertex_type_name(g, dst_vt);
const char* et_name = grin_get_edge_type_name(g, et);
printf("edge type name: %s-%s-%s\n", src_vt_name, et_name, dst_vt_name);
grin_destroy_name(g, src_vt_name);
grin_destroy_name(g, dst_vt_name);
grin_destroy_name(g, et_name);
//grin_destroy_name(g, src_vt_name);
//grin_destroy_name(g, dst_vt_name);
//grin_destroy_name(g, et_name);
grin_destroy_vertex_type(g, src_vt);
grin_destroy_vertex_type(g, dst_vt);
}
Expand All @@ -221,7 +225,7 @@ void test_property_type(int argc, char** argv) {
} else {
const char* et2_name = grin_get_edge_type_name(g, et2);
printf("edge type name: %s\n", et2_name);
grin_destroy_name(g, et2_name);
//grin_destroy_name(g, et2_name);
}
#else
GRIN_EDGE_TYPE et2 = get_one_edge_type(g);
Expand Down Expand Up @@ -297,17 +301,17 @@ void test_property_topology(int argc, char** argv) {
grin_destroy_vertex_list(g, vl);
#endif

#ifdef GRIN_ASSUME_BY_TYPE_VERTEX_ORIGINAL_ID
GRIN_DATATYPE dt = grin_get_vertex_original_id_data_type(g);
#ifdef GRIN_ENABLE_VERTEX_ORIGINAL_ID_OF_INT64
GRIN_DATATYPE dt = grin_get_vertex_original_id_datatype(g);
if (dt == Int64) {
long long int v0id = 4;
GRIN_VERTEX v0 = grin_get_vertex_by_original_id_by_type(g, vt, dt, &v0id);
GRIN_VERTEX v0 = grin_get_vertex_by_original_id_of_int64(g, v0id);
if (v0 == GRIN_NULL_VERTEX) {
printf("(Wrong) vertex of id %lld can not be found\n", v0id);
} else {
printf("vertex of original id %lld found\n", v0id);
const void* oid0 = grin_get_vertex_original_id_value(g, v0);
printf("get vertex original id: %lld\n", *((long long int*) oid0));
long long int oid0 = grin_get_vertex_original_id_of_int64(g, v0);
printf("get vertex original id: %lld\n", oid0);
}
grin_destroy_vertex(g, v0);
} else {
Expand Down Expand Up @@ -362,8 +366,8 @@ void test_property_topology(int argc, char** argv) {
grin_destroy_edge_list(g, el);
#endif

grin_destroy_name(g, vt_name);
grin_destroy_name(g, et_name);
//grin_destroy_name(g, vt_name);
//grin_destroy_name(g, et_name);
grin_destroy_vertex_type(g, vt);
grin_destroy_edge_type(g, et);
grin_destroy_graph(g);
Expand Down Expand Up @@ -438,7 +442,7 @@ void test_property_vertex_table(int argc, char** argv) {
#else
const char* vp_name = "unknown";
#endif
GRIN_DATATYPE dt = grin_get_vertex_property_data_type(g, vp);
GRIN_DATATYPE dt = grin_get_vertex_property_datatype(g, vp);
const void* pv =
grin_get_value_from_vertex_property_table(g, vpt, v, vp);
if (grin_get_last_error_code() == NO_ERROR) {
Expand All @@ -454,8 +458,8 @@ void test_property_vertex_table(int argc, char** argv) {
printf("vp_id %u v%zu %s value: %s %s\n", id, i, vp_name, (char*) pv,
(char*) rv);
}
grin_destroy_value(g, dt, pv);
grin_destroy_value(g, dt, rv);
//grin_destroy_value(g, dt, pv);
//grin_destroy_value(g, dt, rv);
grin_destroy_vertex_property(g, vp);
}
grin_destroy_row(g, row);
Expand Down Expand Up @@ -517,8 +521,8 @@ void test_property_vertex_table(int argc, char** argv) {
vp5_name);
grin_destroy_vertex_property(g, vp5);
grin_destroy_vertex_type(g, vt5);
grin_destroy_name(g, vt5_name);
grin_destroy_name(g, vp5_name);
//grin_destroy_name(g, vt5_name);
//grin_destroy_name(g, vp5_name);
}
grin_destroy_vertex_property_list(g, vpl2);
}
Expand Down Expand Up @@ -599,7 +603,7 @@ void test_property_edge_table(int argc, char** argv) {
#else
unsigned int id = ~0;
#endif
GRIN_DATATYPE dt = grin_get_edge_property_data_type(g, ep);
GRIN_DATATYPE dt = grin_get_edge_property_datatype(g, ep);
const void* pv = grin_get_value_from_edge_property_table(g, ept, e, ep);
const void* rv = grin_get_value_from_row(g, row, dt, k);
if (dt == Int64) {
Expand All @@ -613,9 +617,9 @@ void test_property_edge_table(int argc, char** argv) {
*((double*) pv), *((double*) rv));
}
grin_destroy_edge_property(g, ep);
grin_destroy_name(g, ep_name);
grin_destroy_value(g, dt, pv);
grin_destroy_value(g, dt, rv);
//grin_destroy_name(g, ep_name);
//grin_destroy_value(g, dt, pv);
//grin_destroy_value(g, dt, rv);
}

grin_destroy_row(g, row);
Expand Down Expand Up @@ -646,8 +650,8 @@ void test_property_edge_table(int argc, char** argv) {
et_name);

grin_destroy_edge_type(g, et1);
grin_destroy_name(g, ep_name1);
grin_destroy_name(g, et_name);
//grin_destroy_name(g, ep_name1);
//grin_destroy_name(g, et_name);

#ifdef GRIN_WITH_EDGE_PROPERTY_NAME
const char* ep_name = grin_get_edge_property_name(g, et, ep);
Expand Down Expand Up @@ -704,8 +708,8 @@ void test_property_edge_table(int argc, char** argv) {
ep5_name);
grin_destroy_edge_property(g, ep5);
grin_destroy_edge_type(g, et5);
grin_destroy_name(g, et5_name);
grin_destroy_name(g, ep5_name);
//grin_destroy_name(g, et5_name);
//grin_destroy_name(g, ep5_name);
}
grin_destroy_edge_property_list(g, epl2);
}
Expand Down Expand Up @@ -735,7 +739,7 @@ void test_property_primary_key(int argc, char** argv) {
GRIN_VERTEX_TYPE vt = grin_get_vertex_type_from_list(g, vtl, i);
const char* vt_name = grin_get_vertex_type_name(g, vt);
printf("vertex type name: %s\n", vt_name);
grin_destroy_name(g, vt_name);
//grin_destroy_name(g, vt_name);

GRIN_VERTEX_PROPERTY_LIST vpl = grin_get_primary_keys_by_vertex_type(g, vt);
size_t vpl_size = grin_get_vertex_property_list_size(g, vpl);
Expand All @@ -745,29 +749,25 @@ void test_property_primary_key(int argc, char** argv) {
GRIN_VERTEX_PROPERTY vp = grin_get_vertex_property_from_list(g, vpl, j);
const char* vp_name = grin_get_vertex_property_name(g, vt, vp);
printf("primary key name: %s\n", vp_name);
grin_destroy_name(g, vp_name);
//grin_destroy_name(g, vp_name);
grin_destroy_vertex_property(g, vp);
}

GRIN_VERTEX_PROPERTY vp = grin_get_vertex_property_from_list(g, vpl, 0);
GRIN_DATATYPE dt = grin_get_vertex_property_data_type(g, vp);
GRIN_DATATYPE dt = grin_get_vertex_property_datatype(g, vp);

for (size_t j = 1; j <= 6; ++j) {
GRIN_ROW r = grin_create_row(g);
grin_insert_value_to_row(g, r, dt, (void*) (&j));
if (dt == Int64) {
grin_insert_int64_to_row(g, r, j);
} else {
printf("(Wrong) the primary key type is not int64");
}
GRIN_VERTEX v = grin_get_vertex_by_primary_keys(g, vt, r);
if (id_type[j] == i) {
if (v == GRIN_NULL_VERTEX) {
printf("(Wrong) vertex of primary keys %zu does not exist\n", j);
} else {
GRIN_DATATYPE dt0 = grin_get_vertex_original_id_data_type(g);
const void* oid0 = grin_get_vertex_original_id_value(g, v);
if (dt0 == Int64) {
printf("(Correct) vertex of primary keys %zu exists %lld\n", j,
*((long long int*) oid0));
} else {
printf("(Wrong) unmatch original id type\n");
}
grin_destroy_vertex(g, v);
}
} else {
Expand Down
4 changes: 2 additions & 2 deletions modules/graph/grin/c/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
# 4. in build folder, run: bin/vineyard-graph-loader --socket tmp.sock --config modern_graph/config.json

rm -rf ./test
gcc test.c -I. -L/home/graphscope/gie-grin/v6d/build/shared-lib/ -lvineyard_grin -lvineyard_graph -lvineyard_basic -o test
./test /home/graphscope/gie-grin/v6d/build/tmp.sock 134785075056209698
gcc test.c -I. -L/workspaces/v6d/build/shared-lib/ -lvineyard_grin -lvineyard_graph -lvineyard_basic -o test
./test /workspaces/v6d/build/tmp.sock 4510456268948890
55 changes: 31 additions & 24 deletions modules/graph/grin/predefine.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,6 @@ typedef enum {
*/
#define GRIN_ASSUME_HAS_MULTI_EDGE_GRAPH

/** @ingroup TopologyMacros
* @brief There is original ID for a vertex.
* This facilitates queries starting from a specific vertex,
* since one can get the vertex handler directly using its original ID.
*/
#define GRIN_WITH_VERTEX_ORIGINAL_ID

/** @ingroup TopologyMacros
* @brief There is data on vertex. E.g., the PageRank value of a vertex.
*/
Expand Down Expand Up @@ -161,7 +154,6 @@ typedef enum {
#undef GRIN_ASSUME_HAS_DIRECTED_GRAPH
#undef GRIN_ASSUME_HAS_UNDIRECTED_GRAPH
#undef GRIN_ASSUME_HAS_MULTI_EDGE_GRAPH
#undef GRIN_WITH_VERTEX_ORIGINAL_ID
#undef GRIN_WITH_VERTEX_DATA
#undef GRIN_WITH_EDGE_DATA
#undef GRIN_ENABLE_VERTEX_LIST
Expand All @@ -179,7 +171,6 @@ typedef enum {
#define GRIN_ASSUME_HAS_DIRECTED_GRAPH
#define GRIN_ASSUME_HAS_UNDIRECTED_GRAPH
#define GRIN_ASSUME_HAS_MULTI_EDGE_GRAPH
#define GRIN_WITH_VERTEX_ORIGINAL_ID
#define GRIN_ENABLE_VERTEX_LIST
#define GRIN_ENABLE_VERTEX_LIST_ARRAY
#define GRIN_ENABLE_VERTEX_LIST_ITERATOR
Expand Down Expand Up @@ -463,6 +454,11 @@ typedef enum {
*/
#define GRIN_ENABLE_ROW

/** @ingroup PropertyMacros
* @brief Enable the pure data structure Row, which is used in primary keys and tables.
*/
#define GRIN_TRAIT_CONST_VALUE_PTR

/** @ingroup PropertyMacros
* @brief There are properties bound to vertices. When vertices are typed, vertex
* properties are bound to vertex types, according to the definition of vertex type.
Expand Down Expand Up @@ -502,7 +498,7 @@ typedef enum {
*
* With primary keys, one can get the vertex from the graph or a certain type
* by providing the values of the primary keys. The macro is unset if GRIN_WITH_VERTEX_PROPERTY
* is NOT defined, in which case, one can use GRIN_WITH_VERTEX_ORIGINAL_ID when vertices have
* is NOT defined, in which case, one can use ORIGINAL_ID when vertices have
* no properties.
*/
#define GRIN_ENABLE_VERTEX_PRIMARY_KEYS
Expand All @@ -514,12 +510,6 @@ typedef enum {
*/
#define GRIN_TRAIT_NATURAL_ID_FOR_VERTEX_PROPERTY

/** @ingroup PropertyMacros
* @brief Assume the original id is ONLY unique under each vertex type. This means
* to get a vertex from the original id, the caller must also provide the vertex type.
*/
#define GRIN_ASSUME_BY_TYPE_VERTEX_ORIGINAL_ID


/** @ingroup PropertyMacros
* @brief There are properties bound to edges. When edges are typed, edge
Expand Down Expand Up @@ -560,8 +550,7 @@ typedef enum {
*
* With primary keys, one can get the edge from the graph or a certain type
* by providing the values of the primary keys. The macro is unset if GRIN_WITH_EDGE_PROPERTY
* is NOT defined, in which case, one can use GRIN_WITH_EDGE_ORIGINAL_ID when edges have
* no properties.
* is NOT defined.
*/
#define GRIN_ENABLE_EDGE_PRIMARY_KEYS

Expand Down Expand Up @@ -671,14 +660,14 @@ typedef enum {
#ifndef GRIN_DOXYGEN_SKIP
// GRIN_DEFAULT_DISABLE
#undef GRIN_ENABLE_ROW
#undef GRIN_TRAIT_CONST_VALUE_PTR
#undef GRIN_WITH_VERTEX_PROPERTY
#undef GRIN_WITH_VERTEX_PROPERTY_NAME
#undef GRIN_WITH_VERTEX_TYPE_NAME
#undef GRIN_TRAIT_NATURAL_ID_FOR_VERTEX_TYPE
#undef GRIN_ENABLE_VERTEX_PROPERTY_TABLE
#undef GRIN_ENABLE_VERTEX_PRIMARY_KEYS
#undef GRIN_TRAIT_NATURAL_ID_FOR_VERTEX_PROPERTY
#undef GRIN_ASSUME_BY_TYPE_VERTEX_ORIGINAL_ID
#undef GRIN_WITH_EDGE_PROPERTY
#undef GRIN_WITH_EDGE_PROPERTY_NAME
#undef GRIN_WITH_EDGE_TYPE_NAME
Expand All @@ -703,14 +692,14 @@ typedef enum {

// GRIN_STORAGE_ENABLE
#define GRIN_ENABLE_ROW
#define GRIN_TRAIT_CONST_VALUE_PTR
#define GRIN_WITH_VERTEX_PROPERTY
#define GRIN_WITH_VERTEX_PROPERTY_NAME
#define GRIN_WITH_VERTEX_TYPE_NAME
#define GRIN_TRAIT_NATURAL_ID_FOR_VERTEX_TYPE
#define GRIN_ENABLE_VERTEX_PROPERTY_TABLE
#define GRIN_ENABLE_VERTEX_PRIMARY_KEYS
#define GRIN_TRAIT_NATURAL_ID_FOR_VERTEX_PROPERTY
#define GRIN_ASSUME_BY_TYPE_VERTEX_ORIGINAL_ID
#define GRIN_WITH_EDGE_PROPERTY
#define GRIN_WITH_EDGE_PROPERTY_NAME
#define GRIN_WITH_EDGE_TYPE_NAME
Expand Down Expand Up @@ -790,15 +779,37 @@ typedef enum {
#define GRIN_ASSUME_ALL_VERTEX_LIST_SORTED
///@}

/** @name IndexOIDMacros
* @brief Macros for label features
*/
///@{
/** @ingroup IndexOIDMacros
* @brief There is original ID of type int64 for each vertex
* This facilitates queries starting from a specific vertex,
* since one can get the vertex handler directly using its original ID.
*/
#define GRIN_ENABLE_VERTEX_ORIGINAL_ID_OF_INT64

/** @ingroup IndexOIDMacros
* @brief There is original ID of type string for each vertex
* This facilitates queries starting from a specific vertex,
* since one can get the vertex handler directly using its original ID.
*/
#define GRIN_ENABLE_VERTEX_ORIGINAL_ID_OF_STRING
///@}

#ifndef GRIN_DOXYGEN_SKIP
// GRIN_DEFAULT_DISABLE
#undef GRIN_WITH_VERTEX_LABEL
#undef GRIN_WITH_EDGE_LABEL
#undef GRIN_ASSUME_ALL_VERTEX_LIST_SORTED
#undef GRIN_ENABLE_VERTEX_ORIGINAL_ID_OF_INT64
#undef GRIN_ENABLE_VERTEX_ORIGINAL_ID_OF_STRING
// GRIN_END

// GRIN_STORAGE_ENABLE
#define GRIN_ASSUME_ALL_VERTEX_LIST_SORTED
#define GRIN_ENABLE_VERTEX_ORIGINAL_ID_OF_INT64
// GRIN_END

// GRIN_FEATURE_DEPENDENCY
Expand Down Expand Up @@ -851,10 +862,6 @@ typedef void* GRIN_GRAPH;
typedef void* GRIN_VERTEX;
typedef void* GRIN_EDGE;

#ifdef GRIN_WITH_VERTEX_ORIGINAL_ID
typedef void* GRIN_VERTEX_ORIGINAL_ID;
#endif

#ifdef GRIN_WITH_VERTEX_DATA
typedef void* GRIN_VERTEX_DATA;
#endif
Expand Down
Loading

0 comments on commit fa39361

Please sign in to comment.