文章目录
在右侧代码窗口完成代码编写:
1:MapReduce类已经配置好,只需完成MapReduce的数据分析;
2:在Map节点执行类中把城市ID当成的输出key,酒店价格当成Mapper类的输出value;
3:在Reduce节点执行类中,统计以城市ID为维度的酒店价格均价,并保存到Hbase;需要满足ROWKEY为城市ID、列族为average_infos、表字段名称为price,计算出的价格均价为表字段值。
t_city_hotels_info表结构如下
| 列族名称 | 字段 | 对应的文件数据字段 | 描述 | ROWKEY (格式为:城市ID_酒店ID) |
|---|---|---|---|---|
| cityInfo | cityId | city_id | 城市ID | city_id + “_” + id |
| cityInfo | cityName | city_name | 城市名称 | city_id + “_” + id |
| cityInfo | pinyin | pinyin | 城市拼音 | city_id + “_” + id |
| hotel_info | id | id | 酒店id | city_id + “_” + id |
| hotel_info | name | name | 酒店名称 | city_id + “_” + id |
| hotel_info | price | price | 酒店价格 | city_id + “_” + id |
| hotel_info | lon | lon | 经度 | city_id + “_” + id |
| hotel_info | url | url | url | 地址 |
| hotel_info | img | img | 图片 | city_id + “_” + id |
| hotel_info | address | address | 地址 | city_id + “_” + id |
| hotel_info | score | score | 得分 | city_id + “_” + id |
| hotel_info | dpscore | dpscore | 用户评分 | city_id + “_” + id |
| hotel_info | dpcount | dpcount | 评分个数 | city_id + “_” + id |
| hotel_info | star | star | 星级 | city_id + “_” + id |
| hotel_info | stardesc | stardesc | 舒适度 | city_id + “_” + id |
| hotel_info | shortName | shortName | 酒店简称 | city_id + “_” + id |
测试说明
平台会对你编写的代码进行测试:
测试输入:
t_city_hotels_info,average_table;
预期输出:
row:58
average_infos:price 1145.6170212765958
row:59
average_infos:price 797.2197802197802
package com.processdata;
import java.io.IOException;
import java.util.Scanner;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.mapreduce.TableMapReduceUtil;
import org.apache.hadoop.hbase.mapreduce.TableMapper;
import org.apache.hadoop.hbase.mapreduce.TableReducer;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
import com.util.HBaseUtil;
/**
* 使用MapReduce程序处理HBase中的数据并将最终结果存入到另一张表 1中
*/
public class HBaseMapReduce extends Configured implements Tool {
public static class MyMapper extends TableMapper<Text, DoubleWritable> {
public static final byte[] column = "price".getBytes();
public static final byte[] family = "hotel_info".getBytes();
@Override
protected void map(ImmutableBytesWritable rowKey, Result result, Context context)
throws IOException, InterruptedException {
/********** Begin *********/
String cityId = Bytes.toString(result.getValue("cityInfo".getBytes(), "cityId".getBytes()));
byte[] value = result.getValue(family, column);
Double value1 = Double.parseDouble(Bytes.toString(value));
DoubleWritable i = new DoubleWritable(value1);
String priceKey = cityId;
context.write(new Text(priceKey),i);
/********** End *********/
}
}
public static class MyTableReducer extends TableReducer<Text, DoubleWritable, ImmutableBytesWritable> {
@Override
public void reduce(Text key, Iterable<DoubleWritable> values, Context context) throws IOException, InterruptedException {
/********** Begin *********/
double sum = 0;
int len = 0;
for (DoubleWritable price : values)
{
len ++;
sum += price.get();
}
Put put = new Put(Bytes.toBytes(key.toString()));
put.addColumn("average_infos".getBytes(),"price".getBytes(),Bytes.toBytes(String.valueOf(sum / len)));
context.write(null, put);
/********** End *********/
}
}
public int run(String[] args) throws Exception {
//配置Job
Configuration conf = HBaseConfiguration.create(getConf());
conf.set("hbase.zookeeper.quorum", "127.0.0.1"); //hbase 服务地址
conf.set("hbase.zookeeper.property.clientPort", "2181"); //端口号
Scanner sc = new Scanner(System.in);
String arg1 = sc.next();
String arg2 = sc.next();
//String arg1 = "t_city_hotels_info";
//String arg2 = "average_table";
try {
HBaseUtil.createTable("average_table", new String[] {"average_infos"});
} catch (Exception e) {
// 创建表失败
e.printStackTrace();
}
Job job = configureJob(conf,new String[]{arg1,arg2});
return job.waitForCompletion(true) ? 0 : 1;
}
private Job configureJob(Configuration conf, String[] args) throws IOException {
String tablename = args[0];
String targetTable = args[1];
Job job = new Job(conf,tablename);
Scan scan = new Scan();
scan.setCaching(300);
scan.setCacheBlocks(false);//在mapreduce程序中千万不要设置允许缓存
//初始化Mapreduce程序
TableMapReduceUtil.initTableMapperJob(tablename,scan,MyMapper.class, Text.class, DoubleWritable.class,job);
//初始化Reduce
TableMapReduceUtil.initTableReducerJob(
targetTable, // output table
MyTableReducer.class, // reducer class
job);
job.setNumReduceTasks(1);
return job;
}
}
在右侧代码窗口完成代码编写,MapReduce类已经配置好,只需完成MapReduce的数据分析,你只需将所有分词后的数据存入新表中,平台将会为你输出词频大于100的词组:
1:在Map节点执行类中把评论进行分词当成输出key,Mapper类的输出value为固定值1。
2:在Reduce节点执行类中,统计以评论中分词后的词组为维度的词频数量,并保存到Hbase。需要满足ROWKEY为评论分词、列族为 word_info 、表字段名称为 count 。
t_hotel_comment表结构如下
| 列族名称 | 字段 | 对应的文件数据字段 | 描述 | ROWKEY (格式为:城市ID_酒店ID) |
|---|---|---|---|---|
| hotel_info | hotel_name | hotel_name | 酒店名称 | Hotel_id+ “_” + id |
| hotel_info | hotel_id | hotel_id | 酒店ID | Hotel_id+ “_” + id |
| comment_info | id | id | 评论id | Hotel_id+ “_” + id |
| comment_info | baseRoomId | baseRoomId | 房间类型 | Hotel_id+ “_” + id |
| comment_info | content | content | 评论内容 | Hotel_id+ “_” + id |
| comment_info | checkInDate | checkInDate | 入住时间 | Hotel_id+ “_” + id |
| comment_info | postDate | postDate | 离开时间 | Hotel_id+ “_” + id |
| comment_info | userNickName | userNickName | 用户昵称 | Hotel_id+ “_” + id |
测试说明
平台会对你编写的代码进行测试:
测试输入:
t_hotel_comment,comment_word_count;
预期输出:
word:不错
word_info:count 344
word:位置
word_info:count 159
word:住
word_info:count 150
word:免费
word_info:count 110
word:入住
word_info:count 112
word:卫生
word_info:count 106
word:地铁站
word_info:count 144
word:巴士
word_info:count 174
word:干净
word_info:count 211
word:很好
word_info:count 200
word:性价比
word_info:count 123
word:房间
word_info:count 449
word:早餐
word_info:count 116
word:环境
word_info:count 166
word:葵
word_info:count 112
word:酒店
word_info:count 970
word:香港
word_info:count 224
package com.processdata;
import java.io.IOException;
import java.util.List;
import java.util.Scanner;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.mapreduce.TableMapReduceUtil;
import org.apache.hadoop.hbase.mapreduce.TableMapper;
import org.apache.hadoop.hbase.mapreduce.TableReducer;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
import org.apdplat.word.WordSegmenter;
import org.apdplat.word.segmentation.Word;
import com.util.HBaseUtil;
import com.vdurmont.emoji.EmojiParser;
/**
* 词频统计
*
*/
public class WorldCountMapReduce extends Configured implements Tool {
public static class MyMapper extends TableMapper<Text, IntWritable> {
private static byte[] family = "comment_info".getBytes();
private static byte[] column = "content".getBytes();
@Override
protected void map(ImmutableBytesWritable rowKey, Result result, Context context)
throws IOException, InterruptedException {
/********** Begin *********/
byte[] value = result.getValue(family, column);
String word = new String(value,"utf-8");
if(!word.isEmpty())
{
String filter = EmojiParser.removeAllEmojis(word);
List<Word> segs = WordSegmenter.seg(filter);
for(Word cont : segs)
{
Text text = new Text(cont.getText());
IntWritable v = new IntWritable(1);
context.write(text,v);
}
}
/********** End *********/
}
}
public static class MyReducer extends TableReducer<Text, IntWritable, ImmutableBytesWritable> {
private static byte[] family = "word_info".getBytes();
private static byte[] column = "count".getBytes();
@Override
public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
/********** Begin *********/
int sum = 0;
for (IntWritable value : values)
sum += value.get();
Put put = new Put(Bytes.toBytes(key.toString()));
put.addColumn(family,column,Bytes.toBytes(sum));
context.write(null,put);
/********** End *********/
}
}
public int run(String[] args) throws Exception {
//配置Job
Configuration conf = HBaseConfiguration.create(getConf());
conf.set("hbase.zookeeper.quorum", "127.0.0.1"); //hbase 服务地址
conf.set("hbase.zookeeper.property.clientPort", "2181"); //端口号
Scanner sc = new Scanner(System.in);
String arg1 = sc.next();
String arg2 = sc.next();
try {
HBaseUtil.createTable("comment_word_count", new String[] {"word_info"});
} catch (Exception e) {
// 创建表失败
e.printStackTrace();
}
Job job = configureJob(conf,new String[]{arg1,arg2});
return job.waitForCompletion(true) ? 0 : 1;
}
private Job configureJob(Configuration conf, String[] args) throws IOException {
String tablename = args[0];
String targetTable = args[1];
Job job = new Job(conf,tablename);
Scan scan = new Scan();
scan.setCaching(300);
scan.setCacheBlocks(false);//在mapreduce程序中千万不要设置允许缓存
//初始化Mapper Reduce程序
TableMapReduceUtil.initTableMapperJob(tablename,scan,MyMapper.class, Text.class, IntWritable.class,job);
TableMapReduceUtil.initTableReducerJob(targetTable,MyReducer.class,job);
job.setNumReduceTasks(1);
return job;
}
}
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
有时我需要处理键/值数据。我不喜欢使用数组,因为它们在大小上没有限制(很容易不小心添加超过2个项目,而且您最终需要稍后验证大小)。此外,0和1的索引变成了魔数(MagicNumber),并且在传达含义方面做得很差(“当我说0时,我的意思是head...”)。散列也不合适,因为可能会不小心添加额外的条目。我写了下面的类来解决这个问题:classPairattr_accessor:head,:taildefinitialize(h,t)@head,@tail=h,tendend它工作得很好并且解决了问题,但我很想知道:Ruby标准库是否已经带有这样一个类? 最佳
在Ruby中可以使用哪些替代方法来ping一个ip地址?标准库“ping”库的功能似乎非常有限。我对在这里滚动我自己的代码不感兴趣。有没有好的gem?我应该接受它并忍受它吗?(我在Linux上使用Ruby1.8.6编写代码) 最佳答案 net-ping值得一看。它允许TCPping(如标准rubyping),但也允许UDP、HTTP和ICMPping。ICMPping需要root权限,但其他则不需要。 关于ruby-Pingruby网站?,我们在StackOverflow上找到一个类
我正在尝试使用Curbgem执行以下POST以解析云curl-XPOST\-H"X-Parse-Application-Id:PARSE_APP_ID"\-H"X-Parse-REST-API-Key:PARSE_API_KEY"\-H"Content-Type:image/jpeg"\--data-binary'@myPicture.jpg'\https://api.parse.com/1/files/pic.jpg用这个:curl=Curl::Easy.new("https://api.parse.com/1/files/lion.jpg")curl.multipart_form_
无论您是想搭建桌面端、WEB端或者移动端APP应用,HOOPSPlatform组件都可以为您提供弹性的3D集成架构,同时,由工业领域3D技术专家组成的HOOPS技术团队也能为您提供技术支持服务。如果您的客户期望有一种在多个平台(桌面/WEB/APP,而且某些客户端是“瘦”客户端)快速、方便地将数据接入到3D应用系统的解决方案,并且当访问数据时,在各个平台上的性能和用户体验保持一致,HOOPSPlatform将帮助您完成。利用HOOPSPlatform,您可以开发在任何环境下的3D基础应用架构。HOOPSPlatform可以帮您打造3D创新型产品,HOOPSSDK包含的技术有:快速且准确的CAD
本教程将在Unity3D中混合Optitrack与数据手套的数据流,在人体运动的基础上,添加双手手指部分的运动。双手手背的角度仍由Optitrack提供,数据手套提供双手手指的角度。 01 客户端软件分别安装MotiveBody与MotionVenus并校准人体与数据手套。MotiveBodyMotionVenus数据手套使用、校准流程参照:https://gitee.com/foheart_1/foheart-h1-data-summary.git02 数据转发打开MotiveBody软件的Streaming,开始向Unity3D广播数据;MotionVenus中设置->选项选择Unit
文章目录一、概述简介原理模块二、配置Mysql使用版本环境要求1.操作系统2.mysql要求三、配置canal-server离线下载在线下载上传解压修改配置单机配置集群配置分库分表配置1.修改全局配置2.实例配置垂直分库水平分库3.修改group-instance.xml4.启动监听四、配置canal-adapter1修改启动配置2配置映射文件3启动ES数据同步查询所有订阅同步数据同步开关启动4.验证五、配置canal-admin一、概述简介canal是Alibaba旗下的一款开源项目,Java开发。基于数据库增量日志解析,提供增量数据订阅&消费。Git地址:https://github.co
我正在尝试在Rails上安装ruby,到目前为止一切都已安装,但是当我尝试使用rakedb:create创建数据库时,我收到一个奇怪的错误:dyld:lazysymbolbindingfailed:Symbolnotfound:_mysql_get_client_infoReferencedfrom:/Library/Ruby/Gems/1.8/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundleExpectedin:flatnamespacedyld:Symbolnotfound:_mysql_get_client_infoReferencedf
文章目录1.开发板选择*用到的资源2.串口通信(个人理解)3.代码分析(注释比较详细)1.主函数2.串口1配置3.串口2配置以及中断函数4.注意问题5.源码链接1.开发板选择我用的是STM32F103RCT6的板子,不过代码大概在F103系列的板子上都可以运行,我试过在野火103的霸道板上也可以,主要看一下串口对应的引脚一不一样就行了,不一样的就更改一下。*用到的资源keil5软件这里用到了两个串口资源,采集数据一个,串口通信一个,板子对应引脚如下:串口1,TX:PA9,RX:PA10串口2,TX:PA2,RX:PA32.串口通信(个人理解)我就从串口采集传感器数据这个过程说一下我自己的理解,
SPI接收数据左移一位问题目录SPI接收数据左移一位问题一、问题描述二、问题分析三、探究原理四、经验总结最近在工作在学习调试SPI的过程中遇到一个问题——接收数据整体向左移了一位(1bit)。SPI数据收发是数据交换,因此接收数据时从第二个字节开始才是有效数据,也就是数据整体向右移一个字节(1byte)。请教前辈之后也没有得到解决,通过在网上查阅前人经验终于解决问题,所以写一个避坑经验总结。实际背景:MCU与一款芯片使用spi通信,MCU作为主机,芯片作为从机。这款芯片采用的是它规定的六线SPI,多了两根线:RDY和INT,这样从机就可以主动请求主机给主机发送数据了。一、问题描述根据从机芯片手