hbase-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jinsong Hu" <jinsong...@hotmail.com>
Subject thrift for hbase in CDH3 broken ?
Date Thu, 02 Sep 2010 23:40:45 GMT
Hi, There,
  I am trying to test and see if thrift for hbase works. I followed the 
example from

http://www.workhabit.com/labs/centos-55-and-thriftscribe
http://incubator.apache.org/thrift/
http://wiki.apache.org/hadoop/Hbase/ThriftApi

and wrote test code: I found that client.getTableNames();
returns all table names successfully, but the scanner never returned
any record. and it even throws exception:

org.apache.thrift.TApplicationException: get failed: unknown result
	at 
org.apache.hadoop.hbase.thrift.generated.Hbase$Client.recv_get(Hbase.java:785)
	at 
org.apache.hadoop.hbase.thrift.generated.Hbase$Client.get(Hbase.java:750)
	at 
org.apache.hadoop.hbase.thrift.HbaseThriftTest.testThriftAPI(HbaseThriftTest.java:73)
	at 
org.apache.hadoop.hbase.thrift.HbaseThriftTest.main(HbaseThriftTest.java:128)

I checked the syntax and the table and confirmed that the table does have 
record and it should
return result, but it doesn't. Can anybody tell me what is wrong ?

At this time, I am suspecting the thrift server shipped with CDH3 may have 
problem. if there anyway
I can get this test code working ?

I have to use thrift-0.2.0-incubating.tar.gz , as I found that the code 
generated from hbase-thrift project
doesn't even compile with 0.3.0 and 0.4.0 thrift.


Jimmy.






    public void testThriftAPI()
    {
        // Make socket
        TSocket transport = new TSocket("10.20.12.13", 9090);



        // Wrap in a protocol
        TBinaryProtocol protocol = new  TBinaryProtocol(transport);

        Hbase.Client client = new Hbase.Client(protocol);

        try {
            transport.open();
            List<byte[]> tableNamesList=client.getTableNames();
            for (byte [] name : tableNamesList)
            {
                System.out.println(new String(name));
            }

            String tableName="HEARTBEAT_CLUSTER";
            String startRow="";
            List<byte[]> columns= new ArrayList<byte[]>();
            columns.add("fields:time_format".getBytes());
            columns.add("fields:customer_id".getBytes());

            int aScannerId=0;
            try {

                TCell cell=client.get(tableName.getBytes(), 
"2010-08\tproduction-2".getBytes(), "fields:customer_id".getBytes());
                if (cell != null)
                {
                   String value= new String( cell.value);
                   System.out.println(value);
                }
                aScannerId=client.scannerOpen(tableName.getBytes(), 
startRow.getBytes(), columns);
                TRowResult result=null;
                for (int i=0; i< 10; i++)
                {
                    try {
                    result=client.scannerGet(aScannerId);
                    } catch (Exception ex1)
                    {

                    }
                    if (result ==null) break;

                    String timeFormat=result.getFieldValue(0).toString();
                    String customerId=result.getFieldValue(1).toString();
                    System.out.println(timeFormat + "\t" + customerId);
                }
            } catch (Exception ex)
            {
                ex.printStackTrace();
            }
            finally {
                if (aScannerId >0 ) client.scannerClose(aScannerId);
            }
        } catch (Exception exp)
        {
            exp.printStackTrace();
        }
        finally{
            transport.close();
        }

    } 


Mime
View raw message