Java Code Examples for com.bigdata.rdf.store.AbstractTripleStore#isQuads()

The following examples show how to use com.bigdata.rdf.store.AbstractTripleStore#isQuads() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BigdataGASEngine.java    From database with GNU General Public License v2.0 5 votes vote down vote up
private final SPOKeyOrder getKeyOrder(final AbstractTripleStore kb,
        final boolean inEdges) {
    final SPOKeyOrder keyOrder;
    if (inEdges) {
        // in-edges: OSP / OCSP : [u] is the Object.
        keyOrder = kb.isQuads() ? SPOKeyOrder.OCSP : SPOKeyOrder.OSP;
    } else {
        // out-edges: SPO / (SPOC|SOPC) : [u] is the Subject.
        keyOrder = kb.isQuads() ? SPOKeyOrder.SPOC : SPOKeyOrder.SPO;
    }
    return keyOrder;
}
 
Example 2
Source File: TestSPOAccessPath.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
 * There are 8 distinct triple pattern bindings for a triple store that
 * select among 3 distinct access paths.
 */
public void test_getAccessPath() {
   
    final AbstractTripleStore store = getStore();

    // constants used for s,p,o,c when bound. 0L used when unbound.
    final IV<?,?> S = factory.newTermId(VTE.URI, 1);
    final IV<?,?> P = factory.newTermId(VTE.URI, 2);
    final IV<?,?> O = factory.newTermId(VTE.URI, 3);
    final IV<?,?> C = factory.newTermId(VTE.URI, 4);
    final IV<?,?> _ = factory.newTermId(VTE.URI, 0);

    try {

        final SPORelation r = store.getSPORelation();

        if (store.isQuads()) {

            /*
             * For a quad store there are 16 distinct binding patterns that
             * select among 6 distinct access paths. there are some quad
             * patterns which could be mapped onto more than one access
             * path, but the code here checks the expected mapping. These
             * mappings are similar to those in YARS2, but are the mappings
             * generated by the "Magic" tuple logic.
             */

            // SPOC
            assertEquals(SPOKeyOrder.SPOC, r.getAccessPath(_, _, _, _).getKeyOrder());
            assertEquals(SPOKeyOrder.SPOC, r.getAccessPath(S, _, _, _).getKeyOrder());
            assertEquals(SPOKeyOrder.SPOC, r.getAccessPath(S, P, _, _).getKeyOrder());
            assertEquals(SPOKeyOrder.SPOC, r.getAccessPath(S, P, O, _).getKeyOrder());
            assertEquals(SPOKeyOrder.SPOC, r.getAccessPath(S, P, O, C).getKeyOrder());
            
            // POCS
            assertEquals(SPOKeyOrder.POCS, r.getAccessPath(_, P, _, _).getKeyOrder());
            assertEquals(SPOKeyOrder.POCS, r.getAccessPath(_, P, O, _).getKeyOrder());
            assertEquals(SPOKeyOrder.POCS, r.getAccessPath(_, P, O, C).getKeyOrder());
            
            // OCSP
            assertEquals(SPOKeyOrder.OCSP, r.getAccessPath(_, _, O, _).getKeyOrder());
            assertEquals(SPOKeyOrder.OCSP, r.getAccessPath(_, _, O, C).getKeyOrder());
            assertEquals(SPOKeyOrder.OCSP, r.getAccessPath(S, _, O, C).getKeyOrder());
            
            // CSPO
            assertEquals(SPOKeyOrder.CSPO, r.getAccessPath(_, _, _, C).getKeyOrder());
            assertEquals(SPOKeyOrder.CSPO, r.getAccessPath(S, _, _, C).getKeyOrder());
            assertEquals(SPOKeyOrder.CSPO, r.getAccessPath(S, P, _, C).getKeyOrder());
            
            // PCSO
            assertEquals(SPOKeyOrder.PCSO, r.getAccessPath(_, P, _, C).getKeyOrder());

            // SOPC
            assertEquals(SPOKeyOrder.SOPC, r.getAccessPath(S, _, O, _).getKeyOrder());

        } else {
            
            assertEquals(SPOKeyOrder.SPO, r.getAccessPath(NULL, NULL, NULL,
                    NULL).getKeyOrder());

            assertEquals(SPOKeyOrder.SPO, r.getAccessPath(S, NULL, NULL,
                    NULL).getKeyOrder());

            assertEquals(SPOKeyOrder.SPO, r.getAccessPath(S, S, NULL, NULL)
                    .getKeyOrder());

            assertEquals(SPOKeyOrder.SPO, r.getAccessPath(S, S, S, NULL)
                    .getKeyOrder());

            assertEquals(SPOKeyOrder.POS, r.getAccessPath(NULL, S, NULL,
                    NULL).getKeyOrder());

            assertEquals(SPOKeyOrder.POS, r.getAccessPath(NULL, S, S, NULL)
                    .getKeyOrder());

            assertEquals(SPOKeyOrder.OSP, r.getAccessPath(NULL, NULL, S,
                    NULL).getKeyOrder());

            assertEquals(SPOKeyOrder.OSP, r.getAccessPath(S, NULL, S, NULL)
                    .getKeyOrder());

        }

    } finally {

        store.__tearDownUnitTest();

    }

}
 
Example 3
Source File: AbstractTestNanoSparqlClient.java    From database with GNU General Public License v2.0 4 votes vote down vote up
protected Server newFixture(final String lnamespace) throws Exception {

	   final IIndexManager indexManager = getIndexManager();
		
		final Properties properties = getProperties();

		// Create the triple store instance.
        createTripleStore(indexManager, lnamespace, properties);
        
        // Open an unisolated connection on that namespace and figure out what
        // mode the namespace is using.
        {
            final BigdataSail sail = new BigdataSail(lnamespace, indexManager);
            try {
                sail.initialize();
                final BigdataSailConnection con = sail.getUnisolatedConnection();
                try {
                    final AbstractTripleStore tripleStore = con.getTripleStore();
        if (tripleStore.isStatementIdentifiers()) {
			testMode = TestMode.sids;
        } else if (tripleStore.isQuads()) {
            testMode = TestMode.quads;
        } else {
            testMode = TestMode.triples;
        }
                } finally {
                    con.close();
                }
            } finally {
                sail.shutDown();
            }
        }

        final Map<String, String> initParams = new LinkedHashMap<String, String>();
        {

            initParams.put(ConfigParams.NAMESPACE, lnamespace);

            initParams.put(ConfigParams.CREATE, "false");
            
        }
        // Start server for that kb instance.
        final Server fixture = NanoSparqlServer.newInstance(0/* port */,
                indexManager, initParams);

        fixture.start();
		
        return fixture;
	}
 
Example 4
Source File: ASTConstructIterator.java    From database with GNU General Public License v2.0 4 votes vote down vote up
private IFilterTest createDistinctFilter(final AbstractTripleStore tripleStore, final ConstructNode construct,
		final GraphPatternGroup<?> whereClause) {
	/*
        * Setup the DISTINCT SPO filter.
        * 
        * Note: CONSTRUCT is sometimes used to materialize all triples for some
        * triple pattern. For that use case, the triples are (of necessity)
        * already DISTINCT. Therefore, when there is a single triple pattern in
        * the WHERE clause and a single template in the CONSTRUCT, we DO NOT
        * impose a DISTINCT filter. This saves resources when the CONSTRUCTed
        * graph is large.
        */

	final boolean distinctQuads = construct.isDistinctQuads() && tripleStore.isQuads() && hasMixedQuadData(templates);
	final boolean nativeDistinct = construct.isNativeDistinct();
	
       if (!constructDistinctSPO) {
           /**
            * DISTINCT SPO filter was disabled by a query hint. The output is
            * NOT guaranteed to be distinct.
            * 
            * @see BLZG-1341.
            */
           // No filter will be imposed.
           return null;
       }
       
	if (nativeDistinct && construct.isDistinctQuads()) {
		flagToCheckNativeDistinctQuadsInvocationForJUnitTesting = true;
	}
	
       /*
        * Test the CONSTRUCT clause and WHERE clause to see if we need to
        * impose a DISTINCT SPO filter.
        */
       final boolean isObviouslyDistinct = isObviouslyDistinct(tripleStore.isQuads(),
               templates, whereClause);

	if (isObviouslyDistinct) {

           // Do not impose a DISTINCT filter.
           
           return null;
           
       }

	if (distinctQuads) {
		
		if (nativeDistinct) {
			return createNativeDistinctQuadsFilter(construct);
		} else {
		    return createHashDistinctQuadsFilter(construct);
		}
		
	} else {

		if (nativeDistinct) {
			return createNativeDistinctTripleFilter(construct);
		} else {
			// JVM Based DISTINCT filter.
			return new DistinctFilter.DistinctFilterImpl(construct);
		}
	}
       
}
 
Example 5
Source File: TestAsynchronousStatementBufferFactory.java    From database with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Test with the "broken.rdf" data set (does not contain valid RDF). This
 * tests that the factory will shutdown correctly if there are processing
 * errors.
 * 
 * @throws Exception
 */
public void test_loadFails() throws Exception {
    
    final String resource = "/com/bigdata/rdf/rio/broken.rdf";

    final AbstractTripleStore store = getStore();
    try {
        
        if(!(store.getIndexManager() instanceof AbstractScaleOutFederation)) {
            
            log.warn("Test requires scale-out index views.");
            
            return;
            
        }

        if (store.isQuads()) {

            log.warn("Quads not supported yet.");
            
            return;
            
        }

        // only do load since we expect an error to be reported.
        final AsynchronousStatementBufferFactory<BigdataStatement, File> factory = doLoad2(
                store, new File(resource), parallel);
        
        assertEquals("errorCount", 1, factory.getDocumentErrorCount());
        
    } finally {
        
        store.__tearDownUnitTest();
        
    }

}
 
Example 6
Source File: ExportKB.java    From database with GNU General Public License v2.0 3 votes vote down vote up
/**
     * 
     * @param conn
     *            The connection.
     * @param kbdir
     *            The directory into which the exported properties and RDF data
     *            will be written.
     * @param format
     *            The {@link RDFFormat} to use when exporting the data.
     * @param includeInferred
     *            When <code>true</code> inferences and axioms will also be
     *            exported. Otherwise just the explicitly given (aka told)
     *            triples/quads will be exported.
     */
    public ExportKB(final BigdataSailConnection conn, final File kbdir,
            final RDFFormat format, final boolean includeInferred) {

        if (conn == null)
            throw new IllegalArgumentException("KB not specified.");
        
        if (kbdir == null)
            throw new IllegalArgumentException(
                    "Output directory not specified.");
        
        if (format == null)
            throw new IllegalArgumentException("RDFFormat not specified.");

        final AbstractTripleStore kb = conn.getTripleStore();
        
        if (kb.isStatementIdentifiers() && !RDFFormat.RDFXML.equals(format))
            throw new IllegalArgumentException(
                    "SIDs mode requires RDF/XML interchange.");

        if (kb.isQuads() && !format.supportsContexts())
            throw new IllegalArgumentException(
                    "RDFFormat does not support quads: " + format);

        this.conn = conn;
        
//        this.kb = kb;

        this.namespace = kb.getNamespace();
        
        this.kbdir = kbdir;
        
        this.format = format;

        this.includeInferred = includeInferred;
        
    }
 
Example 7
Source File: VoID.java    From database with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Return an array of the distinct predicates in the KB ordered by their
 * descending frequency of use. The {@link IV}s in the returned array will
 * have been resolved to the corresponding {@link BigdataURI}s which can be
 * accessed using {@link IV#getValue()}.
 * 
 * @param kb
 *            The KB instance.
 */
protected static IVCount[] predicateUsage(final AbstractTripleStore kb) {

    final SPORelation r = kb.getSPORelation();
    
    if (r.oneAccessPath) {

        // The necessary index (POS or POCS) does not exist.
        throw new UnsupportedOperationException();

    }

    final boolean quads = kb.isQuads();

    // the index to use for distinct predicate scan.
    final SPOKeyOrder keyOrder = quads ? SPOKeyOrder.POCS : SPOKeyOrder.POS;

    // visit distinct term identifiers for predicate position on that index.
    @SuppressWarnings("rawtypes")
    final IChunkedIterator<IV> itr = r.distinctTermScan(keyOrder);

    // resolve term identifiers to terms efficiently during iteration.
    final BigdataValueIterator itr2 = new BigdataValueIteratorImpl(
            kb/* resolveTerms */, itr);

    try {

        final Set<IV<?,?>> ivs = new LinkedHashSet<IV<?,?>>();

        final Map<IV<?, ?>, IVCount> counts = new LinkedHashMap<IV<?, ?>, IVCount>();

        while (itr2.hasNext()) {

            final BigdataValue term = itr2.next();

            final IV<?,?> iv = term.getIV();

            final long n = r.getAccessPath(null, iv, null, null)
                    .rangeCount(false/* exact */);

            ivs.add(iv);
            
            counts.put(iv, new IVCount(iv, n));

        }

        // Batch resolve IVs to Values
        final Map<IV<?, ?>, BigdataValue> x = kb.getLexiconRelation()
                .getTerms(ivs);

        for (Map.Entry<IV<?, ?>, BigdataValue> e : x.entrySet()) {

            final IVCount count = counts.get(e.getKey());

            count.setValue(e.getValue());

        }

        final IVCount[] a = counts.values().toArray(
                new IVCount[counts.size()]);

        // Order by descending count.
        Arrays.sort(a);

        return a;

    } finally {

        itr2.close();

    }

}
 
Example 8
Source File: VoID.java    From database with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Return the predicate partition statistics for the named graph.
 * 
 * @param kb
 *            The KB instance.
 * @param civ
 *            The {@link IV} of a named graph (required).
 * 
 * @return The predicate partition statistics for that named graph. Only
 *         predicate partitions which are non-empty are returned.
 */
protected static IVCount[] predicateUsage(final AbstractTripleStore kb,
        final IV<?, ?> civ, final IVCount[] predicatePartitionCounts) {
    
    final SPORelation r = kb.getSPORelation();

    final boolean quads = kb.isQuads();
    
    if (!quads) {
        
        // Named graph only valid in quads mode.
        throw new IllegalArgumentException();
    
    }

    // The non-zero counts.
    final List<IVCount> counts = new LinkedList<IVCount>();

    // Check the known non-empty predicate partitions.
    for(IVCount in : predicatePartitionCounts){

        final long n = r.getAccessPath(null, in.iv, null, civ).rangeCount(
                false/* exact */);

        if (n == 0)
            continue;

        final IVCount out = new IVCount(in.iv, n);

        out.setValue(in.getValue());
        
        counts.add(out);

    }
    

    final IVCount[] a = counts.toArray(new IVCount[counts.size()]);

    // Order by descending count.
    Arrays.sort(a);

    return a;

}
 
Example 9
Source File: VoID.java    From database with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Return the class partition statistics for the named graph.
 * 
 * @param kb
 *            The KB instance.
 * @param civ
 *            The {@link IV} of a named graph (required).
 * 
 * @return The class partition statistics for that named graph. Only class
 *         partitions which are non-empty are returned.
 */
protected static IVCount[] classUsage(final AbstractTripleStore kb,
        final IV<?, ?> civ, final IVCount[] classPartitionCounts) {

    final SPORelation r = kb.getSPORelation();

    final boolean quads = kb.isQuads();

    if (!quads) {

        // Named graph only valid in quads mode.
        throw new IllegalArgumentException();

    }

    // Resolve IV for rdf:type
    final BigdataURI rdfType = kb.getValueFactory().asValue(RDF.TYPE);

    kb.getLexiconRelation().addTerms(new BigdataValue[] { rdfType },
            1/* numTerms */, true/* readOnly */);

    if (rdfType.getIV() == null) {

        // No rdf:type assertions since rdf:type is unknown term.
        return new IVCount[0];

    }

    // The non-zero counts.
    final List<IVCount> counts = new LinkedList<IVCount>();

    // Check the known non-empty predicate partitions.
    for (IVCount in : classPartitionCounts) {

        final long n = r.getAccessPath(null, rdfType.getIV()/* p */,
                in.iv/* o */, civ).rangeCount(false/* exact */);

        if (n == 0)
            continue;
        
        final IVCount out = new IVCount(in.iv, n);

        out.setValue(in.getValue());

        counts.add(out);

    }

    final IVCount[] a = counts.toArray(new IVCount[counts.size()]);

    // Order by descending count.
    Arrays.sort(a);

    return a;

}