com.bigdata.sparse
Class Schema

java.lang.Object
  extended by com.bigdata.sparse.Schema
All Implemented Interfaces:
Externalizable, Serializable
Direct Known Subclasses:
FileMetadataSchema, GlobalRowStoreSchema, RelationSchema

public class Schema
extends Object
implements Externalizable

A schema for a sparse row store. Note that more than one schema may be used with the same index. The name of the schema is always encoded as the first component of the key.

See Also:
Serialized Form
TODO:
support optional strong typing for column values?, support optional required columns?

Constructor Summary
Schema()
          De-serialization ctor.
Schema(String name, String primaryKey, KeyType primaryKeyType)
           
 
Method Summary
protected  IKeyBuilder appendPrimaryKey(IKeyBuilder keyBuilder, Object v, boolean successor)
          Helper method appends a typed value to the compound key (this is used to get the primary key into the compound key).
protected  IKeyBuilder fromKey(IKeyBuilder keyBuilder, Object primaryKey)
          Forms the key in #keyBuilder that should be used as the first key (inclusive) for a range query that will visit all index entries for the specified primary key.
 byte[] getKey(IKeyBuilder keyBuilder, Object primaryKey, String col, long timestamp)
          Encodes a key for the Schema.
 String getName()
          The name of the schema.
 byte[] getPrefix(IKeyBuilder keyBuilder, Object primaryKey)
          The prefix that identifies all tuples in the logical row for this schema having the indicated value for their primary key.
 String getPrimaryKeyName()
          The name of the column whose value is the primary key.
 KeyType getPrimaryKeyType()
          The data type that is used for the primary key when forming the total key.
protected  byte[] getSchemaBytes()
          The Unicode sort key encoding of the schema name.
 void readExternal(ObjectInput in)
           
 String toString()
           
 void writeExternal(ObjectOutput out)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Schema

public Schema()
De-serialization ctor.


Schema

public Schema(String name,
              String primaryKey,
              KeyType primaryKeyType)
Parameters:
name - The schema name.
primaryKey - The name of the column whose value is the (application defined) primary key.
primaryKeyType - The data type for the primary key.
Method Detail

getName

public String getName()
The name of the schema.


getPrimaryKeyName

public String getPrimaryKeyName()
The name of the column whose value is the primary key.


getPrimaryKeyType

public KeyType getPrimaryKeyType()
The data type that is used for the primary key when forming the total key.


getSchemaBytes

protected final byte[] getSchemaBytes()
The Unicode sort key encoding of the schema name.


appendPrimaryKey

protected final IKeyBuilder appendPrimaryKey(IKeyBuilder keyBuilder,
                                             Object v,
                                             boolean successor)
Helper method appends a typed value to the compound key (this is used to get the primary key into the compound key).

Note: This automatically appends the nul terminator byte if KeyType.isFixedLength() is false. That byte flags the end of the primary key for variable length primary keys.

Parameters:
keyType - The target data type.
v - The value.
Returns:
The #keyBuilder.
See Also:
KeyDecoder

fromKey

protected final IKeyBuilder fromKey(IKeyBuilder keyBuilder,
                                    Object primaryKey)
Forms the key in #keyBuilder that should be used as the first key (inclusive) for a range query that will visit all index entries for the specified primary key.

Parameters:
primaryKey - The primary key.
Returns:
The #keyBuilder, which will have the schema and the primary key already formatted in its buffer.
See Also:
KeyDecoder

getPrefix

public final byte[] getPrefix(IKeyBuilder keyBuilder,
                              Object primaryKey)
The prefix that identifies all tuples in the logical row for this schema having the indicated value for their primary key.

Parameters:
primaryKey - The value of the primary key for the logical row.
Returns:

getKey

public byte[] getKey(IKeyBuilder keyBuilder,
                     Object primaryKey,
                     String col,
                     long timestamp)
Encodes a key for the Schema.

Parameters:
keyBuilder -
primaryKey - The primary key for the logical row (required).
col - The column name (required).
timestamp - The timestamp (required).
Returns:
The encoded key.
Throws:
IllegalArgumentException - if keyBuilder is null.
IllegalArgumentException - if primaryKey is null.
IllegalArgumentException - if col is not valid as the name of a column.

readExternal

public void readExternal(ObjectInput in)
                  throws IOException,
                         ClassNotFoundException
Specified by:
readExternal in interface Externalizable
Throws:
IOException
ClassNotFoundException

writeExternal

public void writeExternal(ObjectOutput out)
                   throws IOException
Specified by:
writeExternal in interface Externalizable
Throws:
IOException

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2006-2012 SYSTAP, LLC. All Rights Reserved.