Php 如何在hbase中清除表格?
我想清空hbase中的表。。。例如:Php 如何在hbase中清除表格?,php,hbase,Php,Hbase,我想清空hbase中的表。。。例如:用户。是否有任何命令或函数在不删除表格的情况下清空表格 我的表格结构是: $mutations = array( new Mutation( array( 'column' => 'username:1', 'value' =>$name ) ), new Mutation(
用户
。是否有任何命令或函数在不删除表格的情况下清空表格
我的表格结构是:
$mutations = array(
new Mutation( array(
'column' => 'username:1',
'value' =>$name
) ),
new Mutation( array(
'column' => 'email:1',
'value' =>$email
) )
);
$hbase->mutateRow("user",$key,$mutations);
有人能帮我吗?也许可以使用以下两个命令之一:
DELETE FROM your_table WHERE 1;
或
问候 HBase thrift API(php正在使用的)不提供仅限truncate命令的deleteTable和createTable功能(从您的角度来看有什么区别?)
否则,您必须扫描以获取所有键,并删除每个键的所有行-这不是一个非常有效的选项另一个有效的选项是实际删除表,然后使用与上一个相同的设置重建另一个表 我不知道如何在php中做到这一点,但我知道如何在Java中做到这一点。php中的相应操作应该类似,您只需要检查API的外观 在使用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);
并没有单个命令可以清除Hbase表,但您可以使用两种变通方法:禁用、删除、创建表或扫描所有记录并删除每个记录 实际上,再次禁用、删除和创建表大约需要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);
//获取Hbase客户端
$client=;
$t=“表格名称”;
$tables=$client->getTableNames();
if(在数组中($t,$tables)){
如果($client->isTableEnabled($t))
$client->disableTable($t);
$client->deletetetable($t);
}
$descriptor=数组(
新的列描述符(数组(“名称”=>“c1”,“maxVersions”=>1)),
新的列描述符(数组(“名称”=>“c2”、“maxVersions”=>1))
);
$client->createTable($t,$descriptor);
若表中并没有太多数据,那个么扫描所有行并删除每一行要快得多
$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);
}
$client=;
$t=“表格名称”;
//我不记得这里是否需要列族列表
$columns=数组(“c1”、“c2”);
$scanner=$client->scannerOpen($t,“,$columns);
而($result=$client->scannerGet($scanner)){
$client->deleteAllRow($t,$result[0]->row);
}
在这种情况下,数据不会被物理删除,实际上它被“标记为已删除”,并一直保留在表中,直到下一次主要压缩。如果在HBase外壳中执行此操作:
> truncate 'yourTableName'
然后HBase将对“yourTableName”执行以下操作:
> disable 'yourTableName'
> drop 'yourTableName'
> create 'yourTableName', 'f1', 'f2', 'f3'
使用
hbase shell
,truncate
将完成此任务
truncate'customer\u details'
命令的快照如下所示:
其中,
customer\u details
是表名hbase shell中的truncate命令将为您执行以下操作:
截断前:
截断后:
为此,您可以使用。它是一个用于Apache HBase管理的UI工具。在ALTERTABLE页面中有“Truncate table”甚至“Delete table”按钮。
@Micku这些都是标准的SQL语句,奇怪的是不能工作。您用于连接到数据库的用户,您是否有执行删除或截断的权限?更好的是,有一个shell命令可用于执行此操作。它被称为截断。请在此处阅读:“truncate”不保留表的权限。但是,较新的命令“truncate\u preserve”可以简单地使用“truncate”或“truncate\u preserve”!
> disable 'yourTableName'
> drop 'yourTableName'
> create 'yourTableName', 'f1', 'f2', 'f3'