From: <mrp...@us...> - 2014-03-19 15:13:18
|
Revision: 7998 http://sourceforge.net/p/bigdata/code/7998 Author: mrpersonick Date: 2014-03-19 15:13:12 +0000 (Wed, 19 Mar 2014) Log Message: ----------- changed Lexicon's SID materialization strategy Modified Paths: -------------- branches/RDR/bigdata-rdf/src/java/com/bigdata/bop/rdf/join/ChunkedMaterializationOp.java branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/lexicon/LexiconRelation.java branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/store/BigdataStatementIteratorImpl.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-19 14:32:40 UTC (rev 7997) +++ branches/RDR/bigdata-rdf/src/java/com/bigdata/bop/rdf/join/ChunkedMaterializationOp.java 2014-03-19 15:13:12 UTC (rev 7998) @@ -398,56 +398,56 @@ } - /** - * 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); - - } +// /** +// * 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/lexicon/LexiconRelation.java =================================================================== --- branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/lexicon/LexiconRelation.java 2014-03-19 14:32:40 UTC (rev 7997) +++ branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/lexicon/LexiconRelation.java 2014-03-19 15:13:12 UTC (rev 7998) @@ -36,6 +36,7 @@ import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; +import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -104,6 +105,7 @@ import com.bigdata.rdf.model.BigdataValueSerializer; import com.bigdata.rdf.rio.StatementBuffer; import com.bigdata.rdf.spo.ISPO; +import com.bigdata.rdf.spo.SPO; import com.bigdata.rdf.store.AbstractTripleStore; import com.bigdata.rdf.vocab.NoVocabulary; import com.bigdata.rdf.vocab.Vocabulary; @@ -2471,7 +2473,23 @@ // BlobIVs which must be resolved against an index. final Collection<BlobIV<?>> blobIVs = new LinkedList<BlobIV<?>>(); + final Set<IV<?, ?>> unrequestedSidTerms = new LinkedHashSet<IV<?, ?>>(); + /* + * We need to materialize terms inside of SIDs so that the SIDs + * can be materialized properly. + */ + for (IV<?,?> iv : ivs) { + + if (iv instanceof SidIV) { + + handleSid((SidIV) iv, ivs, unrequestedSidTerms); + + } + + } + + /* * Filter out the inline values first and those that have already * been materialized and cached. */ @@ -2602,8 +2620,7 @@ } /* - * Defer SidIVs until the end so that their ISPO components can be - * materialized first. + * SidIVs require special handling. */ for (IV<?,?> iv : ivs) { @@ -2613,10 +2630,23 @@ // translate it into a value directly ret.put(iv, iv.asValue(this)); + } } + /* + * Remove any IVs that were not explicitly requested in the method + * call but that got pulled into materialization because of a SID. + */ + for (IV<?,?> iv : unrequestedSidTerms) { + + ivs.remove(iv); + + ret.remove(iv); + + } + final long elapsed = System.currentTimeMillis() - begin; if (log.isInfoEnabled()) @@ -2629,6 +2659,58 @@ } /** + * Add the terms inside a SID to the collection of IVs to materialize if + * they are not already there. + */ + @SuppressWarnings("rawtypes") + final private void handleSid(final SidIV sid, + final Collection<IV<?, ?>> ivs, + final Set<IV<?, ?>> unrequested) { + + final ISPO spo = sid.getInlineValue(); + + handleTerm(spo.s(), ivs, unrequested); + + handleTerm(spo.p(), ivs, unrequested); + + handleTerm(spo.o(), ivs, unrequested); + + if (spo.c() != null) { + + handleTerm(spo.c(), ivs, unrequested); + + } + + } + + /** + * Add the terms inside a SID to the collection of IVs to materialize if + * they are not already there. + */ + @SuppressWarnings("rawtypes") + final private void handleTerm(final IV<?, ?> iv, + final Collection<IV<?, ?>> ivs, + final Set<IV<?, ?>> unrequested) { + + if (iv instanceof SidIV) { + + handleSid((SidIV) iv, ivs, unrequested); + + } else { + + if (!ivs.contains(iv)) { + + ivs.add(iv); + + unrequested.add(iv); + + } + + } + + } + + /** * We need to cache the BigdataValues on the IV components within the * SidIV so that the SidIV can materialize itself into a BigdataBNode * properly. Modified: branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/store/BigdataStatementIteratorImpl.java =================================================================== --- branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/store/BigdataStatementIteratorImpl.java 2014-03-19 14:32:40 UTC (rev 7997) +++ branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/store/BigdataStatementIteratorImpl.java 2014-03-19 15:13:12 UTC (rev 7998) @@ -243,12 +243,12 @@ private void handleIV(final IV<?, ?> iv, final Collection<IV<?, ?>> ids) { - if (iv instanceof SidIV) { +// if (iv instanceof SidIV) { +// +// handleSid((SidIV<?>) iv, ids); +// +// } - handleSid((SidIV<?>) iv, ids); - - } - if (bnodes == null || !bnodes.containsKey(iv)) { ids.add(iv); @@ -257,30 +257,30 @@ } - /** - * Sids need to be handled specially because their individual ISPO - * components might need materialization as well. - */ - 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); - - } +// /** +// * Sids need to be handled specially because their individual ISPO +// * components might need materialization as well. +// */ +// 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 a term identifier to the {@link BigdataValue}, checking the This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |