1.Hbase 根据rowkey 查询

conf的配置信息如下:

        conf = new Configuration();

        conf.set("hbase.zookeeper.quorum", "192.168.50.253:2181");
conf.set("hbase.rootdir", "hdfs://192.168.50.253:9000/hbase");

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

public ArrayList<String>  getRoutes(String rowkey,String tablename) throws IOException {

        HTable hTable = new HTable(conf, tablename);//traffic_route
Get get = new Get(rowkey.getBytes());
Result r = hTable.get(get); KeyValue[] kv = r.raw(); // 行健对应的值. ArrayList<String> list = new ArrayList<>();
if (kv.length > 0) {
String ss = kv[0].getValue().toString(); DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Date tempDay = new Date();
tempDay = null;
int sum = 0; String tempDate = "";
String mapStringValue = "";
for (int i = 0; i < kv.length; i++) {
String value = new String(kv[i].getValue());
// System.out.println("value = " + value); String[] station = value.split("--");
// System.out.println(station[0]);
String[] date = station[0].split(" ");
try {
Date day = sdf.parse(date[0]); if (tempDay == null) {
tempDay = day; } if ((day.compareTo(tempDay) == 0)) { tempDate = date[0]; mapStringValue = mapStringValue + station[1] + "-"; } else { Map<String, String> map = new HashMap<>(); map.put(tempDate, mapStringValue); list.add(mapStringValue);
mapStringValue = ""; tempDay = day;
mapStringValue += station[1] + "-"; } } catch (ParseException e) {
e.printStackTrace();
} } // System.out.println("list = " + list.size()); Map<String, String> map = new HashMap<>(); map.put(tempDate, mapStringValue); list.add(mapStringValue);
mapStringValue = "";
} // System.out.println("list.get(0) = " + list.get(0));
// System.out.println("list.get(1) = " + list.get(1));
if (list.size() == 0) {
System.out.println("取出数据为空");
} else {
System.out.println("获取数据成功");
}
return list;
}

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

hadoop之根据Rowkey从HBase中查询数据的更多相关文章

  1. 根据Rowkey从HBase中查询数据

    /** * @Title: queryData * @Description: 从HBase查询出数据 * @author xxxx * @param tableName * 表名 * @param ...

  2. 使用Hive或Impala执行SQL语句,对存储在HBase中的数据操作

    CSSDesk body { background-color: #2574b0; } /*! zybuluo */ article,aside,details,figcaption,figure,f ...

  3. IDEA中Spark读Hbase中的数据

    import org.apache.hadoop.hbase.HBaseConfiguration import org.apache.hadoop.hbase.io.ImmutableBytesWr ...

  4. IDEA中Spark往Hbase中写数据

    import org.apache.hadoop.hbase.HBaseConfiguration import org.apache.hadoop.hbase.io.ImmutableBytesWr ...

  5. Spark读取Hbase中的数据

    大家可能都知道很熟悉Spark的两种常见的数据读取方式(存放到RDD中):(1).调用parallelize函数直接从集合中获取数据,并存入RDD中:Java版本如下: JavaRDD<Inte ...

  6. Sql Server 存储过程中查询数据无法使用 Union(All)

    原文:Sql Server 存储过程中查询数据无法使用 Union(All) 微软Sql Server数据库中,书写存储过程时,关于查询数据,无法使用Union(All)关联多个查询. 1.先看一段正 ...

  7. 从DataTable中查询数据

    /// <summary> /// 从DataTable中查询数据 /// </summary> /// <param name="tb">待处 ...

  8. MongoDB数据库中查询数据(下)

    MongoDB数据库中查询数据(下) 在find中,options参数值为一个对象,用来设置查询数据时使用的选项,下面我们来对该参数值对象中可以使用的属性进行介绍: 1. fields; 该属性值为一 ...

  9. 在MongoDB数据库中查询数据(上)

    在MongoDB数据库中查询数据(上) 在MongoDB数据库中,可以使用Collection对象的find方法从一个集合中查询多个数据文档,find方法使用方法如下所示: collection.fi ...

随机推荐

  1. C++ 参考网站

    Reference Web cites for the C++ standard library cppreference cplusplus sgi IBM MSDN isocpp More res ...

  2. UVA3026Period(最短循环节)

    题目链接 题意: 给定长度为n的字符串s,求他的每个前缀的最短循环节 分析: kmp预处理 next[]数组,然后对于 前 i 个字符,如果 next[i] > 0 && i % ...

  3. BZOJ2124: 等差子序列

    题意:给一个 1 到 N 的排列{Ai},询问是否存在 1<=p1<p2<p3<p4<p5<…<pLen<=N(Len>=3),使得 Ap1,Ap ...

  4. Can not issue data manipulation statements with executeQuery() 异常处理

    1.这个异常的报错翻译过来就是 不能发出数据操纵语句与executeQuery() 2.这里要检查一下你要执行的实际SQL语句要做什么操作 查询呢?还是修改? 3.如果是修改的话,需要添加@Modif ...

  5. python学习笔记-(三)条件判断和循环

    1.条件判断语句 Python中条件选择语句的关键字为:if .elif .else这三个.其基本形式如下: age_of_cc = 27 age = int(input("guessage ...

  6. C++ wMA 算法

    CMakeLists.txt project(aaa) add_library(aaa SHARED aaa.cpp) add_executable(bbb bbb.cpp) target_link_ ...

  7. 找到一款不错的网站压力测试工具webbench

    webbench最多可以模拟3万个并发连接去测试网站的负载能力,个人感觉要比Apache自带的ab压力测试工具好,安装使用也特别方便. 1.适用系统:Linux 2.编译安装: 引用 wget htt ...

  8. xcode 不显示占用内存

    解决办法: Scheme设置中,将 Enable Zombie Objects 勾选去掉.

  9. Java序列化的几种方式以及序列化的作用

    Java序列化的几种方式以及序列化的作用 本文着重讲解一下Java序列化的相关内容. 如果对Java序列化感兴趣的同学可以研究一下. 一.Java序列化的作用    有的时候我们想要把一个Java对象 ...

  10. thinkphp 3.2视图里添加URL参数 实例

    使用TP的时候URL传参 到控制器里 视图里 <ul> <volist name="content" id="data"> <li ...