回覆列表
  • 1 # 使用者834195712159

    程式碼示例:

    Configuration conf = HBaseConfiguration.create();

    conf.set("hbase.zookeeper.quorum", "hadoop1,hadoop2,hadoop3");

    HTable table = new HTable(conf, "DataCollection1");

    System.out.println("scan1");

    Scan scan1 = new Scan();

    new PrefixFilter(Bytes.toBytes("row"));

    Filter filter3= new PrefixFilter(Bytes.toBytes("2017-01-01"));

    scan1.setFilter(filter3);

    scan1.setMaxVersions();

    ResultScanner scanner1 = table.getScanner(scan1);

    System.out.println("scan2");

    int count=0;

    JSONArray array = new JSONArray();

    for (Result r : scanner1) {

    System.out.println("sssss");

    JSONObject mapOfColValues = new JSONObject();// 建立json物件就是一個{name:wp}

    for (KeyValue kv : r.raw()) {

    System.out.println(String.format("row:%s, family:%s, qualifier:%s, qualifiervalue:%s, timestamp:%s.",

    Bytes.toString(kv.getRow()),

    Bytes.toString(kv.getFamily()),

    Bytes.toString(kv.getQualifier()),

    Bytes.toString(kv.getValue()),

    kv.getTimestamp()));

    mapOfColValues.put(Bytes.toString(kv.getQualifier()),Bytes.toString(kv.getValue()));

    }

    array.add(mapOfColValues);

    count++;

    System.out.println(count);

    }

    scanner1.close();

    table.close();

    //pool.close();

    System.out.println(count);

    System.out.println("-------------finished----------------");

  • 中秋節和大豐收的關聯?
  • 青年電影高峰會的影響力如何?