Java HBase如何进行内部分析;hbase shell命令“;?

Java HBase如何进行内部分析;hbase shell命令“;?,java,hadoop,hbase,jruby,Java,Hadoop,Hbase,Jruby,假设我在hbase shell中运行get't1','r1'命令,那么hbase内部如何分析和执行该命令?这是一个jruby脚本。它是在shell命令集下定义的 我在这里引用java HashMap作为更好的示例 理解 插入时,您的rowkey就像java HashMap中的key一样,它将存储在一个区域服务器中(在HashMap的情况下,这些是均匀分布的Bucket…) 在返回该行时,它使用rowkey,它将定位特定的区域服务器,并从您提到的表中为其带来值 这就是为什么在处理hbase时,

假设我在hbase shell中运行
get't1','r1'
命令,那么hbase内部如何分析和执行该命令?

这是一个jruby脚本。它是在shell命令集下定义的

我在这里引用java HashMap作为更好的示例 理解

  • 插入时,您的rowkey就像java HashMap中的key一样,它将存储在一个区域服务器中(在HashMap的情况下,这些是均匀分布的Bucket…)
  • 在返回该行时,它使用rowkey,它将定位特定的区域服务器,并从您提到的表中为其带来值
这就是为什么在处理hbase时,rowkey设计应该是完美的(使用satting技术,使用散列算法for ex:),并且应该在区域服务器之间均匀分布,以防止热点。。。

有关更多详细信息,请查看

注意:java方法和shell方法是两种不同的方法。请。不要把两者混在一起,
因为,我觉得你对它们有点困惑。如果您想像我解释的那样编写jruby,您也可以这样做。但这不是常见的做法。
希望有帮助。

我想用Java覆盖“hbase shell命令”,然后我可以在Java项目中直接发送“hbase shell命令”。如何做?如下所示:
publicstaticvoidmain(stringargs[]){
/get Connection to connect hbase
Connection conn=..;
/hbase shell命令
String cmd=“get't1','r1'”;
结果集rs=conn.execute(cmd);
您的要求是什么,为什么要这样做?我想使用Java或JSP开发一个WEB UI,我可以通过WEB UI发送“hbase外壳命令”。正如我在下面提到的,您可以通过
运行时
类或
ProcessBuilder
类来调用hbase外壳并执行命令。但你要求我发出get命令的内部工作。请参阅本文中的答案以执行shell命令(shell脚本或hbase shell)。希望这次您不会感到困惑:-)我只是在想为什么需要将jsp+hbase shell命令集成为web ui?如果您想显示Hbase的结果,还有其他几种方法,比如solr+solrj可以将结果呈现给RESTAPI?有什么正当的理由吗?
module Shell
  module Commands
    class Get < Command
      def help
        return <<-EOF
Get row or cell contents; pass table name, row, and optionally
a dictionary of column(s), timestamp, timerange and versions. Examples:
  hbase> get 'ns1:t1', 'r1'
  hbase> get 't1', 'r1'
  hbase> get 't1', 'r1', {TIMERANGE => [ts1, ts2]}
  hbase> get 't1', 'r1', {COLUMN => 'c1'}
  hbase> get 't1', 'r1', {COLUMN => ['c1', 'c2', 'c3']}
  hbase> get 't1', 'r1', {COLUMN => 'c1', TIMESTAMP => ts1}
  hbase> get 't1', 'r1', {COLUMN => 'c1', TIMERANGE => [ts1, ts2], VERSIONS => 4}
  hbase> get 't1', 'r1', {COLUMN => 'c1', TIMESTAMP => ts1, VERSIONS => 4}
  hbase> get 't1', 'r1', {FILTER => "ValueFilter(=, 'binary:abc')"}
  hbase> get 't1', 'r1', 'c1'
  hbase> get 't1', 'r1', 'c1', 'c2'
  hbase> get 't1', 'r1', ['c1', 'c2']
  hbase> get 't1', 'r1', {COLUMN => 'c1', ATTRIBUTES => {'mykey'=>'myvalue'}}
  hbase> get 't1', 'r1', {COLUMN => 'c1', AUTHORIZATIONS => ['PRIVATE','SECRET']}
  hbase> get 't1', 'r1', {CONSISTENCY => 'TIMELINE'}
  hbase> get 't1', 'r1', {CONSISTENCY => 'TIMELINE', REGION_REPLICA_ID => 1}
Besides the default 'toStringBinary' format, 'get' also supports custom formatting by
column.  A user can define a FORMATTER by adding it to the column name in the get
specification.  The FORMATTER can be stipulated: 
 1. either as a org.apache.hadoop.hbase.util.Bytes method name (e.g, toInt, toString)
 2. or as a custom class followed by method name: e.g. 'c(MyFormatterClass).format'.
Example formatting cf:qualifier1 and cf:qualifier2 both as Integers: 
  hbase> get 't1', 'r1' {COLUMN => ['cf:qualifier1:toInt',
    'cf:qualifier2:c(org.apache.hadoop.hbase.util.Bytes).toInt'] } 
Note that you can specify a FORMATTER by column only (cf:qualifier).  You cannot specify
a FORMATTER for all columns of a column family.

The same commands also can be run on a reference to a table (obtained via get_table or
create_table). Suppose you had a reference t to table 't1', the corresponding commands
would be:
  hbase> t.get 'r1'
  hbase> t.get 'r1', {TIMERANGE => [ts1, ts2]}
  hbase> t.get 'r1', {COLUMN => 'c1'}
  hbase> t.get 'r1', {COLUMN => ['c1', 'c2', 'c3']}
  hbase> t.get 'r1', {COLUMN => 'c1', TIMESTAMP => ts1}
  hbase> t.get 'r1', {COLUMN => 'c1', TIMERANGE => [ts1, ts2], VERSIONS => 4}
  hbase> t.get 'r1', {COLUMN => 'c1', TIMESTAMP => ts1, VERSIONS => 4}
  hbase> t.get 'r1', {FILTER => "ValueFilter(=, 'binary:abc')"}
  hbase> t.get 'r1', 'c1'
  hbase> t.get 'r1', 'c1', 'c2'
  hbase> t.get 'r1', ['c1', 'c2']
  hbase> t.get 'r1', {CONSISTENCY => 'TIMELINE'}
  hbase> t.get 'r1', {CONSISTENCY => 'TIMELINE', REGION_REPLICA_ID => 1}
EOF
      end

      def command(table, row, *args)
        get(table(table), row, *args)
      end

      def get(table, row, *args)
        @start_time = Time.now
        formatter.header(["COLUMN", "CELL"])

        count, is_stale = table._get_internal(row, *args) do |column, value|
          formatter.row([ column, value ])
        end

        formatter.footer(count, is_stale)
      end
    end
  end
end

#add get command to table
::Hbase::Table.add_shell_command('get')
 /**
     * Get a row
     */
    @Override
    public void getOneRecord(final String tableName, final String rowKey) throws IOException {
        final HTable table = new HTable(HBaseConn.getHBaseConfig(), getTable(tableName));
        final Get get = new Get(rowKey.getBytes());
        final Result rs = table.get(get);
        for (final KeyValue kv : rs.raw()) {
            LOG.info(kv.getRow() + " " + kv.getFamily() + ":" + kv.getQualifier() + " " + +kv.getTimestamp());
            LOG.info(new String(kv.getValue()));
        }
    }