Skip to content

Commit

Permalink
ACCUMULO-411 ACCUMULO-145 added javadocs and a license for gitignore …
Browse files Browse the repository at this point in the history
…file

git-svn-id: https://svn.apache.org/repos/asf/incubator/accumulo/branches/1.4@1303928 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
billierinaldi committed Mar 22, 2012
1 parent 478b6e5 commit 5940fa9
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 35 deletions.
14 changes: 14 additions & 0 deletions .gitignore
@@ -1,3 +1,17 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# /
/logs
Expand Down
125 changes: 100 additions & 25 deletions src/core/src/main/java/org/apache/accumulo/core/data/Key.java
Expand Up @@ -20,7 +20,7 @@
* This is the Key used to store and access individual values in Accumulo. A Key is a tuple composed of a row, column family, column qualifier,
* column visibility, timestamp, and delete marker.
*
* Keys are comparable and therefore have a sorted order.
* Keys are comparable and therefore have a sorted order defined by {@link #compareTo(Key)}.
*
*/

Expand Down Expand Up @@ -82,6 +82,10 @@ private final void init(byte r[], int rOff, int rLen, byte cf[], int cfOff, int
deleted = del;
}

/**
* Creates a key with empty row, empty column family, empty column qualifier, empty column visibility, timestamp {@link Long#MAX_VALUE}, and delete marker
* false.
*/
public Key() {
row = EMPTY_BYTES;
colFamily = EMPTY_BYTES;
Expand All @@ -91,10 +95,18 @@ public Key() {
deleted = false;
}

/**
* Creates a key with the specified row, empty column family, empty column qualifier, empty column visibility, timestamp {@link Long#MAX_VALUE}, and delete
* marker false.
*/
public Key(Text row) {
init(row.getBytes(), 0, row.getLength(), EMPTY_BYTES, 0, 0, EMPTY_BYTES, 0, 0, EMPTY_BYTES, 0, 0, Long.MAX_VALUE, false, true);
}

/**
* Creates a key with the specified row, empty column family, empty column qualifier, empty column visibility, the specified timestamp, and delete marker
* false.
*/
public Key(Text row, long ts) {
this(row);
timestamp = ts;
Expand All @@ -116,57 +128,102 @@ public Key(byte[] row, byte[] cf, byte[] cq, byte[] cv, long ts, boolean deleted
init(row, 0, row.length, cf, 0, cf.length, cq, 0, cq.length, cv, 0, cv.length, ts, deleted, copy);
}

/**
* Creates a key with the specified row, the specified column family, empty column qualifier, empty column visibility, timestamp {@link Long#MAX_VALUE}, and
* delete marker false.
*/
public Key(Text row, Text cf) {
init(row.getBytes(), 0, row.getLength(), cf.getBytes(), 0, cf.getLength(), EMPTY_BYTES, 0, 0, EMPTY_BYTES, 0, 0, Long.MAX_VALUE, false, true);
}

/**
* Creates a key with the specified row, the specified column family, the specified column qualifier, empty column visibility, timestamp
* {@link Long#MAX_VALUE}, and delete marker false.
*/
public Key(Text row, Text cf, Text cq) {
init(row.getBytes(), 0, row.getLength(), cf.getBytes(), 0, cf.getLength(), cq.getBytes(), 0, cq.getLength(), EMPTY_BYTES, 0, 0, Long.MAX_VALUE, false, true);
}

/**
* Creates a key with the specified row, the specified column family, the specified column qualifier, the specified column visibility, timestamp
* {@link Long#MAX_VALUE}, and delete marker false.
*/
public Key(Text row, Text cf, Text cq, Text cv) {
init(row.getBytes(), 0, row.getLength(), cf.getBytes(), 0, cf.getLength(), cq.getBytes(), 0, cq.getLength(), cv.getBytes(), 0, cv.getLength(),
Long.MAX_VALUE, false, true);
}

/**
* Creates a key with the specified row, the specified column family, the specified column qualifier, empty column visibility, the specified timestamp, and
* delete marker false.
*/
public Key(Text row, Text cf, Text cq, long ts) {
init(row.getBytes(), 0, row.getLength(), cf.getBytes(), 0, cf.getLength(), cq.getBytes(), 0, cq.getLength(), EMPTY_BYTES, 0, 0, ts, false, true);
}

/**
* Creates a key with the specified row, the specified column family, the specified column qualifier, the specified column visibility, the specified
* timestamp, and delete marker false.
*/
public Key(Text row, Text cf, Text cq, Text cv, long ts) {
init(row.getBytes(), 0, row.getLength(), cf.getBytes(), 0, cf.getLength(), cq.getBytes(), 0, cq.getLength(), cv.getBytes(), 0, cv.getLength(), ts, false,
true);
}

/**
* Creates a key with the specified row, the specified column family, the specified column qualifier, the specified column visibility, the specified
* timestamp, and delete marker false.
*/
public Key(Text row, Text cf, Text cq, ColumnVisibility cv, long ts) {
byte[] expr = cv.getExpression();
init(row.getBytes(), 0, row.getLength(), cf.getBytes(), 0, cf.getLength(), cq.getBytes(), 0, cq.getLength(), expr, 0, expr.length, ts, false, true);
}

/**
* Converts CharSequence to Text and creates a Key using {@link #Key(Text)}.
*/
public Key(CharSequence row) {
this(new Text(row.toString()));
}

/**
* Converts CharSequence to Text and creates a Key using {@link #Key(Text,Text)}.
*/
public Key(CharSequence row, CharSequence cf) {
this(new Text(row.toString()), new Text(cf.toString()));
}

/**
* Converts CharSequence to Text and creates a Key using {@link #Key(Text,Text,Text)}.
*/
public Key(CharSequence row, CharSequence cf, CharSequence cq) {
this(new Text(row.toString()), new Text(cf.toString()), new Text(cq.toString()));
}

/**
* Converts CharSequence to Text and creates a Key using {@link #Key(Text,Text,Text,Text)}.
*/
public Key(CharSequence row, CharSequence cf, CharSequence cq, CharSequence cv) {
this(new Text(row.toString()), new Text(cf.toString()), new Text(cq.toString()), new Text(cv.toString()));
}

/**
* Converts CharSequence to Text and creates a Key using {@link #Key(Text,Text,Text,long)}.
*/
public Key(CharSequence row, CharSequence cf, CharSequence cq, long ts) {
this(new Text(row.toString()), new Text(cf.toString()), new Text(cq.toString()), ts);
}

/**
* Converts CharSequence to Text and creates a Key using {@link #Key(Text,Text,Text,Text,long)}.
*/
public Key(CharSequence row, CharSequence cf, CharSequence cq, CharSequence cv, long ts) {
this(new Text(row.toString()), new Text(cf.toString()), new Text(cq.toString()), new Text(cv.toString()), ts);
}

/**
* Converts CharSequence to Text and creates a Key using {@link #Key(Text,Text,Text,ColumnVisibility,long)}.
*/
public Key(CharSequence row, CharSequence cf, CharSequence cq, ColumnVisibility cv, long ts) {
this(new Text(row.toString()), new Text(cf.toString()), new Text(cq.toString()), new Text(cv.getExpression()), ts);
}
Expand Down Expand Up @@ -220,6 +277,9 @@ public Key followingKey(PartialKey part) {
return returnKey;
}

/**
* Creates a key with the same row, column family, column qualifier, column visibility, timestamp, and delete marker as the given key.
*/
public Key(Key other) {
set(other);
}
Expand All @@ -240,7 +300,7 @@ public Key(TKey tkey) {
* the key's row will be copied into this Text
* @return the Text that was passed in
*/

public Text getRow(Text r) {
r.set(row, 0, row.length);
return r;
Expand All @@ -251,7 +311,7 @@ public Text getRow(Text r) {
*
* @return ByteSequence that points to the internal key row data.
*/

public ByteSequence getRowData() {
return new ArrayByteSequence(row);
}
Expand All @@ -261,7 +321,7 @@ public ByteSequence getRowData() {
*
* @return Text containing the row field
*/

public Text getRow() {
return getRow(new Text());
}
Expand All @@ -271,9 +331,9 @@ public Text getRow() {
*
* @param r
* row to compare to keys row
* @return same as getRow().compareTo(r)
* @return same as {@link getRow()}.compareTo(r)
*/

public int compareRow(Text r) {
return WritableComparator.compareBytes(row, 0, row.length, r.getBytes(), 0, r.getLength());
}
Expand All @@ -283,7 +343,7 @@ public int compareRow(Text r) {
*
* @return ByteSequence that points to the internal key column family data.
*/

public ByteSequence getColumnFamilyData() {
return new ArrayByteSequence(colFamily);
}
Expand All @@ -295,7 +355,7 @@ public ByteSequence getColumnFamilyData() {
* the key's column family will be copied into this Text
* @return the Text that was passed in
*/

public Text getColumnFamily(Text cf) {
cf.set(colFamily, 0, colFamily.length);
return cf;
Expand All @@ -306,7 +366,7 @@ public Text getColumnFamily(Text cf) {
*
* @return Text containing the column family field
*/

public Text getColumnFamily() {
return getColumnFamily(new Text());
}
Expand All @@ -316,9 +376,9 @@ public Text getColumnFamily() {
*
* @param cf
* column family to compare to keys column family
* @return same as getColumnFamily().compareTo(cf)
* @return same as {@link #getColumnFamily()}.compareTo(cf)
*/

public int compareColumnFamily(Text cf) {
return WritableComparator.compareBytes(colFamily, 0, colFamily.length, cf.getBytes(), 0, cf.getLength());
}
Expand All @@ -328,7 +388,7 @@ public int compareColumnFamily(Text cf) {
*
* @return ByteSequence that points to the internal key column qualifier data.
*/

public ByteSequence getColumnQualifierData() {
return new ArrayByteSequence(colQualifier);
}
Expand All @@ -340,7 +400,7 @@ public ByteSequence getColumnQualifierData() {
* the key's column qualifier will be copied into this Text
* @return the Text that was passed in
*/

public Text getColumnQualifier(Text cq) {
cq.set(colQualifier, 0, colQualifier.length);
return cq;
Expand All @@ -351,7 +411,7 @@ public Text getColumnQualifier(Text cq) {
*
* @return Text containing the column qualifier field
*/

public Text getColumnQualifier() {
return getColumnQualifier(new Text());
}
Expand All @@ -361,9 +421,9 @@ public Text getColumnQualifier() {
*
* @param cq
* column family to compare to keys column qualifier
* @return same as compareColumnQualifier().compareTo(cq)
* @return same as {@link #getColumnQualifier()}.compareTo(cq)
*/

public int compareColumnQualifier(Text cq) {
return WritableComparator.compareBytes(colQualifier, 0, colQualifier.length, cq.getBytes(), 0, cq.getLength());
}
Expand All @@ -389,7 +449,7 @@ public void setDeleted(boolean deleted) {
*
* @return ByteSequence that points to the internal key column visibility data.
*/

public ByteSequence getColumnVisibilityData() {
return new ArrayByteSequence(colVisibility);
}
Expand All @@ -399,7 +459,7 @@ public ByteSequence getColumnVisibilityData() {
*
* @return Text containing the column visibility field
*/

public final Text getColumnVisibility() {
return getColumnVisibility(new Text());
}
Expand All @@ -411,12 +471,15 @@ public final Text getColumnVisibility() {
* the key's column visibility will be copied into this Text
* @return the Text that was passed in
*/

public final Text getColumnVisibility(Text cv) {
cv.set(colVisibility, 0, colVisibility.length);
return cv;
}

/**
* Sets this key's row, column family, column qualifier, column visibility, timestamp, and delete marker to be the same as another key's.
*/
public void set(Key k) {
row = k.row;
colFamily = k.colFamily;
Expand Down Expand Up @@ -476,7 +539,7 @@ public void write(DataOutput out) throws IOException {
* Compare part of a key. For example compare just the row and column family, and if those are equal then return true.
*
*/

public boolean equals(Key other, PartialKey part) {
switch (part) {
case ROW:
Expand All @@ -500,10 +563,12 @@ public boolean equals(Key other, PartialKey part) {
}

/**
* Compare part of a key. For example compare just the row and column family, and if those are equal then return 0.
* Compare elements of a key given by a {@link PartialKey}. For example, for {@link PartialKey#ROW_COLFAM}, compare just the row and column family. If the
* rows are not equal, return the result of the row comparison; otherwise, return the result of the column family comparison.
*
* @see #compareTo(Key)
*/

public int compareTo(Key other, PartialKey part) {
// check for matching row
int result = WritableComparator.compareBytes(row, 0, row.length, other.row, 0, other.row.length);
Expand Down Expand Up @@ -546,9 +611,10 @@ else if (timestamp > other.timestamp)
}

/**
* Compare the elements of a key starting with the row. If the row is equal, then compare the column family, etc. The row, column family, column qualifier,
* and column visibility are compared lexographically and sorted ascending. The timestamps are compared numerically and sorted descending so that the most
* recent data comes first. Last when delete is compared, true come first and false after.
* Compare all elements of a key. The elements (row, column family, column qualifier, column visibility, timestamp, and delete marker) are compared in order
* until an unequal element is found. If the row is equal, then compare the column family, etc. The row, column family, column qualifier, and column
* visibility are compared lexographically and sorted ascending. The timestamps are compared numerically and sorted descending so that the most recent data
* comes first. Lastly, a delete marker of true sorts before a delete marker of false.
*/

public int compareTo(Key other) {
Expand Down Expand Up @@ -609,10 +675,18 @@ public String toStringNoTime() {
return rowColumnStringBuilder().toString();
}

/**
* Returns the sums of the lengths of the row, column family, column qualifier, and visibility.
*
* @return row.length + colFamily.length + colQualifier.length + colVisibility.length;
*/
public int getLength() {
return row.length + colFamily.length + colQualifier.length + colVisibility.length;
}

/**
* Same as {@link #getLength()}.
*/
public int getSize() {
return getLength();
}
Expand Down Expand Up @@ -657,6 +731,7 @@ private static boolean isEqual(byte a1[], byte a2[]) {
* Use this to compress a list of keys before sending them via thrift.
*
* @param param
* a list of key/value pairs
*/
public static List<TKeyValue> compress(List<? extends KeyValue> param) {

Expand Down

0 comments on commit 5940fa9

Please sign in to comment.