diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/coprocessor/AggregationClient.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/coprocessor/AggregationClient.java index 6156402af4e..225a8e48584 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/coprocessor/AggregationClient.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/coprocessor/AggregationClient.java @@ -127,7 +127,7 @@ public class AggregationClient { public R max(final HTable table, final ColumnInterpreter ci, final Scan scan) throws Throwable { - final AggregateRequest requestArg = validateArgAndGetPB(scan, ci); + final AggregateRequest requestArg = validateArgAndGetPB(scan, ci, false); class MaxCallBack implements Batch.Callback { R max = null; @@ -164,7 +164,11 @@ public class AggregationClient { return aMaxCallBack.getMax(); } - private void validateParameters(Scan scan) throws IOException { + /* + * @param scan + * @param canFamilyBeAbsent whether column family can be absent in familyMap of scan + */ + private void validateParameters(Scan scan, boolean canFamilyBeAbsent) throws IOException { if (scan == null || (Bytes.equals(scan.getStartRow(), scan.getStopRow()) && !Bytes .equals(scan.getStartRow(), HConstants.EMPTY_START_ROW)) @@ -172,8 +176,10 @@ public class AggregationClient { !Bytes.equals(scan.getStopRow(), HConstants.EMPTY_END_ROW))) { throw new IOException( "Agg client Exception: Startrow should be smaller than Stoprow"); - } else if (scan.getFamilyMap().size() != 1) { - throw new IOException("There must be only one family."); + } else if (!canFamilyBeAbsent) { + if (scan.getFamilyMap().size() != 1) { + throw new IOException("There must be only one family."); + } } } @@ -214,7 +220,7 @@ public class AggregationClient { public R min(final HTable table, final ColumnInterpreter ci, final Scan scan) throws Throwable { - final AggregateRequest requestArg = validateArgAndGetPB(scan, ci); + final AggregateRequest requestArg = validateArgAndGetPB(scan, ci, false); class MinCallBack implements Batch.Callback { private R min = null; @@ -297,7 +303,7 @@ public class AggregationClient { public long rowCount(final HTable table, final ColumnInterpreter ci, final Scan scan) throws Throwable { - final AggregateRequest requestArg = validateArgAndGetPB(scan, ci); + final AggregateRequest requestArg = validateArgAndGetPB(scan, ci, true); class RowNumCallback implements Batch.Callback { private final AtomicLong rowCountL = new AtomicLong(0); @@ -367,7 +373,7 @@ public class AggregationClient { public S sum(final HTable table, final ColumnInterpreter ci, final Scan scan) throws Throwable { - final AggregateRequest requestArg = validateArgAndGetPB(scan, ci); + final AggregateRequest requestArg = validateArgAndGetPB(scan, ci, false); class SumCallBack implements Batch.Callback { S sumVal = null; @@ -439,7 +445,7 @@ public class AggregationClient { private Pair getAvgArgs(final HTable table, final ColumnInterpreter ci, final Scan scan) throws Throwable { - final AggregateRequest requestArg = validateArgAndGetPB(scan, ci); + final AggregateRequest requestArg = validateArgAndGetPB(scan, ci, false); class AvgCallBack implements Batch.Callback> { S sum = null; Long rowCount = 0l; @@ -536,7 +542,7 @@ public class AggregationClient { private Pair, Long> getStdArgs(final HTable table, final ColumnInterpreter ci, final Scan scan) throws Throwable { - final AggregateRequest requestArg = validateArgAndGetPB(scan, ci); + final AggregateRequest requestArg = validateArgAndGetPB(scan, ci, false); class StdCallback implements Batch.Callback, Long>> { long rowCountVal = 0l; S sumVal = null, sumSqVal = null; @@ -658,7 +664,7 @@ public class AggregationClient { Pair>, List> getMedianArgs(final HTable table, final ColumnInterpreter ci, final Scan scan) throws Throwable { - final AggregateRequest requestArg = validateArgAndGetPB(scan, ci); + final AggregateRequest requestArg = validateArgAndGetPB(scan, ci, false); final NavigableMap> map = new TreeMap>(Bytes.BYTES_COMPARATOR); class StdCallback implements Batch.Callback> { @@ -814,9 +820,9 @@ public class AggregationClient { } AggregateRequest - validateArgAndGetPB(Scan scan, ColumnInterpreter ci) + validateArgAndGetPB(Scan scan, ColumnInterpreter ci, boolean canFamilyBeAbsent) throws IOException { - validateParameters(scan); + validateParameters(scan, canFamilyBeAbsent); final AggregateRequest.Builder requestBuilder = AggregateRequest.newBuilder(); requestBuilder.setInterpreterClassName(ci.getClass().getCanonicalName()); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/AggregateImplementation.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/AggregateImplementation.java index fdb87ef9c75..7408c3b300e 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/AggregateImplementation.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/AggregateImplementation.java @@ -237,8 +237,10 @@ extends AggregateService implements CoprocessorService, Coprocessor { InternalScanner scanner = null; try { Scan scan = ProtobufUtil.toScan(request.getScan()); - byte[] colFamily = scan.getFamilies()[0]; - NavigableSet qualifiers = scan.getFamilyMap().get(colFamily); + byte[][] colFamilies = scan.getFamilies(); + byte[] colFamily = colFamilies != null ? colFamilies[0] : null; + NavigableSet qualifiers = colFamilies != null ? + scan.getFamilyMap().get(colFamily) : null; byte[] qualifier = null; if (qualifiers != null && !qualifiers.isEmpty()) { qualifier = qualifiers.pollFirst(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestAggregateProtocol.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestAggregateProtocol.java index 2dfcc000b03..d358a13de82 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestAggregateProtocol.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestAggregateProtocol.java @@ -173,7 +173,6 @@ public class TestAggregateProtocol { public void testRowCountAllTable() throws Throwable { AggregationClient aClient = new AggregationClient(conf); Scan scan = new Scan(); - scan.addColumn(TEST_FAMILY, TEST_QUALIFIER); final ColumnInterpreter ci = new LongColumnInterpreter(); long rowCount = aClient.rowCount(TEST_TABLE, ci, @@ -190,7 +189,6 @@ public class TestAggregateProtocol { public void testRowCountWithInvalidRange1() { AggregationClient aClient = new AggregationClient(conf); Scan scan = new Scan(); - scan.addColumn(TEST_FAMILY, TEST_QUALIFIER); scan.setStartRow(ROWS[5]); scan.setStopRow(ROWS[2]); @@ -215,7 +213,6 @@ public class TestAggregateProtocol { public void testRowCountWithInvalidRange2() { AggregationClient aClient = new AggregationClient(conf); Scan scan = new Scan(); - scan.addColumn(TEST_FAMILY, TEST_QUALIFIER); scan.setStartRow(ROWS[5]); scan.setStopRow(ROWS[5]); @@ -230,26 +227,6 @@ public class TestAggregateProtocol { assertEquals(0, rowCount); } - /** - * This should return a 0 - */ - @Test (timeout=300000) - public void testRowCountWithNullCF() { - AggregationClient aClient = new AggregationClient(conf); - Scan scan = new Scan(); - scan.setStartRow(ROWS[5]); - scan.setStopRow(ROWS[15]); - final ColumnInterpreter ci = - new LongColumnInterpreter(); - long rowCount = -1; - try { - rowCount = aClient.rowCount(TEST_TABLE, ci, scan); - } catch (Throwable e) { - rowCount = 0; - } - assertEquals(0, rowCount); - } - @Test (timeout=300000) public void testRowCountWithNullCQ() throws Throwable { AggregationClient aClient = new AggregationClient(conf);