hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject svn commit: r707547 - in /hadoop/hbase/trunk: CHANGES.txt src/java/org/apache/hadoop/hbase/filter/ColumnValueFilter.java src/java/org/apache/hadoop/hbase/filter/RowFilterSet.java
Date Fri, 24 Oct 2008 05:19:25 GMT
Author: stack
Date: Thu Oct 23 22:19:24 2008
New Revision: 707547

URL: http://svn.apache.org/viewvc?rev=707547&view=rev
Log:
HBASE-942, HBASE-943 Add convenience methods to RowFilterSet, to ColumnValueFilter: add filterIfColumnMissing
property, add
SubString operator

Modified:
    hadoop/hbase/trunk/CHANGES.txt
    hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/filter/ColumnValueFilter.java
    hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/filter/RowFilterSet.java

Modified: hadoop/hbase/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/CHANGES.txt?rev=707547&r1=707546&r2=707547&view=diff
==============================================================================
--- hadoop/hbase/trunk/CHANGES.txt (original)
+++ hadoop/hbase/trunk/CHANGES.txt Thu Oct 23 22:19:24 2008
@@ -57,6 +57,10 @@
    HBASE-576   Investigate IPC performance
    HBASE-920   Make region balancing sloppier
    HBASE-902   Add force compaction and force split operations to UI and Admin
+   HBASE-942   Add convenience methods to RowFilterSet
+               (Clint Morgan via Stack)
+   HBASE-943   to ColumnValueFilter: add filterIfColumnMissing property, add
+               SubString operator (Clint Morgan via Stack)
 
   NEW FEATURES
    HBASE-875   Use MurmurHash instead of JenkinsHash [in bloomfilters]

Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/filter/ColumnValueFilter.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/filter/ColumnValueFilter.java?rev=707547&r1=707546&r2=707547&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/filter/ColumnValueFilter.java (original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/filter/ColumnValueFilter.java Thu
Oct 23 22:19:24 2008
@@ -53,13 +53,18 @@
     /** greater than or equal to */
     GREATER_OR_EQUAL,
     /** greater than */
-    GREATER;
+    GREATER,
+    // Below are more specific operators.
+    /** sub-string. Case insensitive. */
+    SUB_STRING;
+    
   }
 
   private byte[] columnName;
   private CompareOp compareOp;
   private byte[] value;
   private WritableByteArrayComparable comparator;
+  private boolean filterIfColumnMissing;
 
   ColumnValueFilter() {
     // for Writable
@@ -74,9 +79,23 @@
    */
   public ColumnValueFilter(final byte[] columnName, final CompareOp compareOp,
       final byte[] value) {
+    this(columnName, compareOp, value, true);
+  }
+  
+  /**
+   * Constructor.
+   * 
+   * @param columnName name of column
+   * @param compareOp operator
+   * @param value value to compare column values against
+   * @param filterIfColumnMissing if true then we will filter rows that don't have the column.

+   */
+  public ColumnValueFilter(final byte[] columnName, final CompareOp compareOp,
+      final byte[] value, boolean filterIfColumnMissing) {
     this.columnName = columnName;
     this.compareOp = compareOp;
     this.value = value;
+    this.filterIfColumnMissing = filterIfColumnMissing;
   }
 
   /**
@@ -88,10 +107,24 @@
    */
   public ColumnValueFilter(final byte[] columnName, final CompareOp compareOp,
       final WritableByteArrayComparable comparator) {
-    this.columnName = columnName;
-    this.compareOp = compareOp;
-    this.comparator = comparator;
+    this(columnName, compareOp, comparator, true);
   }
+  
+  /**
+  * Constructor.
+  * 
+  * @param columnName name of column
+  * @param compareOp operator
+  * @param comparator Comparator to use.
+  * @param filterIfColumnMissing if true then we will filter rows that don't have the column.

+  */
+ public ColumnValueFilter(final byte[] columnName, final CompareOp compareOp,
+     final WritableByteArrayComparable comparator, boolean filterIfColumnMissing) {
+   this.columnName = columnName;
+   this.compareOp = compareOp;
+   this.comparator = comparator;
+   this.filterIfColumnMissing = filterIfColumnMissing;
+ }
 
   public boolean filterRowKey(@SuppressWarnings("unused") final byte[] rowKey) {
     return false;
@@ -99,9 +132,22 @@
 
   public boolean filterColumn(@SuppressWarnings("unused") final byte[] rowKey,
       final byte[] colKey, final byte[] data) {
+    if (!filterIfColumnMissing) {
+      return false; // Must filter on the whole row
+    }
     if (!Arrays.equals(colKey, columnName)) {
       return false;
     }
+    return filterColumnValue(data); 
+    
+  }
+
+  private boolean filterColumnValue(final byte [] data) {
+    // Special case for Substring operator
+    if (compareOp == CompareOp.SUB_STRING) {
+      return !Bytes.toString(data).toLowerCase().contains(
+          (Bytes.toString(value)).toLowerCase());
+    }
 
     int compareResult;
     if (comparator != null) {
@@ -127,14 +173,22 @@
       throw new RuntimeException("Unknown Compare op " + compareOp.name());
     }
   }
-
+  
   public boolean filterAllRemaining() {
     return false;
   }
 
   public boolean filterRow(final SortedMap<byte[], Cell> columns) {
-    // Don't let rows through if they don't have the column we are checking
-    return !columns.containsKey(columnName);
+    if (filterIfColumnMissing) {
+      return !columns.containsKey(columnName);
+    } 
+
+    // Otherwise we must do the filter here
+    Cell colCell = columns.get(columnName);
+      if (colCell == null) {
+        return false;
+      }
+      return this.filterColumnValue(colCell.getValue());
   }
 
   private int compare(final byte[] b1, final byte[] b2) {
@@ -175,6 +229,7 @@
     compareOp = CompareOp.valueOf(in.readUTF());
     comparator = (WritableByteArrayComparable) ObjectWritable.readObject(in,
         new HBaseConfiguration());
+    filterIfColumnMissing = in.readBoolean();
   }
 
   public void write(final DataOutput out) throws IOException {
@@ -188,6 +243,7 @@
     out.writeUTF(compareOp.name());
     ObjectWritable.writeObject(out, comparator,
         WritableByteArrayComparable.class, new HBaseConfiguration());
+    out.writeBoolean(filterIfColumnMissing);
   }
 
 }

Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/filter/RowFilterSet.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/filter/RowFilterSet.java?rev=707547&r1=707546&r2=707547&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/filter/RowFilterSet.java (original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/filter/RowFilterSet.java Thu Oct 23
22:19:24 2008
@@ -80,6 +80,22 @@
     this.operator = operator;
   }
 
+  /** Get the operator.
+   * 
+   * @return operator
+   */
+  public Operator getOperator() {
+    return operator;
+  }
+  
+  /** Add a filter.
+   * 
+   * @param filter
+   */
+  public void addFilter(RowFilterInterface filter) {
+    this.filters.add(filter);
+  }
+  
   public void validate(final byte [][] columns) {
     for (RowFilterInterface filter : filters) {
       filter.validate(columns);



Mime
View raw message