Search in sources :

Example 86 with Quad

use of org.apache.jena.sparql.core.Quad in project jena by apache.

the class ExQuadFilter method setup.

/** Example setup - in-memory dataset with two graphs, one triple in each */
private static Dataset setup() {
    Dataset ds = TDBFactory.createDataset();
    DatasetGraph dsg = ds.asDatasetGraph();
    Quad q1 = SSE.parseQuad("(<http://example/g1> <http://example/s> <http://example/p> <http://example/o1>)");
    Quad q2 = SSE.parseQuad("(<http://example/g2> <http://example/s> <http://example/p> <http://example/o2>)");
    dsg.add(q1);
    dsg.add(q2);
    return ds;
}
Also used : Quad(org.apache.jena.sparql.core.Quad) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Example 87 with Quad

use of org.apache.jena.sparql.core.Quad in project jena by apache.

the class IsoMatcher method tuplesQuads.

private static List<Tuple<Node>> tuplesQuads(Iterator<Quad> iter) {
    List<Tuple<Node>> tuples = new ArrayList<>();
    for (; iter.hasNext(); ) {
        Quad q = iter.next();
        Tuple<Node> tuple = tuple(q.getGraph(), q.getSubject(), q.getPredicate(), q.getObject());
        tuples.add(tuple);
    }
    return tuples;
}
Also used : Quad(org.apache.jena.sparql.core.Quad) Node(org.apache.jena.graph.Node) ArrayList(java.util.ArrayList) Tuple(org.apache.jena.atlas.lib.tuple.Tuple)

Example 88 with Quad

use of org.apache.jena.sparql.core.Quad in project jena by apache.

the class AbstractJenaConnectionTests method connection_statement_query_select_04.

/**
     * Runs a SELECT query on a non-empty database and checks it returns
     * non-empty results. Uses high compatibility level to ensure that column
     * type detection doesn't consume the first row.
     * 
     * @throws SQLException
     */
@Test
public void connection_statement_query_select_04() throws SQLException {
    // Prepare a dataset
    Dataset ds = DatasetFactory.createTxnMem();
    ds.asDatasetGraph().add(new Quad(NodeFactory.createURI("http://example/graph"), NodeFactory.createURI("http://example/subject"), NodeFactory.createURI("http://example/predicate"), NodeFactory.createURI("http://example/object")));
    // Work with the connection
    JenaConnection conn = this.getConnection(ds);
    conn.setJdbcCompatibilityLevel(JdbcCompatibility.HIGH);
    Statement stmt = conn.createStatement();
    ResultSet rset = stmt.executeQuery("SELECT * WHERE { GRAPH ?g { ?s ?p ?o } }");
    Assert.assertNotNull(rset);
    Assert.assertFalse(rset.isClosed());
    Assert.assertTrue(rset.isBeforeFirst());
    // Check result set metadata
    checkSelectMetadata(rset, 4);
    // Should have a row
    Assert.assertTrue(rset.next());
    Assert.assertTrue(rset.isFirst());
    Assert.assertEquals(1, rset.getRow());
    // Should be no further rows
    Assert.assertFalse(rset.next());
    Assert.assertTrue(rset.isAfterLast());
    Assert.assertFalse(rset.isClosed());
    // Close things
    rset.close();
    Assert.assertTrue(rset.isClosed());
    stmt.close();
    Assert.assertTrue(stmt.isClosed());
    conn.close();
    Assert.assertTrue(conn.isClosed());
}
Also used : Quad(org.apache.jena.sparql.core.Quad) ResultSet(java.sql.ResultSet) Test(org.junit.Test)

Example 89 with Quad

use of org.apache.jena.sparql.core.Quad in project jena by apache.

the class AbstractJenaConnectionTests method connection_statement_query_select_02.

/**
     * Runs a SELECT query on a non-empty database and checks it returns
     * non-empty results
     * 
     * @throws SQLException
     */
@Test
public void connection_statement_query_select_02() throws SQLException {
    // Prepare a dataset
    Dataset ds = DatasetFactory.createTxnMem();
    ds.asDatasetGraph().add(new Quad(NodeFactory.createURI("http://example/graph"), NodeFactory.createURI("http://example/subject"), NodeFactory.createURI("http://example/predicate"), NodeFactory.createURI("http://example/object")));
    // Work with the connection
    JenaConnection conn = this.getConnection(ds);
    Statement stmt = conn.createStatement();
    ResultSet rset = stmt.executeQuery("SELECT * WHERE { GRAPH ?g { ?s ?p ?o } }");
    Assert.assertNotNull(rset);
    Assert.assertFalse(rset.isClosed());
    Assert.assertTrue(rset.isBeforeFirst());
    // Check result set metadata
    checkSelectMetadata(rset, 4);
    // Should have a row
    Assert.assertTrue(rset.next());
    Assert.assertTrue(rset.isFirst());
    Assert.assertEquals(1, rset.getRow());
    // Should be no further rows
    Assert.assertFalse(rset.next());
    Assert.assertTrue(rset.isAfterLast());
    Assert.assertFalse(rset.isClosed());
    // Close things
    rset.close();
    Assert.assertTrue(rset.isClosed());
    stmt.close();
    Assert.assertTrue(stmt.isClosed());
    conn.close();
    Assert.assertTrue(conn.isClosed());
}
Also used : Quad(org.apache.jena.sparql.core.Quad) ResultSet(java.sql.ResultSet) Test(org.junit.Test)

Example 90 with Quad

use of org.apache.jena.sparql.core.Quad in project jena by apache.

the class PatternTable method process.

// Start a table from the i'th quad 
// Must remove the quad at index i if return is not null.
public SqlStage process(int i, QuadBlock quadBlock) {
    QuadBlock tableQuads = new QuadBlock();
    Set<Node> predicates = new HashSet<Node>(cols.keySet());
    // Use the fact that i'th quad is the trigger  
    Quad trigger = quadBlock.get(i);
    Node subject = trigger.getSubject();
    Node graph = trigger.getGraph();
    for (Node p : predicates) {
        int idx = quadBlock.findFirst(i, graph, subject, p, null);
        if (idx < 0)
            // Liberal - any predicates
            continue;
        Quad q = quadBlock.get(idx);
        tableQuads.add(q);
    }
    quadBlock.removeAll(tableQuads);
    SqlStagePatternTable stage = new SqlStagePatternTable(graph, subject, tableQuads);
    return stage;
}
Also used : Quad(org.apache.jena.sparql.core.Quad) SqlNode(org.apache.jena.sdb.core.sqlnode.SqlNode) Node(org.apache.jena.graph.Node) HashSet(java.util.HashSet)

Aggregations

Quad (org.apache.jena.sparql.core.Quad)161 Test (org.junit.Test)91 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)49 Node (org.apache.jena.graph.Node)36 BaseTest (org.apache.jena.atlas.junit.BaseTest)32 Triple (org.apache.jena.graph.Triple)25 UpdateBuilder (org.apache.jena.arq.querybuilder.UpdateBuilder)14 Update (org.apache.jena.update.Update)14 QuadWritable (org.apache.jena.hadoop.rdf.types.QuadWritable)12 ResultSet (java.sql.ResultSet)8 ArrayList (java.util.ArrayList)8 TripleWritable (org.apache.jena.hadoop.rdf.types.TripleWritable)7 Var (org.apache.jena.sparql.core.Var)7 LongWritable (org.apache.hadoop.io.LongWritable)6 UpdateDataDelete (org.apache.jena.sparql.modify.request.UpdateDataDelete)6 UpdateDataInsert (org.apache.jena.sparql.modify.request.UpdateDataInsert)6 Element (org.apache.jena.sparql.syntax.Element)6 Graph (org.apache.jena.graph.Graph)5 BasicPattern (org.apache.jena.sparql.core.BasicPattern)4 IOException (java.io.IOException)3