Support Questions
Find answers, ask questions, and share your expertise

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?



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?

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 =
        count += 1

    # Return the counter
    return count


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.