Return-Path: Delivered-To: apmail-hadoop-hbase-commits-archive@minotaur.apache.org Received: (qmail 96545 invoked from network); 24 Nov 2009 20:24:54 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 24 Nov 2009 20:24:54 -0000 Received: (qmail 62458 invoked by uid 500); 24 Nov 2009 20:24:54 -0000 Delivered-To: apmail-hadoop-hbase-commits-archive@hadoop.apache.org Received: (qmail 62403 invoked by uid 500); 24 Nov 2009 20:24:54 -0000 Mailing-List: contact hbase-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: hbase-dev@hadoop.apache.org Delivered-To: mailing list hbase-commits@hadoop.apache.org Received: (qmail 62394 invoked by uid 99); 24 Nov 2009 20:24:54 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 24 Nov 2009 20:24:54 +0000 X-ASF-Spam-Status: No, hits=-2.6 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 24 Nov 2009 20:24:51 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 2B1FC23888DD; Tue, 24 Nov 2009 20:24:31 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r883851 - in /hadoop/hbase/branches/0.20: CHANGES.txt src/java/org/apache/hadoop/hbase/client/Put.java Date: Tue, 24 Nov 2009 20:24:31 -0000 To: hbase-commits@hadoop.apache.org From: stack@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20091124202431.2B1FC23888DD@eris.apache.org> Author: stack Date: Tue Nov 24 20:24:30 2009 New Revision: 883851 URL: http://svn.apache.org/viewvc?rev=883851&view=rev Log: HBASE-1987 The Put object has no simple read methods for checking what has already been added Modified: hadoop/hbase/branches/0.20/CHANGES.txt hadoop/hbase/branches/0.20/src/java/org/apache/hadoop/hbase/client/Put.java Modified: hadoop/hbase/branches/0.20/CHANGES.txt URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.20/CHANGES.txt?rev=883851&r1=883850&r2=883851&view=diff ============================================================================== --- hadoop/hbase/branches/0.20/CHANGES.txt (original) +++ hadoop/hbase/branches/0.20/CHANGES.txt Tue Nov 24 20:24:30 2009 @@ -17,6 +17,8 @@ HBASE-1975 SingleColumnValueFilter: Add ability to match the value of previous versions of the specified column (Jeremiah Jacquet via Stack) + HBASE-1987 The Put object has no simple read methods for checking what + has already been added (Ryan Smith via Stack) Release 0.20.2 - November 18th, 2009 INCOMPATIBLE CHANGES Modified: hadoop/hbase/branches/0.20/src/java/org/apache/hadoop/hbase/client/Put.java URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.20/src/java/org/apache/hadoop/hbase/client/Put.java?rev=883851&r1=883850&r2=883851&view=diff ============================================================================== --- hadoop/hbase/branches/0.20/src/java/org/apache/hadoop/hbase/client/Put.java (original) +++ hadoop/hbase/branches/0.20/src/java/org/apache/hadoop/hbase/client/Put.java Tue Nov 24 20:24:30 2009 @@ -132,12 +132,8 @@ * @param value column value */ public Put add(byte [] family, byte [] qualifier, long ts, byte [] value) { - List list = familyMap.get(family); - if(list == null) { - list = new ArrayList(0); - } - KeyValue kv = new KeyValue(this.row, family, qualifier, ts, - KeyValue.Type.Put, value); + List list = getKeyValueList(family); + KeyValue kv = createPutKeyValue(family, qualifier, ts, value); list.add(kv); familyMap.put(kv.getFamily(), list); return this; @@ -151,10 +147,7 @@ */ public Put add(KeyValue kv) throws IOException{ byte [] family = kv.getFamily(); - List list = familyMap.get(family); - if(list == null) { - list = new ArrayList(); - } + List list = getKeyValueList(family); //Checking that the row of the kv is the same as the put int res = Bytes.compareTo(this.row, 0, row.length, kv.getBuffer(), kv.getRowOffset(), kv.getRowLength()); @@ -168,7 +161,162 @@ familyMap.put(family, list); return this; } + + /** + * Create a KeyValue with this objects row key and the Put identifier. + * + * @param family + * @param qualifier + * @param ts + * @param value + * @return a KeyValue with this objects row key and the Put identifier. + */ + private KeyValue createPutKeyValue(byte[] family, byte[] qualifier, long ts, + byte[] value) { + return new KeyValue(this.row, family, qualifier, ts, KeyValue.Type.Put, + value); + } + + /** + * A convenience method to determine if this object's familyMap contains + * a value assigned to the given family & qualifier. + * Both given arguments must match the KeyValue object to return true. + * + * @param family + * @param qualifier + * @return returns true if the given family and qualifier already has an + * existing KeyValue object in the family map. + */ + public boolean has(byte [] family, byte [] qualifier) { + return has(family, qualifier, this.timestamp, new byte[0], true, true); + } + + /** + * A convenience method to determine if this object's familyMap contains + * a value assigned to the given family, qualifier and timestamp. + * All 3 given arguments must match the KeyValue object to return true. + * + * @param family + * @param qualifier + * @param ts + * @return returns true if the given family, qualifier and timestamp already has an + * existing KeyValue object in the family map. + */ + public boolean has(byte [] family, byte [] qualifier, long ts) { + return has(family, qualifier, ts, new byte[0], false, true); + } + + /** + * A convenience method to determine if this object's familyMap contains + * a value assigned to the given family, qualifier and timestamp. + * All 3 given arguments must match the KeyValue object to return true. + * + * @param family + * @param qualifier + * @param value + * @return returns true if the given family, qualifier and value already has an + * existing KeyValue object in the family map. + */ + public boolean has(byte [] family, byte [] qualifier, byte [] value) { + return has(family, qualifier, this.timestamp, value, true, false); + } + + /** + * A convenience method to determine if this object's familyMap contains + * the given value assigned to the given family, qualifier and timestamp. + * All 4 given arguments must match the KeyValue object to return true. + * + * @param family + * @param qualifier + * @param ts + * @param value + * @return returns true if the given family, qualifier timestamp and value + * already has an existing KeyValue object in the family map. + */ + public boolean has(byte [] family, byte [] qualifier, long ts, byte [] value) { + return has(family, qualifier, ts, value, false, false); + } + + /** + * Private method to determine if this object's familyMap contains + * the given value assigned to the given family, qualifier and timestamp + * respecting the 2 boolean arguments + * + * @param family + * @param qualifier + * @param ts + * @param value + * @param ignoreTS + * @param ignoreValue + * @return returns true if the given family, qualifier timestamp and value + * already has an existing KeyValue object in the family map. + */ + private boolean has(byte [] family, byte [] qualifier, long ts, byte [] value, + boolean ignoreTS, boolean ignoreValue) { + List list = getKeyValueList(family); + if (list.size() == 0 ) { + return false; + } + if (!ignoreTS && !ignoreValue) { + KeyValue kv = createPutKeyValue(family, qualifier, ts, value); + return (list.contains(kv)); + } else if (ignoreValue) { + for (KeyValue kv: list) { + if (Arrays.equals(kv.getFamily(), family) && Arrays.equals(kv.getQualifier(), qualifier) + && kv.getTimestamp() == ts) { + return true; + } + } + } else if (ignoreTS) { + for (KeyValue kv: list) { + if (Arrays.equals(kv.getFamily(), family) && Arrays.equals(kv.getQualifier(), qualifier) + && Arrays.equals(kv.getValue(), value)) { + return true; + } + } + } else { + for (KeyValue kv: list) { + if (Arrays.equals(kv.getFamily(), family) && Arrays.equals( + kv.getQualifier(), qualifier)) { + return true; + } + } + } + return false; + } + /** + * Returns a list of all KeyValue objects with matching column family and qualifier. + * + * @param family + * @param qualifier + * @return a list of KeyValue objects with the matching family and qualifier, + * returns an empty list if one doesnt exist for the given family. + */ + public List get(byte[] family, byte[] qualifier) { + List filteredList = new ArrayList(); + for (KeyValue kv: getKeyValueList(family)) { + if (Arrays.equals(kv.getQualifier(), qualifier)) { + filteredList.add(kv); + } + } + return filteredList; + } + + /** + * Creates an empty list if one doesnt exist for the given column family + * or else it returns the associated list of KeyValue objects. + * + * @param family + * @return a list of KeyValue objects, returns an empty list if one doesnt exist. + */ + private List getKeyValueList(byte[] family) { + List list = familyMap.get(family); + if(list == null) { + list = new ArrayList(0); + } + return list; + } /** * Method for retrieving the put's familyMap