hadoop - 了解 HBase Java 客户端

标签 hadoop mapreduce hbase hortonworks-data-platform bigdata

几天前我开始使用 Hbase 并浏览了所有在线资料。

我已经安装并配置了 HBase,shell 命令运行良好。

我得到了一个从 HBase 表中获取数据的 Java 客户端示例,它成功执行了,但我不明白它是如何工作的?在代码中我们没有提到Hbase服务器的端口,主机?它如何从表中获取数据?

这是我的代码:

public class RetriveData {

  public static void main(String[] args) throws IOException {

      // Instantiating Configuration class
      Configuration config = HBaseConfiguration.create();

      // Instantiating HTable class
      @SuppressWarnings({ "deprecation", "resource" })
      HTable table = new HTable(config, "emp");

      // Instantiating Get class
      Get g = new Get(Bytes.toBytes("1"));

      // Reading the data
      Result result = table.get(g);

      // Reading values from Result class object
      byte [] value = result.getValue(Bytes.toBytes("personal data"),Bytes.toBytes("name"));

      byte [] value1 = result.getValue(Bytes.toBytes("personal data"),Bytes.toBytes("city"));

      // Printing the values
      String name = Bytes.toString(value);
      String city = Bytes.toString(value1);

      System.out.println("name: " + name + " city: " + city);         
  }

}

输出如下:

输出:
名称:raju 城市:hyderabad

最佳答案

我同意Binary Nerds 的回答

添加一些更有趣的信息以便更好地理解。

你的问题:

I could not understand how it is working? In the code nowhere we have mentioned the port, host of Hbase server? How it able to fetch the data from table?

因为你在集群中执行这个程序

// Instantiating Configuration class
  Configuration config = HBaseConfiguration.create()

所有集群属性都将在集群内部得到处理。因为您在集群中并且正在执行 hbase java 客户端程序。

现在像下面这样尝试(在 Windows 上以不同的方式从远程计算机 eclipse 执行相同的程序,以找出您之前和现在所做的不同之处)。

  public static Configuration configuration; // this is class variable
        static { //fill clusternode1,clusternode2,clusternode3 from your cluster 
            configuration = HBaseConfiguration.create();
             configuration.set("hbase.zookeeper.property.clientPort", "2181");
             configuration.set("hbase.zookeeper.quorum",
             "clusternode1,clusternode2,clusternode3");
             configuration.set("hbase.master", "clusternode1:600000");
         }

希望这能帮助您理解。

关于hadoop - 了解 HBase Java 客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37874623/

相关文章:

hadoop - 我如何关联 Amazon EC2、S3 和我的 HDFS?

apache - 如何在Hbase Shell中编写CheckAndPut操作?

linux - Hive 表字段由 '¬' 分隔 hive 不接受此字符

hadoop - r-00000部分中的重复值

java - 可以启动 apache Spark 节点的嵌入式实例吗?

java - 为什么 Hadoop Mapreduce 分布式处理比正常的顺序处理需要更长的时间?

python - Spark 无法 pickle method_descriptor

java - Hadoop 分布式文件系统是否像 Google 文件系统那样支持任何更新操作?

hadoop - winutils和HBase之间是什么关系?

java - 在 Spring Boot 可执行 jar 中包含 Hortonworks 存储库