Using the AnzoGraph CLI

You can use the azgi command line interface (CLI) in the <install_path>/bin directory to issue commands directly to the database.

The azgi CLI works on the SPARQL HTTPS port and is enabled only when SSL protocol is enabled. SSL access is controlled by the enable_ssl_protocol setting. If you disabled HTTPS access and want to enable it so that you can use the command line, see Changing AnzoGraph Configuration Settings for instructions.

This section describes the available azgi commands. To view the list of options from the command line, run azgi -help.

AZGI Usage

azgi [-f filename] [-c "command"] [-set param=value] [-h host_url] [-p port]
     [-u username:password] [-v] [-timer] [-raw] [-csv] [-json] [-xml] [-silent] 
     [-nohead] [-noprogress] [-maxwid width] [-wide]
     [-o file] [-nossl] [-certs directory] [-context json_file] 
Option Description
-f filename Runs the specified SPARQL query file. For example, the following command runs the query or queries in the query.rq file:
azgi -f /home/user/query.rq
-c "command" Runs the command in quotation marks. For example, this command runs a query:
azgi -c "select distinct ?eventname from <tickit>
where {?event <eventname> ?eventname} limit 100"

You can include multiple -c options to run multiple commands. For example, this command runs two queries:

azgi -c "select * from <tickit> where {?s ?p ?o} limit 100" 
-c "select distinct ?likes from <tickit> where {?person <like> ?likes}"

And this command sets the query_label configuration setting to "events" before running the query:

azgi -c "set query_label to 'events'" -c "select distinct ?eventname
from <tickit> where {?event <eventname> ?eventname} limit 100"
-set param=value Sets or changes parameter values in query files. For example this command runs the query in the query_summary.rq file with the $query parameter set to 2:
azgi -set query=2 -f query_summary.rq
-h host_url Connects to a remote AnzoGraph server. For example, the following statement runs a query against AnzoGraph installed on host 10.104.55.27:
azgi -h 10.104.55.27 -c "select * from <tickit> where {?s ?p ?o} limit 100"
-p port Used to connect to AnzoGraph on a non-default port. The default azgi port is 8256.
-u username:password Connects to the database with credentials (HTTP basic authentication). If you type -u username and exclude the password, the client prompts for the password. For example, the following command uses basic authentication to run a query:
azgi -u admin:Passw0rd1 -c "select ?g where {graph ?g {?s ?p ?o}} limit 100"
-v Displays verbose output such as client connection details. For example:
azgi -v -c "select distinct ?p from <tickit> where {<person1> ?p ?o}"
Connecting to host=localhost port=8256
IPv4: connected
POST /sparql HTTP/1.1
Host: Anon
Accept: application/sparql-results+xml
User-Agent: azgi
Connection: keep-alive
Content-Length: 38
Content-Type: application/sparql-query
select distinct ?p from <tickit> where {<person1> ?p ?o}
HTTP/1.1 200 OK
Date: Tue, 30 Jun 2020 00:24:42 GMT
Server: AnzoGraph
Access-Control-Allow-Origin: *
X-AnzoGraph-QueryExecution-Time: 20
Connection: close
Content-Type: application/sparql-results+xml; charset=utf-8
...
-timer Reports query execution time in milliseconds.
-raw Displays query results in raw XML, JSON, or CSV format, depending on what format you request.
-csv Displays results in CSV format. For example:
azgi -csv -c "select * from <tickit> where {<person1> ?p ?o} order by ?p limit 10"
p,o
birthday,1939-11-19
card,3876972207981477
city,Kent
dislike,jazz
dislike,broadway
email,Etiam.laoreet.libero@sodalesMaurisblandit.edu
firstname,Rafael
friend,person13826
friend,person33618
friend,person15410
-json Displays results in JSON format.
-xml Displays results in XML format
-silent Suppresses the query output.
-nohead Suppresses headings in query results.
-noprogress Suppresses the progress messages that are displayed for queries that are in flight.
-maxwid width Overrides the default maximum column width of 50 characters for tabular query results. For example, for a data set with long graph names, you can expand column width to view the entire name:
azgi -maxwid 10000 -c "select ?g where {graph ?g {?s ?p ?o}} limit 100"

Using the -wide option described below is equivalent to "maxwid 60000."

-wide Increases the column width for tabular query results from the default 50 characters to 60,000 characters. Equivalent to -maxwid 60000.
-nossl Instructs the client to make a non-SSL (HTTP) connection to the database. When using AZGI to send a request to a remote AnzoGraph server, include the -h host_url and -p port options when using -nossl. The default HTTP port is 7070. For example:
azgi -nossl -h 10.100.0.20 -p 7070 -c "select (count(*) as ?cnt) where {?s ?p ?o}"
-o file Writes the response to the specified file. If the file exists, it is overwritten.
-certs directory Instructs the client to make a certified secure connection to the database. The AnzoGraph certificates are ca.crt, serv.crt (public key), and serv.key (private key) in the install_path/config directory. When sending requests to a remote AnzoGraph server, you can copy the AnzoGraph certificates to the server where you are using AZGI. For example, the following command runs a query on a remote AnzoGraph server. The command makes a certified connection using the AnzoGraph certificates, which were copied to the /home/user/certs directory:
azgi -h 10.10.10.01 -certs /home/user/certs 
-c "select ?g where {graph ?g {?s ?p ?o}} limit 100"

This command runs the same query from the AnzoGraph server.

azgi -certs /opt/anzograph/config -c "select ?g where {graph ?g {?s ?p ?o}} limit 100"
-context json_file Specifies the query context file to use with the request. Context files are JSON-formatted files with key-value pairs that provide connection details, such as user credentials, keys, and tokens, for authentication against data sources. For example:
{
  "url": "jdbc:mysql://10.111.4.9:3306/NORTHWIND",
  "username": "sysadmin",
  "password": "admin123"
}
Related Topics