hadoop之根据Rowkey从HBase中查询数据
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中查询数据的更多相关文章
- 根据Rowkey从HBase中查询数据
/** * @Title: queryData * @Description: 从HBase查询出数据 * @author xxxx * @param tableName * 表名 * @param ...
- 使用Hive或Impala执行SQL语句,对存储在HBase中的数据操作
CSSDesk body { background-color: #2574b0; } /*! zybuluo */ article,aside,details,figcaption,figure,f ...
- IDEA中Spark读Hbase中的数据
import org.apache.hadoop.hbase.HBaseConfiguration import org.apache.hadoop.hbase.io.ImmutableBytesWr ...
- IDEA中Spark往Hbase中写数据
import org.apache.hadoop.hbase.HBaseConfiguration import org.apache.hadoop.hbase.io.ImmutableBytesWr ...
- Spark读取Hbase中的数据
大家可能都知道很熟悉Spark的两种常见的数据读取方式(存放到RDD中):(1).调用parallelize函数直接从集合中获取数据,并存入RDD中:Java版本如下: JavaRDD<Inte ...
- Sql Server 存储过程中查询数据无法使用 Union(All)
原文:Sql Server 存储过程中查询数据无法使用 Union(All) 微软Sql Server数据库中,书写存储过程时,关于查询数据,无法使用Union(All)关联多个查询. 1.先看一段正 ...
- 从DataTable中查询数据
/// <summary> /// 从DataTable中查询数据 /// </summary> /// <param name="tb">待处 ...
- MongoDB数据库中查询数据(下)
MongoDB数据库中查询数据(下) 在find中,options参数值为一个对象,用来设置查询数据时使用的选项,下面我们来对该参数值对象中可以使用的属性进行介绍: 1. fields; 该属性值为一 ...
- 在MongoDB数据库中查询数据(上)
在MongoDB数据库中查询数据(上) 在MongoDB数据库中,可以使用Collection对象的find方法从一个集合中查询多个数据文档,find方法使用方法如下所示: collection.fi ...
随机推荐
- Npoi实现Excel绘制功能
使用Npoi操作Excel,是我一直很喜欢的一种方式. 说简单也简单,但是封装好重用性,易用性,也稍稍费了些时间.在这里做个记录,免得以后遗忘. 首先说一下需求,需求有两点 1.新建Excel,并下载 ...
- U型进度条
今天同事说要做一个U型进度条的效果. 本打算上网找一个,结果找了一个纯CSS3打造的,不过最坑人的是他把进度条从1到100,挨个设置了CSS属性. 这不得活活累死宝宝~~~~~~~~~~~~~~. 于 ...
- android service 的各种用法(IPC、AIDL)
http://my.oschina.net/mopidick/blog/132325 最近在学android service,感觉终于把service的各种使用场景和用到的技术整理得比较明白了,受益颇 ...
- iOS - CAEmitterLayer流星
效果图: 流星: #pragma mark - loading animation - (void)showLoadingAnimation { CGRect mainBounds = [[UIScr ...
- js020-JSON
js020-JSON 20.1 语法 JSON的语法可以表示为一下三种类型的值. 简单值 使用与JS相同的语法,可以在JSON中表示字符串.数值.布尔值和null,但是JSON不支持JS中的特殊性Un ...
- 过滤字符串的Html标记 c#函数 .
.public static string StripHTML(string strHtml) . { . string[] aryReg ={ . @"<script[^>]* ...
- matlab注释
单行注释: 两个'%': 多行注释: A. %{ 若干语句 %} B. 注释: 选中要注释的若干语句, 编辑器菜单Text->Comment, 或者快捷键Ctrl+R 取消注释: 选中要取消注释 ...
- MFC学习-第一课 MFC运行机制
最近由于兴趣爱好,学习了孙鑫的MFC教程的第一课.看完视频了,自己便用visual studio 2010尝试了MFC编程,其中遇到了一些问题. 1.vs2010不像vs6.0那样可以新建一个空的MF ...
- ecshop mobile 文件介绍
mobile手机端 1.common位置:include\apps\default\common\ function.php show_message 成功跳转页面 其他页面引用 show_m ...
- guid正则表达
a-fA-F0-9 加上下划线 _ 可以用 \w 来代替. ^\w{8}-(\w{4}-){3}\w{12}$ 如果不可以用下划线, 0-9 用 \d 代替 a-fA-F 就用其中一个 a-f,然后匹 ...