You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ji...@apache.org on 2008/04/23 03:03:40 UTC
svn commit: r650711 [1/2] - in /hadoop/hbase/trunk: ./
src/java/org/apache/hadoop/hbase/filter/
src/java/org/apache/hadoop/hbase/regionserver/
src/test/org/apache/hadoop/hbase/filter/
Author: jimk
Date: Tue Apr 22 18:03:38 2008
New Revision: 650711
URL: http://svn.apache.org/viewvc?rev=650711&view=rev
Log:
HBASE-584 Names in the filter interface are confusing (Clint Morgan via Jim Kellerman) (API change for filters)
Modified:
hadoop/hbase/trunk/CHANGES.txt
hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/filter/InclusiveStopRowFilter.java
hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/filter/PageRowFilter.java
hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/filter/RegExpRowFilter.java
hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/filter/RowFilterInterface.java
hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/filter/RowFilterSet.java
hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/filter/StopRowFilter.java
hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/filter/WhileMatchRowFilter.java
hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/regionserver/HRegion.java
hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/regionserver/HStoreScanner.java
hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/filter/TestInclusiveStopRowFilter.java
hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/filter/TestPageRowFilter.java
hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/filter/TestRegExpRowFilter.java
hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/filter/TestRowFilterSet.java
hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/filter/TestStopRowFilter.java
hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/filter/TestWhileMatchRowFilter.java
Modified: hadoop/hbase/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/CHANGES.txt?rev=650711&r1=650710&r2=650711&view=diff
==============================================================================
--- hadoop/hbase/trunk/CHANGES.txt (original)
+++ hadoop/hbase/trunk/CHANGES.txt Tue Apr 22 18:03:38 2008
@@ -1,4 +1,9 @@
Hbase Change Log
+
+ INCOMPATIBLE CHANGES
+ HBASE-584 Names in the filter interface are confusing (Clint Morgan via
+ Jim Kellerman) (API change for filters)
+
BUG FIXES
HBASE-574 HBase does not load hadoop native libs (Rong-En Fan via Stack)
HBASE-573 HBase does not read hadoop-*.xml for dfs configuration after
Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/filter/InclusiveStopRowFilter.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/filter/InclusiveStopRowFilter.java?rev=650711&r1=650710&r2=650711&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/filter/InclusiveStopRowFilter.java (original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/filter/InclusiveStopRowFilter.java Tue Apr 22 18:03:38 2008
@@ -1,61 +1,61 @@
-/**
- * Copyright 2007 The Apache Software Foundation
- *
- * 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.
- */
-package org.apache.hadoop.hbase.filter;
-
-import org.apache.hadoop.io.Text;
-
-/**
- * Subclass of StopRowFilter that filters rows > the stop row,
- * making it include up to the last row but no further.
- */
-public class InclusiveStopRowFilter extends StopRowFilter{
- /**
- * Default constructor, filters nothing. Required though for RPC
- * deserialization.
- */
- public InclusiveStopRowFilter() {super();}
-
- /**
- * Constructor that takes a stopRowKey on which to filter
- *
- * @param stopRowKey rowKey to filter on.
- */
- public InclusiveStopRowFilter(final Text stopRowKey) {
- super(stopRowKey);
- }
-
- /** {@inheritDoc} */
- @Override
- public boolean filter(final Text rowKey) {
- if (rowKey == null) {
- if (this.stopRowKey == null) {
- return true;
- }
- return false;
- }
- boolean result = this.stopRowKey.compareTo(rowKey) < 0;
- if (LOG.isDebugEnabled()) {
- LOG.debug("Filter result for rowKey: " + rowKey + ". Result: " +
- result);
- }
- return result;
- }
-
-}
+/**
+ * Copyright 2007 The Apache Software Foundation
+ *
+ * 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.
+ */
+package org.apache.hadoop.hbase.filter;
+
+import org.apache.hadoop.io.Text;
+
+/**
+ * Subclass of StopRowFilter that filters rows > the stop row,
+ * making it include up to the last row but no further.
+ */
+public class InclusiveStopRowFilter extends StopRowFilter{
+ /**
+ * Default constructor, filters nothing. Required though for RPC
+ * deserialization.
+ */
+ public InclusiveStopRowFilter() {super();}
+
+ /**
+ * Constructor that takes a stopRowKey on which to filter
+ *
+ * @param stopRowKey rowKey to filter on.
+ */
+ public InclusiveStopRowFilter(final Text stopRowKey) {
+ super(stopRowKey);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public boolean filterRowKey(final Text rowKey) {
+ if (rowKey == null) {
+ if (this.stopRowKey == null) {
+ return true;
+ }
+ return false;
+ }
+ boolean result = this.stopRowKey.compareTo(rowKey) < 0;
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Filter result for rowKey: " + rowKey + ". Result: " +
+ result);
+ }
+ return result;
+ }
+
+}
Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/filter/PageRowFilter.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/filter/PageRowFilter.java?rev=650711&r1=650710&r2=650711&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/filter/PageRowFilter.java (original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/filter/PageRowFilter.java Tue Apr 22 18:03:38 2008
@@ -1,159 +1,159 @@
-/**
- * Copyright 2007 The Apache Software Foundation
- *
- * 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.
- */
-package org.apache.hadoop.hbase.filter;
-
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import java.util.SortedMap;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.hadoop.io.Text;
-
-/**
- * Implementation of RowFilterInterface that limits results to a specific page
- * size. It terminates scanning once the number of filter-passed results is >=
- * the given page size.
- *
- * <p>
- * Note that this filter cannot guarantee that the number of results returned
- * to a client are <= page size. This is because the filter is applied
- * separately on different region servers. It does however optimize the scan of
- * individual HRegions by making sure that the page size is never exceeded
- * locally.
- * </p>
- */
-public class PageRowFilter implements RowFilterInterface {
-
- private long pageSize = Long.MAX_VALUE;
- private int rowsAccepted = 0;
-
- static final Log LOG = LogFactory.getLog(PageRowFilter.class);
-
- /**
- * Default constructor, filters nothing. Required though for RPC
- * deserialization.
- */
- public PageRowFilter() {
- super();
- }
-
- /**
- * Constructor that takes a maximum page size.
- *
- * @param pageSize Maximum result size.
- */
- public PageRowFilter(final long pageSize) {
- this.pageSize = pageSize;
- }
-
- /**
- *
- * {@inheritDoc}
- */
- public void validate(@SuppressWarnings("unused") final Text[] columns) {
- // Doesn't filter columns
- }
-
- /**
- *
- * {@inheritDoc}
- */
- public void reset() {
- rowsAccepted = 0;
- }
-
- /** {@inheritDoc} */
- public void rowProcessed(boolean filtered,
- @SuppressWarnings("unused") Text rowKey) {
- if (!filtered) {
- this.rowsAccepted++;
- if (LOG.isDebugEnabled()) {
- LOG.debug("rowProcessed incremented rowsAccepted to " +
- this.rowsAccepted);
- }
- }
- }
-
- /**
- *
- * {@inheritDoc}
- */
- public boolean processAlways() {
- return false;
- }
-
- /**
- *
- * {@inheritDoc}
- */
- public boolean filterAllRemaining() {
- boolean result = this.rowsAccepted > this.pageSize;
- if (LOG.isDebugEnabled()) {
- LOG.debug("filtering decision is " + result + " with rowsAccepted: " +
- this.rowsAccepted);
- }
- return result;
- }
-
- /**
- *
- * {@inheritDoc}
- */
- public boolean filter(@SuppressWarnings("unused") final Text rowKey) {
- return filterAllRemaining();
- }
-
- /**
- *
- * {@inheritDoc}
- */
- public boolean filter(@SuppressWarnings("unused") final Text rowKey,
- @SuppressWarnings("unused") final Text colKey,
- @SuppressWarnings("unused") final byte[] data) {
- return filterAllRemaining();
- }
-
- /**
- *
- * {@inheritDoc}
- */
- public boolean filterNotNull(@SuppressWarnings("unused")
- final SortedMap<Text, byte[]> columns) {
- return filterAllRemaining();
- }
-
- /**
- *
- * {@inheritDoc}
- */
- public void readFields(final DataInput in) throws IOException {
- this.pageSize = in.readLong();
- }
-
- /**
- *
- * {@inheritDoc}
- */
- public void write(final DataOutput out) throws IOException {
- out.writeLong(pageSize);
- }
+/**
+ * Copyright 2007 The Apache Software Foundation
+ *
+ * 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.
+ */
+package org.apache.hadoop.hbase.filter;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.util.SortedMap;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.io.Text;
+
+/**
+ * Implementation of RowFilterInterface that limits results to a specific page
+ * size. It terminates scanning once the number of filter-passed results is >=
+ * the given page size.
+ *
+ * <p>
+ * Note that this filter cannot guarantee that the number of results returned
+ * to a client are <= page size. This is because the filter is applied
+ * separately on different region servers. It does however optimize the scan of
+ * individual HRegions by making sure that the page size is never exceeded
+ * locally.
+ * </p>
+ */
+public class PageRowFilter implements RowFilterInterface {
+
+ private long pageSize = Long.MAX_VALUE;
+ private int rowsAccepted = 0;
+
+ static final Log LOG = LogFactory.getLog(PageRowFilter.class);
+
+ /**
+ * Default constructor, filters nothing. Required though for RPC
+ * deserialization.
+ */
+ public PageRowFilter() {
+ super();
+ }
+
+ /**
+ * Constructor that takes a maximum page size.
+ *
+ * @param pageSize Maximum result size.
+ */
+ public PageRowFilter(final long pageSize) {
+ this.pageSize = pageSize;
+ }
+
+ /**
+ *
+ * {@inheritDoc}
+ */
+ public void validate(@SuppressWarnings("unused") final Text[] columns) {
+ // Doesn't filter columns
+ }
+
+ /**
+ *
+ * {@inheritDoc}
+ */
+ public void reset() {
+ rowsAccepted = 0;
+ }
+
+ /** {@inheritDoc} */
+ public void rowProcessed(boolean filtered,
+ @SuppressWarnings("unused") Text rowKey) {
+ if (!filtered) {
+ this.rowsAccepted++;
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("rowProcessed incremented rowsAccepted to " +
+ this.rowsAccepted);
+ }
+ }
+ }
+
+ /**
+ *
+ * {@inheritDoc}
+ */
+ public boolean processAlways() {
+ return false;
+ }
+
+ /**
+ *
+ * {@inheritDoc}
+ */
+ public boolean filterAllRemaining() {
+ boolean result = this.rowsAccepted > this.pageSize;
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("filtering decision is " + result + " with rowsAccepted: " +
+ this.rowsAccepted);
+ }
+ return result;
+ }
+
+ /**
+ *
+ * {@inheritDoc}
+ */
+ public boolean filterRowKey(@SuppressWarnings("unused") final Text rowKey) {
+ return filterAllRemaining();
+ }
+
+ /**
+ *
+ * {@inheritDoc}
+ */
+ public boolean filterColumn(@SuppressWarnings("unused") final Text rowKey,
+ @SuppressWarnings("unused") final Text colKey,
+ @SuppressWarnings("unused") final byte[] data) {
+ return filterAllRemaining();
+ }
+
+ /**
+ *
+ * {@inheritDoc}
+ */
+ public boolean filterRow(@SuppressWarnings("unused")
+ final SortedMap<Text, byte[]> columns) {
+ return filterAllRemaining();
+ }
+
+ /**
+ *
+ * {@inheritDoc}
+ */
+ public void readFields(final DataInput in) throws IOException {
+ this.pageSize = in.readLong();
+ }
+
+ /**
+ *
+ * {@inheritDoc}
+ */
+ public void write(final DataOutput out) throws IOException {
+ out.writeLong(pageSize);
+ }
}
Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/filter/RegExpRowFilter.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/filter/RegExpRowFilter.java?rev=650711&r1=650710&r2=650711&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/filter/RegExpRowFilter.java (original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/filter/RegExpRowFilter.java Tue Apr 22 18:03:38 2008
@@ -1,340 +1,340 @@
-/**
- * Copyright 2007 The Apache Software Foundation
- *
- * 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.
- */
-package org.apache.hadoop.hbase.filter;
-
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.SortedMap;
-import java.util.Map.Entry;
-import java.util.regex.Pattern;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.hadoop.io.Text;
-
-import org.apache.hadoop.hbase.regionserver.HLogEdit;
-
-/**
- * Implementation of RowFilterInterface that can filter by rowkey regular
- * expression and/or individual column values (equals comparison only).
- * Multiple column filters imply an implicit conjunction of filter criteria.
- */
-public class RegExpRowFilter implements RowFilterInterface {
-
- private Pattern rowKeyPattern = null;
- private String rowKeyRegExp = null;
-
- private Map<Text, byte[]> equalsMap = new HashMap<Text, byte[]>();
- private Set<Text> nullColumns = new HashSet<Text>();
-
- static final Log LOG = LogFactory.getLog(RegExpRowFilter.class);
-
- /**
- * Default constructor, filters nothing. Required though for RPC
- * deserialization.
- */
- public RegExpRowFilter() {
- super();
- }
-
- /**
- * Constructor that takes a row key regular expression to filter on.
- *
- * @param rowKeyRegExp
- */
- public RegExpRowFilter(final String rowKeyRegExp) {
- this.rowKeyRegExp = rowKeyRegExp;
- }
-
- /**
- * Constructor that takes a row key regular expression to filter on.
- *
- * @param rowKeyRegExp
- * @param columnFilter
- */
- public RegExpRowFilter(final String rowKeyRegExp,
- final Map<Text, byte[]> columnFilter) {
- this.rowKeyRegExp = rowKeyRegExp;
- this.setColumnFilters(columnFilter);
- }
-
- /** {@inheritDoc} */
- @SuppressWarnings("unused")
- public void rowProcessed(boolean filtered, Text rowKey) {
- //doesn't care
- }
-
- /** {@inheritDoc} */
- public boolean processAlways() {
- return false;
- }
-
- /**
- * Specify a value that must be matched for the given column.
- *
- * @param colKey
- * the column to match on
- * @param value
- * the value that must equal the stored value.
- */
- public void setColumnFilter(final Text colKey, final byte[] value) {
- if (value == null) {
- nullColumns.add(colKey);
- } else {
- equalsMap.put(colKey, value);
- }
- }
-
- /**
- * Set column filters for a number of columns.
- *
- * @param columnFilter
- * Map of columns with value criteria.
- */
- public void setColumnFilters(final Map<Text, byte[]> columnFilter) {
- if (null == columnFilter) {
- nullColumns.clear();
- equalsMap.clear();
- } else {
- for (Entry<Text, byte[]> entry : columnFilter.entrySet()) {
- setColumnFilter(entry.getKey(), entry.getValue());
- }
- }
- }
-
- /**
- *
- * {@inheritDoc}
- */
- public void reset() {
- // Nothing to reset
- }
-
- /**
- *
- * {@inheritDoc}
- */
- public boolean filterAllRemaining() {
- return false;
- }
-
- /**
- *
- * {@inheritDoc}
- */
- public boolean filter(final Text rowKey) {
- if (filtersByRowKey() && rowKey != null) {
- boolean result = !getRowKeyPattern().matcher(rowKey.toString()).matches();
- if (LOG.isDebugEnabled()) {
- LOG.debug("filter returning " + result + " for rowKey: " + rowKey);
- }
- return result;
- }
- return false;
- }
-
- /**
- *
- * {@inheritDoc}
- */
- public boolean filter(final Text rowKey, final Text colKey,
- final byte[] data) {
- if (filter(rowKey)) {
- return true;
- }
- if (filtersByColumnValue()) {
- byte[] filterValue = equalsMap.get(colKey);
- if (null != filterValue) {
- boolean result = !Arrays.equals(filterValue, data);
- if (LOG.isDebugEnabled()) {
- LOG.debug("filter returning " + result + " for rowKey: " + rowKey +
- " colKey: " + colKey);
- }
- return result;
- }
- }
- if (nullColumns.contains(colKey)) {
- if (data != null && !HLogEdit.isDeleted(data)) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("filter returning true for rowKey: " + rowKey +
- " colKey: " + colKey);
- }
- return true;
- }
- }
- if (LOG.isDebugEnabled()) {
- LOG.debug("filter returning false for rowKey: " + rowKey + " colKey: " +
- colKey);
- }
- return false;
- }
-
- /**
- *
- * {@inheritDoc}
- */
- public boolean filterNotNull(final SortedMap<Text, byte[]> columns) {
- for (Entry<Text, byte[]> col : columns.entrySet()) {
- if (nullColumns.contains(col.getKey())
- && !HLogEdit.isDeleted(col.getValue())) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("filterNotNull returning true for colKey: " + col.getKey()
- + ", column should be null.");
- }
- return true;
- }
- }
- for (Text col : equalsMap.keySet()) {
- if (!columns.containsKey(col)) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("filterNotNull returning true for colKey: " + col +
- ", column not found in given SortedMap<Text, byte[]>.");
- }
- return true;
- }
- }
- if (LOG.isDebugEnabled()) {
- LOG.debug("filterNotNull returning false.");
- }
- return false;
- }
-
- private boolean filtersByColumnValue() {
- return equalsMap != null && equalsMap.size() > 0;
- }
-
- private boolean filtersByRowKey() {
- return null != rowKeyPattern || null != rowKeyRegExp;
- }
-
- private String getRowKeyRegExp() {
- if (null == rowKeyRegExp && rowKeyPattern != null) {
- rowKeyRegExp = rowKeyPattern.toString();
- }
- return rowKeyRegExp;
- }
-
- private Pattern getRowKeyPattern() {
- if (rowKeyPattern == null && rowKeyRegExp != null) {
- rowKeyPattern = Pattern.compile(rowKeyRegExp);
- }
- return rowKeyPattern;
- }
-
- /**
- *
- * {@inheritDoc}
- */
- public void readFields(final DataInput in) throws IOException {
- boolean hasRowKeyPattern = in.readBoolean();
- if (hasRowKeyPattern) {
- rowKeyRegExp = in.readUTF();
- }
- // equals map
- equalsMap.clear();
- int size = in.readInt();
- for (int i = 0; i < size; i++) {
- Text key = new Text();
- key.readFields(in);
- int len = in.readInt();
- byte[] value = null;
- if (len >= 0) {
- value = new byte[len];
- in.readFully(value);
- }
- setColumnFilter(key, value);
- }
- // nullColumns
- nullColumns.clear();
- size = in.readInt();
- for (int i = 0; i < size; i++) {
- Text key = new Text();
- key.readFields(in);
- setColumnFilter(key, null);
- }
- }
-
- /**
- *
- * {@inheritDoc}
- */
- public void validate(final Text[] columns) {
- Set<Text> invalids = new HashSet<Text>();
- for (Text colKey : getFilterColumns()) {
- boolean found = false;
- for (Text col : columns) {
- if (col.equals(colKey)) {
- found = true;
- break;
- }
- }
- if (!found) {
- invalids.add(colKey);
- }
- }
-
- if (invalids.size() > 0) {
- throw new InvalidRowFilterException(String.format(
- "RowFilter contains criteria on columns %s not in %s", invalids,
- Arrays.toString(columns)));
- }
- }
-
- private Set<Text> getFilterColumns() {
- Set<Text> cols = new HashSet<Text>();
- cols.addAll(equalsMap.keySet());
- cols.addAll(nullColumns);
- return cols;
- }
-
- /**
- *
- * {@inheritDoc}
- */
- public void write(final DataOutput out) throws IOException {
- if (!filtersByRowKey()) {
- out.writeBoolean(false);
- } else {
- out.writeBoolean(true);
- out.writeUTF(getRowKeyRegExp());
- }
-
- // equalsMap
- out.writeInt(equalsMap.size());
- for (Entry<Text, byte[]> entry : equalsMap.entrySet()) {
- entry.getKey().write(out);
- byte[] value = entry.getValue();
- out.writeInt(value.length);
- out.write(value);
- }
-
- // null columns
- out.writeInt(nullColumns.size());
- for (Text col : nullColumns) {
- col.write(out);
- }
- }
+/**
+ * Copyright 2007 The Apache Software Foundation
+ *
+ * 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.
+ */
+package org.apache.hadoop.hbase.filter;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.Map.Entry;
+import java.util.regex.Pattern;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.io.Text;
+
+import org.apache.hadoop.hbase.regionserver.HLogEdit;
+
+/**
+ * Implementation of RowFilterInterface that can filter by rowkey regular
+ * expression and/or individual column values (equals comparison only).
+ * Multiple column filters imply an implicit conjunction of filter criteria.
+ */
+public class RegExpRowFilter implements RowFilterInterface {
+
+ private Pattern rowKeyPattern = null;
+ private String rowKeyRegExp = null;
+
+ private Map<Text, byte[]> equalsMap = new HashMap<Text, byte[]>();
+ private Set<Text> nullColumns = new HashSet<Text>();
+
+ static final Log LOG = LogFactory.getLog(RegExpRowFilter.class);
+
+ /**
+ * Default constructor, filters nothing. Required though for RPC
+ * deserialization.
+ */
+ public RegExpRowFilter() {
+ super();
+ }
+
+ /**
+ * Constructor that takes a row key regular expression to filter on.
+ *
+ * @param rowKeyRegExp
+ */
+ public RegExpRowFilter(final String rowKeyRegExp) {
+ this.rowKeyRegExp = rowKeyRegExp;
+ }
+
+ /**
+ * Constructor that takes a row key regular expression to filter on.
+ *
+ * @param rowKeyRegExp
+ * @param columnFilter
+ */
+ public RegExpRowFilter(final String rowKeyRegExp,
+ final Map<Text, byte[]> columnFilter) {
+ this.rowKeyRegExp = rowKeyRegExp;
+ this.setColumnFilters(columnFilter);
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("unused")
+ public void rowProcessed(boolean filtered, Text rowKey) {
+ //doesn't care
+ }
+
+ /** {@inheritDoc} */
+ public boolean processAlways() {
+ return false;
+ }
+
+ /**
+ * Specify a value that must be matched for the given column.
+ *
+ * @param colKey
+ * the column to match on
+ * @param value
+ * the value that must equal the stored value.
+ */
+ public void setColumnFilter(final Text colKey, final byte[] value) {
+ if (value == null) {
+ nullColumns.add(colKey);
+ } else {
+ equalsMap.put(colKey, value);
+ }
+ }
+
+ /**
+ * Set column filters for a number of columns.
+ *
+ * @param columnFilter
+ * Map of columns with value criteria.
+ */
+ public void setColumnFilters(final Map<Text, byte[]> columnFilter) {
+ if (null == columnFilter) {
+ nullColumns.clear();
+ equalsMap.clear();
+ } else {
+ for (Entry<Text, byte[]> entry : columnFilter.entrySet()) {
+ setColumnFilter(entry.getKey(), entry.getValue());
+ }
+ }
+ }
+
+ /**
+ *
+ * {@inheritDoc}
+ */
+ public void reset() {
+ // Nothing to reset
+ }
+
+ /**
+ *
+ * {@inheritDoc}
+ */
+ public boolean filterAllRemaining() {
+ return false;
+ }
+
+ /**
+ *
+ * {@inheritDoc}
+ */
+ public boolean filterRowKey(final Text rowKey) {
+ if (filtersByRowKey() && rowKey != null) {
+ boolean result = !getRowKeyPattern().matcher(rowKey.toString()).matches();
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("filter returning " + result + " for rowKey: " + rowKey);
+ }
+ return result;
+ }
+ return false;
+ }
+
+ /**
+ *
+ * {@inheritDoc}
+ */
+ public boolean filterColumn(final Text rowKey, final Text colKey,
+ final byte[] data) {
+ if (filterRowKey(rowKey)) {
+ return true;
+ }
+ if (filtersByColumnValue()) {
+ byte[] filterValue = equalsMap.get(colKey);
+ if (null != filterValue) {
+ boolean result = !Arrays.equals(filterValue, data);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("filter returning " + result + " for rowKey: " + rowKey +
+ " colKey: " + colKey);
+ }
+ return result;
+ }
+ }
+ if (nullColumns.contains(colKey)) {
+ if (data != null && !HLogEdit.isDeleted(data)) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("filter returning true for rowKey: " + rowKey +
+ " colKey: " + colKey);
+ }
+ return true;
+ }
+ }
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("filter returning false for rowKey: " + rowKey + " colKey: " +
+ colKey);
+ }
+ return false;
+ }
+
+ /**
+ *
+ * {@inheritDoc}
+ */
+ public boolean filterRow(final SortedMap<Text, byte[]> columns) {
+ for (Entry<Text, byte[]> col : columns.entrySet()) {
+ if (nullColumns.contains(col.getKey())
+ && !HLogEdit.isDeleted(col.getValue())) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("filterNotNull returning true for colKey: " + col.getKey()
+ + ", column should be null.");
+ }
+ return true;
+ }
+ }
+ for (Text col : equalsMap.keySet()) {
+ if (!columns.containsKey(col)) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("filterNotNull returning true for colKey: " + col +
+ ", column not found in given SortedMap<Text, byte[]>.");
+ }
+ return true;
+ }
+ }
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("filterNotNull returning false.");
+ }
+ return false;
+ }
+
+ private boolean filtersByColumnValue() {
+ return equalsMap != null && equalsMap.size() > 0;
+ }
+
+ private boolean filtersByRowKey() {
+ return null != rowKeyPattern || null != rowKeyRegExp;
+ }
+
+ private String getRowKeyRegExp() {
+ if (null == rowKeyRegExp && rowKeyPattern != null) {
+ rowKeyRegExp = rowKeyPattern.toString();
+ }
+ return rowKeyRegExp;
+ }
+
+ private Pattern getRowKeyPattern() {
+ if (rowKeyPattern == null && rowKeyRegExp != null) {
+ rowKeyPattern = Pattern.compile(rowKeyRegExp);
+ }
+ return rowKeyPattern;
+ }
+
+ /**
+ *
+ * {@inheritDoc}
+ */
+ public void readFields(final DataInput in) throws IOException {
+ boolean hasRowKeyPattern = in.readBoolean();
+ if (hasRowKeyPattern) {
+ rowKeyRegExp = in.readUTF();
+ }
+ // equals map
+ equalsMap.clear();
+ int size = in.readInt();
+ for (int i = 0; i < size; i++) {
+ Text key = new Text();
+ key.readFields(in);
+ int len = in.readInt();
+ byte[] value = null;
+ if (len >= 0) {
+ value = new byte[len];
+ in.readFully(value);
+ }
+ setColumnFilter(key, value);
+ }
+ // nullColumns
+ nullColumns.clear();
+ size = in.readInt();
+ for (int i = 0; i < size; i++) {
+ Text key = new Text();
+ key.readFields(in);
+ setColumnFilter(key, null);
+ }
+ }
+
+ /**
+ *
+ * {@inheritDoc}
+ */
+ public void validate(final Text[] columns) {
+ Set<Text> invalids = new HashSet<Text>();
+ for (Text colKey : getFilterColumns()) {
+ boolean found = false;
+ for (Text col : columns) {
+ if (col.equals(colKey)) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ invalids.add(colKey);
+ }
+ }
+
+ if (invalids.size() > 0) {
+ throw new InvalidRowFilterException(String.format(
+ "RowFilter contains criteria on columns %s not in %s", invalids,
+ Arrays.toString(columns)));
+ }
+ }
+
+ private Set<Text> getFilterColumns() {
+ Set<Text> cols = new HashSet<Text>();
+ cols.addAll(equalsMap.keySet());
+ cols.addAll(nullColumns);
+ return cols;
+ }
+
+ /**
+ *
+ * {@inheritDoc}
+ */
+ public void write(final DataOutput out) throws IOException {
+ if (!filtersByRowKey()) {
+ out.writeBoolean(false);
+ } else {
+ out.writeBoolean(true);
+ out.writeUTF(getRowKeyRegExp());
+ }
+
+ // equalsMap
+ out.writeInt(equalsMap.size());
+ for (Entry<Text, byte[]> entry : equalsMap.entrySet()) {
+ entry.getKey().write(out);
+ byte[] value = entry.getValue();
+ out.writeInt(value.length);
+ out.write(value);
+ }
+
+ // null columns
+ out.writeInt(nullColumns.size());
+ for (Text col : nullColumns) {
+ col.write(out);
+ }
+ }
}
Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/filter/RowFilterInterface.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/filter/RowFilterInterface.java?rev=650711&r1=650710&r2=650711&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/filter/RowFilterInterface.java (original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/filter/RowFilterInterface.java Tue Apr 22 18:03:38 2008
@@ -1,125 +1,115 @@
-/**
- * Copyright 2007 The Apache Software Foundation
- *
- * 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.
- */
-package org.apache.hadoop.hbase.filter;
-
-import java.util.SortedMap;
-
-import org.apache.hadoop.io.Text;
-import org.apache.hadoop.io.Writable;
-
-/**
- *
- * Interface used for row-level filters applied to HRegion.HScanner scan
- * results during calls to next().
- */
-public interface RowFilterInterface extends Writable {
-
- /**
- * Resets the state of the filter. Used prior to the start of a Region scan.
- *
- */
- void reset();
-
- /**
- * Called to let filter know the final decision (to pass or filter) on a
- * given row. With out HScanner calling this, the filter does not know if a
- * row passed filtering even if it passed the row itself because other
- * filters may have failed the row. E.g. when this filter is a member of a
- * RowFilterSet with an OR operator.
- *
- * @see RowFilterSet
- * @param filtered
- * @param key
- */
- void rowProcessed(boolean filtered, Text key);
-
- /**
- * Returns whether or not the filter should always be processed in any
- * filtering call. This precaution is necessary for filters that maintain
- * state and need to be updated according to their response to filtering
- * calls (see WhileMatchRowFilter for an example). At times, filters nested
- * in RowFilterSets may or may not be called because the RowFilterSet
- * determines a result as fast as possible. Returning true for
- * processAlways() ensures that the filter will always be called.
- *
- * @return whether or not to always process the filter
- */
- boolean processAlways();
-
- /**
- * Determines if the filter has decided that all remaining results should be
- * filtered (skipped). This is used to prevent the scanner from scanning a
- * the rest of the HRegion when for sure the filter will exclude all
- * remaining rows.
- *
- * @return true if the filter intends to filter all remaining rows.
- */
- boolean filterAllRemaining();
-
- /**
- * Filters on just a row key.
- *
- * @param rowKey
- * @return true if given row key is filtered and row should not be processed.
- */
- boolean filter(final Text rowKey);
-
- /**
- * Filters on row key and/or a column key.
- *
- * @param rowKey
- * row key to filter on. May be null for no filtering of row key.
- * @param colKey
- * column whose data will be filtered
- * @param data
- * column value
- * @return true if row filtered and should not be processed.
- */
- boolean filter(final Text rowKey, final Text colKey, final byte[] data);
-
- /**
- * Filters a row if:
- * 1) The given row (@param columns) has a columnKey expected to be null AND
- * the value associated with that columnKey is non-null.
- * 2) The filter has a criterion for a particular columnKey, but that
- * columnKey is not in the given row (@param columns).
- *
- * Note that filterNotNull does not care whether the values associated with a
- * columnKey match. Also note that a "null value" associated with a columnKey
- * is expressed as HConstants.DELETE_BYTES.
- *
- * @param columns
- * @return true if null/non-null criteria not met.
- */
- boolean filterNotNull(final SortedMap<Text, byte[]> columns);
-
- /**
- * Validates that this filter applies only to a subset of the given columns.
- * This check is done prior to opening of scanner due to the limitation that
- * filtering of columns is dependent on the retrieval of those columns within
- * the HRegion. Criteria on columns that are not part of a scanner's column
- * list will be ignored. In the case of null value filters, all rows will pass
- * the filter. This behavior should be 'undefined' for the user and therefore
- * not permitted.
- *
- * @param columns
- */
- void validate(final Text[] columns);
+/**
+ * Copyright 2007 The Apache Software Foundation
+ *
+ * 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.
+ */
+package org.apache.hadoop.hbase.filter;
+
+import java.util.SortedMap;
+
+import org.apache.hadoop.io.Text;
+import org.apache.hadoop.io.Writable;
+
+/**
+ *
+ * Interface used for row-level filters applied to HRegion.HScanner scan
+ * results during calls to next().
+ */
+public interface RowFilterInterface extends Writable {
+
+ /**
+ * Resets the state of the filter. Used prior to the start of a Region scan.
+ *
+ */
+ void reset();
+
+ /**
+ * Called to let filter know the final decision (to pass or filter) on a
+ * given row. With out HScanner calling this, the filter does not know if a
+ * row passed filtering even if it passed the row itself because other
+ * filters may have failed the row. E.g. when this filter is a member of a
+ * RowFilterSet with an OR operator.
+ *
+ * @see RowFilterSet
+ * @param filtered
+ * @param key
+ */
+ void rowProcessed(boolean filtered, Text key);
+
+ /**
+ * Returns whether or not the filter should always be processed in any
+ * filtering call. This precaution is necessary for filters that maintain
+ * state and need to be updated according to their response to filtering
+ * calls (see WhileMatchRowFilter for an example). At times, filters nested
+ * in RowFilterSets may or may not be called because the RowFilterSet
+ * determines a result as fast as possible. Returning true for
+ * processAlways() ensures that the filter will always be called.
+ *
+ * @return whether or not to always process the filter
+ */
+ boolean processAlways();
+
+ /**
+ * Determines if the filter has decided that all remaining results should be
+ * filtered (skipped). This is used to prevent the scanner from scanning a
+ * the rest of the HRegion when for sure the filter will exclude all
+ * remaining rows.
+ *
+ * @return true if the filter intends to filter all remaining rows.
+ */
+ boolean filterAllRemaining();
+
+ /**
+ * Filters on just a row key. This is the first chance to stop a row.
+ *
+ * @param rowKey
+ * @return true if given row key is filtered and row should not be processed.
+ */
+ boolean filterRowKey(final Text rowKey);
+
+ /**
+ * Filters on row key, column name, and column value. This will take individual columns out of a row,
+ * but the rest of the row will still get through.
+ *
+ * @param rowKey row key to filter on.
+ * @param colunmName column name to filter on
+ * @param columnValue column value to filter on
+ * @return true if row filtered and should not be processed.
+ */
+ boolean filterColumn(final Text rowKey, final Text colunmName, final byte[] columnValue);
+
+ /**
+ * Filter on the fully assembled row. This is the last chance to stop a row.
+ *
+ * @param columns
+ * @return true if row filtered and should not be processed.
+ */
+ boolean filterRow(final SortedMap<Text, byte[]> columns);
+
+ /**
+ * Validates that this filter applies only to a subset of the given columns.
+ * This check is done prior to opening of scanner due to the limitation that
+ * filtering of columns is dependent on the retrieval of those columns within
+ * the HRegion. Criteria on columns that are not part of a scanner's column
+ * list will be ignored. In the case of null value filters, all rows will pass
+ * the filter. This behavior should be 'undefined' for the user and therefore
+ * not permitted.
+ *
+ * @param columns
+ */
+ void validate(final Text[] columns);
}
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=650711&r1=650710&r2=650711&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 Tue Apr 22 18:03:38 2008
@@ -1,313 +1,302 @@
-/**
- * Copyright 2007 The Apache Software Foundation
- *
- * 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.
- */
-package org.apache.hadoop.hbase.filter;
-
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.SortedMap;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.hadoop.io.Text;
-
-/**
- * Implementation of RowFilterInterface that represents a set of RowFilters
- * which will be evaluated with a specified boolean operator MUST_PASS_ALL
- * (!AND) or MUST_PASS_ONE (!OR). Since you can use RowFilterSets as children
- * of RowFilterSet, you can create a hierarchy of filters to be evaluated.
- */
-public class RowFilterSet implements RowFilterInterface {
-
- /** set operator */
- public static enum Operator {
- /** !AND */
- MUST_PASS_ALL,
- /** !OR */
- MUST_PASS_ONE
- }
-
- private Operator operator = Operator.MUST_PASS_ALL;
- private Set<RowFilterInterface> filters = new HashSet<RowFilterInterface>();
-
- static final Log LOG = LogFactory.getLog(RowFilterSet.class);
-
- /**
- * Default constructor, filters nothing. Required though for RPC
- * deserialization.
- */
- public RowFilterSet() {
- super();
- }
-
- /**
- * Constructor that takes a set of RowFilters. The default operator
- * MUST_PASS_ALL is assumed.
- *
- * @param rowFilters
- */
- public RowFilterSet(final Set<RowFilterInterface> rowFilters) {
- this.filters = rowFilters;
- }
-
- /**
- * Constructor that takes a set of RowFilters and an operator.
- *
- * @param operator Operator to process filter set with.
- * @param rowFilters Set of row filters.
- */
- public RowFilterSet(final Operator operator,
- final Set<RowFilterInterface> rowFilters) {
- this.filters = rowFilters;
- this.operator = operator;
- }
-
- /** {@inheritDoc} */
- public void validate(final Text[] columns) {
- for (RowFilterInterface filter : filters) {
- filter.validate(columns);
- if (LOG.isDebugEnabled()) {
- LOG.debug("Validated subfilter of type " +
- filter.getClass().getSimpleName());
- }
- }
- }
-
- /** {@inheritDoc} */
- public void reset() {
- for (RowFilterInterface filter : filters) {
- filter.reset();
- if (LOG.isDebugEnabled()) {
- LOG.debug("Reset subfilter of type " +
- filter.getClass().getSimpleName());
- }
- }
- }
-
- /** {@inheritDoc} */
- public void rowProcessed(boolean filtered, Text rowKey) {
- for (RowFilterInterface filter : filters) {
- filter.rowProcessed(filtered, rowKey);
- if (LOG.isDebugEnabled()) {
- LOG.debug("Called rowProcessed on subfilter of type " +
- filter.getClass().getSimpleName());
- }
- }
- }
-
- /** {@inheritDoc} */
- public boolean processAlways() {
- for (RowFilterInterface filter : filters) {
- if (filter.processAlways()) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("processAlways() is true due to subfilter of type " +
- filter.getClass().getSimpleName());
- }
- return true;
- }
- }
- return false;
- }
-
- /** {@inheritDoc} */
- public boolean filterAllRemaining() {
- boolean result = operator == Operator.MUST_PASS_ONE;
- for (RowFilterInterface filter : filters) {
- if (operator == Operator.MUST_PASS_ALL) {
- if (filter.filterAllRemaining()) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("op.MPALL filterAllRemaining returning true due" +
- " to subfilter of type " + filter.getClass().getSimpleName());
- }
- return true;
- }
- } else if (operator == Operator.MUST_PASS_ONE) {
- if (!filter.filterAllRemaining()) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("op.MPONE filterAllRemaining returning false due" +
- " to subfilter of type " + filter.getClass().getSimpleName());
- }
- return false;
- }
- }
- }
- if (LOG.isDebugEnabled()) {
- LOG.debug("filterAllRemaining default returning " + result);
- }
- return result;
- }
-
- /** {@inheritDoc} */
- public boolean filter(final Text rowKey) {
- boolean resultFound = false;
- boolean result = operator == Operator.MUST_PASS_ONE;
- for (RowFilterInterface filter : filters) {
- if (!resultFound) {
- if (operator == Operator.MUST_PASS_ALL) {
- if (filter.filterAllRemaining() || filter.filter(rowKey)) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("op.MPALL filter(Text) will return true due" +
- " to subfilter of type " + filter.getClass().getSimpleName());
- }
- result = true;
- resultFound = true;
- }
- } else if (operator == Operator.MUST_PASS_ONE) {
- if (!filter.filterAllRemaining() && !filter.filter(rowKey)) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("op.MPONE filter(Text) will return false due" +
- " to subfilter of type " + filter.getClass().getSimpleName());
- }
- result = false;
- resultFound = true;
- }
- }
- } else if (filter.processAlways()) {
- filter.filter(rowKey);
- }
- }
- if (LOG.isDebugEnabled()) {
- LOG.debug("filter(Text) returning " + result);
- }
- return result;
- }
-
- /** {@inheritDoc} */
- public boolean filter(final Text rowKey, final Text colKey,
- final byte[] data) {
- boolean resultFound = false;
- boolean result = operator == Operator.MUST_PASS_ONE;
- for (RowFilterInterface filter : filters) {
- if (!resultFound) {
- if (operator == Operator.MUST_PASS_ALL) {
- if (filter.filterAllRemaining() ||
- filter.filter(rowKey, colKey, data)) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("op.MPALL filter(Text, Text, byte[]) will" +
- " return true due to subfilter of type " +
- filter.getClass().getSimpleName());
- }
- result = true;
- resultFound = true;
- }
- } else if (operator == Operator.MUST_PASS_ONE) {
- if (!filter.filterAllRemaining() &&
- !filter.filter(rowKey, colKey, data)) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("op.MPONE filter(Text, Text, byte[]) will" +
- " return false due to subfilter of type " +
- filter.getClass().getSimpleName());
- }
- result = false;
- resultFound = true;
- }
- }
- } else if (filter.processAlways()) {
- filter.filter(rowKey, colKey, data);
- }
- }
- if (LOG.isDebugEnabled()) {
- LOG.debug("filter(Text, Text, byte[]) returning " + result);
- }
- return result;
- }
-
- /** {@inheritDoc} */
- public boolean filterNotNull(final SortedMap<Text, byte[]> columns) {
- boolean resultFound = false;
- boolean result = operator == Operator.MUST_PASS_ONE;
- for (RowFilterInterface filter : filters) {
- if (!resultFound) {
- if (operator == Operator.MUST_PASS_ALL) {
- if (filter.filterAllRemaining() || filter.filterNotNull(columns)) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("op.MPALL filterNotNull will return true due" +
- " to subfilter of type " + filter.getClass().getSimpleName());
- }
- result = true;
- resultFound = true;
- }
- } else if (operator == Operator.MUST_PASS_ONE) {
- if (!filter.filterAllRemaining() && !filter.filterNotNull(columns)) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("op.MPONE filterNotNull will return false due" +
- " to subfilter of type " + filter.getClass().getSimpleName());
- }
- result = false;
- resultFound = true;
- }
- }
- } else if (filter.processAlways()) {
- filter.filterNotNull(columns);
- }
- }
- if (LOG.isDebugEnabled()) {
- LOG.debug("filterNotNull returning " + result);
- }
- return result;
- }
-
- /** {@inheritDoc} */
- public void readFields(final DataInput in) throws IOException {
- byte opByte = in.readByte();
- operator = Operator.values()[opByte];
- int size = in.readInt();
- if (size > 0) {
- filters = new HashSet<RowFilterInterface>();
- try {
- for (int i = 0; i < size; i++) {
- String className = in.readUTF();
- Class<?> clazz = Class.forName(className);
- RowFilterInterface filter;
- filter = (RowFilterInterface) clazz.newInstance();
- filter.readFields(in);
- filters.add(filter);
- if (LOG.isDebugEnabled()) {
- LOG.debug("Successfully read in subfilter of type " +
- filter.getClass().getSimpleName());
- }
- }
- } catch (InstantiationException e) {
- throw new RuntimeException("Failed to deserialize RowFilterInterface.",
- e);
- } catch (IllegalAccessException e) {
- throw new RuntimeException("Failed to deserialize RowFilterInterface.",
- e);
- } catch (ClassNotFoundException e) {
- throw new RuntimeException("Failed to deserialize RowFilterInterface.",
- e);
- }
- }
-
- }
-
- /** {@inheritDoc} */
- public void write(final DataOutput out) throws IOException {
- out.writeByte(operator.ordinal());
- out.writeInt(filters.size());
- for (RowFilterInterface filter : filters) {
- out.writeUTF(filter.getClass().getName());
- filter.write(out);
- }
- }
-
-}
+/**
+ * Copyright 2007 The Apache Software Foundation
+ *
+ * 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.
+ */
+package org.apache.hadoop.hbase.filter;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.SortedMap;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.HBaseConfiguration;
+import org.apache.hadoop.io.ObjectWritable;
+import org.apache.hadoop.io.Text;
+
+/**
+ * Implementation of RowFilterInterface that represents a set of RowFilters
+ * which will be evaluated with a specified boolean operator MUST_PASS_ALL
+ * (!AND) or MUST_PASS_ONE (!OR). Since you can use RowFilterSets as children
+ * of RowFilterSet, you can create a hierarchy of filters to be evaluated.
+ */
+public class RowFilterSet implements RowFilterInterface {
+
+ /** set operator */
+ public static enum Operator {
+ /** !AND */
+ MUST_PASS_ALL,
+ /** !OR */
+ MUST_PASS_ONE
+ }
+
+ private Operator operator = Operator.MUST_PASS_ALL;
+ private Set<RowFilterInterface> filters = new HashSet<RowFilterInterface>();
+
+ static final Log LOG = LogFactory.getLog(RowFilterSet.class);
+
+ /**
+ * Default constructor, filters nothing. Required though for RPC
+ * deserialization.
+ */
+ public RowFilterSet() {
+ super();
+ }
+
+ /**
+ * Constructor that takes a set of RowFilters. The default operator
+ * MUST_PASS_ALL is assumed.
+ *
+ * @param rowFilters
+ */
+ public RowFilterSet(final Set<RowFilterInterface> rowFilters) {
+ this.filters = rowFilters;
+ }
+
+ /**
+ * Constructor that takes a set of RowFilters and an operator.
+ *
+ * @param operator Operator to process filter set with.
+ * @param rowFilters Set of row filters.
+ */
+ public RowFilterSet(final Operator operator,
+ final Set<RowFilterInterface> rowFilters) {
+ this.filters = rowFilters;
+ this.operator = operator;
+ }
+
+ /** {@inheritDoc} */
+ public void validate(final Text[] columns) {
+ for (RowFilterInterface filter : filters) {
+ filter.validate(columns);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Validated subfilter of type " +
+ filter.getClass().getSimpleName());
+ }
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void reset() {
+ for (RowFilterInterface filter : filters) {
+ filter.reset();
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Reset subfilter of type " +
+ filter.getClass().getSimpleName());
+ }
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void rowProcessed(boolean filtered, Text rowKey) {
+ for (RowFilterInterface filter : filters) {
+ filter.rowProcessed(filtered, rowKey);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Called rowProcessed on subfilter of type " +
+ filter.getClass().getSimpleName());
+ }
+ }
+ }
+
+ /** {@inheritDoc} */
+ public boolean processAlways() {
+ for (RowFilterInterface filter : filters) {
+ if (filter.processAlways()) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("processAlways() is true due to subfilter of type " +
+ filter.getClass().getSimpleName());
+ }
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /** {@inheritDoc} */
+ public boolean filterAllRemaining() {
+ boolean result = operator == Operator.MUST_PASS_ONE;
+ for (RowFilterInterface filter : filters) {
+ if (operator == Operator.MUST_PASS_ALL) {
+ if (filter.filterAllRemaining()) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("op.MPALL filterAllRemaining returning true due" +
+ " to subfilter of type " + filter.getClass().getSimpleName());
+ }
+ return true;
+ }
+ } else if (operator == Operator.MUST_PASS_ONE) {
+ if (!filter.filterAllRemaining()) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("op.MPONE filterAllRemaining returning false due" +
+ " to subfilter of type " + filter.getClass().getSimpleName());
+ }
+ return false;
+ }
+ }
+ }
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("filterAllRemaining default returning " + result);
+ }
+ return result;
+ }
+
+ /** {@inheritDoc} */
+ public boolean filterRowKey(final Text rowKey) {
+ boolean resultFound = false;
+ boolean result = operator == Operator.MUST_PASS_ONE;
+ for (RowFilterInterface filter : filters) {
+ if (!resultFound) {
+ if (operator == Operator.MUST_PASS_ALL) {
+ if (filter.filterAllRemaining() || filter.filterRowKey(rowKey)) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("op.MPALL filter(Text) will return true due" +
+ " to subfilter of type " + filter.getClass().getSimpleName());
+ }
+ result = true;
+ resultFound = true;
+ }
+ } else if (operator == Operator.MUST_PASS_ONE) {
+ if (!filter.filterAllRemaining() && !filter.filterRowKey(rowKey)) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("op.MPONE filter(Text) will return false due" +
+ " to subfilter of type " + filter.getClass().getSimpleName());
+ }
+ result = false;
+ resultFound = true;
+ }
+ }
+ } else if (filter.processAlways()) {
+ filter.filterRowKey(rowKey);
+ }
+ }
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("filter(Text) returning " + result);
+ }
+ return result;
+ }
+
+ /** {@inheritDoc} */
+ public boolean filterColumn(final Text rowKey, final Text colKey,
+ final byte[] data) {
+ boolean resultFound = false;
+ boolean result = operator == Operator.MUST_PASS_ONE;
+ for (RowFilterInterface filter : filters) {
+ if (!resultFound) {
+ if (operator == Operator.MUST_PASS_ALL) {
+ if (filter.filterAllRemaining() ||
+ filter.filterColumn(rowKey, colKey, data)) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("op.MPALL filter(Text, Text, byte[]) will" +
+ " return true due to subfilter of type " +
+ filter.getClass().getSimpleName());
+ }
+ result = true;
+ resultFound = true;
+ }
+ } else if (operator == Operator.MUST_PASS_ONE) {
+ if (!filter.filterAllRemaining() &&
+ !filter.filterColumn(rowKey, colKey, data)) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("op.MPONE filter(Text, Text, byte[]) will" +
+ " return false due to subfilter of type " +
+ filter.getClass().getSimpleName());
+ }
+ result = false;
+ resultFound = true;
+ }
+ }
+ } else if (filter.processAlways()) {
+ filter.filterColumn(rowKey, colKey, data);
+ }
+ }
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("filter(Text, Text, byte[]) returning " + result);
+ }
+ return result;
+ }
+
+ /** {@inheritDoc} */
+ public boolean filterRow(final SortedMap<Text, byte[]> columns) {
+ boolean resultFound = false;
+ boolean result = operator == Operator.MUST_PASS_ONE;
+ for (RowFilterInterface filter : filters) {
+ if (!resultFound) {
+ if (operator == Operator.MUST_PASS_ALL) {
+ if (filter.filterAllRemaining() || filter.filterRow(columns)) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("op.MPALL filterNotNull will return true due" +
+ " to subfilter of type " + filter.getClass().getSimpleName());
+ }
+ result = true;
+ resultFound = true;
+ }
+ } else if (operator == Operator.MUST_PASS_ONE) {
+ if (!filter.filterAllRemaining() && !filter.filterRow(columns)) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("op.MPONE filterNotNull will return false due" +
+ " to subfilter of type " + filter.getClass().getSimpleName());
+ }
+ result = false;
+ resultFound = true;
+ }
+ }
+ } else if (filter.processAlways()) {
+ filter.filterRow(columns);
+ }
+ }
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("filterNotNull returning " + result);
+ }
+ return result;
+ }
+
+ /** {@inheritDoc} */
+ public void readFields(final DataInput in) throws IOException {
+ Configuration conf = new HBaseConfiguration();
+ byte opByte = in.readByte();
+ operator = Operator.values()[opByte];
+ int size = in.readInt();
+ if (size > 0) {
+ filters = new HashSet<RowFilterInterface>();
+ for (int i = 0; i < size; i++) {
+ RowFilterInterface filter = (RowFilterInterface) ObjectWritable
+ .readObject(in, conf);
+ filters.add(filter);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Successfully read in subfilter of type "
+ + filter.getClass().getSimpleName());
+ }
+ }
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void write(final DataOutput out) throws IOException {
+ Configuration conf = new HBaseConfiguration();
+ out.writeByte(operator.ordinal());
+ out.writeInt(filters.size());
+ for (RowFilterInterface filter : filters) {
+ ObjectWritable.writeObject(out, filter, RowFilterInterface.class, conf);
+ }
+ }
+
+}
Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/filter/StopRowFilter.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/filter/StopRowFilter.java?rev=650711&r1=650710&r2=650711&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/filter/StopRowFilter.java (original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/filter/StopRowFilter.java Tue Apr 22 18:03:38 2008
@@ -1,148 +1,148 @@
-/**
- * Copyright 2007 The Apache Software Foundation
- *
- * 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.
- */
-package org.apache.hadoop.hbase.filter;
-
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import java.util.SortedMap;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.hadoop.io.Text;
-
-/**
- * Implementation of RowFilterInterface that filters out rows greater than or
- * equal to a specified rowKey.
- */
-public class StopRowFilter implements RowFilterInterface {
-
- protected Text stopRowKey;
-
- static final Log LOG = LogFactory.getLog(StopRowFilter.class);
-
- /**
- * Default constructor, filters nothing. Required though for RPC
- * deserialization.
- */
- public StopRowFilter() {
- super();
- }
-
- /**
- * Constructor that takes a stopRowKey on which to filter
- *
- * @param stopRowKey rowKey to filter on.
- */
- public StopRowFilter(final Text stopRowKey) {
- this.stopRowKey = stopRowKey;
- }
-
- /**
- * An accessor for the stopRowKey
- *
- * @return the filter's stopRowKey
- */
- public Text getStopRowKey() {
- return this.stopRowKey;
- }
-
- /**
- *
- * {@inheritDoc}
- */
- public void validate(@SuppressWarnings("unused") final Text[] columns) {
- // Doesn't filter columns
- }
-
- /**
- *
- * {@inheritDoc}
- */
- public void reset() {
- // Nothing to reset
- }
-
- /** {@inheritDoc} */
- @SuppressWarnings("unused")
- public void rowProcessed(boolean filtered, Text rowKey) {
- // Doesn't care
- }
-
- /** {@inheritDoc} */
- public boolean processAlways() {
- return false;
- }
-
- /** {@inheritDoc} */
- public boolean filterAllRemaining() {
- return false;
- }
-
- /** {@inheritDoc} */
- public boolean filter(final Text rowKey) {
- if (rowKey == null) {
- if (this.stopRowKey == null) {
- return true;
- }
- return false;
- }
- boolean result = this.stopRowKey.compareTo(rowKey) <= 0;
- if (LOG.isDebugEnabled()) {
- LOG.debug("Filter result for rowKey: " + rowKey + ". Result: " +
- result);
- }
- return result;
- }
-
- /**
- * {@inheritDoc}
- *
- * Because StopRowFilter does not examine column information, this method
- * defaults to calling the rowKey-only version of filter.
- */
- public boolean filter(@SuppressWarnings("unused") final Text rowKey,
- @SuppressWarnings("unused") final Text colKey,
- @SuppressWarnings("unused") final byte[] data) {
- return filter(rowKey);
- }
-
- /** {@inheritDoc}
- *
- * Because StopRowFilter does not examine column information, this method
- * defaults to calling filterAllRemaining().
- *
- * @param columns
- */
- public boolean filterNotNull(@SuppressWarnings("unused")
- final SortedMap<Text, byte[]> columns) {
- return filterAllRemaining();
- }
-
- /** {@inheritDoc} */
- public void readFields(DataInput in) throws IOException {
- stopRowKey = new Text(in.readUTF());
- }
-
- /** {@inheritDoc} */
- public void write(DataOutput out) throws IOException {
- out.writeUTF(stopRowKey.toString());
- }
-}
+/**
+ * Copyright 2007 The Apache Software Foundation
+ *
+ * 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.
+ */
+package org.apache.hadoop.hbase.filter;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.util.SortedMap;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.io.Text;
+
+/**
+ * Implementation of RowFilterInterface that filters out rows greater than or
+ * equal to a specified rowKey.
+ */
+public class StopRowFilter implements RowFilterInterface {
+
+ protected Text stopRowKey;
+
+ static final Log LOG = LogFactory.getLog(StopRowFilter.class);
+
+ /**
+ * Default constructor, filters nothing. Required though for RPC
+ * deserialization.
+ */
+ public StopRowFilter() {
+ super();
+ }
+
+ /**
+ * Constructor that takes a stopRowKey on which to filter
+ *
+ * @param stopRowKey rowKey to filter on.
+ */
+ public StopRowFilter(final Text stopRowKey) {
+ this.stopRowKey = stopRowKey;
+ }
+
+ /**
+ * An accessor for the stopRowKey
+ *
+ * @return the filter's stopRowKey
+ */
+ public Text getStopRowKey() {
+ return this.stopRowKey;
+ }
+
+ /**
+ *
+ * {@inheritDoc}
+ */
+ public void validate(@SuppressWarnings("unused") final Text[] columns) {
+ // Doesn't filter columns
+ }
+
+ /**
+ *
+ * {@inheritDoc}
+ */
+ public void reset() {
+ // Nothing to reset
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("unused")
+ public void rowProcessed(boolean filtered, Text rowKey) {
+ // Doesn't care
+ }
+
+ /** {@inheritDoc} */
+ public boolean processAlways() {
+ return false;
+ }
+
+ /** {@inheritDoc} */
+ public boolean filterAllRemaining() {
+ return false;
+ }
+
+ /** {@inheritDoc} */
+ public boolean filterRowKey(final Text rowKey) {
+ if (rowKey == null) {
+ if (this.stopRowKey == null) {
+ return true;
+ }
+ return false;
+ }
+ boolean result = this.stopRowKey.compareTo(rowKey) <= 0;
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Filter result for rowKey: " + rowKey + ". Result: " +
+ result);
+ }
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Because StopRowFilter does not examine column information, this method
+ * defaults to calling the rowKey-only version of filter.
+ */
+ public boolean filterColumn(@SuppressWarnings("unused") final Text rowKey,
+ @SuppressWarnings("unused") final Text colKey,
+ @SuppressWarnings("unused") final byte[] data) {
+ return filterRowKey(rowKey);
+ }
+
+ /** {@inheritDoc}
+ *
+ * Because StopRowFilter does not examine column information, this method
+ * defaults to calling filterAllRemaining().
+ *
+ * @param columns
+ */
+ public boolean filterRow(@SuppressWarnings("unused")
+ final SortedMap<Text, byte[]> columns) {
+ return filterAllRemaining();
+ }
+
+ /** {@inheritDoc} */
+ public void readFields(DataInput in) throws IOException {
+ stopRowKey = new Text(in.readUTF());
+ }
+
+ /** {@inheritDoc} */
+ public void write(DataOutput out) throws IOException {
+ out.writeUTF(stopRowKey.toString());
+ }
+}
Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/filter/WhileMatchRowFilter.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/filter/WhileMatchRowFilter.java?rev=650711&r1=650710&r2=650711&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/filter/WhileMatchRowFilter.java (original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/filter/WhileMatchRowFilter.java Tue Apr 22 18:03:38 2008
@@ -1,181 +1,181 @@
-/**
- * Copyright 2007 The Apache Software Foundation
- *
- * 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.
- */
-package org.apache.hadoop.hbase.filter;
-
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import java.util.SortedMap;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.hadoop.io.Text;
-
-/**
- * WhileMatchRowFilter is a wrapper filter that filters everything after the
- * first filtered row. Once the nested filter returns true for either of it's
- * filter(..) methods or filterNotNull(SortedMap<Text, byte[]>), this wrapper's
- * filterAllRemaining() will return true. All filtering methods will
- * thereafter defer to the result of filterAllRemaining().
- */
-public class WhileMatchRowFilter implements RowFilterInterface {
-
- private boolean filterAllRemaining = false;
- private RowFilterInterface filter;
-
- static final Log LOG = LogFactory.getLog(WhileMatchRowFilter.class);
-
- /**
- * Default constructor, filters nothing. Required though for RPC
- * deserialization.
- */
- public WhileMatchRowFilter() {
- super();
- }
-
- /**
- * Constructor
- * @param filter
- */
- public WhileMatchRowFilter(RowFilterInterface filter) {
- this.filter = filter;
- }
-
- /**
- * Returns the internal filter being wrapped
- *
- * @return the internal filter
- */
- public RowFilterInterface getInternalFilter() {
- return this.filter;
- }
-
- /** {@inheritDoc} */
- public void reset() {
- if (LOG.isDebugEnabled()) {
- LOG.debug("Resetting.");
- }
- this.filterAllRemaining = false;
- this.filter.reset();
- }
-
- /** {@inheritDoc} */
- public boolean processAlways() {
- return true;
- }
-
- /**
- * Returns true once the nested filter has filtered out a row (returned true
- * on a call to one of it's filtering methods). Until then it returns false.
- *
- * @return true/false whether the nested filter has returned true on a filter
- * call.
- */
- public boolean filterAllRemaining() {
- return this.filterAllRemaining || this.filter.filterAllRemaining();
- }
-
- /** {@inheritDoc} */
- public boolean filter(final Text rowKey) {
- changeFAR(this.filter.filter(rowKey));
- boolean result = filterAllRemaining();
- if (LOG.isDebugEnabled()) {
- LOG.debug("Filter on rowKey:" + rowKey + ". Result = " + result);
- }
- return result;
- }
-
- /** {@inheritDoc} */
- public boolean filter(final Text rowKey, final Text colKey,
- final byte[] data) {
- changeFAR(this.filter.filter(rowKey, colKey, data));
- boolean result = filterAllRemaining();
- if (LOG.isDebugEnabled()) {
- LOG.debug("Filter on rowKey:" + rowKey + ", colKey: " + colKey +
- ", data: " + data + ". Result = " + result);
- }
- return result;
- }
-
- /** {@inheritDoc} */
- public boolean filterNotNull(final SortedMap<Text, byte[]> columns) {
- changeFAR(this.filter.filterNotNull(columns));
- boolean result = filterAllRemaining();
- if (LOG.isDebugEnabled()) {
- LOG.debug("FilterNotNull on cols:" + columns + ". Result = " +
- result);
- }
- return result;
- }
-
- /**
- * Change filterAllRemaining from false to true if value is true, otherwise
- * leave as is.
- *
- * @param value
- */
- private void changeFAR(boolean value) {
- this.filterAllRemaining = this.filterAllRemaining || value;
- if (LOG.isDebugEnabled()) {
- LOG.debug("this.filterAllRemaining is now: " +
- this.filterAllRemaining);
- }
- }
-
- /** {@inheritDoc} */
- public void rowProcessed(boolean filtered, Text rowKey) {
- this.filter.rowProcessed(filtered, rowKey);
- }
-
- /** {@inheritDoc} */
- public void validate(Text[] columns) {
- this.filter.validate(columns);
- }
-
- /** {@inheritDoc} */
- public void readFields(DataInput in) throws IOException {
- String className = in.readUTF();
-
- try {
- this.filter = (RowFilterInterface)(Class.forName(className).
- newInstance());
- this.filter.readFields(in);
- if (LOG.isDebugEnabled()) {
- LOG.debug("Successfully read a sub-filter of type: " +
- className);
- }
- } catch (InstantiationException e) {
- throw new RuntimeException("Failed to deserialize WhileMatchRowFilter.",
- e);
- } catch (IllegalAccessException e) {
- throw new RuntimeException("Failed to deserialize WhileMatchRowFilter.",
- e);
- } catch (ClassNotFoundException e) {
- throw new RuntimeException("Failed to deserialize WhileMatchRowFilter.",
- e);
- }
- }
-
- /** {@inheritDoc} */
- public void write(DataOutput out) throws IOException {
- out.writeUTF(this.filter.getClass().getName());
- this.filter.write(out);
- }
-}
+/**
+ * Copyright 2007 The Apache Software Foundation
+ *
+ * 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.
+ */
+package org.apache.hadoop.hbase.filter;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.util.SortedMap;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.io.Text;
+
+/**
+ * WhileMatchRowFilter is a wrapper filter that filters everything after the
+ * first filtered row. Once the nested filter returns true for either of it's
+ * filter(..) methods or filterNotNull(SortedMap<Text, byte[]>), this wrapper's
+ * filterAllRemaining() will return true. All filtering methods will
+ * thereafter defer to the result of filterAllRemaining().
+ */
+public class WhileMatchRowFilter implements RowFilterInterface {
+
+ private boolean filterAllRemaining = false;
+ private RowFilterInterface filter;
+
+ static final Log LOG = LogFactory.getLog(WhileMatchRowFilter.class);
+
+ /**
+ * Default constructor, filters nothing. Required though for RPC
+ * deserialization.
+ */
+ public WhileMatchRowFilter() {
+ super();
+ }
+
+ /**
+ * Constructor
+ * @param filter
+ */
+ public WhileMatchRowFilter(RowFilterInterface filter) {
+ this.filter = filter;
+ }
+
+ /**
+ * Returns the internal filter being wrapped
+ *
+ * @return the internal filter
+ */
+ public RowFilterInterface getInternalFilter() {
+ return this.filter;
+ }
+
+ /** {@inheritDoc} */
+ public void reset() {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Resetting.");
+ }
+ this.filterAllRemaining = false;
+ this.filter.reset();
+ }
+
+ /** {@inheritDoc} */
+ public boolean processAlways() {
+ return true;
+ }
+
+ /**
+ * Returns true once the nested filter has filtered out a row (returned true
+ * on a call to one of it's filtering methods). Until then it returns false.
+ *
+ * @return true/false whether the nested filter has returned true on a filter
+ * call.
+ */
+ public boolean filterAllRemaining() {
+ return this.filterAllRemaining || this.filter.filterAllRemaining();
+ }
+
+ /** {@inheritDoc} */
+ public boolean filterRowKey(final Text rowKey) {
+ changeFAR(this.filter.filterRowKey(rowKey));
+ boolean result = filterAllRemaining();
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Filter on rowKey:" + rowKey + ". Result = " + result);
+ }
+ return result;
+ }
+
+ /** {@inheritDoc} */
+ public boolean filterColumn(final Text rowKey, final Text colKey,
+ final byte[] data) {
+ changeFAR(this.filter.filterColumn(rowKey, colKey, data));
+ boolean result = filterAllRemaining();
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Filter on rowKey:" + rowKey + ", colKey: " + colKey +
+ ", data: " + data + ". Result = " + result);
+ }
+ return result;
+ }
+
+ /** {@inheritDoc} */
+ public boolean filterRow(final SortedMap<Text, byte[]> columns) {
+ changeFAR(this.filter.filterRow(columns));
+ boolean result = filterAllRemaining();
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("FilterNotNull on cols:" + columns + ". Result = " +
+ result);
+ }
+ return result;
+ }
+
+ /**
+ * Change filterAllRemaining from false to true if value is true, otherwise
+ * leave as is.
+ *
+ * @param value
+ */
+ private void changeFAR(boolean value) {
+ this.filterAllRemaining = this.filterAllRemaining || value;
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("this.filterAllRemaining is now: " +
+ this.filterAllRemaining);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void rowProcessed(boolean filtered, Text rowKey) {
+ this.filter.rowProcessed(filtered, rowKey);
+ }
+
+ /** {@inheritDoc} */
+ public void validate(Text[] columns) {
+ this.filter.validate(columns);
+ }
+
+ /** {@inheritDoc} */
+ public void readFields(DataInput in) throws IOException {
+ String className = in.readUTF();
+
+ try {
+ this.filter = (RowFilterInterface)(Class.forName(className).
+ newInstance());
+ this.filter.readFields(in);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Successfully read a sub-filter of type: " +
+ className);
+ }
+ } catch (InstantiationException e) {
+ throw new RuntimeException("Failed to deserialize WhileMatchRowFilter.",
+ e);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException("Failed to deserialize WhileMatchRowFilter.",
+ e);
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException("Failed to deserialize WhileMatchRowFilter.",
+ e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void write(DataOutput out) throws IOException {
+ out.writeUTF(this.filter.getClass().getName());
+ this.filter.write(out);
+ }
+}
Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/regionserver/HRegion.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/regionserver/HRegion.java?rev=650711&r1=650710&r2=650711&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/regionserver/HRegion.java (original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/regionserver/HRegion.java Tue Apr 22 18:03:38 2008
@@ -1801,7 +1801,7 @@
moreToFollow = false;
}
- filtered = filter == null ? false : filter.filterNotNull(results);
+ filtered = filter == null ? false : filter.filterRow(results);
if (moreToFollow) {
if (filter != null) {