spark-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Madabhattula Rajesh Kumar <mrajaf...@gmail.com>
Subject Re: Hbase
Date Fri, 01 Aug 2014 11:14:52 GMT
Hi Akhil,

Thank you for your response. I'm facing below issues.

I'm not able to print the values. Am I missing any thing. Could you please
look into this issue.

    JavaPairRDD<ImmutableBytesWritable, Result> hBaseRDD =
sc.newAPIHadoopRDD(
            conf,
    TableInputFormat.class,
    ImmutableBytesWritable.class,
    Result.class);

    System.out.println(" ROWS COUNT = "+ hBaseRDD.count());

  JavaRDD R = hBaseRDD.map(new Function<Tuple2<ImmutableBytesWritable,
Result>, Iterator<String>>(){
        public Iterator<String> call(Tuple2<ImmutableBytesWritable, Result>
test)
        {
            Result tmp = (Result) test._2;

            System.out.println("Inside ");

        //    List<KeyValue> kvl = tmp.getColumn("post".getBytes(),
"title".getBytes());
            for(KeyValue kl:tmp.raw())
            {
            String sb = new String(kl.getValue());
            System.out.println(sb);
            }
            return null;
        }
    }
    );

*Output :*

ROWS COUNT = 8

It is not printing "Inside" statement also. I think it is not going into
this function.

Could you please help me on this issue.

Thank you for your support and help

Regards,
Rajesh



On Fri, Aug 1, 2014 at 12:17 PM, Akhil Das <akhil@sigmoidanalytics.com>
wrote:

> You can use a map function like the following and do whatever you want
> with the Result.
>
> Function<Tuple2<ImmutableBytesWritable, Result>, Iterator<String>>{
>>             public Iterator<String> call(Tuple2<ImmutableBytesWritable,
>> Result> test) {
>>             Result tmp = (Result) test._2;
>>  List<KeyValue> kvl = *tmp.getColumn("post".getBytes(),
>> "title".getBytes());*
>> for(KeyValue kl:kvl){
>>  String sb = new String(kl.getValue());
>> System.out.println(sb);
>>  }
>
>
>
>
> Thanks
> Best Regards
>
>
> On Thu, Jul 31, 2014 at 10:19 PM, Madabhattula Rajesh Kumar <
> mrajaforu@gmail.com> wrote:
>
>> Hi Team,
>>
>> I'm using below code to read table from hbase
>>
>> Configuration conf = HBaseConfiguration.create();
>> conf.set(TableInputFormat.INPUT_TABLE, "table1");
>>
>> JavaPairRDD hBaseRDD = sc.newAPIHadoopRDD(
>>             conf,
>>     TableInputFormat.class,
>>     ImmutableBytesWritable.class,
>>     Result.class);
>>
>> I got hBaseRDD. I'm not able to read the column values from hBaseRDD.
>>
>> *Could you please let me know, how to read the column values from
>> hBaseRDD?*
>>
>> Thank you for your help.
>>
>> Regards,
>> Rajesh
>>
>>
>

Mime
View raw message