1

I am using R to call the web API of GridDB. GridDB is an in-memory database.

Using R , I was able to successfully create containers( akin to tables) in the GridDB database, using a POST call to GridDB's prescribed "container creation" API, which takes the form of "/:cluster/dbs/:database/containers" .

e.g. 
container_url = "https://cloud1.griddb.com/trial1234/griddb/v2/my_Cluster1234/dbs/test_DB/containers/"
r <- POST(container_url, 
          add_headers("Content-Type" = "application/json; charset=UTF-8" ) ,      
          config = authenticate("myUser", "myPass"), 
          encode = "json", 
          body= my_data_obj) 
      
showcontainer()   
......................................

The above call successfully creates a container. Then I can populate the data inside the container via the "row registration" API call, to the prescribed path "/:cluster/dbs/:database/containers/:container/rows" .

``
insert_url = "https://cloud1.griddb.com/trial1234/griddb/v2/my_Cluster1234/dbs/test_DB/containers/my_DB_Table/rows"  
r <- PUT(insert_url, 
       add_headers("Content-Type" = "application/json; charset=UTF-8" ) ,      
       config = authenticate("myUser", "myPass"), 
       body = myn_data_JSON , 
       encode = "json" ) 

#To check if all rows have been inserted
print(str(json.loads(r.text)['count']) + ' rows have been registered in the container my_DB_Table.') `  
`

I see the insertion success message as:- Rows 89090, columns 61

But, when I query the same table , via the SQL SELECT execution API , I get an error. The Path is:- "/:cluster/dbs/:database/sql"

``query_request_body = '[ {"type" : "sql-select", "stmt" : "SELECT country_name, country_code, score_2015 FROM   my_DB_Table where indicator_code=\'NY.GNP.PCAP.CD\' 

ORDER BY score_2015 " , "limit":"10" }]'  
#Invoke the GridDB WebAPI request 
qr1 <- POST ( my_query_url, 
       add_headers("Content-Type" = "application/json" ) ,      
       config = authenticate("myUser", "myPass"), 
       body = query_request_body 
       )                            
print(qr1) ` `

Now I get a NULL, and the call does not return any data. When run directly on the database, the query inside the "query_request_body" runs well and returns desired data.

I am perturbed as the first 2 calls complete successfully, but the 3rd API CALL gives me a 400 HTTP error.
My questions are: -

  1. How do you debug the R code, is there a way I can see what R language is sending to the Web API behind the scenes ?
  2. Do you see any probable error or have any suggestions as to why the SQL query call fails ?

Ref:- www.toshiba-sol.co.jp/en/pro/griddb/docs-en/v4_3/GridDB_Web_API_Reference.html

Thanks for your time Pratik

Explained above with code examples

0 Answers0