FROM Clause
The optional FROM clause defines the data sets or graphs to query. You can include any number of FROM or FROM NAMED statements.
By default, if a query omits FROM clauses, the scope of the query is limited to the default graph (DEFAULTSET). Triples in named graphs will not be included in the scope of the query. The default behavior is controlled by the sparql_spec_default_graph configuration setting. To configure AnzoGraph to conform to the SPARQL specification and include the default graph and all named graphs in the scope of a query that omits the FROM clause, change the value of sparql_spec_default_graph to true. For more information, see Changing the Default FROM Clause Behavior.
Syntax
FROM [ NAMED ] graph_uri
AnzoGraph also supports FROM EXTERNAL syntax for running queries against external files. See Analyzing Load Files Without Loading Data for more information.
Use FROM <graph_uri> when you want to query for the same triple pattern match against one or more graphs. Use FROM NAMED <graph_uri> when you want to query multiple graphs and specify which patterns to match against which graph by naming the graphs in the WHERE clause.
For example, the statement FROM <graphA> means that AnzoGraph takes all of the triples that belong to graphA and adds them to the default graph (called DEFAULTSET).
For the following FROM clause:
FROM <graphA>
FROM <graphB>
AnzoGraph takes all of the triples associated with graphA and graphB and adds them to the default graph. The triple patterns in the query's WHERE clause are matched against all of the graphA and graphB triples in the default graph. For example, the following query looks for the ?s ?p ?o triple pattern match in graphA and graphB:
SELECT *
FROM <graphA>
FROM <graphB>
WHERE {
?s ?p ?o .
}
The statement FROM NAMED <graphA> means that the graphA triples are not added to the default graph. Patterns in the WHERE clause are only matched against graphA when a graph pattern is specified (such as GRAPH <graphA> { triple_patterns } or GRAPH ?g { triple_patterns}). Triple patterns without a GRAPH clause are still matched against the default graph.
For example, the following query only finds matches in graphA because graphB is not named in the WHERE clause:
SELECT * FROM <graphA> FROM NAMED <graphB> WHERE { ?s ?p ?o . }
To match the ?s ?p ?o triple pattern against graphA and graphB, the query needs to name graphB using a GRAPH clause. For example:
SELECT * FROM <graphA> FROM NAMED <graphB> WHERE { ?s ?p ?o . { GRAPH <graphB> { ?s ?p ?o . } } }
When using FROM NAMED, triple patterns that are outside of a GRAPH clause are matched against the default graph. Triple patterns that are included in a GRAPH clause are matched against that named graph. You can also use the GRAPH ?variable construct (such as GRAPH ?g) to allow a pattern to match against one of the named graphs in the query. The URI of the matching graph is bound to the variable.
Examples
The FROM clause in the following example query includes two FROM NAMED statements. The WHERE clause includes two graph patterns to find the events in the Tickit graph and the movies in the Movies graph.
SELECT (COUNT(?eventid) as ?tickit_events) (COUNT(?movieid) as ?num_movies) FROM NAMED <tickit> FROM NAMED <movies> WHERE { { GRAPH <tickit> { ?event <eventid> ?events . } } { GRAPH <movies> { ?film <movieid> ?movieid . } } }