返回介绍

HBase Exists - HBase 教程

发布于 2025-02-22 13:46:37 字数 1498 浏览 0 评论 0 收藏 0

可以使用 exists 命令验证表的存在。下面的示例演示了如何使用这个命令。

hbase(main):024:0> exists 'emp'
Table emp does exist

0 row(s) in 0.0750 seconds

==================================================================

hbase(main):015:0> exists 'student'
Table student does not exist

0 row(s) in 0.0480 seconds

使用 Java API 验证表的存在

可以使用 HBaseAdmin 类的 tableExists() 方法验证表在 HBase 中是否存在。按照下面给出的步骤验证 HBase 表存在。

第 1 步

Instantiate the HBaseAdimn class

// Instantiating configuration object
Configuration conf = HBaseConfiguration.create();

// Instantiating HBaseAdmin class
HBaseAdmin admin = new HBaseAdmin(conf);

第 2 步

使用 tableExists() 方法来验证表的存在。

下面给出的是使用 java 程序中的 Java API 来测试一个 HBase 表的存在。

import java.io.IOException;

import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.client.HBaseAdmin;

public class TableExists{

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

   // Instantiating configuration class
   Configuration conf = HBaseConfiguration.create();

   // Instantiating HBaseAdmin class
   HBaseAdmin admin = new HBaseAdmin(conf);

   // Verifying the existance of the table
   boolean bool = admin.tableExists("emp");
   System.out.println( bool);
   }
}

编译和执行上述程序如下所示。

$javac TableExists.java
$java TableExists

下面列出的是输出:

true

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文