From: <mrp...@us...> - 2010-07-20 17:06:30
|
Revision: 3246 http://bigdata.svn.sourceforge.net/bigdata/?rev=3246&view=rev Author: mrpersonick Date: 2010-07-20 17:06:24 +0000 (Tue, 20 Jul 2010) Log Message: ----------- move to bigdata-rdf module from bigdata module Added Paths: ----------- branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/relation/rule/BindingSetSortKeyBuilder.java Removed Paths: ------------- branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/relation/rule/BindingSetSortKeyBuilder.java Deleted: branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/relation/rule/BindingSetSortKeyBuilder.java =================================================================== --- branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/relation/rule/BindingSetSortKeyBuilder.java 2010-07-20 17:05:39 UTC (rev 3245) +++ branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/relation/rule/BindingSetSortKeyBuilder.java 2010-07-20 17:06:24 UTC (rev 3246) @@ -1,103 +0,0 @@ -/* - -Copyright (C) SYSTAP, LLC 2006-2008. All rights reserved. - -Contact: - SYSTAP, LLC - 4501 Tower Road - Greensboro, NC 27410 - lic...@bi... - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; version 2 of the License. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -*/ -/* - * Created on Sep 15, 2008 - */ - -package com.bigdata.relation.rule; - -import com.bigdata.btree.keys.IKeyBuilder; -import com.bigdata.btree.keys.ISortKeyBuilder; -import com.bigdata.rdf.internal.IV; - -/** - * Builds unsigned byte[] sort keys from {@link IBindingSet}s. - * - * @author <a href="mailto:tho...@us...">Bryan Thompson</a> - * @version $Id$ - */ -public class BindingSetSortKeyBuilder implements ISortKeyBuilder<IBindingSet> { - - private final IKeyBuilder keyBuilder; - private final IVariable[] vars; - - /** - * - * @param keyBuilder - * Used to generate the unsigned byte[] key for each bound - * variable. In particular, the configuration for the - * {@link IKeyBuilder} governs how Unicode fields are handled. - * @param vars - * An array of {@link IVariable}s, all of which MUST be bound. - */ - public BindingSetSortKeyBuilder(final IKeyBuilder keyBuilder, - final IVariable[] vars) { - - if (keyBuilder == null) - throw new IllegalArgumentException(); - - if (vars == null || vars.length == 0) - throw new IllegalArgumentException(); - - this.keyBuilder = keyBuilder; - - this.vars = vars; - - } - - public byte[] getSortKey(final IBindingSet bindingSet) { - - keyBuilder.reset(); - - for (int i = 0; i < vars.length; i++) { - - final IVariable var = vars[i]; - - Object val = bindingSet.get(var); - if(val==null) { - val=Long.valueOf(0); - }else if(val instanceof Constant) { - val=((Constant)val).get(); - } - - if (val instanceof IV) { - - final IV iv = (IV) val; - - iv.encode(keyBuilder); - - } else { - - keyBuilder.append(val); - - } - - } - - return keyBuilder.getKey(); - - } - -} Copied: branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/relation/rule/BindingSetSortKeyBuilder.java (from rev 3242, branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/relation/rule/BindingSetSortKeyBuilder.java) =================================================================== --- branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/relation/rule/BindingSetSortKeyBuilder.java (rev 0) +++ branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/relation/rule/BindingSetSortKeyBuilder.java 2010-07-20 17:06:24 UTC (rev 3246) @@ -0,0 +1,110 @@ +/* + +Copyright (C) SYSTAP, LLC 2006-2008. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ +/* + * Created on Sep 15, 2008 + */ + +package com.bigdata.rdf.relation.rule; + +import com.bigdata.btree.keys.IKeyBuilder; +import com.bigdata.btree.keys.ISortKeyBuilder; +import com.bigdata.rdf.internal.IV; +import com.bigdata.relation.rule.Constant; +import com.bigdata.relation.rule.IBindingSet; +import com.bigdata.relation.rule.IVariable; + +/** + * Builds unsigned byte[] sort keys from {@link IBindingSet}s. + * + * @author <a href="mailto:tho...@us...">Bryan Thompson</a> + * @version $Id$ + */ +public class BindingSetSortKeyBuilder implements ISortKeyBuilder<IBindingSet> { + + private final IKeyBuilder keyBuilder; + private final IVariable[] vars; + + /** + * + * @param keyBuilder + * Used to generate the unsigned byte[] key for each bound + * variable. In particular, the configuration for the + * {@link IKeyBuilder} governs how Unicode fields are handled. + * @param vars + * An array of {@link IVariable}s, all of which MUST be bound. + */ + public BindingSetSortKeyBuilder(final IKeyBuilder keyBuilder, + final IVariable[] vars) { + + if (keyBuilder == null) + throw new IllegalArgumentException(); + + if (vars == null || vars.length == 0) + throw new IllegalArgumentException(); + + this.keyBuilder = keyBuilder; + + this.vars = vars; + + } + + public byte[] getSortKey(final IBindingSet bindingSet) { + + keyBuilder.reset(); + + for (int i = 0; i < vars.length; i++) { + + final IVariable var = vars[i]; + + /* + * FIXME Do we ever get unbound values here? This looks suspiciously + * like old Long code to me. + */ + Object val = bindingSet.get(var); + if(val==null) { + val=Long.valueOf(0); + }else if(val instanceof Constant) { + val=((Constant)val).get(); + } + + if (val instanceof IV) { + + final IV iv = (IV) val; + + iv.encode(keyBuilder); + + } else { + + keyBuilder.append(val); + + } + + } + + return keyBuilder.getKey(); + + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <tho...@us...> - 2010-07-20 19:50:29
|
Revision: 3252 http://bigdata.svn.sourceforge.net/bigdata/?rev=3252&view=rev Author: thompsonbry Date: 2010-07-20 19:50:22 +0000 (Tue, 20 Jul 2010) Log Message: ----------- Added test suite for the non-inline mode. Made BufferMode#Disk a synonym for DiskWORM. Deprecated DiskOnlyStrategy. It has been replaced by WORMStrategy. Removed some dead code in LexiconKeyBuilder. Modified Paths: -------------- branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/journal/AbstractBufferStrategy.java branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/journal/AbstractJournal.java branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/journal/BufferMode.java branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/journal/DiskOnlyStrategy.java branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/journal/FileMetadata.java branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/journal/Options.java branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/relation/IRelation.java branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/relation/rule/IPredicate.java branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/LexiconConfiguration.java branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/lexicon/LexiconKeyBuilder.java branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/lexicon/LexiconRelation.java branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/store/AbstractTripleStore.java branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/lexicon/TestTerm2IdTupleSerializer.java branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/store/TestAll.java Added Paths: ----------- branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/store/TestLocalTripleStoreWithoutInlining.java Removed Paths: ------------- branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/store/TestLocalTripleStoreWORM.java Modified: branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/journal/AbstractBufferStrategy.java =================================================================== --- branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/journal/AbstractBufferStrategy.java 2010-07-20 19:42:57 UTC (rev 3251) +++ branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/journal/AbstractBufferStrategy.java 2010-07-20 19:50:22 UTC (rev 3252) @@ -421,7 +421,7 @@ * * @return The extent. */ - static long assertNonDiskExtent(long extent) { + static long assertNonDiskExtent(final long extent) { if( extent > Integer.MAX_VALUE ) { @@ -432,8 +432,9 @@ * disk-based strategy. */ - throw new RuntimeException("The extent requires the " - + BufferMode.Disk + " mode: extent=" + extent); + throw new RuntimeException( + "The extent requires a disk-backed buffer mode: extent=" + + extent); } Modified: branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/journal/AbstractJournal.java =================================================================== --- branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/journal/AbstractJournal.java 2010-07-20 19:42:57 UTC (rev 3251) +++ branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/journal/AbstractJournal.java 2010-07-20 19:50:22 UTC (rev 3252) @@ -1027,32 +1027,33 @@ } - case Disk: { +// case Disk: { +// +// /* +// * Setup the buffer strategy. +// */ +// +// fileMetadata = new FileMetadata(file, BufferMode.Disk, +// useDirectBuffers, initialExtent, maximumExtent, create, +// isEmptyFile, deleteOnExit, readOnly, forceWrites, +// offsetBits, //readCacheCapacity, readCacheMaxRecordSize, +// //readOnly ? null : writeCache, +// writeCacheEnabled, +// validateChecksum, +// createTime, checker, alternateRootBlock); +// +// _bufferStrategy = new DiskOnlyStrategy( +// 0L/* soft limit for maximumExtent */, +//// minimumExtension, +// fileMetadata); +// +// this._rootBlock = fileMetadata.rootBlock; +// +// break; +// +// } - /* - * Setup the buffer strategy. - */ - - fileMetadata = new FileMetadata(file, BufferMode.Disk, - useDirectBuffers, initialExtent, maximumExtent, create, - isEmptyFile, deleteOnExit, readOnly, forceWrites, - offsetBits, //readCacheCapacity, readCacheMaxRecordSize, - //readOnly ? null : writeCache, - writeCacheEnabled, - validateChecksum, - createTime, checker, alternateRootBlock); - - _bufferStrategy = new DiskOnlyStrategy( - 0L/* soft limit for maximumExtent */, -// minimumExtension, - fileMetadata); - - this._rootBlock = fileMetadata.rootBlock; - - break; - - } - + case Disk: case DiskWORM: { /* Modified: branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/journal/BufferMode.java =================================================================== --- branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/journal/BufferMode.java 2010-07-20 19:42:57 UTC (rev 3251) +++ branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/journal/BufferMode.java 2010-07-20 19:50:22 UTC (rev 3252) @@ -100,13 +100,10 @@ /** * <p> - * The journal is managed on disk. This option may be used with files of - * more than {@link Integer#MAX_VALUE} bytes in extent. Journal performance - * for large files should be fair on write, but performance will degrade as - * the journal is NOT optimized for random reads (poor locality). + * This is a synonym for {@link #DiskWORM}. * </p> * - * @see DiskOnlyStrategy + * @see WORMStrategy */ Disk(true/* stable */, false/* fullyBuffered */), @@ -119,12 +116,6 @@ * </p> * * @see WORMStrategy - * - * @deprecated This mode exists to test a new version of the - * {@link DiskOnlyStrategy} which does not require - * synchronization for disk read/write operations except when - * the file size is being changed. Once this is working properly - * it will replace the {@link DiskOnlyStrategy}. */ DiskWORM(true/* stable */, false/* fullyBuffered */), Modified: branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/journal/DiskOnlyStrategy.java =================================================================== --- branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/journal/DiskOnlyStrategy.java 2010-07-20 19:42:57 UTC (rev 3251) +++ branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/journal/DiskOnlyStrategy.java 2010-07-20 19:50:22 UTC (rev 3252) @@ -155,6 +155,8 @@ * * @see BufferMode#Disk * @see BufferMode#Temporary + * + * @deprecated This has been replaced by {@link WORMStrategy}. */ public class DiskOnlyStrategy extends AbstractBufferStrategy implements IDiskBasedStrategy { Modified: branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/journal/FileMetadata.java =================================================================== --- branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/journal/FileMetadata.java 2010-07-20 19:42:57 UTC (rev 3251) +++ branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/journal/FileMetadata.java 2010-07-20 19:50:22 UTC (rev 3252) @@ -582,8 +582,8 @@ break; } case Disk: - buffer = null; - break; +// buffer = null; +// break; case DiskWORM: buffer = null; break; @@ -757,8 +757,8 @@ buffer = null; break; case Disk: - buffer = null; - break; +// buffer = null; +// break; case DiskWORM: buffer = null; break; Modified: branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/journal/Options.java =================================================================== --- branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/journal/Options.java 2010-07-20 19:42:57 UTC (rev 3251) +++ branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/journal/Options.java 2010-07-20 19:50:22 UTC (rev 3252) @@ -495,7 +495,7 @@ /** * The default for the {@link #BUFFER_MODE}. */ - String DEFAULT_BUFFER_MODE = BufferMode.Disk.toString(); + String DEFAULT_BUFFER_MODE = BufferMode.DiskWORM.toString(); /** * The default for {@link #USE_DIRECT_BUFFERS}. Modified: branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/relation/IRelation.java =================================================================== --- branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/relation/IRelation.java 2010-07-20 19:42:57 UTC (rev 3251) +++ branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/relation/IRelation.java 2010-07-20 19:50:22 UTC (rev 3252) @@ -123,6 +123,8 @@ * relation. * * @return An immutable set of the index names for the relation. + * + * @todo replace with getKeyOrders()? */ Set<String> getIndexNames(); @@ -157,6 +159,8 @@ // // /** // * Return the primary index for the relation. +// * +// * @todo how about getIndex(IKeyOrder) instead? // */ // IIndex getPrimaryIndex(); Modified: branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/relation/rule/IPredicate.java =================================================================== --- branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/relation/rule/IPredicate.java 2010-07-20 19:42:57 UTC (rev 3251) +++ branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/relation/rule/IPredicate.java 2010-07-20 19:50:22 UTC (rev 3252) @@ -171,6 +171,8 @@ /** * An optional constraint on the visitable elements. + * + * @todo rename as get(Element)Filter(). */ public IElementFilter<E> getConstraint(); Modified: branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/LexiconConfiguration.java =================================================================== --- branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/LexiconConfiguration.java 2010-07-20 19:42:57 UTC (rev 3251) +++ branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/LexiconConfiguration.java 2010-07-20 19:50:22 UTC (rev 3252) @@ -29,6 +29,18 @@ import java.io.Serializable; +/** + * An object which describes which kinds of RDF Values are inlined into the + * statement indices and how other RDF Values are coded into the lexicon. + * + * @author <a href="mailto:tho...@us...">Bryan Thompson</a> + * @version $Id$ + * + * FIXME Version information in serialization format. + * + * @todo large literal size boundary. + * @todo other configuration options. + */ public class LexiconConfiguration implements Serializable, ILexiconConfiguration { Modified: branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/lexicon/LexiconKeyBuilder.java =================================================================== --- branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/lexicon/LexiconKeyBuilder.java 2010-07-20 19:42:57 UTC (rev 3251) +++ branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/lexicon/LexiconKeyBuilder.java 2010-07-20 19:50:22 UTC (rev 3252) @@ -1,18 +1,13 @@ package com.bigdata.rdf.lexicon; -import java.util.HashMap; -import java.util.Map; - import org.openrdf.model.BNode; import org.openrdf.model.Literal; import org.openrdf.model.URI; import org.openrdf.model.Value; -import org.openrdf.model.vocabulary.RDF; import org.openrdf.model.vocabulary.XMLSchema; import com.bigdata.btree.keys.IKeyBuilder; import com.bigdata.btree.keys.IKeyBuilderFactory; -import com.bigdata.btree.keys.KeyBuilder; import com.bigdata.btree.keys.StrengthEnum; /** @@ -78,257 +73,577 @@ public final IKeyBuilder keyBuilder; - /** - * Interface for classes encapsulating the logic to encode (and where - * possible, decode) datatype literals. - * - * @author <a href="mailto:tho...@us...">Bryan - * Thompson</a> - * @version $Id$ - */ - public static interface IDatatypeKeyCoder { - - /** - * Interpret the text as some specific data type and encode a - * representation of that data type value suitable for an index whose - * keys are unsigned byte[]s. - * - * @param keyBuilder - * The object used to build up the key. - * @param text - * A lexical representation of the value. - */ - void encode(IKeyBuilder keyBuilder, String text); - - /** - * Decode a slice of a byte[] containing a key formed by - * {@link #encode(IKeyBuilder, String)}. - * - * @param key - * The byte[]. - * @param off - * The first byte in the slice. - * @param len - * The length of the slice. - * - * @return A lexical representation of the decoded value. - * - * @throws UnsupportedOperationException - * If the keys for the datatype encoded by this interface - * can not be decoded without loss. For example, this is - * true of {@link XMLSchema#STRING} when compressed Unicode - * sort keys are used. - * - * @todo the [len] parameter is probably not necessary for most things, - * but there are some cool key types that are both variable length - * and totally ordered. E.g., eXist XML node identifiers. - */ - String decode(byte[] key, int off, int len); - - /** - * Return <code>true</code> if the implementation of this interface - * encodes keys which can be decoded without loss. "Loss" means that it - * is not possible to decode a value which correspond to the same point - * in the value space of the datatype. For example, <code>.5</code> and - * <code>0.5</code> both represent the same point in the - * {@link XMLSchema#FLOAT} value space. These values are therefore - * decodable without loss, even though the decoded value might not have - * the same lexical representation. - */ - boolean isDecodable(); - - /** - * Return the unique code designated for the primitive data type handled - * by this coder. Coders which self-report values for this method which - * are in conflict will be reported by a runtime exception. The - * appropriate code values are declared by this interface. The primitive - * datatypes include: - * - * <pre> - * 3.2.1 string - * 3.2.2 boolean - * 3.2.3 decimal - * 3.2.4 float - * 3.2.5 double - * 3.2.6 duration - * 3.2.7 dateTime - * 3.2.8 time - * 3.2.9 date - * 3.2.10 gYearMonth - * 3.2.11 gYear - * 3.2.12 gMonthDay - * 3.2.13 gDay - * 3.2.14 gMonth - * 3.2.15 hexBinary - * 3.2.16 base64Binary - * 3.2.17 anyURI - * 3.2.18 QName - * 3.2.19 NOTATION - * </pre> - * - * @see http://www.w3.org/TR/swbp-xsch-datatypes/ - * @see <a ref="http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#built-in-primitive-datatypes>primitiv - * e data types.</a> - */ - int code(); - - /** - * Code used for unrecognized or otherwise unhandled data types. - */ - int CODE_OTHER = 0; - - int CODE_XSD_STRING = 1; - - int CODE_XSD_BOOLEAN = 2; - - /** - * Arbitrary magnitude decimal values with arbitrary digits after the - * decimal. - */ - int CODE_XSD_DECIMAL = 3; - - int CODE_XSD_FLOAT = 4; - - int CODE_XSD_DOUBLE = 5; - - /** @deprecated until good semantics have been developed. */ - int CODE_XSD_DURATION = 6; - - int CODE_XSD_DATETIME = 7; - - int CODE_XSD_TIME = 8; - - int CODE_XSD_DATE = 9; - - int CODE_XSD_GYEARMONTH = 10; - - int CODE_XSD_GYEAR = 11; - - int CODE_XSD_GMONTHDAY = 12; - - int CODE_XSD_HEXBINARY = 13; - - int CODE_XSD_BASE64BINARY = 14; - - int CODE_XSD_ANYURI = 15; - - int CODE_XSD_QNAME = 16; - - int CODE_XSD_NOTATION = 17; - - /* - * Arbitrary magnitude integers. - */ - int CODE_XSD_INTEGER = 18; - - /* - * Various signed fixed width integer types. - */ - int CODE_XSD_LONG = 32; - - int CODE_XSD_INT = 33; - - int CODE_XSD_SHORT = 34; - - int CODE_XSD_BYTE = 35; - - /* - * Various unsigned fixed with integer types. - */ - int CODE_XSD_ULONG = 36; - - int CODE_XSD_UINT = 37; - - int CODE_XSD_USHORT = 38; - - int CODE_XSD_UBYTE = 39; - - /** - * An {@link RDF#XMLLITERAL}. - */ - int CODE_XML_LITERAL = 40; - - } - - /** - * Handles anything derived from the primitive data type - * {@link XMLSchema#BOOLEAN}. All such values are coded in a single byte. - * - * @author <a href="mailto:tho...@us...">Bryan - * Thompson</a> - * @version $Id$ - */ - public static class XSDBooleanCoder implements IDatatypeKeyCoder { - - public static transient final IDatatypeKeyCoder INSTANCE = new XSDBooleanCoder(); - - public int code() { - - return CODE_XSD_BOOLEAN; - - } - - public String decode(byte[] buf, int off, int len) { - - return KeyBuilder.decodeByte(buf[off]) == 1 ? "true" : "false"; - - } - - public void encode(IKeyBuilder keyBuilder, String text) { - - text = text.trim(); - - final boolean t; - - if ("true".equalsIgnoreCase(text) || "1".equals(text)) { - - t = true; - - } else if ("false".equalsIgnoreCase(text) || "0".equals(text)) { - - t = false; - - } else { - - throw new RuntimeException("Does not match xsd:boolean : " - + text); - - } - - keyBuilder.append((byte) (t ? 1 : 0)); - - } - - /** Yes. */ - public boolean isDecodable() { - - return true; - - } - - } - // /** +// * Interface for classes encapsulating the logic to encode (and where +// * possible, decode) datatype literals. +// * +// * @author <a href="mailto:tho...@us...">Bryan +// * Thompson</a> +// * @version $Id$ +// */ +// public static interface IDatatypeKeyCoder { +// +// /** +// * Interpret the text as some specific data type and encode a +// * representation of that data type value suitable for an index whose +// * keys are unsigned byte[]s. +// * +// * @param keyBuilder +// * The object used to build up the key. +// * @param text +// * A lexical representation of the value. +// */ +// void encode(IKeyBuilder keyBuilder, String text); +// +// /** +// * Decode a slice of a byte[] containing a key formed by +// * {@link #encode(IKeyBuilder, String)}. +// * +// * @param key +// * The byte[]. +// * @param off +// * The first byte in the slice. +// * @param len +// * The length of the slice. +// * +// * @return A lexical representation of the decoded value. +// * +// * @throws UnsupportedOperationException +// * If the keys for the datatype encoded by this interface +// * can not be decoded without loss. For example, this is +// * true of {@link XMLSchema#STRING} when compressed Unicode +// * sort keys are used. +// * +// * @todo the [len] parameter is probably not necessary for most things, +// * but there are some cool key types that are both variable length +// * and totally ordered. E.g., eXist XML node identifiers. +// */ +// String decode(byte[] key, int off, int len); +// +// /** +// * Return <code>true</code> if the implementation of this interface +// * encodes keys which can be decoded without loss. "Loss" means that it +// * is not possible to decode a value which correspond to the same point +// * in the value space of the datatype. For example, <code>.5</code> and +// * <code>0.5</code> both represent the same point in the +// * {@link XMLSchema#FLOAT} value space. These values are therefore +// * decodable without loss, even though the decoded value might not have +// * the same lexical representation. +// */ +// boolean isDecodable(); +// +// /** +// * Return the unique code designated for the primitive data type handled +// * by this coder. Coders which self-report values for this method which +// * are in conflict will be reported by a runtime exception. The +// * appropriate code values are declared by this interface. The primitive +// * datatypes include: +// * +// * <pre> +// * 3.2.1 string +// * 3.2.2 boolean +// * 3.2.3 decimal +// * 3.2.4 float +// * 3.2.5 double +// * 3.2.6 duration +// * 3.2.7 dateTime +// * 3.2.8 time +// * 3.2.9 date +// * 3.2.10 gYearMonth +// * 3.2.11 gYear +// * 3.2.12 gMonthDay +// * 3.2.13 gDay +// * 3.2.14 gMonth +// * 3.2.15 hexBinary +// * 3.2.16 base64Binary +// * 3.2.17 anyURI +// * 3.2.18 QName +// * 3.2.19 NOTATION +// * </pre> +// * +// * @see http://www.w3.org/TR/swbp-xsch-datatypes/ +// * @see <a ref="http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#built-in-primitive-datatypes>primitiv +// * e data types.</a> +// */ +// int code(); +// +// /** +// * Code used for unrecognized or otherwise unhandled data types. +// */ +// int CODE_OTHER = 0; +// +// int CODE_XSD_STRING = 1; +// +// int CODE_XSD_BOOLEAN = 2; +// +// /** +// * Arbitrary magnitude decimal values with arbitrary digits after the +// * decimal. +// */ +// int CODE_XSD_DECIMAL = 3; +// +// int CODE_XSD_FLOAT = 4; +// +// int CODE_XSD_DOUBLE = 5; +// +// /** @deprecated until good semantics have been developed. */ +// int CODE_XSD_DURATION = 6; +// +// int CODE_XSD_DATETIME = 7; +// +// int CODE_XSD_TIME = 8; +// +// int CODE_XSD_DATE = 9; +// +// int CODE_XSD_GYEARMONTH = 10; +// +// int CODE_XSD_GYEAR = 11; +// +// int CODE_XSD_GMONTHDAY = 12; +// +// int CODE_XSD_HEXBINARY = 13; +// +// int CODE_XSD_BASE64BINARY = 14; +// +// int CODE_XSD_ANYURI = 15; +// +// int CODE_XSD_QNAME = 16; +// +// int CODE_XSD_NOTATION = 17; +// +// /* +// * Arbitrary magnitude integers. +// */ +// int CODE_XSD_INTEGER = 18; +// +// /* +// * Various signed fixed width integer types. +// */ +// int CODE_XSD_LONG = 32; +// +// int CODE_XSD_INT = 33; +// +// int CODE_XSD_SHORT = 34; +// +// int CODE_XSD_BYTE = 35; +// +// /* +// * Various unsigned fixed with integer types. +// */ +// int CODE_XSD_ULONG = 36; +// +// int CODE_XSD_UINT = 37; +// +// int CODE_XSD_USHORT = 38; +// +// int CODE_XSD_UBYTE = 39; +// +// /** +// * An {@link RDF#XMLLITERAL}. +// */ +// int CODE_XML_LITERAL = 40; +// +// } +// +// /** // * Handles anything derived from the primitive data type -// * {@link XMLSchema#STRING}. Values are coded as Unicode sort keys and ARE -// * NOT decodable. +// * {@link XMLSchema#BOOLEAN}. All such values are coded in a single byte. // * // * @author <a href="mailto:tho...@us...">Bryan // * Thompson</a> // * @version $Id$ // */ -// public static class XSDStringCoder implements IDatatypeKeyCoder { +// public static class XSDBooleanCoder implements IDatatypeKeyCoder { // -// public static transient final IDatatypeKeyCoder INSTANCE = new XSDStringCoder(); +// public static transient final IDatatypeKeyCoder INSTANCE = new XSDBooleanCoder(); // // public int code() { // -// return CODE_XSD_STRING; +// return CODE_XSD_BOOLEAN; // // } // // public String decode(byte[] buf, int off, int len) { // +// return KeyBuilder.decodeByte(buf[off]) == 1 ? "true" : "false"; +// +// } +// +// public void encode(IKeyBuilder keyBuilder, String text) { +// +// text = text.trim(); +// +// final boolean t; +// +// if ("true".equalsIgnoreCase(text) || "1".equals(text)) { +// +// t = true; +// +// } else if ("false".equalsIgnoreCase(text) || "0".equals(text)) { +// +// t = false; +// +// } else { +// +// throw new RuntimeException("Does not match xsd:boolean : " +// + text); +// +// } +// +// keyBuilder.append((byte) (t ? 1 : 0)); +// +// } +// +// /** Yes. */ +// public boolean isDecodable() { +// +// return true; +// +// } +// +// } +// +//// /** +//// * Handles anything derived from the primitive data type +//// * {@link XMLSchema#STRING}. Values are coded as Unicode sort keys and ARE +//// * NOT decodable. +//// * +//// * @author <a href="mailto:tho...@us...">Bryan +//// * Thompson</a> +//// * @version $Id$ +//// */ +//// public static class XSDStringCoder implements IDatatypeKeyCoder { +//// +//// public static transient final IDatatypeKeyCoder INSTANCE = new XSDStringCoder(); +//// +//// public int code() { +//// +//// return CODE_XSD_STRING; +//// +//// } +//// +//// public String decode(byte[] buf, int off, int len) { +//// +//// throw new UnsupportedOperationException(); +//// +//// } +//// +//// public void encode(IKeyBuilder keyBuilder, String text) { +//// +//// keyBuilder.append(text); +//// +//// } +//// +//// /** No - this class uses Unicode sort keys, which are not decodable. */ +//// public boolean isDecodable() { +//// +//// return false; +//// +//// } +//// +//// } +// +// /** +// * Handles {@link XMLSchema#LONG}. All such values are coded as 64-bit +// * integers. +// * +// * @author <a href="mailto:tho...@us...">Bryan +// * Thompson</a> +// * @version $Id$ +// */ +// public static class XSDLongCoder implements IDatatypeKeyCoder { +// +// public static transient final IDatatypeKeyCoder INSTANCE = new XSDLongCoder(); +// +// public int code() { +// +// return CODE_XSD_LONG; +// +// } +// +// public String decode(byte[] buf, int off, int len) { +// +// return Long.toString(KeyBuilder.decodeLong(buf, off)); +// +// } +// +// public void encode(IKeyBuilder keyBuilder, String text) { +// +// keyBuilder.append(Long.valueOf(text).longValue()); +// +// } +// +// /** Yes. */ +// public boolean isDecodable() { +// +// return true; +// +// } +// +// } +// +// /** +// * Handles {@link XMLSchema#INT}. All such values are coded as 32-bit +// * integers. +// * +// * @author <a href="mailto:tho...@us...">Bryan +// * Thompson</a> +// * @version $Id$ +// */ +// public static class XSDIntCoder implements IDatatypeKeyCoder { +// +// public static transient final IDatatypeKeyCoder INSTANCE = new XSDIntCoder(); +// +// public int code() { +// +// return CODE_XSD_INT; +// +// } +// +// public String decode(byte[] buf, int off, int len) { +// +// return Integer.toString(KeyBuilder.decodeInt(buf, off)); +// +// } +// +// public void encode(IKeyBuilder keyBuilder, String text) { +// +// keyBuilder.append(Integer.valueOf(text).intValue()); +// +// } +// +// /** Yes. */ +// public boolean isDecodable() { +// +// return true; +// +// } +// +// } +// +// /** +// * Handles {@link XMLSchema#SHORT}. All such values are coded as 16-bit +// * integers. +// * +// * @author <a href="mailto:tho...@us...">Bryan +// * Thompson</a> +// * @version $Id$ +// */ +// public static class XSDShortCoder implements IDatatypeKeyCoder { +// +// public static transient final IDatatypeKeyCoder INSTANCE = new XSDShortCoder(); +// +// public int code() { +// +// return CODE_XSD_SHORT; +// +// } +// +// public String decode(byte[] buf, int off, int len) { +// +// return Short.toString(KeyBuilder.decodeShort(buf, off)); +// +// } +// +// public void encode(IKeyBuilder keyBuilder, String text) { +// +// keyBuilder.append(Short.valueOf(text).shortValue()); +// +// } +// +// /** Yes. */ +// public boolean isDecodable() { +// +// return true; +// +// } +// +// } +// +// /** +// * Handles {@link XMLSchema#BYTE}. All such values are coded as 8-bit +// * integers. +// * +// * @author <a href="mailto:tho...@us...">Bryan +// * Thompson</a> +// * @version $Id$ +// */ +// public static class XSDByteCoder implements IDatatypeKeyCoder { +// +// public static transient final IDatatypeKeyCoder INSTANCE = new XSDByteCoder(); +// +// public int code() { +// +// return CODE_XSD_BYTE; +// +// } +// +// public String decode(byte[] buf, int off, int len) { +// +// return Byte.toString(KeyBuilder.decodeByte(buf[off])); +// +// } +// +// public void encode(IKeyBuilder keyBuilder, String text) { +// +// keyBuilder.append(Byte.valueOf(text).byteValue()); +// +// } +// +// /** Yes. */ +// public boolean isDecodable() { +// +// return true; +// +// } +// +// } +// +// /** +// * Handles anything derived from the primitive data type +// * {@link XMLSchema#FLOAT}. All such values are coded as 32-bit integers. +// * +// * @author <a href="mailto:tho...@us...">Bryan +// * Thompson</a> +// * @version $Id$ +// */ +// public static class XSDFloatCoder implements IDatatypeKeyCoder { +// +// public static transient final IDatatypeKeyCoder INSTANCE = new XSDFloatCoder(); +// +// public int code() { +// +// return CODE_XSD_FLOAT; +// +// } +// +// public String decode(byte[] buf, int off, int len) { +// +// return Float.toString(KeyBuilder.decodeFloat(buf, off)); +// +// } +// +// public void encode(IKeyBuilder keyBuilder, String text) { +// +// keyBuilder.append(Float.valueOf(text).floatValue()); +// +// } +// +// /** Yes. */ +// public boolean isDecodable() { +// +// return true; +// +// } +// +// } +// +// /** +// * Handles anything derived from the primitive data type +// * {@link XMLSchema#DOUBLE}. All such values are coded as 64-bit integers. +// * +// * @author <a href="mailto:tho...@us...">Bryan +// * Thompson</a> +// * @version $Id$ +// */ +// public static class XSDDoubleCoder implements IDatatypeKeyCoder { +// +// public static transient final IDatatypeKeyCoder INSTANCE = new XSDDoubleCoder(); +// +// public int code() { +// +// return CODE_XSD_DOUBLE; +// +// } +// +// public String decode(byte[] buf, int off, int len) { +// +// return Double.toString(KeyBuilder.decodeDouble(buf, off)); +// +// } +// +// public void encode(IKeyBuilder keyBuilder, String text) { +// +// keyBuilder.append(Double.valueOf(text).doubleValue()); +// +// } +// +// /** Yes. */ +// public boolean isDecodable() { +// +// return true; +// +// } +// +// } +// +//// /** +//// * Handles anything derived from the primitive data type +//// * {@link XMLSchema#DATETIME}. +//// * +//// * @author <a href="mailto:tho...@us...">Bryan +//// * Thompson</a> +//// * @version $Id$ +//// */ +//// public static class XSDDateTimeCoder implements IDatatypeKeyCoder { +//// +//// public static transient final IDatatypeKeyCoder INSTANCE = new XSDDateTimeCoder(); +//// +//// public int code() { +//// +//// return CODE_XSD_DATETIME; +//// +//// } +//// +//// public String decode(byte[] buf, int off, int len) { +//// +//// throw new UnsupportedOperationException(); +////// return Double.toString(KeyBuilder.decodeDouble(buf, off)); +//// +//// } +//// +//// public void encode(IKeyBuilder keyBuilder, String text) { +//// +//// final XMLGregorianCalendar cal = XMLDatatypeUtil.parseCalendar(text); +//// +//// // FIXME normalize to UTC and encode as int64 seconds since epoch or what? +//// +////// keyBuilder.append(.doubleValue()); +//// +//// throw new UnsupportedOperationException(); +//// +//// } +//// +//// /** No. */ +//// public boolean isDecodable() { +//// +//// return false; +//// +//// } +//// +//// } +// +// /** +// * Handles anything derived from the primitive data type +// * {@link XMLSchema#STRING}. Values are coded as Unicode sort keys and +// * ARE NOT decodable. +// * +// * @author <a href="mailto:tho...@us...">Bryan +// * Thompson</a> +// * @version $Id$ +// */ +// public static class XSDAnyURICoder implements IDatatypeKeyCoder { +// +// public static transient final IDatatypeKeyCoder INSTANCE = new XSDAnyURICoder(); +// +// public int code() { +// +// return CODE_XSD_ANYURI; +// +// } +// +// public String decode(byte[] buf, int off, int len) { +// // throw new UnsupportedOperationException(); // // } @@ -347,529 +662,209 @@ // } // // } - - /** - * Handles {@link XMLSchema#LONG}. All such values are coded as 64-bit - * integers. - * - * @author <a href="mailto:tho...@us...">Bryan - * Thompson</a> - * @version $Id$ - */ - public static class XSDLongCoder implements IDatatypeKeyCoder { - - public static transient final IDatatypeKeyCoder INSTANCE = new XSDLongCoder(); - - public int code() { - - return CODE_XSD_LONG; - - } - - public String decode(byte[] buf, int off, int len) { - - return Long.toString(KeyBuilder.decodeLong(buf, off)); - - } - - public void encode(IKeyBuilder keyBuilder, String text) { - - keyBuilder.append(Long.valueOf(text).longValue()); - - } - - /** Yes. */ - public boolean isDecodable() { - - return true; - - } - - } - - /** - * Handles {@link XMLSchema#INT}. All such values are coded as 32-bit - * integers. - * - * @author <a href="mailto:tho...@us...">Bryan - * Thompson</a> - * @version $Id$ - */ - public static class XSDIntCoder implements IDatatypeKeyCoder { - - public static transient final IDatatypeKeyCoder INSTANCE = new XSDIntCoder(); - - public int code() { - - return CODE_XSD_INT; - - } - - public String decode(byte[] buf, int off, int len) { - - return Integer.toString(KeyBuilder.decodeInt(buf, off)); - - } - - public void encode(IKeyBuilder keyBuilder, String text) { - - keyBuilder.append(Integer.valueOf(text).intValue()); - - } - - /** Yes. */ - public boolean isDecodable() { - - return true; - - } - - } - - /** - * Handles {@link XMLSchema#SHORT}. All such values are coded as 16-bit - * integers. - * - * @author <a href="mailto:tho...@us...">Bryan - * Thompson</a> - * @version $Id$ - */ - public static class XSDShortCoder implements IDatatypeKeyCoder { - - public static transient final IDatatypeKeyCoder INSTANCE = new XSDShortCoder(); - - public int code() { - - return CODE_XSD_SHORT; - - } - - public String decode(byte[] buf, int off, int len) { - - return Short.toString(KeyBuilder.decodeShort(buf, off)); - - } - - public void encode(IKeyBuilder keyBuilder, String text) { - - keyBuilder.append(Short.valueOf(text).shortValue()); - - } - - /** Yes. */ - public boolean isDecodable() { - - return true; - - } - - } - - /** - * Handles {@link XMLSchema#BYTE}. All such values are coded as 8-bit - * integers. - * - * @author <a href="mailto:tho...@us...">Bryan - * Thompson</a> - * @version $Id$ - */ - public static class XSDByteCoder implements IDatatypeKeyCoder { - - public static transient final IDatatypeKeyCoder INSTANCE = new XSDByteCoder(); - - public int code() { - - return CODE_XSD_BYTE; - - } - - public String decode(byte[] buf, int off, int len) { - - return Byte.toString(KeyBuilder.decodeByte(buf[off])); - - } - - public void encode(IKeyBuilder keyBuilder, String text) { - - keyBuilder.append(Byte.valueOf(text).byteValue()); - - } - - /** Yes. */ - public boolean isDecodable() { - - return true; - - } - - } - - /** - * Handles anything derived from the primitive data type - * {@link XMLSchema#FLOAT}. All such values are coded as 32-bit integers. - * - * @author <a href="mailto:tho...@us...">Bryan - * Thompson</a> - * @version $Id$ - */ - public static class XSDFloatCoder implements IDatatypeKeyCoder { - - public static transient final IDatatypeKeyCoder INSTANCE = new XSDFloatCoder(); - - public int code() { - - return CODE_XSD_FLOAT; - - } - - public String decode(byte[] buf, int off, int len) { - - return Float.toString(KeyBuilder.decodeFloat(buf, off)); - - } - - public void encode(IKeyBuilder keyBuilder, String text) { - - keyBuilder.append(Float.valueOf(text).floatValue()); - - } - - /** Yes. */ - public boolean isDecodable() { - - return true; - - } - - } - - /** - * Handles anything derived from the primitive data type - * {@link XMLSchema#DOUBLE}. All such values are coded as 64-bit integers. - * - * @author <a href="mailto:tho...@us...">Bryan - * Thompson</a> - * @version $Id$ - */ - public static class XSDDoubleCoder implements IDatatypeKeyCoder { - - public static transient final IDatatypeKeyCoder INSTANCE = new XSDDoubleCoder(); - - public int code() { - - return CODE_XSD_DOUBLE; - - } - - public String decode(byte[] buf, int off, int len) { - - return Double.toString(KeyBuilder.decodeDouble(buf, off)); - - } - - public void encode(IKeyBuilder keyBuilder, String text) { - - keyBuilder.append(Double.valueOf(text).doubleValue()); - - } - - /** Yes. */ - public boolean isDecodable() { - - return true; - - } - - } - +// // /** // * Handles anything derived from the primitive data type -// * {@link XMLSchema#DATETIME}. +// * {@link RDF#XMLLITERAL}. Values are coded as Unicode sort keys and ARE NOT +// * decodable. // * // * @author <a href="mailto:tho...@us...">Bryan // * Thompson</a> // * @version $Id$ // */ -// public static class XSDDateTimeCoder implements IDatatypeKeyCoder { +// public static class XSDXmlLiteralCoder implements IDatatypeKeyCoder { // -// public static transient final IDatatypeKeyCoder INSTANCE = new XSDDateTimeCoder(); +// public static transient final IDatatypeKeyCoder INSTANCE = new XSDXmlLiteralCoder(); // // public int code() { // -// return CODE_XSD_DATETIME; +// return CODE_XML_LITERAL; // // } // // public String decode(byte[] buf, int off, int len) { // // throw new UnsupportedOperationException(); -//// return Double.toString(KeyBuilder.decodeDouble(buf, off)); // // } // // public void encode(IKeyBuilder keyBuilder, String text) { // -// final XMLGregorianCalendar cal = XMLDatatypeUtil.parseCalendar(text); +// keyBuilder.append(text); // -// // FIXME normalize to UTC and encode as int64 seconds since epoch or what? -// -//// keyBuilder.append(.doubleValue()); +// } // +// /** No - this class uses Unicode sort keys, which are not decodable. */ +// public boolean isDecodable() { +// +// return false; +// +// } +// +// } +// +// /** +// * Map from the specific datatype URI to the coder instance for that +// * datatype. +// */ +// private static final Map<URI/* datatype */, IDatatypeKeyCoder> coders; +// +// private static final Map<Integer, IDatatypeKeyCoder> codes; +// +// synchronized static private void registerCoder(final URI datatype, +// IDatatypeKeyCoder newCoder) { +// +// if (coders == null) // throw new UnsupportedOperationException(); +// +// if (newCoder == null) +// throw new IllegalArgumentException(); // +// final int code = newCoder.code(); +// +// if (codes.containsKey(code)) { +// +// throw new IllegalStateException( +// "Coder already registered for code: code=" + code +// + ", val=" + codes.get(code) + ", new=" + newCoder); +// // } // -// /** No. */ -// public boolean isDecodable() { +// if (coders.containsKey(code)) { // -// return false; +// throw new IllegalStateException( +// "Coder already registered for datatype: datatype=" +// + datatype + ", val=" + codes.get(code) + ", new=" +// + newCoder); // // } // +// coders.put(datatype, newCoder); +// +// codes.put(code, newCoder); +// // } +// +// static { +// +// if(true) { +// +// /* +// * Disable coders. +// * +// * FIXME configuration option for coders? Per triple store instance? +// * Or are the coders just not compatible with the SPARQL +// * specification? +// */ +// +// coders = null; +// +// codes = null; +// +// } else { +// +// // datatype URI to coder map. +// coders = new HashMap<URI, IDatatypeKeyCoder>(); +// +// // code to coder map. +// codes = new HashMap<Integer, IDatatypeKeyCoder>(); +// +// // 3.2.1 string and derived types. +// // Note: string is mapped onto plainLiteral by RDF Semantics. +//// registerCoder(XMLSchema.STRING, XSDStringCoder.INSTANCE); +//// registerCoder(XMLSchema.NORMALIZEDSTRING, XSDStringCoder.INSTANCE); +//// registerCoder(XMLSchema.TOKEN, XSDStringCoder.INSTANCE); +//// registerCoder(XMLSchema.LANGUAGE, XSDStringCoder.INSTANCE); +//// registerCoder(XMLSchema.NAME, XSDStringCoder.INSTANCE); +//// registerCoder(XMLSchema.NCNAME, XSDStringCoder.INSTANCE); +//// registerCoder(XMLSchema.ID, XSDStringCoder.INSTANCE); +//// registerCoder(XMLSchema.IDREF, XSDStringCoder.INSTANCE); +//// registerCoder(XMLSchema.IDREFS, XSDStringCoder.INSTANCE); +//// registerCoder(XMLSchema.ENTITY, XSDStringCoder.INSTANCE); +//// registerCoder(XMLSchema.ENTITIES, XSDStringCoder.INSTANCE); +//// registerCoder(XMLSchema.NMTOKEN, XSDStringCoder.INSTANCE); +//// registerCoder(XMLSchema.NMTOKENS, XSDStringCoder.INSTANCE); +// +// // 3.2.2 boolean +// registerCoder(XMLSchema.BOOLEAN, XSDBooleanCoder.INSTANCE); +// +// // 3.2.3 decimal and derived types. +// +// /* +// * @todo decimal really needs to be a BigDecimal representation if such +// * a thing can be mapped onto a totally ordered unsigned byte[] key. +// * Failing that, it needs to be projected to a maximum magnitude fixed +// * byte length representation. Failing that, all comparison of order +// * must be done by the SPARQL engine. +// */ +//// registerCoder(XMLSchema.DECIMAL, XSDDecimalCoder.INSTANCE); +// +// /* +// * @todo integer really needs to be a BigInteger representation if such +// * a thing can be mapped onto a totally ordered unsigned byte[] key +// * (negative integers always appear to be larger than positive integers +// * with naive encoding). Failing that, it needs to be projected to a +// * maximum magnitude fixed byte length representation. Failing that, all +// * comparison of order must be done by the SPARQL engine. +// */ +//// registerCoder(XMLSchema.INTEGER, XSDDecimalCoder.INSTANCE); +//// registerCoder(XMLSchema.POSITIVE_INTEGER, XSDDecimalCoder.INSTANCE); +//// registerCoder(XMLSchema.NON_POSITIVE_INTEGER, XSDDecimalCoder.INSTANCE); +//// registerCoder(XMLSchema.NON_NEGATIVE_INTEGER, XSDDecimalCoder.INSTANCE); +// +// /* +// * These are all fixed width signed datatypes. Each has its own code and +// * its own disjoint value space. +// */ +// registerCoder(XMLSchema.LONG, XSDLongCoder.INSTANCE); // 64-bits +// registerCoder(XMLSchema.INT, XSDIntCoder.INSTANCE); // 32-bits +// registerCoder(XMLSchema.SHORT, XSDShortCoder.INSTANCE); // 16-bits +// registerCoder(XMLSchema.BYTE, XSDByteCoder.INSTANCE); // 8 bits. +// /* +// * These are all fixed width unsigned datatypes. Each has its own code +// * and its own disjoint value space. +// * +// * @todo unsigned long +// * @todo unsigned int +// * @todo unsigned short +// * @todo unsigned byte +// */ +//// registerCoder(XMLSchema.UNSIGNED_LONG, XSDULongCoder.INSTANCE); // 64-bits +//// registerCoder(XMLSchema.UNSIGNED_INT, XSDUIntCoder.INSTANCE);// 32-bits +//// registerCoder(XMLSchema.UNSIGNED_SHORT, XSDUShortecimalCoder.INSTANCE); // 16-bits +//// registerCoder(XMLSchema.UNSIGNED_BYTE, XSDUByteCoder.INSTANCE); // 8-bits +// +// // 3.2.4 float +// registerCoder(XMLSchema.FLOAT, XSDFloatCoder.INSTANCE); +// +// // 3.2.5 double +// registerCoder(XMLSchema.DOUBLE, XSDDoubleCoder.INSTANCE); +// +// // 3.2.6 duration Note: not implemented yet per W3C Note. +// +// // @todo 3.2.7 dateTime +//// registerCoder(XMLSchema.DATETIME, XSDDateTimeCoder.INSTANCE); +// // @todo 3.2.8 time +// // @todo 3.2.9 date +// // @todo 3.2.10 gYearMonth +// // @todo 3.2.11 gYear +// // @todo 3.2.12 gMonthDay +// // @todo 3.2.13 gDay +// // @todo 3.2.14 gMonth +// // @todo 3.2.15 hexBinary +// // @todo 3.2.16 base64Binary +// // 3.2.17 anyURI +// registerCoder(XMLSchema.ANYURI, XSDAnyURICoder.INSTANCE); +// // @todo 3.2.18 QName +// // @todo 3.2.19 NOTATION +// +// registerCoder(RDF.XMLLITERAL, XSDXmlLiteralCoder.INSTANCE); +// +// } +// +// } /** - * Handles anything derived from the primitive data type - * {@link XMLSchema#STRING}. Values are coded as Unicode sort keys and - * ARE NOT decodable. - * - * @author <a href="mailto:tho...@us...">Bryan - * Thompson</a> - * @version $Id$ - */ - public static class XSDAnyURICoder implements IDatatypeKeyCoder { - - public static transient final IDatatypeKeyCoder INSTANCE = new XSDAnyURICoder(); - - public int code() { - - return CODE_XSD_ANYURI; - - } - - public String decode(byte[] buf, int off, int len) { - - throw new UnsupportedOperationException(); - - } - - public void encode(IKeyBuilder keyBuilder, String text) { - - keyBuilder.append(text); - - } - - /** No - this class uses Unicode sort keys, which are not decodable. */ - public boolean isDecodable() { - - return false; - - } - - } - - /** - * Handles anything derived from the primitive data type - * {@link RDF#XMLLITERAL}. Values are coded as Unicode sort keys and ARE NOT - * decodable. - * - * @author <a href="mailto:tho...@us...">Bryan - * Thompson</a> - * @version $Id$ - */ - public static class XSDXmlLiteralCoder implements IDatatypeKeyCoder { - - public static transient final IDatatypeKeyCoder INSTANCE = new XSDXmlLiteralCoder(); - - public int code() { - - return CODE_XML_LITERAL; - - } - - public String decode(byte[] buf, int off, int len) { - - throw new UnsupportedOperationException(); - - } - - public void encode(IKeyBuilder keyBuilder, String text) { - - keyBuilder.append(text); - - } - - /** No - this class uses Unicode sort keys, which are not decodable. */ - public boolean isDecodable() { - - return false; - - } - - } - - /** - * Map from the specific datatype URI to the coder instance for that - * datatype. - */ - private static final Map<URI/* datatype */, IDatatypeKeyCoder> coders; - - private static final Map<Integer, IDatatypeKeyCoder> codes; - - synchronized static private void registerCoder(final URI datatype, - IDatatypeKeyCoder newCoder) { - - if (coders == null) - throw new UnsupportedOperationException(); - - if (newCoder == null) - throw new IllegalArgumentException(); - - final int code = newCoder.code(); - - if (codes.containsKey(code)) { - - throw new IllegalStateException( - "Coder already registered for code: code=" + code - + ", val=" + codes.get(code) + ", new=" + newCoder); - - } - - if (coders.containsKey(code)) { - - throw new IllegalStateException( - "Coder already registered for datatype: datatype=" - + datatype + ", val=" + codes.get(code) + ", new=" - + newCoder); - - } - - coders.put(datatype, newCoder); - - codes.put(code, newCoder); - - } - - static { - - if(true) { - - /* - * Disable coders. - * - * FIXME configuration option for coders? Per triple store instance? - * Or are the coders just not compatible with the SPARQL - * specification? - */ - - coders = null; - - codes = null; - - } else { - - // datatype URI to coder map. - coders = new HashMap<URI, IDatatypeKeyCoder>(); - - // code to coder map. - codes = new HashMap<Integer, IDatatypeKeyCoder>(); - - // 3.2.1 string and derived types. - // Note: string is mapped onto plainLiteral by RDF Semantics. -// registerCoder(XMLSchema.STRING, XSDStringCoder.INSTANCE); -// registerCoder(XMLSchema.NORMALIZEDSTRING, XSDStringCoder.INSTANCE); -// registerCoder(XMLSchema.TOKEN, XSDStringCoder.INSTANCE); -// registerCoder(XMLSchema.LANGUAGE, XSDStringCoder.INSTANCE); -// registerCoder(XMLSchema.NAME, XSDStringCoder.INSTANCE); -// registerCoder(XMLSchema.NCNAME, XSDStringCoder.INSTANCE); -// registerCoder(XMLSchema.ID, XSDStringCoder.INSTANCE); -// registerCoder(XMLSchema.IDREF, XSDStringCoder.INSTANCE); -// registerCoder(XMLSchema.IDREFS, XSDStringCoder.INSTANCE); -// registerCoder(XMLSchema.ENTITY, XSDStringCoder.INSTANCE); -// registerCoder(XMLSchema.ENTITIES, XSDStringCoder.INSTANCE); -// registerCoder(XMLSchema.NMTOKEN, XSDStringCoder.INSTANCE); -// registerCoder(XMLSchema.NMTOKENS, XSDStringCoder.INSTANCE); - - // 3.2.2 boolean - registerCoder(XMLSchema.BOOLEAN, XSDBooleanCoder.INSTANCE); - - // 3.2.3 decimal and derived types. - - /* - * @todo decimal really needs to be a BigDecimal representation if such - * a thing can be mapped onto a totally ordered unsigned byte[] key. - * Failing that, it needs to be projected to a maximum magnitude fixed - * byte length representation. Failing that, all comparison of order - * must be done by the SPARQL engine. - */ -// registerCoder(XMLSchema.DECIMAL, XSDDecimalCoder.INSTANCE); - - /* - * @todo integer really needs to be a BigInteger representation if such - * a thing can be mapped onto a totally ordered unsigned byte[] key - * (negative integers always appear to be larger than positive integers - * with naive encoding). Failing that, it needs to be projected to a - * maximum magnitude fixed byte length representation. Failing that, all - * comparison of order must be done by the SPARQL engine. - */ -// registerCoder(XMLSchema.INTEGER, XSDDecimalCoder.INSTANCE); -// registerCoder(XMLSchema.POSITIVE_INTEGER, XSDDecimalCoder.INSTANCE); -// registerCoder(XMLSchema.NON_POSITIVE_INTEGER, XSDDecimalCoder.INSTANCE); -// registerCoder(XMLSchema.NON_NEGATIVE_INTEGER, XSDDecimalCoder.INSTANCE); - - /* - * These are all fixed width signed datatypes. Each has its own code and - * its own disjoint value space. - */ - registerCoder(XMLSchema.LONG, XSDLongCoder.INSTANCE); // 64-bits - registerCoder(XMLSchema.INT, XSDIntCoder.INSTANCE); // 32-bits - registerCoder(XMLSchema.SHORT, XSDShortCoder.INSTANCE); // 16-bits - registerCoder(XMLSchema.BYTE, XSDByteCoder.INSTANCE); // 8 bits. - /* - * These are all fixed width unsigned datatypes. Each has its own code - * and its own disjoint value space. - * - * @todo unsigned long - * @todo unsigned int - * @todo unsigned short - * @todo unsigned byte - */ -// registerCoder(XMLSchema.UNSIGNED_LONG, XSDULongCoder.INSTANCE); // 64-bits -// registerCoder(XMLSchema.UNSIGNED_INT, XSDUIntCoder.INSTANCE);// 32-bits -// registerCoder(XMLSchema.UNSIGNED_SHORT, XSDUShortecimalCoder.INSTANCE); // 16-bits -// registerCoder(XMLSchema.UNSIGNED_BYTE, XSDUByteCoder.INSTANCE); // 8-bits - - // 3.2.4 float - registerCoder(XMLSchema.FLOAT, XSDFloatCoder.INSTANCE); - - // 3.2.5 double - registerCoder(XMLSchema.DOUBLE, XSDDoubleCoder.INSTANCE); - - // 3.2.6 duration Note: not implemented yet per W3C Note. - - // @todo 3.2.7 dateTime -// registerCoder(XMLSchema.DATETIME, XSDDateTimeCoder.INSTANCE); - // @todo 3.2.8 time - // @todo 3.2.9 date - // @todo 3.2.10 gYearMonth - // @todo 3.2.11 gYear - // @todo 3.2.12 gMonthDay - // @todo 3.2.13 gDay - // @todo 3.2.14 gMonth - // @todo 3.2.15 hexBinary - // @todo 3.2.16 base64Binary - // 3.2.17 anyURI - registerCoder(XMLSchema.ANYURI, XSDAnyURICoder.INSTANCE); - // @todo 3.2.18 QName - // @todo 3.2.19 NOTATION - - registerCoder(RDF.XMLLITERAL, XSDXmlLiteralCoder.INSTANCE); - - } - - } - - /** * Normally invoked by {@link Term2IdTupleSerializer#getLexiconKeyBuilder()} * * @param keyBuilder @@ -972,7 +967,7 @@ } - if (coders == null) { +// if (coders == null) { /* * Note: This is the original DTL code space. The full lexical form @@ -995,52 +990,52 @@ return keyBuilder.getKey(); - } else { +// } else { +// +// // clear out any existing key and add prefix for the DTL space. +// keyBuilder.reset().append(TERM_CODE_DTL2); +// +// final IDatatypeKeyCoder coder = coders.get(datatype); +// +// if (coder == null) { +// +// /* +// * Unknown datatypes are placed into a disjoint space first, for +// * all unknown data types, and second, for the specific data +// * type using its URI encoded as a sort key. Finally, the +// * unknown data type value is encoded on the key. +// */ +// +// // disjoint value space for all unknown data type URIs. +// keyBuilder.append(IDatatypeKeyCoder.CODE_OTHER); +// +// // encode the datatype URI as Unicode sort key to make all +// ... [truncated message content] |
From: <tho...@us...> - 2010-07-26 14:24:25
|
Revision: 3288 http://bigdata.svn.sourceforge.net/bigdata/?rev=3288&view=rev Author: thompsonbry Date: 2010-07-26 14:24:18 +0000 (Mon, 26 Jul 2010) Log Message: ----------- Working through xsd:decimal issues with MartynC. Moved much of the byteLength() logic for xsd:integer and xsd:decimal onto KeyBuilder. Modified Paths: -------------- branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/btree/keys/KeyBuilder.java branches/LEXICON_REFACTOR_BRANCH/bigdata/src/test/com/bigdata/btree/keys/TestKeyBuilder.java branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/XSDDecimalIV.java branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/XSDIntegerIV.java Modified: branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/btree/keys/KeyBuilder.java =================================================================== --- branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/btree/keys/KeyBuilder.java 2010-07-26 02:16:07 UTC (rev 3287) +++ branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/btree/keys/KeyBuilder.java 2010-07-26 14:24:18 UTC (rev 3288) @@ -247,7 +247,7 @@ * {@link #buf buffer} may be grown by this operation but it will not be * truncated. * <p> - * This operation is equivilent to + * This operation is equivalent to * * <pre> * ensureCapacity(this.len + len) @@ -945,28 +945,57 @@ } - // The encoding ot a BigDecimal requires the expression - // of scale and length - // BigDecimal.scale indicates the precision of the number, where - // '3' is three decimal places and '-3' rounded to '000' - // BigDecimal.precision() is the number of unscaled digits - // therefore the precision - scale is an expression of the - // exponent of the normalised number. - // This means that the exponent could be zero or negative so the sign of the - // number cannot be indicated by adding to the exponent. - // Instead an explicit sign byte,'0' or '1' is used. - // The actual BigDecimal serialization uses the String conversions - // supported by BigDecimal, less the '-' sign character if applicable. - // The length of this data is terminated by a zero byte. - // - // The variable encoding of BigNumbers requires this String representation - // and negative representations are further encoded using flipDigits - // for the equivalent of 2s compliment negative representation. - + /** + * Return the #of bytes in the unsigned byte[] representation of the + * {@link BigInteger} value. + * + * @param value + * The {@link BigInteger} value. + * + * @return The byte length of its unsigned byte[] representation. + */ + static public int byteLength(final BigInteger value) { + + return 2/* runLength */+ (value.bitLength() / 8 + 1)/* data */; + + } + + /** + * {@inheritDoc} + * <p> + * Note: Precision is NOT preserved by this encoding. + * <h2>Implementation details</h2> + * The encoding to a BigDecimal requires the expression of scale and length + * {@link BigDecimal#scale()} indicates the precision of the number, where + * '3' is three decimal places and '-3' rounded to '000' + * {@link BigDecimal#precision()} is the number of unscaled digits therefore + * <code>precision - scale</code> is an expression of the exponent of the + * normalized number. This means that the exponent could be zero or negative + * so the sign of the number cannot be indicated by adding to the exponent. + * Instead an explicit sign byte,'0' or '1' is used. The actual + * {@link BigDecimal} serialization uses the {@link String} conversions + * supported by {@link BigDecimal}, less the '-' sign character if + * applicable. The length of this data is terminated by a trailing byte. The + * value of that byte depends on the sign of the original {@link BigDecimal} + * and is used to impose the correct sort order on negative + * {@link BigDecimal} values which differ only in the digits in the decimal + * portion. + *<p> + * The variable encoding of BigNumbers requires this String representation + * and negative representations are further encoded using + * {@link #flipDigits(String)} for the equivalent of 2s compliment negative + * representation. + * + * @todo document the handling of trailing zeros. these are normalized out + * as they reflect a quality of precision which is not preserved by + * the corresponding sort key. + * + * @see #decodeBigDecimal(int, byte[]) + */ public KeyBuilder append(final BigDecimal d) { - int sign = d.signum(); - int precision = d.precision(); - int scale = d.scale(); + final int sign = d.signum(); + final int precision = d.precision(); + final int scale = d.scale(); int exponent = precision - scale; if (sign == -1) { exponent = -exponent; @@ -975,16 +1004,43 @@ append((byte) sign); append(exponent); + // Note: coded as digits String unscaledStr = d.unscaledValue().toString(); if (sign == -1) { unscaledStr = flipDigits(unscaledStr); } appendASCII(unscaledStr); // the unscaled BigInteger representation - append((byte) 0); + // Note: uses unsigned 255 if negative and unsigned 0 if positive. + append(sign == -1 ? (byte) Byte.MAX_VALUE: (byte) 0); return this; } + /** + * Return the #of bytes in the unsigned byte[] representation of the + * {@link BigDecimal} value. + * + * @param value + * The {@link BigDecimal} value. + * + * @return The byte length of its unsigned byte[] representation. + */ + static public int byteLength(final BigDecimal value) { + + // FIXME Make sure to normalize trailing zeros first if necessary. + final int dataLen = value.unscaledValue().toString().length(); + + final int byteLength = + + 1 /* sign */ + + 4 /* exponent */ + + dataLen /* data */ + + 1 /* termination byte */ + ; + + return byteLength; + + } + /* * static helper methods. */ @@ -1420,47 +1476,73 @@ } - private static final byte eos = decodeByte(0); - private static final byte negSign = decodeByte(-1); - - // FIXME decodeBigDecimal(int, byte[]) + /** + * Decodes a {@link BigDecimal} key, returning a byte[] which may be used to + * construct a {@link BigDecimal} having the decoded value. + * + * The number of bytes consumed by the key component is + * <code>2 + runLength</2>. The + * <code>2</code> is a fixed length field coding the signum of the value and + * its runLength. The length of the returned array is the runLength of the + * variable length portion of the value. + * + * This method may be used to scan through a key containing + * {@link BigDecimal} components. + * + * @param offset + * The offset of the start of the {@link BigDecimal} in the key. + * @param key + * The key. + * @return The byte[] to be passed to {@link BigDecimal#BigInteger(byte[])}. + * + * @todo update javadoc + * + * FIXME We need a version which has all the metadata to support scanning + * through a key as well as one that does a simple decode. + */ static public BigDecimal decodeBigDecimal(final int offset, final byte[] key) { int curs = offset; - byte sign = key[curs++]; + final byte sign = key[curs++]; int exponent = decodeInt(key, curs); - boolean neg = sign == negSign; + final boolean neg = sign == negSign; if (neg) { exponent = -exponent; } curs += 4; int len = 0; - for (int i = curs; key[i] != eos; i++) len++; + for (int i = curs; key[i] != (neg ? eos2 : eos); i++) len++; String unscaledStr = decodeASCII(key, curs, len); if (neg) { unscaledStr = flipDigits(unscaledStr); } - BigInteger unscaled = new BigInteger(unscaledStr); + final BigInteger unscaled = new BigInteger(unscaledStr); - int precision = len; - int scale = precision - exponent - (neg ? 1 : 0); + final int precision = len; + final int scale = precision - exponent - (neg ? 1 : 0); - BigDecimal ret = new BigDecimal(unscaled, scale); + final BigDecimal ret = new BigDecimal(unscaled, scale); return ret; // relative scale adjustment } - static final char[] flipMap = {'0', '1', '2', '3', '4', + private static final byte eos = decodeByte(0); + private static final byte eos2 = decodeByte(Byte.MAX_VALUE); + private static final byte negSign = decodeByte(-1); + + private static final char[] flipMap = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; - - /* - * Flip numbers such that 0/9,1/8,2/7,3/6,4/5 + + /** + * Flip numbers such that <code>0/9,1/8,2/7,3/6,4/5</code> - this is the + * equivalent of a two-complement representation for the base 10 character + * digits. */ - static private String flipDigits(String str) { - char[] chrs = str.toCharArray(); + static private String flipDigits(final String str) { + final char[] chrs = str.toCharArray(); for (int i = 0; i < chrs.length; i++) { - int flip = '9' - chrs[i]; + final int flip = '9' - chrs[i]; if (flip >= 0 && flip < 10) { chrs[i] = flipMap[flip]; } Modified: branches/LEXICON_REFACTOR_BRANCH/bigdata/src/test/com/bigdata/btree/keys/TestKeyBuilder.java =================================================================== --- branches/LEXICON_REFACTOR_BRANCH/bigdata/src/test/com/bigdata/btree/keys/TestKeyBuilder.java 2010-07-26 02:16:07 UTC (rev 3287) +++ branches/LEXICON_REFACTOR_BRANCH/bigdata/src/test/com/bigdata/btree/keys/TestKeyBuilder.java 2010-07-26 14:24:18 UTC (rev 3288) @@ -1995,8 +1995,52 @@ } } - + /** + * Test with positive and negative {@link BigInteger}s having a common + * prefix with varying digits after the prefix. + */ + public void test_BigInteger_sortOrder() { + + final BigInteger p1 = new BigInteger("15"); + final BigInteger p2 = new BigInteger("151"); + final BigInteger m1 = new BigInteger("-15"); + final BigInteger m2 = new BigInteger("-151"); + + doEncodeDecodeTest(p1); + doEncodeDecodeTest(p2); + doEncodeDecodeTest(m1); + doEncodeDecodeTest(m2); + + doLTTest(p1, p2); // 15 LT 151 + doLTTest(m1, p1); // -15 LT 15 + doLTTest(m2, m1); // -151 LT -15 + + } + + /** + * Test with positive and negative {@link BigDecimal}s having varying + * digits after the decimals. + */ + public void test_BigDecimal_negativeSortOrder() { + + final BigDecimal p1 = new BigDecimal("1.5"); + final BigDecimal p2 = new BigDecimal("1.51"); + final BigDecimal m1 = new BigDecimal("-1.5"); + final BigDecimal m2 = new BigDecimal("-1.51"); + + doEncodeDecodeTest(p1); + doEncodeDecodeTest(p2); + doEncodeDecodeTest(m1); + doEncodeDecodeTest(m2); + + doLTTest(p1, p2); // 1.5 LT 1.51 + doLTTest(m1, p1); // -1.5 LT 1.5 + doLTTest(m2, m1); // -1.51 LT -1.5 + + } + + /** * Stress test with random byte[]s from which we then construct * {@link BigInteger}s. */ @@ -2074,12 +2118,8 @@ /** * Stress test with random byte[]s from which we then construct * {@link BigDecimal}s. - * - * FIXME: At present the comparisons fail proably due to a failure to - * understand the limits of the BigDecimal representations - so this - * test has been deactivated by name prefix. */ - public void badTest_BigDecimal_stress_byteArray_values() { + public void test_BigDecimal_stress_byteArray_values() { final Random r = new Random(); @@ -2211,48 +2251,48 @@ // return key; // // } -// -// /** -// * Normalize the {@link BigDecimal} by setting the scale such that there are -// * no digits before the decimal point. -// * -// * FIXME This fails for "0" and "0.0". The trailing .0 is considered a -// * significant digit and is not being stripped. We need to also strip -// * trailing zeros which are significant. -// * -// * <pre> -// * i=0 (scale=0,prec=1) : 0, scale=0, precision=1, unscaled=0, unscaled_byte[]=[0] -// * i=0.0 (scale=1,prec=1) : 0.0, scale=1, precision=1, unscaled=0, unscaled_byte[]=[0] -// * </pre> -// */ -// private BigDecimal normalizeBigDecimal(final BigDecimal i) { -// -// return i.stripTrailingZeros(); -// -// } -// -// /** -// * Dumps out interesting bits of the {@link BigDecimal} state. -// * -// * @return The dump. -// */ -// private String dumpBigDecimal(final BigDecimal i) { -// -// final BigInteger unscaled = i.unscaledValue(); -// -// final String msg = i.toString() + ", scale=" + i.scale() -// + // -// ", precision=" + i.precision() -// + // -// ", unscaled=" + unscaled -// + // -// ", unscaled_byte[]=" -// + BytesUtil.toString(unscaled.toByteArray())// -// ; -// -// return msg; -// -// } + + /** + * Normalize the {@link BigDecimal} by setting the scale such that there are + * no digits before the decimal point. + * + * FIXME This fails for "0" and "0.0". The trailing .0 is considered a + * significant digit and is not being stripped. We need to also strip + * trailing zeros which are significant. + * + * <pre> + * i=0 (scale=0,prec=1) : 0, scale=0, precision=1, unscaled=0, unscaled_byte[]=[0] + * i=0.0 (scale=1,prec=1) : 0.0, scale=1, precision=1, unscaled=0, unscaled_byte[]=[0] + * </pre> + */ + private BigDecimal normalizeBigDecimal(final BigDecimal i) { + + return i.stripTrailingZeros(); + + } + + /** + * Dumps out interesting bits of the {@link BigDecimal} state. + * + * @return The dump. + */ + private String dumpBigDecimal(final BigDecimal i) { + + final BigInteger unscaled = i.unscaledValue(); + + final String msg = i.toString() + ", scale=" + i.scale() + + // + ", precision=" + i.precision() + + // + ", unscaled=" + unscaled + + // + ", unscaled_byte[]=" + + BytesUtil.toString(unscaled.toByteArray())// + ; + + return msg; + + } // // /** // * Note: must have normalized representation of the BigDecimal to do @@ -2308,101 +2348,101 @@ // // } // -// private enum CompareEnum { -// -// LT(-1), EQ(0), GT(1); -// -// private CompareEnum(final int ret) { -// this.ret = ret; -// } -// -// private int ret; -// -// static public CompareEnum valueOf(final int ret) { -// if(ret<0) return LT; -// if(ret>0) return GT; -// return EQ; -// } -// -// } -// -// protected void doCompareTest(BigDecimal i1, BigDecimal i2, final CompareEnum cmp) { -// -// i1 = normalizeBigDecimal(i1); -// i2 = normalizeBigDecimal(i2); -// -// final byte[] k1 = encodeBigDecimal(i1); -// -// final byte[] k2 = encodeBigDecimal(i2); -// -// final int ret = BytesUtil.compareBytes(k1, k2); -// -// final CompareEnum cmp2 = CompareEnum.valueOf(ret); -// -// if (cmp2 != cmp) { -// -// fail("BigDecimal" + // -// "\ni1=" + dumpBigDecimal(i1) + // -// "\ni2=" + dumpBigDecimal(i2) + // -// "\nk1=" + BytesUtil.toString(k1) + // -// "\nk2=" + BytesUtil.toString(k2) + // -// "\nret=" + cmp2 +", but expected="+cmp// -// ); -// -// } -// -// } -// -// /** -// * Test encode/decode for various values of zero. -// */ -// public void test_BigDecimal0() { -// -// final BigDecimal[] a = new BigDecimal[] { -// new BigDecimal("0"), // scale=0, precision=1 -// new BigDecimal("0."), // scale=0, precision=1 -// new BigDecimal("0.0"), // scale=1, precision=1 -// new BigDecimal("0.00"), // scale=2, precision=1 -// new BigDecimal("00.0"), // scale=1, precision=1 -// new BigDecimal("00.00"),// scale=2, precision=1 -// new BigDecimal(".0"), // scale=1, precision=1 -// // NB: The precision is the #of decimal digits in the unscaled value. -// // NB: scaled := unscaled * (10 ^ -scale) -// new BigDecimal(".010"), // scale=3, precision=2 -// new BigDecimal(".01"), // scale=2, precision=1 -// new BigDecimal(".1"), // scale=1, precision=1 -// new BigDecimal("1."), // scale=0, precision=1 -// new BigDecimal("10."), // scale=0, precision=2 -// new BigDecimal("10.0"), // scale=1, precision=3 -// new BigDecimal("010.0"), // scale=1, precision=3 -// new BigDecimal("0010.00"), // scale=2, precision=4 -// // @todo Test with cases where scale is negative (large powers of 10). -// }; -// -// for (BigDecimal i : a) { -// i = i.stripTrailingZeros(); -// System.err.println("i=" -// + i -// + "\t(scale=" -// + i.scale() -// + ",prec=" -// + i.precision() -// + ") : " -// + dumpBigDecimal(i) -//// i.scaleByPowerOfTen(i.scale()- i.precision())) -// ); -// } -// -// for (BigDecimal i : a) { -// doEncodeDecodeTest(i); -// } -// -// for (int i = 0; i < a.length; i++) { -// for (int j = 0; j < a.length; j++) { -// doCompareTest(a[i], a[j], CompareEnum.EQ); -// } -// } -// -// } + private enum CompareEnum { + + LT(-1), EQ(0), GT(1); + + private CompareEnum(final int ret) { + this.ret = ret; + } + + private int ret; + + static public CompareEnum valueOf(final int ret) { + if(ret<0) return LT; + if(ret>0) return GT; + return EQ; + } + + } + + protected void doCompareTest(BigDecimal i1, BigDecimal i2, final CompareEnum cmp) { + + i1 = normalizeBigDecimal(i1); + i2 = normalizeBigDecimal(i2); + + final byte[] k1 = encodeBigDecimal(i1); + + final byte[] k2 = encodeBigDecimal(i2); + + final int ret = BytesUtil.compareBytes(k1, k2); + + final CompareEnum cmp2 = CompareEnum.valueOf(ret); + + if (cmp2 != cmp) { + + fail("BigDecimal" + // + "\ni1=" + dumpBigDecimal(i1) + // + "\ni2=" + dumpBigDecimal(i2) + // + "\nk1=" + BytesUtil.toString(k1) + // + "\nk2=" + BytesUtil.toString(k2) + // + "\nret=" + cmp2 +", but expected="+cmp// + ); + + } + + } + + /** + * Test encode/decode for various values of zero. + */ + public void test_BigDecimal0() { + + final BigDecimal[] a = new BigDecimal[] { + new BigDecimal("0"), // scale=0, precision=1 + new BigDecimal("0."), // scale=0, precision=1 + new BigDecimal("0.0"), // scale=1, precision=1 + new BigDecimal("0.00"), // scale=2, precision=1 + new BigDecimal("00.0"), // scale=1, precision=1 + new BigDecimal("00.00"),// scale=2, precision=1 + new BigDecimal(".0"), // scale=1, precision=1 + // NB: The precision is the #of decimal digits in the unscaled value. + // NB: scaled := unscaled * (10 ^ -scale) + new BigDecimal(".010"), // scale=3, precision=2 + new BigDecimal(".01"), // scale=2, precision=1 + new BigDecimal(".1"), // scale=1, precision=1 + new BigDecimal("1."), // scale=0, precision=1 + new BigDecimal("10."), // scale=0, precision=2 + new BigDecimal("10.0"), // scale=1, precision=3 + new BigDecimal("010.0"), // scale=1, precision=3 + new BigDecimal("0010.00"), // scale=2, precision=4 + // @todo Test with cases where scale is negative (large powers of 10). + }; + + for (BigDecimal i : a) { + i = i.stripTrailingZeros(); + System.err.println("i=" + + i + + "\t(scale=" + + i.scale() + + ",prec=" + + i.precision() + + ") : " + + dumpBigDecimal(i) +// i.scaleByPowerOfTen(i.scale()- i.precision())) + ); + } + + for (BigDecimal i : a) { + doEncodeDecodeTest(i); + } + + for (int i = 0; i < a.length; i++) { + for (int j = 0; j < a.length; j++) { + doCompareTest(a[i], a[j], CompareEnum.EQ); + } + } + + } } Modified: branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/XSDDecimalIV.java =================================================================== --- branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/XSDDecimalIV.java 2010-07-26 02:16:07 UTC (rev 3287) +++ branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/XSDDecimalIV.java 2010-07-26 14:24:18 UTC (rev 3288) @@ -27,7 +27,7 @@ import java.math.BigDecimal; import java.math.BigInteger; -import com.bigdata.rawstore.Bytes; +import com.bigdata.btree.keys.KeyBuilder; import com.bigdata.rdf.model.BigdataLiteral; import com.bigdata.rdf.model.BigdataValueFactory; @@ -137,23 +137,18 @@ } public int byteLength() { + if (byteLength == 0) { /* * Cache the byteLength if not yet set. */ - int dataLen = value.unscaledValue().toString().length(); - - byteLength = - 1 /* flags */ - + 1 /* sign */ - + 4 /* exponent */ - + dataLen - + 1 /* data and null termination */; + byteLength = 1 /* flags */ + KeyBuilder.byteLength(value); } return byteLength; + } @Override Modified: branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/XSDIntegerIV.java =================================================================== --- branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/XSDIntegerIV.java 2010-07-26 02:16:07 UTC (rev 3287) +++ branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/XSDIntegerIV.java 2010-07-26 14:24:18 UTC (rev 3288) @@ -27,6 +27,7 @@ import java.math.BigDecimal; import java.math.BigInteger; +import com.bigdata.btree.keys.KeyBuilder; import com.bigdata.rdf.model.BigdataLiteral; import com.bigdata.rdf.model.BigdataValueFactory; @@ -143,7 +144,7 @@ * Cache the byteLength if not yet set. */ - byteLength = 1 /* prefix */+ 2/* runLength */+ (value.bitLength() / 8 + 1)/* data */; + byteLength = 1 /* prefix */+ KeyBuilder.byteLength(value); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <tho...@us...> - 2010-07-26 18:15:16
|
Revision: 3295 http://bigdata.svn.sourceforge.net/bigdata/?rev=3295&view=rev Author: thompsonbry Date: 2010-07-26 18:15:10 +0000 (Mon, 26 Jul 2010) Log Message: ----------- Added / simplified explicit versioning. Modified Paths: -------------- branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/btree/DefaultTupleSerializer.java branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/lexicon/Id2TermTupleSerializer.java Modified: branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/btree/DefaultTupleSerializer.java =================================================================== --- branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/btree/DefaultTupleSerializer.java 2010-07-26 18:14:42 UTC (rev 3294) +++ branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/btree/DefaultTupleSerializer.java 2010-07-26 18:15:10 UTC (rev 3295) @@ -308,20 +308,42 @@ } - public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + /** + * The initial version. + * <p> + * Note: Explicit versioning for the {@link DefaultTupleSerializer} was + * introduced with inlining of datatype literals for the RDF database. + */ + private final static transient int VERSION0 = 0; - delegateKeyBuilderFactory = (IKeyBuilderFactory)in.readObject(); - - threadLocalKeyBuilderFactory = new ThreadLocalKeyBuilderFactory(delegateKeyBuilderFactory); - - leafKeysCoder = (IRabaCoder) in.readObject(); + /** + * The current version. + */ + private final static transient int VERSION = VERSION0; - leafValsCoder = (IRabaCoder) in.readObject(); + public void readExternal(final ObjectInput in) throws IOException, + ClassNotFoundException { + final short version = in.readShort(); + switch (version) { + case VERSION0: + delegateKeyBuilderFactory = (IKeyBuilderFactory) in.readObject(); + threadLocalKeyBuilderFactory = new ThreadLocalKeyBuilderFactory( + delegateKeyBuilderFactory); + leafKeysCoder = (IRabaCoder) in.readObject(); + leafValsCoder = (IRabaCoder) in.readObject(); + break; + default: + throw new UnsupportedOperationException("Unknown version: " + + version); + } + } - public void writeExternal(ObjectOutput out) throws IOException { + public void writeExternal(final bjectOutput out) throws IOException { + out.writeShort(VERSION); + out.writeObject(delegateKeyBuilderFactory); out.writeObject(leafKeysCoder); Modified: branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/lexicon/Id2TermTupleSerializer.java =================================================================== --- branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/lexicon/Id2TermTupleSerializer.java 2010-07-26 18:14:42 UTC (rev 3294) +++ branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/lexicon/Id2TermTupleSerializer.java 2010-07-26 18:15:10 UTC (rev 3295) @@ -32,7 +32,9 @@ import java.io.ObjectOutput; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; + import org.openrdf.model.Value; + import com.bigdata.btree.DefaultTupleSerializer; import com.bigdata.btree.ITuple; import com.bigdata.btree.keys.ASCIIKeyBuilderFactory; @@ -202,55 +204,30 @@ return tmp; } - + /** - * Included only the UTF serialization of the namespace field without - * explicit version support. - * * <pre> + * valueFactoryClass:UTF * namespace:UTF * </pre> */ static final transient short VERSION0 = 0; - /** - * Added the UTF serialization of the class name of the value factory - * and an explicit version number in the serialization format. This - * version is detected by a read of an empty string from the original - * UTF field. - * - * <pre> - * "":UTF - * valueFactoryClass:UTF - * namespace:UTF - * </pre> - * - * Note: THere are unit tests for this backward compatible serialization - * change in TestId2TermTupleSerializer. - */ - static final transient short VERSION1 = 1; + private static final transient short VERSION = VERSION0; - private static final transient short VERSION = VERSION1; - - public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { super.readExternal(in); - short version = VERSION0; - String s1 = in.readUTF(); - String s2 = BigdataValueFactoryImpl.class.getName(); - if (s1.length() == 0) { - version = in.readShort(); - s1 = in.readUTF(); - s2 = in.readUTF(); - } + final short version = in.readShort(); + final String namespace; + final String valueFactoryClass; switch (version) { case VERSION0: - case VERSION1: + namespace = in.readUTF(); + valueFactoryClass = in.readUTF(); break; default: throw new IOException("unknown version=" + version); } - final String namespace = s1; - final String valueFactoryClass = s2; // set the namespace field. this.namespace = namespace; // resolve the valueSerializer from the value factory class. @@ -275,18 +252,14 @@ valueSer = this.valueFactory.getValueSerializer(); } - public void writeExternal(ObjectOutput out) throws IOException { + public void writeExternal(final ObjectOutput out) throws IOException { super.writeExternal(out); final short version = VERSION; final String valueFactoryClass = valueFactory.getClass().getName(); + out.writeShort(version); switch (version) { case VERSION0: out.writeUTF(namespace); - break; - case VERSION1: - out.writeUTF(""); - out.writeShort(version); - out.writeUTF(namespace); out.writeUTF(valueFactoryClass); break; default: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <tho...@us...> - 2010-07-26 19:32:06
|
Revision: 3299 http://bigdata.svn.sourceforge.net/bigdata/?rev=3299&view=rev Author: thompsonbry Date: 2010-07-26 19:31:59 +0000 (Mon, 26 Jul 2010) Log Message: ----------- Added explicit version control to a number of Externalizable implementations. Modified Paths: -------------- branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/btree/proc/AbstractKeyArrayIndexProcedure.java branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/mdi/IndexPartitionCause.java branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/relation/accesspath/SameVariableConstraint.java branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/relation/rule/eval/DefaultRuleTaskFactory.java branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/service/proxy/RemoteAsynchronousIteratorImpl.java branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/service/proxy/RemoteChunk.java branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/sparse/AbstractAtomicRowReadOrWrite.java branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/axioms/BaseAxioms.java branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/inf/RdfTypeRdfsResourceFilter.java branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/lexicon/Term2IdTupleSerializer.java branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/spo/InGraphBinarySearchFilter.java branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/vocab/BaseVocabulary.java branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/spo/TestSPOValueCoders.java Removed Paths: ------------- branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/spo/FastRDFValueCoder.java Modified: branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/btree/proc/AbstractKeyArrayIndexProcedure.java =================================================================== --- branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/btree/proc/AbstractKeyArrayIndexProcedure.java 2010-07-26 19:14:39 UTC (rev 3298) +++ branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/btree/proc/AbstractKeyArrayIndexProcedure.java 2010-07-26 19:31:59 UTC (rev 3299) @@ -677,6 +677,16 @@ public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { + final byte version = in.readByte(); + + switch (version) { + case VERSION0: + break; + default: + throw new UnsupportedOperationException("Unknown version: " + + version); + } + final InputBitStream ibs = new InputBitStream((InputStream) in, 0/* unbuffered */, false/* reflectionTest */); @@ -699,6 +709,8 @@ public void writeExternal(final ObjectOutput out) throws IOException { + out.writeByte(VERSION); + final OutputBitStream obs = new OutputBitStream((OutputStream) out, 0/* unbuffered! */, false/*reflectionTest*/); @@ -716,6 +728,16 @@ } + /** + * The initial version. + */ + private static final transient byte VERSION0 = 0; + + /** + * The current version. + */ + private static final transient byte VERSION = VERSION0; + } /** Modified: branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/mdi/IndexPartitionCause.java =================================================================== --- branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/mdi/IndexPartitionCause.java 2010-07-26 19:14:39 UTC (rev 3298) +++ branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/mdi/IndexPartitionCause.java 2010-07-26 19:31:59 UTC (rev 3299) @@ -189,9 +189,24 @@ } + /** + * The initial version. + */ + private static final transient byte VERSION0 = 0; + + /** + * The current version. + */ + private static final transient byte VERSION = VERSION0; + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + final byte version = in.readByte(); + + if (version != VERSION0) + throw new UnsupportedOperationException("version=" + version); + cause = CauseEnum.valueOf(in.readByte()); synchronousOverflowCounter = in.readLong(); @@ -202,6 +217,7 @@ public void writeExternal(ObjectOutput out) throws IOException { + out.writeByte(VERSION); out.writeByte(cause.code); out.writeLong(synchronousOverflowCounter); out.writeLong(lastCommitTime); Modified: branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/relation/accesspath/SameVariableConstraint.java =================================================================== --- branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/relation/accesspath/SameVariableConstraint.java 2010-07-26 19:14:39 UTC (rev 3298) +++ branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/relation/accesspath/SameVariableConstraint.java 2010-07-26 19:31:59 UTC (rev 3299) @@ -183,10 +183,30 @@ } + /** + * The initial version. + */ + private static final transient byte VERSION0 = 0; + + /** + * The current version. + */ + private static final transient byte VERSION = VERSION0; + @SuppressWarnings("unchecked") public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + final short version = in.readByte(); + + switch (version) { + case VERSION0: + break; + default: + throw new UnsupportedOperationException("Unknown version: " + + version); + } + p = (IPredicate<E>) in.readObject(); final int len = (int) LongPacker.unpackLong(in); @@ -203,6 +223,8 @@ public void writeExternal(ObjectOutput out) throws IOException { + out.writeByte(VERSION); + out.writeObject(p); LongPacker.packLong(out, indices.length); Modified: branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/relation/rule/eval/DefaultRuleTaskFactory.java =================================================================== --- branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/relation/rule/eval/DefaultRuleTaskFactory.java 2010-07-26 19:14:39 UTC (rev 3298) +++ branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/relation/rule/eval/DefaultRuleTaskFactory.java 2010-07-26 19:31:59 UTC (rev 3299) @@ -134,15 +134,37 @@ } + /** + * The initial version. + */ + private static final transient byte VERSION0 = 0; + + /** + * The current version. + */ + private static final transient byte VERSION = VERSION0; + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + final byte version = in.readByte(); + + switch (version) { + case VERSION0: + break; + default: + throw new UnsupportedOperationException("Unknown version: " + + version); + } + subquery = in.readBoolean(); } public void writeExternal(ObjectOutput out) throws IOException { + out.writeByte(VERSION); + out.writeBoolean(subquery); } Modified: branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/service/proxy/RemoteAsynchronousIteratorImpl.java =================================================================== --- branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/service/proxy/RemoteAsynchronousIteratorImpl.java 2010-07-26 19:14:39 UTC (rev 3298) +++ branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/service/proxy/RemoteAsynchronousIteratorImpl.java 2010-07-26 19:31:59 UTC (rev 3299) @@ -195,8 +195,28 @@ } + /** + * The initial version. + */ + private static final transient byte VERSION0 = 0; + + /** + * The current version. + */ + private static final transient byte VERSION = VERSION0; + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + final byte version = in.readByte(); + + switch (version) { + case VERSION0: + break; + default: + throw new UnsupportedOperationException("Unknown version: " + + version); + } ser = (IStreamSerializer<E>) in.readObject(); @@ -206,6 +226,8 @@ public void writeExternal(ObjectOutput out) throws IOException { + out.writeByte(VERSION); + out.writeObject(ser); ser.serialize(out, e); Modified: branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/service/proxy/RemoteChunk.java =================================================================== --- branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/service/proxy/RemoteChunk.java 2010-07-26 19:14:39 UTC (rev 3298) +++ branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/service/proxy/RemoteChunk.java 2010-07-26 19:31:59 UTC (rev 3299) @@ -89,8 +89,28 @@ } + /** + * The initial version. + */ + private static final transient byte VERSION0 = 0; + + /** + * The current version. + */ + private static final transient byte VERSION = VERSION0; + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + final byte version = in.readByte(); + + switch (version) { + case VERSION0: + break; + default: + throw new UnsupportedOperationException("Unknown version: " + + version); + } + // true iff exhausted. exhausted = in.readBoolean(); @@ -114,6 +134,8 @@ public void writeExternal(ObjectOutput out) throws IOException { + out.writeByte(VERSION); + out.writeBoolean(exhausted); // true iff there are any elements in this chunk. Modified: branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/sparse/AbstractAtomicRowReadOrWrite.java =================================================================== --- branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/sparse/AbstractAtomicRowReadOrWrite.java 2010-07-26 19:14:39 UTC (rev 3298) +++ branches/LEXICON_REFACTOR_BRANCH/bigdata/src/java/com/bigdata/sparse/AbstractAtomicRowReadOrWrite.java 2010-07-26 19:31:59 UTC (rev 3299) @@ -426,9 +426,29 @@ } + /** + * The initial version. + */ + private static final transient byte VERSION0 = 0; + + /** + * The current version. + */ + private static final transient byte VERSION = VERSION0; + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + final byte version = in.readByte(); + + switch (version) { + case VERSION0: + break; + default: + throw new UnsupportedOperationException("Unknown version: " + + version); + } + schema = (Schema) in.readObject(); primaryKey = in.readObject(); @@ -442,7 +462,9 @@ } public void writeExternal(ObjectOutput out) throws IOException { - + + out.writeByte(VERSION); + out.writeObject(schema); out.writeObject(primaryKey); Modified: branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/axioms/BaseAxioms.java =================================================================== --- branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/axioms/BaseAxioms.java 2010-07-26 19:14:39 UTC (rev 3298) +++ branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/axioms/BaseAxioms.java 2010-07-26 19:31:59 UTC (rev 3299) @@ -294,8 +294,29 @@ } - public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { - + /** + * The initial version. + */ + private static final transient byte VERSION0 = 0; + + /** + * The current version. + */ + private static final transient byte VERSION = VERSION0; + + public void readExternal(final ObjectInput in) throws IOException, + ClassNotFoundException { + + final byte version = in.readByte(); + + switch (version) { + case VERSION0: + break; + default: + throw new UnsupportedOperationException("Unknown version: " + + version); + } + final long naxioms = LongPacker.unpackLong(in); if (naxioms < 0 || naxioms > Integer.MAX_VALUE) @@ -332,6 +353,8 @@ if (btree == null) throw new IllegalStateException(); + out.writeByte(VERSION); + final long naxioms = btree.rangeCount(); LongPacker.packLong(out, naxioms); Modified: branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/inf/RdfTypeRdfsResourceFilter.java =================================================================== --- branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/inf/RdfTypeRdfsResourceFilter.java 2010-07-26 19:14:39 UTC (rev 3298) +++ branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/inf/RdfTypeRdfsResourceFilter.java 2010-07-26 19:31:59 UTC (rev 3299) @@ -70,8 +70,28 @@ } + /** + * The initial version. + */ + private static final transient short VERSION0 = 0; + + /** + * The current version. + */ + private static final transient short VERSION = VERSION0; + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + final short version = in.readShort(); + switch (version) { + case VERSION0: + break; + default: + throw new UnsupportedOperationException("Unknown version: " + + version); + } + // rdfType = LongPacker.unpackLong(in); // // rdfsResource = LongPacker.unpackLong(in); @@ -84,6 +104,8 @@ public void writeExternal(ObjectOutput out) throws IOException { + out.writeShort(VERSION); + // LongPacker.packLong(out,rdfType); // // LongPacker.packLong(out,rdfsResource); Modified: branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/lexicon/Term2IdTupleSerializer.java =================================================================== --- branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/lexicon/Term2IdTupleSerializer.java 2010-07-26 19:14:39 UTC (rev 3298) +++ branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/lexicon/Term2IdTupleSerializer.java 2010-07-26 19:31:59 UTC (rev 3299) @@ -48,6 +48,8 @@ package com.bigdata.rdf.lexicon; import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; import java.util.Properties; import org.openrdf.model.Value; import com.bigdata.btree.DefaultTupleSerializer; @@ -55,6 +57,8 @@ import com.bigdata.btree.keys.DefaultKeyBuilderFactory; import com.bigdata.btree.keys.IKeyBuilderFactory; import com.bigdata.btree.keys.KeyBuilder; +import com.bigdata.btree.keys.ThreadLocalKeyBuilderFactory; +import com.bigdata.btree.raba.codec.IRabaCoder; import com.bigdata.io.DataOutputBuffer; import com.bigdata.rawstore.Bytes; import com.bigdata.rdf.internal.IV; @@ -205,4 +209,33 @@ } + /** + * The initial version (no additional persistent state). + */ + private final static transient int VERSION0 = 0; + + /** + * The current version. + */ + private final static transient int VERSION = VERSION0; + + public void readExternal(final ObjectInput in) throws IOException, + ClassNotFoundException { + super.readExternal(in); + final short version = in.readShort(); + switch (version) { + case VERSION0: + break; + default: + throw new UnsupportedOperationException("Unknown version: " + + version); + } + + } + + public void writeExternal(final ObjectOutput out) throws IOException { + super.writeExternal(out); + out.writeShort(VERSION); + } + } Deleted: branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/spo/FastRDFValueCoder.java =================================================================== --- branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/spo/FastRDFValueCoder.java 2010-07-26 19:14:39 UTC (rev 3298) +++ branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/spo/FastRDFValueCoder.java 2010-07-26 19:31:59 UTC (rev 3299) @@ -1,474 +0,0 @@ -package com.bigdata.rdf.spo; - -import it.unimi.dsi.io.InputBitStream; -import it.unimi.dsi.io.OutputBitStream; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.io.OutputStream; - -import org.apache.log4j.Logger; - -import com.bigdata.btree.BytesUtil; -import com.bigdata.btree.raba.IRaba; -import com.bigdata.btree.raba.codec.AbstractCodedRaba; -import com.bigdata.btree.raba.codec.IRabaCoder; -import com.bigdata.btree.raba.codec.ICodedRaba; -import com.bigdata.io.AbstractFixedByteArrayBuffer; -import com.bigdata.io.DataOutputBuffer; -import com.bigdata.rawstore.Bytes; -import com.bigdata.rdf.model.StatementEnum; -import com.bigdata.rdf.store.AbstractTripleStore; - -/** - * Coder for statement index with inference enabled but without SIDS. We encode - * the value in 3 bits per statement. The 1st bit is the override flag. The - * remaining two bits are the statement type {inferred, explicit, or axiom}. The - * bit sequence <code>111</code> is used as a place holder for a - * <code>null</code> value and de-serializes to a [null]. - * <p> - * Note: the 'override' flag is NOT stored in the statement indices, but it is - * passed by the procedure that writes on the statement indices so that we can - * decide whether or not to override the type when the statement is pre-existing - * in the index. - * <p> - * Note: this procedure can not be used if - * {@link AbstractTripleStore.Options#STATEMENT_IDENTIFIERS} are enabled. - * - * @see StatementEnum - * - * @author <a href="mailto:tho...@us...">Bryan Thompson</a> - * @version $Id$ - * - * @deprecated by {@link FastRDFValueCoder2} - */ -public class FastRDFValueCoder implements Externalizable, IRabaCoder { - - protected static final Logger log = Logger - .getLogger(FastRDFValueCoder.class); - - /** - * - */ - private static final long serialVersionUID = 1933430721504168533L; - - /** - * The only version defined so far. - */ - private static transient final byte VERSION0 = 0x00; - - /** - * The bit offset of the start of the coded values. Each value is 3 bits. - */ - private static transient final long O_values = (1/* version */+ Bytes.SIZEOF_INT/* size */) << 3; - - /** - * No. - */ - final public boolean isKeyCoder() { - - return false; - - } - - /** - * Yes. - */ - final public boolean isValueCoder() { - - return true; - - } - - /** - * Sole constructor (handles de-serialization also). - */ - public FastRDFValueCoder() { - - } - - public void writeExternal(ObjectOutput out) throws IOException { - - // NOP - - } - - public void readExternal(ObjectInput in) throws IOException, - ClassNotFoundException { - - // NOP - - } - - public AbstractFixedByteArrayBuffer encode(final IRaba raba, - final DataOutputBuffer buf) { - - /* - * Note: This code path has nearly zero overhead when compared to - * encodeLive(). - */ - - return encodeLive(raba, buf).data(); - - } - - public ICodedRaba encodeLive(final IRaba raba, final DataOutputBuffer buf) { - - if (raba == null) - throw new UnsupportedOperationException(); - - if (buf == null) - throw new UnsupportedOperationException(); - - final int n = raba.size(); - - // This is sufficient capacity to code the data. - final int initialCapacity = 1 + Bytes.SIZEOF_INT - + BytesUtil.bitFlagByteLength(3 * n); - - buf.ensureCapacity(initialCapacity); - - // The byte offset of the start of the coded record in the buffer. - final int O_origin = buf.pos(); - - final int size = raba.size(); - - buf.putByte(VERSION0); - - buf.putInt(size); - - /* - * @todo use variant OBS(byte[], off, len) constructor and - * pre-extend the buffer to have sufficient capacity so the OBS can - * write directly onto the backing byte[], which will be much - * faster. - */ - final OutputBitStream obs = buf.getOutputBitStream(); -// final long O_values; - try { - -// obs.writeInt(VERSION0, 8/* nbits */); -// -// obs.writeNibble(size); -// -// // Note: the bit offset where we start to code the values. -// O_values = obs.writtenBits(); - - for (int i = 0; i < size; i++) { - - if (raba.isNull(i)) { - - // flag a deleted value (de-serialize to a null). - obs.writeInt(7, 3/* nbits */); - - } else { - - final byte[] val = raba.get(i); - - obs.writeInt((int) val[0], 3/* nbits */); - - } - - } - - // ALWAYS FLUSH. - obs.flush(); - - } catch (IOException ex) { - - throw new RuntimeException(ex); - - } - - // slice on just the coded data record. - final AbstractFixedByteArrayBuffer slice = buf.slice(O_origin, buf.pos() - - O_origin); - -// // adjusted bit offset to the start of the coded values in the slice. -// final int O_valuesAdjusted = ((int) O_values) - O_origin << 3; -// -// return new CodedRabaImpl(slice, size, O_valuesAdjusted); - - return new CodedRabaImpl(slice, size); - - } - - public ICodedRaba decode(final AbstractFixedByteArrayBuffer data) { - - return new CodedRabaImpl(data); - - } - - /** - * Decoder. - * - * @author <a href="mailto:tho...@us...">Bryan Thompson</a> - * @version $Id$ - */ - private static class CodedRabaImpl extends AbstractCodedRaba { - - private final AbstractFixedByteArrayBuffer data; - - /** - * Cached. - */ - private final int size; - -// /** -// * Bit offset to the first coded value. -// */ -// private final int O_values; - - final public AbstractFixedByteArrayBuffer data() { - - return data; - - } - - /** - * No. - */ - final public boolean isKeys() { - - return false; - - } - - final public int size() { - - return size; - - } - - final public int capacity() { - - return size; - - } - - final public boolean isEmpty() { - - return size == 0; - - } - - /** - * Always <code>true</code>. - */ - final public boolean isFull() { - - return true; - - } - - /** - * Constructor used when encoding a data record. - * - * @param data - * The coded data record. - * @param size - * The size of the coded {@link IRaba}. - */ -// * @param O_values -// * The bit offset of the start of the coded values. - public CodedRabaImpl(final AbstractFixedByteArrayBuffer data, - final int size) { //, final int O_values) { - - this.data = data; - - this.size = size; - -// this.O_values = O_values; - - } - - /** - * Constructor used when decoding a data record. - * - * @param data - * The coded data record. - */ - public CodedRabaImpl(final AbstractFixedByteArrayBuffer data) { - - if (data == null) - throw new IllegalArgumentException(); - - this.data = data; - - final byte version = data.getByte(0/*off*/); - - if (version != VERSION0) { - - throw new RuntimeException("Unknown version=" + version); - - } - - size = data.getInt(1/*off*/);//ibs.readNibble(); - -// final InputBitStream ibs = data.getInputBitStream(); -// -// try { -// -// final byte version = (byte) ibs.readInt(8/* nbits */); -// -// if (version != VERSION0) { -// -// throw new RuntimeException("Unknown version=" + version); -// -// } -// -// size = ibs.readNibble(); -// -// O_values = (int) ibs.readBits(); -// -// } catch (IOException ex) { -// -// throw new RuntimeException(ex); -// -//// close not required for IBS backed by byte[] and has high overhead. -//// } finally { -//// -//// try { -//// -//// ibs.close(); -//// -//// } catch (IOException ex) { -//// -//// log.error(ex); -//// -//// } -//// -// } - - } - - /** - * Thread-safe extract of the bits coded value for the specified index. - * - * @param index - * The specified index. - * - * @return The bit coded value. - * - * @throws IndexOutOfBoundsException - * unless the index is in [0:size-1]. - */ - final protected byte getBits(final int index) { - - if (index < 0 || index >= size) - throw new IndexOutOfBoundsException(); - - final InputBitStream ibs = data.getInputBitStream(); - try { - - ibs.position(O_values + (index * 3L)); - - final int value = ibs.readInt(3/* nbits */); - - return (byte) (0xff & value); - - } catch(IOException ex) { - - throw new RuntimeException(ex); - -// close not required for IBS backed by byte[] and has high overhead. -// } finally { -// try { -// ibs.close(); -// } catch(IOException ex) { -// log.error(ex); -// } - } - -// int value = 0; -// -// for (int i = 0; i < 3; i++, bitIndex++) { -// -// final boolean bit = data.getBit(bitIndex); -// -// value |= (bit ? 1 : 0) << i; -// -// } -// -// return (byte) (value & 0xff); - - } - - final public int copy(final int index, final OutputStream os) { - - final byte bits = getBits(index); - - if (bits == 7) { - - // A null. - throw new NullPointerException(); - - } else { - - try { - - os.write(bits); - - } catch (IOException e) { - - throw new RuntimeException(e); - - } - - } - - return 1; - - } - - final public byte[] get(final int index) { - - final byte bits = getBits(index); - - if (bits == 7) { - - // A null. - return null; - - } else { - - return new byte[] { bits }; - - } - - } - - final public boolean isNull(final int index) { - - return getBits(index) == 7; - - } - - /** - * Returns ONE (1) unless the value is a <code>null</code>. - * - * {@inheritDoc} - */ - final public int length(final int index) { - - if (isNull(index)) - throw new NullPointerException(); - - return 1; - - } - - /** - * Not supported. - */ - final public int search(final byte[] searchKey) { - - throw new UnsupportedOperationException(); - - } - - } - -} Modified: branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/spo/InGraphBinarySearchFilter.java =================================================================== --- branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/spo/InGraphBinarySearchFilter.java 2010-07-26 19:14:39 UTC (rev 3298) +++ branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/spo/InGraphBinarySearchFilter.java 2010-07-26 19:31:59 UTC (rev 3299) @@ -88,8 +88,28 @@ } - public void readExternal(ObjectInput in) throws IOException, + /** + * The initial version. + */ + private static final transient short VERSION0 = 0; + + /** + * The current version. + */ + private static final transient short VERSION = VERSION0; + + public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { + + final short version = in.readShort(); + + switch (version) { + case VERSION0: + break; + default: + throw new UnsupportedOperationException("Unknown version: " + + version); + } final int size = in.readInt(); @@ -103,8 +123,10 @@ } - public void writeExternal(ObjectOutput out) throws IOException { + public void writeExternal(final ObjectOutput out) throws IOException { + out.writeShort(VERSION); + out.writeInt(a.length); for(IV iv : a) { Modified: branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/vocab/BaseVocabulary.java =================================================================== --- branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/vocab/BaseVocabulary.java 2010-07-26 19:14:39 UTC (rev 3298) +++ branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/vocab/BaseVocabulary.java 2010-07-26 19:31:59 UTC (rev 3299) @@ -36,16 +36,17 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Map; + import org.apache.log4j.Logger; import org.openrdf.model.Value; import org.openrdf.model.ValueFactory; import org.openrdf.model.impl.ValueFactoryImpl; + import com.bigdata.btree.keys.IKeyBuilder; import com.bigdata.btree.keys.KeyBuilder; import com.bigdata.io.DataOutputBuffer; import com.bigdata.rdf.internal.IV; import com.bigdata.rdf.internal.IVUtility; -import com.bigdata.rdf.internal.TermId; import com.bigdata.rdf.model.BigdataValue; import com.bigdata.rdf.model.BigdataValueFactory; import com.bigdata.rdf.model.BigdataValueSerializer; @@ -246,6 +247,16 @@ } /** + * The initial version. + */ + private static final transient short VERSION0 = 0; + + /** + * The current version. + */ + private static final transient short VERSION = VERSION0; + + /** * Note: The de-serialized state contains {@link Value}s but not * {@link BigdataValue}s since the {@link AbstractTripleStore} reference is * not available and we can not obtain the appropriate @@ -258,6 +269,16 @@ if (values != null) throw new IllegalStateException(); + final short version = in.readShort(); + + switch (version) { + case VERSION0: + break; + default: + throw new UnsupportedOperationException("Unknown version: " + + version); + } + final ValueFactory valueFactory = new ValueFactoryImpl(); final BigdataValueSerializer<Value> valueSer = new BigdataValueSerializer<Value>( @@ -305,6 +326,8 @@ if (values == null) throw new IllegalStateException(); + + out.writeShort(VERSION); final int nvalues = values.size(); Modified: branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/spo/TestSPOValueCoders.java =================================================================== --- branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/spo/TestSPOValueCoders.java 2010-07-26 19:14:39 UTC (rev 3298) +++ branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/spo/TestSPOValueCoders.java 2010-07-26 19:31:59 UTC (rev 3299) @@ -29,7 +29,9 @@ import java.io.IOException; import java.util.Random; + import junit.framework.TestCase2; + import com.bigdata.btree.AbstractBTreeTestCase; import com.bigdata.btree.ICounter; import com.bigdata.btree.raba.IRaba; @@ -40,7 +42,6 @@ import com.bigdata.io.AbstractFixedByteArrayBuffer; import com.bigdata.io.DataOutputBuffer; import com.bigdata.io.FixedByteArrayBuffer; -import com.bigdata.rdf.internal.IV; import com.bigdata.rdf.internal.TermId; import com.bigdata.rdf.internal.VTE; import com.bigdata.rdf.lexicon.ITermIdCodes; @@ -186,12 +187,12 @@ } - public void test_FastRDFValueCoder() { +// public void test_FastRDFValueCoder() { +// +// doRoundTripTests(new FastRDFValueCoder(), false/* sids */, true/* inference */); +// +// } - doRoundTripTests(new FastRDFValueCoder(), false/* sids */, true/* inference */); - - } - /** * Simple tests for {@link FastRDFValueCoder2}. * <P> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |