【问题标题】:Find count of rows with empty value in Hbase在 Hbase 中查找具有空值的行数
【发布时间】:2018-01-03 00:50:34
【问题描述】:

我已经填充了一个 Hbase 表,其中包含与推文有关的 rowid 和 vrious 信息,例如纯文本、url、hashtag 等,如下所示

902221655086211073    column=clean-tweet:clean-text-cta, timestamp=1514793745304, value=democrat mayor order hurricane harvey stand houston

但是在填充时我注意到有些行是空的,就像

902487280543305728    column=clean-tweet:clean-text-cta, timestamp=1514622371008, value=  

现在我如何找到有数据的行数?

请帮帮我

【问题讨论】:

    标签: hadoop count hbase bigdata apache-zookeeper


    【解决方案1】:

    到目前为止,在 HBase shell 中没有执行此操作的规定。也许您可以使用这样的简单代码来获取许多对提供的列限定符没有值的记录。

    CountAndFilter [tableName] [columnFamily] [columnQualifier]

    import java.io.IOException;
    
    import org.apache.hadoop.hbase.HBaseConfiguration;
    import org.apache.hadoop.hbase.TableName;
    import org.apache.hadoop.hbase.client.Admin;
    import org.apache.hadoop.hbase.client.Connection;
    import org.apache.hadoop.hbase.client.ConnectionFactory;
    import org.apache.hadoop.hbase.client.Result;
    import org.apache.hadoop.hbase.client.ResultScanner;
    import org.apache.hadoop.hbase.client.Scan;
    import org.apache.hadoop.hbase.client.Table;
    import org.apache.hadoop.hbase.util.Bytes;
    
    public class CountAndFilter {
    
    private static Connection conn;
    private static int recordsWithoutValue = 0;
    public static Admin getConnection() throws IOException {
        if (conn == null) {
            conn = ConnectionFactory.createConnection(HBaseConfiguration.create());
        }
        return conn.getAdmin();
    }
    
    public static void main(String args[]) throws IOException {
        getConnection();
        scan(args[0], args[1], args[2]);
        System.out.println("Records with empty value : " + recordsWithoutValue);
    }
    
    public static void scan(String tableName, String columnFamily, String columnQualifier) throws IOException {
        Table table = conn.getTable(TableName.valueOf(tableName));
        ResultScanner rs = table.getScanner(new Scan().addColumn(Bytes.toBytes(columnFamily), Bytes.toBytes(columnQualifier)));
    
        Result res = null;
        try {
            while ((res = rs.next()) != null) {
                if (res.containsEmptyColumn(Bytes.toBytes(columnFamily), Bytes.toBytes(columnQualifier))){
                    recordsWithoutValue++;
                }
            }
        } finally {
            rs.close();
        }
    }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-08
      • 1970-01-01
      相关资源
      最近更新 更多