From 08de99e30708b697617295710c92199975d2205c Mon Sep 17 00:00:00 2001 From: Michael Stack Date: Tue, 5 May 2009 03:57:26 +0000 Subject: [PATCH] HBASE-889 The current Thrift API does not allow a new scanner to be created without supplying a column list unlike the other APIs. git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@771545 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 3 + .../hadoop/hbase/thrift/ThriftServer.java | 57 +++++++++++++++---- 2 files changed, 48 insertions(+), 12 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index e76466ae784..d648a7be446 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -193,6 +193,9 @@ Release 0.20.0 - Unreleased (Evgeny Ryabitskiy via Stack) HBASE-1112 we will lose data if the table name happens to be the logs' dir name (Samuel Guo via Stack) + HBASE-889 The current Thrift API does not allow a new scanner to be + created without supplying a column list unlike the other APIs. + (Tim Sell via Stack) Release 0.19.0 - 01/21/2009 INCOMPATIBLE CHANGES diff --git a/src/java/org/apache/hadoop/hbase/thrift/ThriftServer.java b/src/java/org/apache/hadoop/hbase/thrift/ThriftServer.java index 55b5ec9bd14..8b221528a39 100644 --- a/src/java/org/apache/hadoop/hbase/thrift/ThriftServer.java +++ b/src/java/org/apache/hadoop/hbase/thrift/ThriftServer.java @@ -80,6 +80,22 @@ public class ThriftServer { protected int nextScannerId = 0; protected HashMap scannerMap = null; + /** + * Returns a list of all the column families for a given htable. + * + * @param table + * @return + * @throws IOException + */ + byte[][] getAllColumns(HTable table) throws IOException { + HColumnDescriptor[] cds = table.getTableDescriptor().getColumnFamilies(); + byte[][] columns = new byte[cds.length][]; + for (int i = 0; i < cds.length; i++) { + columns[i] = cds[i].getNameWithColon(); + } + return columns; + } + /** * Creates and returns an HTable instance from a given table name. * @@ -468,9 +484,13 @@ public class ThriftServer { List columns) throws IOError { try { HTable table = getTable(tableName); - Scanner scanner = table.getScanner(columns.toArray(new byte[0][]), - startRow); - return addScanner(scanner); + byte[][] columnsArray = null; + if ((columns == null) || (columns.size() == 0)) { + columnsArray = getAllColumns(table); + } else { + columnsArray = columns.toArray(new byte[0][]); + } + return addScanner(table.getScanner(columnsArray, startRow)); } catch (IOException e) { throw new IOError(e.getMessage()); } @@ -480,9 +500,13 @@ public class ThriftServer { byte[] stopRow, List columns) throws IOError, TException { try { HTable table = getTable(tableName); - Scanner scanner = table.getScanner(columns.toArray(new byte[0][]), - startRow, stopRow); - return addScanner(scanner); + byte[][] columnsArray = null; + if ((columns == null) || (columns.size() == 0)) { + columnsArray = getAllColumns(table); + } else { + columnsArray = columns.toArray(new byte[0][]); + } + return addScanner(table.getScanner(columnsArray, startRow, stopRow)); } catch (IOException e) { throw new IOError(e.getMessage()); } @@ -492,9 +516,13 @@ public class ThriftServer { List columns, long timestamp) throws IOError, TException { try { HTable table = getTable(tableName); - Scanner scanner = table.getScanner(columns.toArray(new byte[0][]), - startRow, timestamp); - return addScanner(scanner); + byte[][] columnsArray = null; + if ((columns == null) || (columns.size() == 0)) { + columnsArray = getAllColumns(table); + } else { + columnsArray = columns.toArray(new byte[0][]); + } + return addScanner(table.getScanner(columnsArray, startRow, timestamp)); } catch (IOException e) { throw new IOError(e.getMessage()); } @@ -505,9 +533,14 @@ public class ThriftServer { throws IOError, TException { try { HTable table = getTable(tableName); - Scanner scanner = table.getScanner(columns.toArray(new byte[0][]), - startRow, stopRow, timestamp); - return addScanner(scanner); + byte[][] columnsArray = null; + if ((columns == null) || (columns.size() == 0)) { + columnsArray = getAllColumns(table); + } else { + columnsArray = columns.toArray(new byte[0][]); + } + return addScanner(table.getScanner(columnsArray, startRow, stopRow, + timestamp)); } catch (IOException e) { throw new IOError(e.getMessage()); }