php 如何清除hbase中的表?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9902353/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 07:53:05  来源:igfitidea点击:

How to clear a table in hbase?

phphbase

提问by Micku

I want to empty a table in hbase... eg: user. Is there any command or function to empty the table without deleting it...

我想清空 hbase 中的一个表...例如:user。是否有任何命令或函数可以清空表而不删除它...

My table structure is :

我的表结构是:

$mutations = array(
                new Mutation( array(
                    'column' => 'username:1',
                    'value' =>$name
                ) ),
                new Mutation( array(
                    'column' => 'email:1',
                    'value' =>$email
                ) )
        );          
$hbase->mutateRow("user",$key,$mutations);

Can someone help me?

有人能帮我吗?

采纳答案by starl1ng

There's no single command to clear Hbase table, but you can use 2 workarounds: disable, delete, create table, or scan all records and delete each.

没有单一的命令可以清除 Hbase 表,但您可以使用 2 种解决方法:禁用、删除、创建表或扫描所有记录并删除每个记录。

Actually, disable, delete and create table again takes about 4 seconds.

实际上,禁用、删除和再次创建表大约需要 4 秒钟。

// get Hbase client
$client = <Your code here>;
$t = "table_name";

$tables = $client->getTableNames();

if (in_array($t, $tables)) {
  if ($client->isTableEnabled($t))
    $client->disableTable($t);

  $client->deleteTable($t);
}

$descriptors = array(
  new ColumnDescriptor(array("name" =>  "c1", "maxVersions" => 1)),
  new ColumnDescriptor(array("name" =>  "c2", "maxVersions" => 1))
);

$client->createTable($t, $descriptors);

If there's not a lot of data in table - scan all rows and delete each is much faster.

如果表中的数据不多 - 扫描所有行并删除每一行会快得多。

$client = <Your code here>;
$t = "table_name";

// i don't remember, if list of column families is actually needed here
$columns = array("c1", "c2");

$scanner = $client->scannerOpen($t, "", $columns);
while ($result = $client->scannerGet($scanner)) {
  $client->deleteAllRow($t, $result[0]->row);
}

In this case data is not deleted physically, actually it's "marked as deleted" and stays in table until next major compact.

在这种情况下,数据不会被物理删除,实际上它被“标记为已删除”并保留在表中直到下一个主要压缩。

回答by Alexis Gamarra

If you execute this in HBase shell:

如果您在 HBase shell 中执行此操作:

 > truncate 'yourTableName'

Then HBase will execute this operations for 'yourTableName':

然后 HBase 将为“yourTableName”执行以下操作:

 > disable 'yourTableName'
 > drop 'yourTableName'
 > create 'yourTableName', 'f1', 'f2', 'f3'

回答by André Staltz

Another efficient option is to actually delete the table then reconstruct another one with all the same settings as the previous.

另一个有效的选择是实际删除该表,然后使用与前一个相同的所有设置重建另一个表。

I don't know how to do this in php, but I do know how to do it in Java. The corresponding actions in php should be similar, you just need to check how the API looks like.

我不知道如何在 php 中做到这一点,但我知道如何在 Java 中做到这一点。php中对应的action应该是类似的,你只需要看看API是什么样子就行了。

In Java using HBase 0.90.4:

在使用 HBase 0.90.4 的 Java 中:

// Remember the "schema" of your table
HBaseAdmin admin = new HBaseAdmin(yourConfiguration);
HTableDescriptor td = admin.getTableDescriptor(Bytes.toBytes("yourTableName");

// Delete your table
admin.disableTable("yourTableName");
admin.deleteTable("yourTableName");

// Recreate your talbe
admin.createTable(td);

回答by Farooque

Using hbase shell, truncate <table_name>will do the task.

使用hbase shell,truncate <table_name>将完成任务。

The snapshot of truncate 'customer_details'command is shown below:enter image description here

的快照truncate 'customer_details'的命令如下所示:在此处输入图片说明

where customer_detailsis the table name

customer_details表名在哪里

回答by Heapify

truncate command in hbase shell will do the job for you:

hbase shell 中的 truncate 命令将为您完成这项工作:

Before truncate: enter image description here

截断前: 在此处输入图片说明

After truncate: enter image description here

截断后: 在此处输入图片说明

回答by grbulat

For the purposes of this you can use HAdmin. It is an UI tool for Apache HBase administration. There are "Truncate table" and even "Delete table" buttons in alter table page. enter image description here

为此,您可以使用HAdmin。它是一个用于 Apache HBase 管理的 UI 工具。更改表页面中有“截断表”甚至“删除表”按钮。 在此处输入图片说明

回答by Arnon Rotem-Gal-Oz

HBase thrift API (which is what php is using) doesn't provide a truncate command only deleteTable and createTable functionality (what's the diff from your point of view?)

HBase thrift API(这是 php 正在使用的)不提供截断命令,仅提供 deleteTable 和 createTable 功能(从您的角度来看有什么区别?)

otherwise you have to scan to get all the keys and deleteAllRow for each key - which isn't a very efficient option

否则您必须扫描以获取所有键并为每个键删除所有行 - 这不是一个非常有效的选择

回答by Lobo

Perhaps using one of these two commands:

也许使用这两个命令之一:

DELETE FROM your_table WHERE 1;

Or

或者

TRUNCATE your_table;

Regards!

问候!