Sha256: 655e1ae0f50bc5f222397a5c1e94d8d52ccd2313107c47aeece04f5fd22a3283

Contents?: true

Size: 1.43 KB

Versions: 1

Compression:

Stored size: 1.43 KB

Contents

class HBase
class Scoped
# Basic data aggregation with coprocessor based on AggregateImplementation
# @author Junegunn Choi <junegunn.c@gmail.com>
module Aggregation
  module Admin
    # Enables aggregation support for the table
    # @return [nil]
    def enable_aggregation!
      cpc = 'org.apache.hadoop.hbase.coprocessor.AggregateImplementation'
      add_coprocessor! cpc unless has_coprocessor?(cpc)
    end
  end

  # Performs aggregation with coprocessor
  # @param [Symbol] op Aggregation type: :sum, :min, :max, :avg, :std, :row_count
  # @param [Symbol, org.apache.hadoop.hbase.coprocessor.ColumnInterpreter] type
  #   Column type (only :fixnum is supported as of now) or ColumnInterpreter object used to decode the value
  def aggregate op, type = :fixnum
    aggregation_impl op, type
  end

private
  def aggregation_impl method, type
    raise ArgumentError.new("No column specified") if method != :row_count && @project.empty?

    @aggregation_client ||= AggregationClient.new(table.config)
    @aggregation_client.send(
      method,
      Util.to_bytes(table.name),
      column_interpreter_for(type),
      filtered_scan)
  end

  def column_interpreter_for type
    case type
    when :fixnum, :long
      LongColumnInterpreter.new
    when org.apache.hadoop.hbase.coprocessor.ColumnInterpreter
      type
    else
      raise ArgumentError, "Column interpreter for #{type} not implemented."
    end
  end
end#Aggregation
end#Scoped
end#HBase

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hbase-jruby-0.1.5-java lib/hbase-jruby/scoped/aggregation.rb