Repository: accumulo Updated Branches: refs/heads/1.8 a8f804e9e -> 3ee5af077 refs/heads/master 5c5290b70 -> 7ad5dd68d
ACCUMULO-4375 Add missing byte[]-based Key constructors Closes apache/accumulo#125 Signed-off-by: Josh Elser <els...@apache.org> Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/3ee5af07 Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/3ee5af07 Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/3ee5af07 Branch: refs/heads/1.8 Commit: 3ee5af0774b77733d8f76c8c6436af6e081fcf4b Parents: a8f804e Author: Mario Pastorelli <mario.pastore...@teralytics.ch> Authored: Sun Jul 17 01:01:31 2016 +0200 Committer: Josh Elser <els...@apache.org> Committed: Sun Jul 17 15:40:19 2016 -0400 ---------------------------------------------------------------------- .../java/org/apache/accumulo/core/data/Key.java | 82 +++++++++++++++++++- .../org/apache/accumulo/core/data/KeyTest.java | 41 ++++++++++ 2 files changed, 120 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/accumulo/blob/3ee5af07/core/src/main/java/org/apache/accumulo/core/data/Key.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/data/Key.java b/core/src/main/java/org/apache/accumulo/core/data/Key.java index 758436d..f7737dc 100644 --- a/core/src/main/java/org/apache/accumulo/core/data/Key.java +++ b/core/src/main/java/org/apache/accumulo/core/data/Key.java @@ -107,6 +107,18 @@ public class Key implements WritableComparable<Key>, Cloneable { } /** + * 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. This constructor creates a copy of row. If you don't want to create a copy of row, you should call + * {@link Key#Key(byte[] row, byte[] cf, byte[] cq, byte[] cv, long ts, boolean deleted, boolean copy)} instead. + * + * @param row + * row ID + */ + public Key(byte[] row) { + init(row, 0, row.length, 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. * @@ -121,7 +133,23 @@ public class Key implements WritableComparable<Key>, Cloneable { } /** - * Creates a key. The delete marker defaults to false. + * Creates a key with the specified row, empty column family, empty column qualifier, empty column visibility, the specified timestamp, and delete marker + * false. This constructor creates a copy of row. If you don't want to create a copy, you should call + * {@link Key#Key(byte[] row, byte[] cf, byte[] cq, byte[] cv, long ts, boolean deleted, boolean copy)} instead. + * + * @param row + * row ID + * @param ts + * timestamp + */ + public Key(byte[] row, long ts) { + this(row); + timestamp = ts; + } + + /** + * Creates a key. The delete marker defaults to false. This constructor creates a copy of each specified array. If you don't want to create a copy of the + * arrays, you should call {@link Key#Key(byte[] row, byte[] cf, byte[] cq, byte[] cv, long ts, boolean deleted, boolean copy)} instead. * * @param row * bytes containing row ID @@ -155,7 +183,8 @@ public class Key implements WritableComparable<Key>, Cloneable { } /** - * Creates a key. The delete marker defaults to false. + * Creates a key. The delete marker defaults to false. This constructor creates a copy of each specified array. If you don't want to create a copy of the + * arrays, you should call {@link Key#Key(byte[] row, byte[] cf, byte[] cq, byte[] cv, long ts, boolean deleted, boolean copy)} instead. * * @param row * row ID @@ -173,7 +202,8 @@ public class Key implements WritableComparable<Key>, Cloneable { } /** - * Creates a key. + * Creates a key. This constructor creates a copy of each specified arrays. If you don't want to create a copy, you should call + * {@link Key#Key(byte[] row, byte[] cf, byte[] cq, byte[] cv, long ts, boolean deleted, boolean copy)} instead. * * @param row * row ID @@ -223,6 +253,15 @@ public class Key implements WritableComparable<Key>, Cloneable { } /** + * 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. This constructor creates a copy of each specified array. If you don't want to create a copy of the arrays, you should call + * {@link Key#Key(byte[] row, byte[] cf, byte[] cq, byte[] cv, long ts, boolean deleted, boolean copy)} instead. + */ + public Key(byte[] row, byte[] cf) { + init(row, 0, row.length, cf, 0, cf.length, 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. */ @@ -231,6 +270,15 @@ public class Key implements WritableComparable<Key>, Cloneable { } /** + * 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. This constructor creates a copy of each specified array. If you don't want to create a copy of the arrays, + * you should call {@link Key#Key(byte[] row, byte[] cf, byte[] cq, byte[] cv, long ts, boolean deleted, boolean copy)} instead. + */ + public Key(byte[] row, byte[] cf, byte[] cq) { + init(row, 0, row.length, cf, 0, cf.length, cq, 0, cq.length, 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. */ @@ -240,6 +288,15 @@ public class Key implements WritableComparable<Key>, Cloneable { } /** + * 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. This constructor creates a copy of each specified array. If you don't want to create a copy of the arrays, + * you should call {@link Key#Key(byte[] row, byte[] cf, byte[] cq, byte[] cv, long ts, boolean deleted, boolean copy)} instead. + */ + public Key(byte[] row, byte[] cf, byte[] cq, byte[] cv) { + init(row, 0, row.length, cf, 0, cf.length, cq, 0, cq.length, cv, 0, cv.length, 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. */ @@ -248,6 +305,15 @@ public class Key implements WritableComparable<Key>, Cloneable { } /** + * 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. This constructor creates a copy of each specified array. If you don't want to create a copy of the arrays, you should call + * {@link Key#Key(byte[] row, byte[] cf, byte[] cq, byte[] cv, long ts, boolean deleted, boolean copy)} instead. + */ + public Key(byte[] row, byte[] cf, byte[] cq, long ts) { + init(row, 0, row.length, cf, 0, cf.length, cq, 0, cq.length, 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. */ @@ -266,6 +332,16 @@ public class Key implements WritableComparable<Key>, Cloneable { } /** + * 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. This constructor creates a copy of each specified array. If you don't want to create a copy of the arrays, you should + * call {@link Key#Key(byte[] row, byte[] cf, byte[] cq, byte[] cv, long ts, boolean deleted, boolean copy)} instead. + */ + public Key(byte[] row, byte[] cf, byte[] cq, ColumnVisibility cv, long ts) { + byte[] expr = cv.getExpression(); + init(row, 0, row.length, cf, 0, cf.length, cq, 0, cq.length, expr, 0, expr.length, ts, false, true); + } + + /** * Converts CharSequence to Text and creates a Key using {@link #Key(Text)}. */ public Key(CharSequence row) { http://git-wip-us.apache.org/repos/asf/accumulo/blob/3ee5af07/core/src/test/java/org/apache/accumulo/core/data/KeyTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/accumulo/core/data/KeyTest.java b/core/src/test/java/org/apache/accumulo/core/data/KeyTest.java index c94c6b4..f14786f 100644 --- a/core/src/test/java/org/apache/accumulo/core/data/KeyTest.java +++ b/core/src/test/java/org/apache/accumulo/core/data/KeyTest.java @@ -166,4 +166,45 @@ public class KeyTest { assertEquals(kv.getKey(), new Key(tkv.getKey())); } } + + @Test + public void testBytesText() { + byte[] row = new byte[] {1}; + Key bytesRowKey = new Key(row); + Key textRowKey = new Key(new Text(row)); + assertEquals(bytesRowKey, textRowKey); + + byte[] colFamily = new byte[] {0, 1}; + Key bytesColFamilyKey = new Key(row, colFamily); + Key textColFamilyKey = new Key(new Text(row), new Text(colFamily)); + assertEquals(bytesColFamilyKey, textColFamilyKey); + + byte[] colQualifier = new byte[] {0, 0, 1}; + Key bytesColQualifierKey = new Key(row, colFamily, colQualifier); + Key textColQualifierKey = new Key(new Text(row), new Text(colFamily), new Text(colQualifier)); + assertEquals(bytesColQualifierKey, textColQualifierKey); + + byte[] colVisibility = new byte[] {0, 0, 0, 1}; + Key bytesColVisibilityKey = new Key(row, colFamily, colQualifier, colVisibility); + Key textColVisibilityKey = new Key(new Text(row), new Text(colFamily), new Text(colQualifier), new Text(colVisibility)); + assertEquals(bytesColVisibilityKey, textColVisibilityKey); + + long ts = 0L; + Key bytesTSKey = new Key(row, colFamily, colQualifier, colVisibility, ts); + Key textTSKey = new Key(new Text(row), new Text(colFamily), new Text(colQualifier), new Text(colVisibility), ts); + assertEquals(bytesTSKey, textTSKey); + + Key bytesTSKey2 = new Key(row, ts); + Key textTSKey2 = new Key(new Text(row), ts); + assertEquals(bytesTSKey2, textTSKey2); + + Key bytesTSKey3 = new Key(row, colFamily, colQualifier, ts); + Key testTSKey3 = new Key(new Text(row), new Text(colFamily), new Text(colQualifier), ts); + assertEquals(bytesTSKey3, testTSKey3); + + ColumnVisibility colVisibility2 = new ColumnVisibility("v1"); + Key bytesColVisibilityKey2 = new Key(row, colFamily, colQualifier, colVisibility2, ts); + Key textColVisibilityKey2 = new Key(new Text(row), new Text(colFamily), new Text(colQualifier), colVisibility2, ts); + assertEquals(bytesColVisibilityKey2, textColVisibilityKey2); + } }