From: <mrp...@us...> - 2014-03-12 17:47:39
|
Revision: 7942 http://sourceforge.net/p/bigdata/code/7942 Author: mrpersonick Date: 2014-03-12 17:47:35 +0000 (Wed, 12 Mar 2014) Log Message: ----------- Added support for resolving the RDR statement attached to a BigdataBNode representing a statement identifier. This is a precursor to being able to write RDF and SPARQL results in the RDR syntax. Ticket 849 Modified Paths: -------------- branches/RDR/bigdata-rdf/src/java/com/bigdata/bop/rdf/join/ChunkedMaterializationOp.java branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/internal/impl/AbstractNonInlineIV.java branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/internal/impl/bnode/SidIV.java branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/lexicon/LexiconRelation.java branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/store/BigdataBindingSetResolverator.java Modified: branches/RDR/bigdata-rdf/src/java/com/bigdata/bop/rdf/join/ChunkedMaterializationOp.java =================================================================== --- branches/RDR/bigdata-rdf/src/java/com/bigdata/bop/rdf/join/ChunkedMaterializationOp.java 2014-03-12 14:28:25 UTC (rev 7941) +++ branches/RDR/bigdata-rdf/src/java/com/bigdata/bop/rdf/join/ChunkedMaterializationOp.java 2014-03-12 17:47:35 UTC (rev 7942) @@ -48,8 +48,10 @@ import com.bigdata.bop.engine.BOpStats; import com.bigdata.rdf.internal.IV; import com.bigdata.rdf.internal.IVCache; +import com.bigdata.rdf.internal.impl.bnode.SidIV; import com.bigdata.rdf.lexicon.LexiconRelation; import com.bigdata.rdf.model.BigdataValue; +import com.bigdata.rdf.spo.ISPO; import com.bigdata.rdf.store.BigdataBindingSetResolverator; import com.bigdata.relation.accesspath.IBlockingBuffer; @@ -337,6 +339,8 @@ } +// handleIV(iv, ids, materializeInlineIVs); + } } else { @@ -365,6 +369,8 @@ } +// handleIV(iv, ids, materializeInlineIVs); + } } @@ -391,7 +397,57 @@ } } + + /** + * Either add the IV to the list if it needs materialization, or else + * delegate to {@link #handleSid(SidIV, Collection, boolean)} if it's a + * SidIV. + */ + static private void handleIV(final IV<?, ?> iv, + final Collection<IV<?, ?>> ids, + final boolean materializeInlineIVs) { + + if (iv instanceof SidIV) { + + handleSid((SidIV<?>) iv, ids, materializeInlineIVs); + + } else if (iv.needsMaterialization() || materializeInlineIVs) { + + ids.add(iv); + + } + + } + + /** + * Sids need to be handled specially because their individual ISPO + * components might need materialization. + */ + static private void handleSid(final SidIV<?> sid, + final Collection<IV<?, ?>> ids, + final boolean materializeInlineIVs) { + + final ISPO spo = sid.getInlineValue(); + + System.err.println("handling a sid"); + System.err.println("adding s: " + spo.s()); + System.err.println("adding p: " + spo.p()); + System.err.println("adding o: " + spo.o()); + + handleIV(spo.s(), ids, materializeInlineIVs); + + handleIV(spo.p(), ids, materializeInlineIVs); + + handleIV(spo.o(), ids, materializeInlineIVs); + + if (spo.c() != null) { + + handleIV(spo.c(), ids, materializeInlineIVs); + + } + } + /** * Resolve the term identifiers in the {@link IBindingSet} using the map * populated when we fetched the current chunk. Modified: branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/internal/impl/AbstractNonInlineIV.java =================================================================== --- branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/internal/impl/AbstractNonInlineIV.java 2014-03-12 14:28:25 UTC (rev 7941) +++ branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/internal/impl/AbstractNonInlineIV.java 2014-03-12 17:47:35 UTC (rev 7942) @@ -87,7 +87,8 @@ */ final public V asValue(final LexiconRelation lex) { - throw new UnsupportedOperationException(); + return getValue(); +// throw new UnsupportedOperationException(); } Modified: branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/internal/impl/bnode/SidIV.java =================================================================== --- branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/internal/impl/bnode/SidIV.java 2014-03-12 14:28:25 UTC (rev 7941) +++ branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/internal/impl/bnode/SidIV.java 2014-03-12 17:47:35 UTC (rev 7942) @@ -46,6 +46,9 @@ import com.bigdata.rdf.internal.impl.AbstractInlineIV; import com.bigdata.rdf.lexicon.LexiconRelation; import com.bigdata.rdf.model.BigdataBNode; +import com.bigdata.rdf.model.BigdataResource; +import com.bigdata.rdf.model.BigdataURI; +import com.bigdata.rdf.model.BigdataValue; import com.bigdata.rdf.model.BigdataValueFactory; import com.bigdata.rdf.model.StatementEnum; import com.bigdata.rdf.spo.ISPO; @@ -169,6 +172,15 @@ bnode = (V) lex.getValueFactory().createBNode(getID()); bnode.setIV(this); bnode.setStatementIdentifier(true); + + final BigdataResource c = spo.c() != null ? + (BigdataResource) spo.c().asValue(lex) : null; + + bnode.setStatement(lex.getValueFactory().createStatement( + (BigdataResource) spo.s().asValue(lex), + (BigdataURI) spo.p().asValue(lex), + (BigdataValue) spo.o().asValue(lex), + c)); } return bnode; } Modified: branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/lexicon/LexiconRelation.java =================================================================== --- branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/lexicon/LexiconRelation.java 2014-03-12 14:28:25 UTC (rev 7941) +++ branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/lexicon/LexiconRelation.java 2014-03-12 17:47:35 UTC (rev 7942) @@ -93,6 +93,7 @@ import com.bigdata.rdf.internal.VTE; import com.bigdata.rdf.internal.impl.BlobIV; import com.bigdata.rdf.internal.impl.TermId; +import com.bigdata.rdf.internal.impl.bnode.SidIV; import com.bigdata.rdf.internal.impl.extensions.XSDStringExtension; import com.bigdata.rdf.model.BigdataBNode; import com.bigdata.rdf.model.BigdataLiteral; @@ -2491,6 +2492,11 @@ // already materialized ret.put(iv, iv.getValue()); + } else if (iv instanceof SidIV) { + + // defer until the end + continue; + } else if (iv.isInline()) { // translate it into a value directly @@ -2532,61 +2538,83 @@ } - if (numNotFound == 0) { +// if (numNotFound == 0) { +// +// // Done. +// return ret; +// +// } - // Done. - return ret; + if (numNotFound > 0) { + // go to the indices + + /* + * Setup and run task(s) to resolve IV(s). + */ + + final ExecutorService service = getExecutorService(); + + final List<Callable<Void>> tasks = new LinkedList<Callable<Void>>(); + + if (!termIVs.isEmpty()) { + + tasks.add(new BatchResolveTermIVsTask(service, getId2TermIndex(), + termIVs, ret, termCache, valueFactory, termsChunksSize)); + + } + + if (!blobIVs.isEmpty()) { + + tasks.add(new BatchResolveBlobIVsTask(service, getBlobsIndex(), + blobIVs, ret, termCache, valueFactory, blobsChunkSize)); + + } + + if (log.isInfoEnabled()) + log.info("nterms=" + n + ", numNotFound=" + numNotFound + + ", cacheSize=" + termCache.size()); + + try { + + if (tasks.size() == 1) { + + tasks.get(0).call(); + + } else { + + // Co-thread tasks. + final List<Future<Void>> futures = getExecutorService() + .invokeAll(tasks); + + // Verify no errors. + for (Future<Void> f : futures) + f.get(); + + } + + } catch (Exception ex) { + + throw new RuntimeException(ex); + + } + } - + /* - * Setup and run task(s) to resolve IV(s). + * Defer SidIVs until the end so that their ISPO components can be + * materialized first. */ + for (IV<?,?> iv : ivs) { + + if (iv instanceof SidIV) { - final ExecutorService service = getExecutorService(); - - final List<Callable<Void>> tasks = new LinkedList<Callable<Void>>(); - - if (!termIVs.isEmpty()) { - - tasks.add(new BatchResolveTermIVsTask(service, getId2TermIndex(), - termIVs, ret, termCache, valueFactory, termsChunksSize)); - - } - - if (!blobIVs.isEmpty()) { - - tasks.add(new BatchResolveBlobIVsTask(service, getBlobsIndex(), - blobIVs, ret, termCache, valueFactory, blobsChunkSize)); - - } - - if (log.isInfoEnabled()) - log.info("nterms=" + n + ", numNotFound=" + numNotFound - + ", cacheSize=" + termCache.size()); - - try { - - if (tasks.size() == 1) { - - tasks.get(0).call(); - - } else { - - // Co-thread tasks. - final List<Future<Void>> futures = getExecutorService() - .invokeAll(tasks); - - // Verify no errors. - for (Future<Void> f : futures) - f.get(); + cacheTerms((SidIV<?>) iv, ret); + + // translate it into a value directly + ret.put(iv, iv.asValue(this)); + } - } - - } catch (Exception ex) { - - throw new RuntimeException(ex); - } final long elapsed = System.currentTimeMillis() - begin; @@ -2601,6 +2629,52 @@ } /** + * We need to cache the BigdataValues on the IV components within the + * SidIV so that the SidIV can materialize itself into a BigdataBNode + * properly. + */ + @SuppressWarnings("rawtypes") + final private void cacheTerms(final SidIV sid, + final Map<IV<?, ?>, BigdataValue> terms) { + + final ISPO spo = sid.getInlineValue(); + + cacheTerm(spo.s(), terms); + + cacheTerm(spo.p(), terms); + + cacheTerm(spo.o(), terms); + + if (spo.c() != null) { + + cacheTerm(spo.c(), terms); + + } + + } + + /** + * We need to cache the BigdataValues on the IV components within the + * SidIV so that the SidIV can materialize itself into a BigdataBNode + * properly. + */ + @SuppressWarnings({ "unchecked", "rawtypes" }) + final private void cacheTerm(final IV iv, + final Map<IV<?, ?>, BigdataValue> terms) { + + if (iv instanceof SidIV) { + + cacheTerms((SidIV<?>) iv, terms); + + } else { + + iv.setValue(terms.get(iv)); + + } + + } + + /** * Recently resolved term identifiers are cached to improve performance when * externalizing statements. * Modified: branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/store/BigdataBindingSetResolverator.java =================================================================== --- branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/store/BigdataBindingSetResolverator.java 2014-03-12 14:28:25 UTC (rev 7941) +++ branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/store/BigdataBindingSetResolverator.java 2014-03-12 17:47:35 UTC (rev 7942) @@ -21,8 +21,10 @@ import com.bigdata.rdf.internal.IV; import com.bigdata.rdf.internal.impl.BlobIV; import com.bigdata.rdf.internal.impl.TermId; +import com.bigdata.rdf.internal.impl.bnode.SidIV; import com.bigdata.rdf.lexicon.LexiconRelation; import com.bigdata.rdf.model.BigdataValue; +import com.bigdata.rdf.spo.ISPO; import com.bigdata.relation.accesspath.BlockingBuffer; import com.bigdata.striterator.AbstractChunkedResolverator; import com.bigdata.striterator.IChunkedOrderedIterator; @@ -218,10 +220,13 @@ } - if (iv.hasValue()) - continue; - ids.add(iv); + handleIV(iv, ids); + +// if (iv.hasValue()) +// continue; +// +// ids.add(iv); } @@ -244,11 +249,13 @@ } - if (iv.hasValue()) - continue; - - ids.add(iv); - +// if (iv.hasValue()) +// continue; +// +// ids.add(iv); + + handleIV(iv, ids); + } } @@ -302,7 +309,50 @@ } } + + /** + * Add the IV to the list of terms to materialize, and also + * delegate to {@link #handleSid(SidIV, Collection, boolean)} if it's a + * SidIV. + */ + static private void handleIV(final IV<?, ?> iv, + final Collection<IV<?, ?>> ids) { + + if (iv instanceof SidIV) { + + handleSid((SidIV<?>) iv, ids); + + } + + ids.add(iv); + + } + + /** + * Sids need to be handled specially because their individual ISPO + * components might need materialization as well. + */ + static private void handleSid(final SidIV<?> sid, + final Collection<IV<?, ?>> ids) { + + final ISPO spo = sid.getInlineValue(); + + handleIV(spo.s(), ids); + + handleIV(spo.p(), ids); + + handleIV(spo.o(), ids); + + if (spo.c() != null) { + + handleIV(spo.c(), ids); + + } + } + + + /** * Resolve the term identifiers in the {@link IBindingSet} using the map * populated when we fetched the current chunk and return the This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |