hbase-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jean-Marc Spaggiari <jean-m...@spaggiari.org>
Subject Re: How to use put command in Java for dynamic field name creation
Date Fri, 08 Feb 2013 13:53:35 GMT
Hi Rams,

I think I understand the way you want to build your table, but what
I'm not sure is, what's the issue?

Are you asking how to write java code? If so, you put code should look
like that:
byte[] tableName = Bytes.toBytes("branch");
byte[] row = Bytes.toBytes("1");
byte[] columnFamilly = Bytes.toBytes("cf1");
byte[] column = Bytes.toBytes("CCY" + currencyField);
byte[] data = Bytes.toBytes(currencyField + currencyName);
Put put = new Put (row).add(columnFamilly, column, data);
HTable table = new HTable (tableName);
table.put (put);
table.close ();

Is that what you are looking for? I wrote that on the email directly
so there might be some compilation issues, but that should give you an
idea. There is many issues with this scenario, like using "1" as the
rowkey will most probably hotspot a server, and the table might be
cached if you are doing more than one put, or use a .put(List<Put>)...
And so on.


2013/2/8, Ramasubramanian Narayanan <ramasubramanian.narayanan@gmail.com>:
> Hi,
> Can someone help on this pls..
> regards,
> Rams
> On Thu, Feb 7, 2013 at 9:19 PM, Ramasubramanian Narayanan <
> ramasubramanian.narayanan@gmail.com> wrote:
>> Hi,
>> I have a requirement to create dynamic field name (based on value of a
>> column)  at run time... I think this is the usual approach that we will
>> used in HBASE for one to many relationships..
>> For example, physical table has the following structure
>>   *Branch Number* *Branch Name* *Supported Currency Code* *Currency Name*
>> 1 ABC INR India Rupee  1 ABC USD US Dollar  2 EFG SGD Singapore Dollar  2
>> EFG INR India Rupee
>> Row key is Branch Number...
>> To flatten it out, we have to redesign the HBASE table as follows :
>> The fields related to currency will be grouped and created under a single
>> field (supported currency code & currency name) and the field name is
>> dynamically created as "CCY"+<actual value for supported currency code>
>> For the above scenario, the HBASE table will look llike following...
>>   *Branch Number* *Branch Name* *CCY_INR* *CCY_USD* *CCY_SGD*  1 ABC
>> INR|India
>> Rupee USD|US Dollar
>>  2 EFG INR|India Rupee
>> SGD|Singapore Dollar
>> Now the question is,
>> what is the syntax for the put statement in JAVA so that the Column name
>> is dynamically created...
>> put ('branch','1','cf1:'+'CCY'+<valueof currency field>,<value of
>> currency
>> field>+<value of currency name field>);
>> the above sytax is not working for me...
>> Please let me know the syntax of the put statement in this scenario using
>> JAVA...
>> regards,
>> Rams

View raw message