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 ...
随机推荐
- mainBundle和CustomBundle
iOS中NSBundle类 An NSBundle object represents a location in the file system that groups code and resou ...
- openssl生成https证书 (转)
1.首先要生成服务器端的私钥(key文件):openssl genrsa -des3 -out server.key 1024运行时会提示输入密码,此密码用于加密key文件去除key文件口令的命令:o ...
- ubuntu下安装wine1.8和阿里旺旺
参考:http://www.linuxidc.com/Linux/2015-12/126722.htm和http://www.linuxidc.com/Linux/2016-05/131131.htm ...
- 安装ubuntu和安装ubuntu后要安装的软件列表
安装ubuntu 老毛桃进入win pe修复启动项 在win pe下面制作ubuntu的安装盘,只用的软件是ultraISO 参考博客下面的分区的那篇文章 http://jingyan.baidu. ...
- BufferedReader类
BufferedReader类用于从缓冲区中读取内容,多有的输入字节数据都将放在缓冲区中. BufferedReader中定义的构造方法只能接收字符输入流的实例,所以必须使用字符输入流和字节输入流的转 ...
- 在VS中向命令行添加参数的方法
在VS中向命令行添加参数的方法 在VS中向命令行添加参数,即向main()函数传递参数的方法: 右键单击要 添加参数的工程-->属性-->配置属性-->调试,在右侧“命令参数”栏输入 ...
- DllMaps
http://www.mono-project.com/docs/advanced/pinvoke/dllmap/ http://www.mono-project.com/docs/advanced/ ...
- Robot Framework--07 变量的声明、赋值及其使用
转自:http://blog.csdn.net/tulituqi/article/details/7984642 一.变量的声明 1.变量标识符 每个变量都可以用 变量标识符{变量名} 来进行 ...
- WebAPI文件上传与下载
http://www.cnblogs.com/GarsonZhang/p/5511427.html https://github.com/GarsonZhang/FileUpLoadAPI
- 关于win10输入法问题(打不出中文)解决方法
提问过windous10打不出字,通过安装第三方输入法和所有有关切换的快捷键都没用,现在找到了解决方法 win键+x,打开命令提示符,输入ctfmon,回车 这样就能看到桌面右下角的输入法上面的叉叉消 ...