Compile SPARQL Commands Using the CGE compile Command
Purpose, syntax, examples, modes and output of the CGE CLI's compile command.
The compile command is used to compile SPARQL commands into the logical and/or physical plans that the database server will use for command execution. This can be useful for understanding how the system is interpreting and optimizing a query or update. Specify multiple files to compile a large number of files at the same time.
Compilation Modes
The -c/--compiler-mode option is used to specify the desired compilation output type. Supported values include:| Compilation Mode | Output Mode |
|---|---|
algebra | The optimized SPARQL algebra for the query/update as text in SPARQL Set Expression (SSE) format. This can be thought of as the logical plan for the query. |
raw-algebra | The unoptimized SPARQL algebra for the query/update as text in SSE format. This is the unoptimized logical plan for the query. |
rpn | The physical plan for the query/update in binary form. Primarily intended for Cray developer use only. |
rpn-string | The physical plan for the query/update in text. Primarily intended for Cray developer use only. |
all | Produces all of the above. |
Compilation Output
By default, the compilation output is sent to standard output and can be redirected to a file if desired. It is recommended to use the -f or --files option if multiple files need to be processed, or if more than one output type needs to be generated. This will output a file for each input and compilation mode combination in the directory that the cge-cli command is being executed. The output file names are automatically generated, based upon the input file name by replacing the extension with the appropriate extension for the output type:| Output Type | Output File Extension |
|---|---|
algebra | .algebra |
raw-algebra | .rawalgebra |
rpn | .rpn |
rpn-string | .rpnstring |
Examples
The following example will compile the SPARQL command found in the example.rq file into algebraic form and display it to standard output.
$ cge-cli compile -c algebra example.rq
Suppose that there is a file named getTenRows.rq that contains the following SPARQL query:
sparql query: select * {?s ?p ?o} limit 10Now execute the compile command on getTenRows.qr$ cge-cli compile -c all getTenRows.rq --files 0 [main] INFO com.cray.cge.parser.sparql.algebra.OpAsRpnMessage - Started Algebra to RPN message conversion 2 [main] INFO com.cray.cge.parser.sparql.algebra.OpAsRpnMessage - Finished Algebra to RPN message conversion (3 operations)
The above command would create the following files:
- getTenRows.rawalgebra
- getTenRows.rawalgebra
- getTenRows.rpn
- getTenRows.rpnstring