Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

Is there a way to add a custom function from HBase Shell?

Highlighted

Is there a way to add a custom function from HBase Shell?

Expert Contributor

I have a custom function written in Ruby to count the number of columns. But I don't know how to add this function in HBase shell? Is there a way to add any custom functions of UDFs in HBase shell?

3 REPLIES 3

Re: Is there a way to add a custom function from HBase Shell?

Contributor

Most likely you would prefer to pipe the results of your HBase shell command into your Ruby function.

Could you show some of the source code or pseudo logic of your Ruby function so that we can verify?

Re: Is there a way to add a custom function from HBase Shell?

Expert Contributor

Here is the ruby function.

def count_table(tablename, args = {})

    table = @shell.hbase_table(tablename)

    # Run the scanner
    scanner = table._get_scanner(args)

    count = 0
    iter = scanner.iterator

    # Iterate results
    while iter.hasNext
        row = iter.next
        count += 1
    end

    # Return the counter
    return count
end

Re: Is there a way to add a custom function from HBase Shell?

Contributor

Could you describe why you want to add this Ruby function to HBase shell?

Also - why are you looking to count the number of columns? Do you mean column families in HBase or Column Qualifiers?

If you can give a recap of your overall project, that will help. There may be a much easier solution with a different approach.

Don't have an account?
Coming from Hortonworks? Activate your account here