Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7716219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:34:56+00:00 2026-06-01T02:34:56+00:00

I am trying to read in a Hbase atomic increment column into Pig and

  • 0

I am trying to read in a Hbase atomic increment column into Pig and have access to it as Long value.

However, the column value uses Hbases Hex like structure: \x00\x00\x00\x00\x00\x00\x00\x01

Does anyone know of a method to convert that in Pig to become equivilant to the get_counter value: 1

I have posted a solution using a UDF:

import java.io.IOException;
import org.apache.pig.EvalFunc;
import org.apache.pig.backend.executionengine.ExecException;
import org.apache.pig.data.DataByteArray;
import org.apache.pig.data.DataType;
import org.apache.pig.data.Tuple;
import org.apache.pig.impl.logicalLayer.schema.Schema;


public class ConvertToLong extends EvalFunc<Long> {

@Override
public Long exec(Tuple input) throws IOException {

    if (input == null || input.size() == 0) {
        return null;
    }

    try {

        long value = 0;
        DataByteArray dba = (DataByteArray)input.get(0);
        System.out.println( dba.toString() );
        byte[] ba = dba.get();

        for (int i = 0; i < ba.length; i++)
        {
            value = (value << 8) + (ba[i] & 0xff);
        }
        return value;
        //return value;
    } catch (ExecException e) {
        log.warn("Error reading input: " + e.getMessage());
        return 3L;
    } catch( Exception e ){
        log.warn("Error:" + e.getMessage() );
        return 2L;
    }
}

@Override
public Schema outputSchema(Schema input) {
    return new Schema(new Schema.FieldSchema(null, DataType.LONG));
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T02:34:57+00:00Added an answer on June 1, 2026 at 2:34 am

    You do not need an UDF to load long integers from HBase.
    You can rely on the -caster=HBaseBinaryConverter option on HBaseStorage.

    Example:
    I have a table named counters, the value is stored under the val:val column (using the increment feature which stores data as 8 bytes long).
    To list all the counters in PIG:

    counters = LOAD 'hbase://counters' USING org.apache.pig.backend.hadoop.hbase.HBaseStorage('val:val', '-caster=HBaseBinaryConverter -loadKey') AS (key:chararray, val:long);
    DUMP counters
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to Read HBase table TableMapReduceUtil and dump data into HDFS (Don't
I have been trying to read a picture saved in Access DB as a
Im trying to read a column of String values from my DB. Im trying
I'm trying to read a .doc file into a database so that I can
I'm playing around with an install of HBase cluster, and am trying to access
Trying to read in some information from the google maps api into my application
Trying to read JSON from hidden input value. <html> <body> <input id=hdn type=hidden value='{products:{id:100001,name:Ram}}'>
Trying to read into an object the following XML file (can be changed) into
Am trying to read the value of a checkbox from a BackgroundWorker in WPF:
Im trying to read a text file, x bytes at a time into a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.