Using the AnzoGraph Command Line Interface

You can use the AZGI command line interpreter to run SPARQL commands and access AnzoGraph data from your AnzoGraph deployment environment's command line interface (CLI).

Note: AnzoGraph also provides an alternate command line interface (AZGBOLT), which uses the Bolt protocol, that allows you to run Cypher commands and queries against AnzoGraph data. For more information, see Using the Cypher Command Line Interface (AZGBOLT). The remainder of this section describes use of the AZGI command line interpreter for executing SPARQL commands using the SPARQL protocol.

Running the AZGI Command

The method by which you run AZGI varies slightly by the deployment option you have deployed.

  • AWS CloudFormation Deployments – Use the AnzoGraph AZGI command line interface (CLI) in the /opt/anzograph/bin directory to issue commands to the database. For security reasons, the AnzoGraph CloudFormation service does not automatically enable secure shell access to AnzoGraph instances. If you want to enable SSH access to a cluster, see How do I enable SSH access to AnzoGraph instances?

    Important: The AZGI CLI works on the SPARQL HTTP port and is enabled only when HTTP access is enabled (if you specified yes for the Do you want insecured (HTTP) access to cluster prompt during the AnzoGraph deployment). If you disabled HTTP access and want to enable it so that you can use the command line, see Enabling HTTP Protocol for instructions.

  • Docker and Kubernetes Deployments – You can run the AZGI command line interpreter LI) from the /opt/anzograph/bin directory to issue commands to the database.
  • Important: The AZGI CLI works on the SPARQL HTTP port and is enabled only when HTTP access is enabled. If SPARQL HTTP access is disabled and want to enable it so that you can use the command line, see Enabling HTTP Protocol for instructions.

  • RHEL/Centos Tarball Deployment – Use the AnzoGraph AZGI command line interface (CLI) in the azg/bin directory to issue commands to the database. AZGI uses the SPARQL HTTP protocol to interact with the database, and SPARQL protocol must be enabled to use the command line client.

AZGI Syntax

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

azgi [-f filename] [-c "command"] [-raw] [-csv] [-silent] [-v] [-h host_url] [-p port] [-timer] 
     [-maxwid width] [ -wide ] [-nohead] [-ssl] [-certs directory] [-u username:password]

-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 output format to JSON before running the query:

azgi -raw -c "set output_format to 'json'" -c "select distinct ?eventname
from <tickit> where {?event <eventname> ?eventname} limit 100"

-raw

Displays query results in raw XML, JSON, or CSV format, depending on what the format you request. You must specify this option if you request JSON or CSV. You must also use the raw option when running CONSTRUCT queries. For example:

azgi -raw -c "construct {<person00> ?p ?o} from <tickit> where {<person1> ?p ?o}"

-csv

Displays query results in CSV format. When you use this option on the command line, you do not need to specify -raw. 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

-slient

Suppresses the query output.

-v

Displays verbose output such as client connection details. For example:

azgi -v -c "select distinct ?p from <tickit> where {<person1> ?p ?o}"
do_connect: connecting to host=localhost
POST /sparql/ HTTP/1.1
Host: Anon
Accept: text/html, application/sparql-results+xml, text/csv, 
application/xhtml+xml, application/xml, application/sparql, 
application/turtle; q=0.9,*/*;q=0.8
User-Agent: isbx
Connection: keep-alive
Content-Length: 57
Content-Type: application/sparql-query
select distinct ?p from <tickit> where {<person1> ?p ?o}
HTTP/1.1 200 OK
Date: Wed, 10 Jan 2018 20:25:47 GMT
Server: SPARQLverse
Access-Control-Allow-Origin: *
Connection: close
Content-Type: application/sparql-results+xml; charset=utf-8
<?xml version="1.0"?>
<sparql xmlns="http://www.w3.org/2005/sparql-results#">
<head>
<variable name="p"/>
</head>
<results>
...

-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 port is 7070.

-timer

Reports query execution time in milliseconds.

-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"

Note: 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.

-nohead

Suppresses headings in query results.

-ssl

Instructs the client to make an SSL-based (HTTPS) connection to the database. The connection is anonymous/uncertified (equivalent to the cURL "--insecure" option). To make a certified secure connection, use the -certs option instead. When using AZGI to send a request to a remote AnzoGraph server, include the -h host_url and -p port options when using -ssl. The default HTTPS port is 443. For example:

azgi -ssl -h 10.100.0.20 -p 443 -c "select (count(*) as ?cnt) where {?s ?p ?o}"

-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 opt/anzograph/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"

-u username:password

Enables user authentication (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"