Use gRPC to connect with OrpheusDB
Client applications can communicate with the gRPC protocol to use the OrpheusDB versioning functionality directly. An example of the client application can be found in implementation/orpheus/grpc/db_client.py
. To start with, users can simply execute python orpheus/grpc/db_client.py
to see all of the supported requests and the returned results.
The details of each client request are described below.
The hostname and the port number of OrpheusDB are
hilda.cs.illinois.edu:1503
To connect to the PostgreSQL on the server side, the default authentication information is
dbname = 'postgres', user = 'postgres', password = 'postgres'
Users can create new users in OrpheusDB via the CreateUserRequest. The request below creates a user named tester
with password tester
.
CreateUserRequest(user="tester", password="tester")
The server returns a successful message if the user is created with no error. If the username exists in OrpheusDB already, the server will return an error message: 'role "tester" already exists'.
The InitRequest allows users to initialize a Collaborative Versioned Dataset(CVD) on the server side. It takes three parameters: datafile
,schema
and cvd
. The datafile
and schema
specify the external csv file and its schema that the users want to load into OrpheusDB, and the cvd
specifies the CVD name that the user want to use for this datafile. An example of the request is shown below:
InitRequest(datafile = "test/protein.csv", cvd = "protein_interaction", schema = "test/protein_schema.csv")
The CheckoutRequest allows users to materialize one or more versions from a cvd
into a csv file, whose name is specified in the file
parameter.
versions = msg_pb2.Versions()
versions.vals.append(1)
CheckoutRequest(cvd = 'protein_interaction', version = versions, file = 'protein_tmp.csv')
The CommitRequest allows users to commit a versioned csv file
back to its CVD with a commit message
.
CommitRequest(file = 'protein_tmp.csv', message = 'init commit')
The RunRequest allows users to pass the versioning SQL queries to the server side.
query = "SELECT protein1, protein2, neighborhood FROM VERSION 1,2 OF CVD protein WHERE neighborhood > 300"
msg_pb2.RunRequest(query = query)
If the query is successfully executed, the query results are returned to the client. An example of printing the query results in the table format is shown below:
for row in response.data.rows:
row_str = [(col) for col in row.columns]
print(row_str)
In addition, users can list all CVDs on the server side via the ListRequest, and drop any cvd
via the DropRequest