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 ...
随机推荐
- python合并2个字典
2种方式,update()和items()方式 In [14]: a Out[14]: {'a': 1, 'b': 2, 'c': 3} In [15]: c = {'d': 4} In [16]: ...
- PHP之:PHP编程效率的20个要点
[导读] 用单引号代替双引号来包含字符串,这样做会更快一些.因为PHP会在双引号包围的字符串中搜寻变量,单引号则 不会,注意:只有echo能这么做,它是一种可以把多个字符串当作参数的“函数” 用单引号 ...
- struts2文件目录结构
apps 文件夹包含了多个 example 示例应用的压缩包. docs 文件夹包含了 struts 官方的帮助文档. lib 文件夹包含了 struts 提供的类库 jar 包. src 文件夹包含 ...
- SVN cleanup操作反复失败解决办法
今天在更新项目的时候遇到一个问题,按惯例要cleanup才能重新更新.但是很不幸,在cleanup的时候又遇到了问题! 1 svn cleanup failed–previous operati ...
- nginx常用命令
ps -ef | grep nginx在进程列表里面找master进程,它的编号就是主进程号了. 步骤2:发送信号 从容停止Nginx: kill -QUIT 主进程号 快速停止Nginx: kill ...
- ntp服务器搭建与客户端设置
服务器对时间要求非常严格,linux服务器文件的生成,日志,以及数据库的连接都是根据时间的逻辑 进行任务处理,如果时间不同步,那么,处理的任务,以及出问题的分析日志,时间不对,很难分析 直接更改lin ...
- 基础SQL语句
SQL语句: 1.插入 方法一: "INSERT INTO [DB].[dbo].[T_Table] ([ID],[Name],[Amount],[Creater],[CreatedOn], ...
- 自然语言16_Chunking with NLTK
Chunking with NLTK 对chunk分类数据结构可以图形化输出,用于分析英语句子主干结构 # -*- coding: utf-8 -*-"""Created ...
- 20145212 《Java程序设计》第2周学习总结
20145212 <Java程序设计>第2周学习总结 教材学习内容总结 第二周主要学习了Java的基本语法,在第一周熟悉了Java基本操作的基础上我们可以自行的利用这些语法编译具有实用价值 ...
- Spring MVC学习笔记——用户增删该查和服务器端验证
建立一个动态web项目,起名为SpringMVC_crud 导包,其中包括jstl的一些包等 1.先写一个User.java,是用户类 文件User.java文件 package org.common ...