Defining extension functions

The SPARQL query language has a specified way for the introduction of custom extension functions. An extension function for a function with the name can be defined in SPARQL.ex like this:

defmodule ExampleFunction do
  use SPARQL.ExtensionFunction, name: ""

  def call(distinct, arguments, _, execution) do
    # your implementation

The name of the module is arbitrary and has no further meaning. The first argument distinct is a boolean flag telling, if the function was called with the DISTINCT keyword, which is syntactically allowed in custom aggregate function calls only. The arguments argument is the list of already evaluated RDF terms with which the extension function was called in the SPARQL query. The ignored third argument contains the currently evaluated solution and some other internal information and shouldn't be relied upon. Since the arguments are already evaluated against the current solution, this shouldn't be necessary anyway. The execution argument is a map with some global query execution context information. In particular:

  • base: the base IRI
  • time: the query execution time
  • bnode_generator: the name of the RDF.BlankNode.Generator (see RDF.ex documentation) used to generate unique blank nodes consistently