Using getvid() to access a particular vertex

Hello all,

I am using UDF to do some processing in C++. I am using getvid() to pass a unique INT ID of a vertex to my C++ UDF so that I do not have to convert a VERTEX primary ID to an INT and at the end of processing I have a subset of VID’s left. How do I access the VERTEX using vid? I want to be able to display the VERTICES using vid. I can always do a SELECT p FROM list:p where getvid(p) == returned_vid, but that will be slow.

Thank you,


Currently, we don’t support this vid to vertex function. I added it to our wish list.

Here is a workaround. You can define a boolean expression function, which takes a vertex as its argument. Inside the function, you can use v.vid to access its internal id.

//return true if a survives this function. 

**bool**  exprUDF(Vertex v) {

   uint64_t vid = a.vid;


   return true; //if v should be kept. return false otherwise. 



SetAccum<Vertex> @@result;


       FROM Seed:v

       ACCUM  CASE WHEN exprUDF (v) THEN

                        @@result += v; 


Print @@result;


Hi Kumar,

From your expression function, you can directly convert your uint_64 to a vertex type. For example:

uint_64 int_var = 11;

return VERTEX (int_var);

In the future, we may provide built-in UDF for this.


That should do it! So it will not create a new vertex if a vertex with that vid exists?

You can consider that as type conversion, nothing is physically changed.

Hi @Jon_Herke
I have a similar case, I defined a set of vertices, population = {Person.*}, after my UDF function, I got a list of ID of type INT, I should find back the vertex through the ID, I declared a UDF function
uint64_t getvidID(int64_t ID){
return getvid(VERTEX(ID));
But I found, the returned value sometimes is negative, and it has no relationship with vertices union population, because population has a type of VERTEX, not VERTEX. And if I use getvid to every Person in population, the returned value is quite normal. So how can I get the proper Vertex with ID number

UDF function:
inline ListAccum<uint64_t> udf_getvidId() {
ListAccum<uint64_t> ids;
for(int i = 0; i < 15; ++i){
ids += getvid(VERTEX(i));
return ids;

start = {Person.*};
tmp0 = SELECT s FROM start:s
ACCUM file1.println(getvid(s));
@@Iddd = udf_getvidId();
PRINT @@Iddd;

In this test, @Iddd shows 0~14, but the vid in start union has a very different internal IDs