How to get all vertices count and vertex type even if zero data found for any vertextype

I have implemented GSQL custom query to getAllvertices count , but the problem is in response count 0 records are getting excluded . How do i include all vertices ?

CREATE OR REPLACE QUERY getAllVerticesCount() {

start = {ANY};
SELECT v.type as resourceType, count(v) as countValue into resources FROM start:v
GROUP BY v.type;
print resources;
}

> Actual Response :

{
“resources”: [
{
“resourceType”: “Cabinet”,
“countValue”: 1
},
{
“resourceType”: “FiberLink”,
“countValue”: 22147
}
]
}

> Expected Response :

{
“resources”: [
{
“resourceType”: “Cabinet”,
“countValue”: 1
},
{
“resourceType”: “FiberLink”,
“countValue”: 22147
},
{
“resourceType”: “Region”,
“countValue”: 0
},
]
}

As you can see I am expecting records with countValue 0 as well.

Thanks in advance

@sushmakundapur There is a Built-In REST endpoint that will do this for you. Use the “List Vertices” endpoint with the parameter of count_only="True"

Sample CURL call using that endpoint:

curl --location --request GET 'https://jh-covid.i.tgcloud.io:443/restpp/graph/MyGraph/vertices/Patient/?count_only=True' \
--header 'Authorization: Bearer d463bgj41fvd7nhhg8jiape91rd3crsn'

Link to documentation: Built-in Endpoints :: TigerGraph Server

If you’re using pyTigerGraph (Python) there is also a function that allows you to pull the data as well

Sample Notebook: Google Colab

@Jon_Herke Thanks for the reply.

But in List vertices endpoint it is mandatory to pass vertex type , but I need count of all vertices not specific to any vertex type. In Tiger graph studio , we have load data option , to the right we show Graph statistics . I am looking for something like that .

Actually, I believe you may want to use this one:

curl -s -X POST "http://100.67.80.14:9000/builtins/experiments" -d  '{"function":"stat_vertex_number","type":"*"}' | jq .

{
  "version": {
    "edition": "enterprise",
    "api": "v2",
    "schema": 3
  },
  "error": false,
  "message": "",
  "results": [
    {
      "v_type": "Cabinet",
      "count": 1
    },
    {
      "v_type": "Region",
      "count": 0
    }
  ]

(where ‘experiments’ is the name of the database)

Please, look at Built-in Endpoints :: TigerGraph Server to see other builtins.

Regards,
Karol

2 Likes

@gruby_karol Thank you !. Issue resolved.

Thanks, @gruby_karol for helping with the topic resolution! :pray: It’s very much appreciated!