我在这里遇到了一个小问题: - 我可以使用shell中的过滤器扫描表格 - 我可以使用hbase shell删除一行 但我找不到扫描表格的方法,迭代结果并删除它们。是否有可能“管道”? hbase shell中的命令还是我必须做一个ruby脚本(注意:我不知道如何做)
我想做什么:
扫描' mytable',{COLUMNS => [' c:1],FILTER => " SingleColumnValueFilter(' c',' 1',=,'二进制:-1',true,true)"} |删除' mytable',$ result_i,' c:1'
由于
答案 0 :(得分:0)
好的,我明白了,我在这里发布了rb脚本
require 'java'
require 'net/http'
import java.io.IOException
import org.apache.hadoop.hbase.HBaseConfiguration
import org.apache.hadoop.hbase.HConstants
import org.apache.hadoop.hbase.MasterNotRunningException
import org.apache.hadoop.hbase.client.HBaseAdmin
import org.apache.hadoop.hbase.client.HTable
import org.apache.hadoop.hbase.client.Scan
import org.apache.hadoop.hbase.client.Delete
import org.apache.hadoop.hbase.filter.FirstKeyOnlyFilter
import org.apache.hadoop.hbase.filter.SingleColumnValueFilter
import org.apache.hadoop.hbase.filter.CompareFilter
import org.apache.hadoop.hbase.util.Bytes
import org.apache.hadoop.hbase.util.Writables
import org.apache.hadoop.hbase.HTableDescriptor
import org.apache.hadoop.hbase.HColumnDescriptor
log_level = org.apache.log4j.Level::ERROR
org.apache.log4j.Logger.getLogger("org.apache.zookeeper").setLevel(log_level)
org.apache.log4j.Logger.getLogger("org.apache.hadoop.hbase").setLevel(log_level)
config = HBaseConfiguration.create
config.set 'fs.default.name', config.get(HConstants::HBASE_DIR)
TAB = 'mytable'.to_java_bytes
FAM = 'c'.to_java_bytes
ID = '1'.to_java_bytes
scan = Scan.new()
scan.cache_blocks = false
scan.caching = 10
scan.addColumn FAM, ID
filter = SingleColumnValueFilter.new(FAM, ID, CompareFilter::CompareOp.valueOf('EQUAL'), '-1'.to_java_bytes)
filter.setFilterIfMissing(true)
scan.setFilter(filter)
iter = nil
table = nil
scanner = nil
while true
begin
table = HTable.new config, TAB
scanner = table.getScanner(scan)
iter = scanner.iterator
break
rescue IOException => ioe
print "Exception trying to scan #{TAB}: #{ioe}"
sleep 1
end
end
start = Time.at(java.util.Date.new.getTime/1000)
print "Start Time : " + start.inspect
while iter.hasNext
result = iter.next
delete = Delete.new result.getRow()
delete.deleteColumn(FAM, ID)
table.delete delete
end
scanner.close
ending = Time.at(java.util.Date.new.getTime/1000)
print "Start Time : " + ending.inspect