• 大小: 23KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-16
  • 语言: 其他
  • 标签: MapReduce  

资源简介

完整的基于MapReduce的商品推荐算法,包括对信息采集,得到用户购买向量和商品推荐矩阵并相乘,去重后将数据提交给数据库等。本代码在Yarn集群下可以完美执行 。

资源截图

代码片段和文件信息

package com.briup.bigdata.project.grms.main;

import com.briup.bigdata.project.grms.step1.UserBuyGoodsList;
import com.briup.bigdata.project.grms.step2.GoodsCooccurrenceList;
import com.briup.bigdata.project.grms.step3.GoodsCooccurrenceMatrix;
import com.briup.bigdata.project.grms.step4.UserBuyGoodsVector;
import com.briup.bigdata.project.grms.step5.MultiplyGoodsMatrixAndUserVector;
import com.briup.bigdata.project.grms.step6.MakeSumForMultiplication;
import com.briup.bigdata.project.grms.step7.DuplicateDataForResult;
import com.briup.bigdata.project.grms.step8.RecommendResultDB;
import com.briup.bigdata.project.grms.step8.SaveRecommendResultToDB;
import java.util.Properties;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.db.DBConfiguration;
import org.apache.hadoop.mapreduce.lib.db.DBOutputFormat;
import org.apache.hadoop.mapreduce.lib.input.MultipleInputs;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.jobcontrol.ControlledJob;
import org.apache.hadoop.mapreduce.lib.jobcontrol.JobControl;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
import org.apache.hadoop.util.Tool;

public class JobController extends Configured implements Tool{
@Override
public final int run(String[] args) throws Exception{
Configuration conf=getConf();
Path inStep1=new Path(conf.get(“inStep1“));
Path outStep1=new Path(conf.get(“outStep1“));
Path outStep2=new Path(conf.get(“outStep2“));
Path outStep3=new Path(conf.get(“outStep3“));
Path outStep4=new Path(conf.get(“outStep4“));
Path outStep5=new Path(conf.get(“outStep5“));
Path outStep6=new Path(conf.get(“outStep6“));
Path outStep7=new Path(conf.get(“outStep7“));

//----第1步作业配置--------------------
Job job1=Job.getInstance(confUserBuyGoodsList.class.getSimpleName());
job1.setJarByClass(this.getClass());

job1.setMapperClass(UserBuyGoodsList.UserBuyGoodsListMapper.class);
job1.setMapOutputKeyClass(Text.class);
job1.setMapOutputValueClass(Text.class);
job1.setInputFormatClass(TextInputFormat.class);
// 数据来源:原始数据
TextInputFormat.addInputPath(job1inStep1);

job1.setReducerClass(UserBuyGoodsList.UserBuyGoodsListReducer.class);
job1.setOutputKeyClass(Text.class);
job1.setOutputValueClass(Text.class);
job1.setOutputFormatClass(TextOutputFormat.class);
TextOutputFormat.setOutputPath(job1outStep1);

//----第2步作业配置--------------------
Job job2=Job.getInstance(confGoodsCooccurrenceList.class.getSimpleName());
job2.setJarByClass(this.getClass());

job2.setMapperClass(GoodsCooccurrenceList.GoodsCooccurrenceListMapper.class);
job2.setMapOutputKeyClass(Text.class);
job2.setMapOut

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-04-18 16:01  M00010_GRMS_0010\
     文件        9601  2018-04-18 14:46  M00010_GRMS_0010\M00010_GRMS_0010.iml
     文件        2699  2018-04-18 14:46  M00010_GRMS_0010\pom.xml
     目录           0  2018-04-17 15:16  M00010_GRMS_0010\src\
     目录           0  2018-04-17 15:16  M00010_GRMS_0010\src\main\
     目录           0  2018-04-17 15:17  M00010_GRMS_0010\src\main\java\
     目录           0  2018-04-17 15:17  M00010_GRMS_0010\src\main\java\com\
     目录           0  2018-04-17 15:17  M00010_GRMS_0010\src\main\java\com\briup\
     目录           0  2018-04-17 15:17  M00010_GRMS_0010\src\main\java\com\briup\bigdata\
     目录           0  2018-04-17 15:17  M00010_GRMS_0010\src\main\java\com\briup\bigdata\project\
     目录           0  2018-04-18 14:37  M00010_GRMS_0010\src\main\java\com\briup\bigdata\project\grms\
     目录           0  2018-04-18 14:54  M00010_GRMS_0010\src\main\java\com\briup\bigdata\project\grms\main\
     文件       10173  2018-04-18 14:54  M00010_GRMS_0010\src\main\java\com\briup\bigdata\project\grms\main\JobController.java
     文件         608  2018-04-18 14:54  M00010_GRMS_0010\src\main\java\com\briup\bigdata\project\grms\main\RunApp.java
     目录           0  2018-04-17 15:17  M00010_GRMS_0010\src\main\java\com\briup\bigdata\project\grms\step1\
     文件        1826  2018-04-18 14:43  M00010_GRMS_0010\src\main\java\com\briup\bigdata\project\grms\step1\UserBuyGoodsList.java
     目录           0  2018-04-17 15:17  M00010_GRMS_0010\src\main\java\com\briup\bigdata\project\grms\step2\
     文件        1788  2018-04-18 14:47  M00010_GRMS_0010\src\main\java\com\briup\bigdata\project\grms\step2\GoodsCooccurrenceList.java
     目录           0  2018-04-17 15:17  M00010_GRMS_0010\src\main\java\com\briup\bigdata\project\grms\step3\
     文件        2179  2018-04-18 14:43  M00010_GRMS_0010\src\main\java\com\briup\bigdata\project\grms\step3\GoodsCooccurrenceMatrix.java
     目录           0  2018-04-17 15:17  M00010_GRMS_0010\src\main\java\com\briup\bigdata\project\grms\step4\
     文件        1890  2018-04-18 14:47  M00010_GRMS_0010\src\main\java\com\briup\bigdata\project\grms\step4\UserBuyGoodsVector.java
     目录           0  2018-04-17 15:17  M00010_GRMS_0010\src\main\java\com\briup\bigdata\project\grms\step5\
     文件        3219  2018-04-18 14:44  M00010_GRMS_0010\src\main\java\com\briup\bigdata\project\grms\step5\MultiplyGoodsMatrixAndUserVector.java
     目录           0  2018-04-17 15:17  M00010_GRMS_0010\src\main\java\com\briup\bigdata\project\grms\step6\
     文件        1862  2018-04-18 14:45  M00010_GRMS_0010\src\main\java\com\briup\bigdata\project\grms\step6\MakeSumForMultiplication.java
     目录           0  2018-04-17 15:17  M00010_GRMS_0010\src\main\java\com\briup\bigdata\project\grms\step7\
     文件        3243  2018-04-18 14:45  M00010_GRMS_0010\src\main\java\com\briup\bigdata\project\grms\step7\DuplicateDataForResult.java
     目录           0  2018-04-17 15:17  M00010_GRMS_0010\src\main\java\com\briup\bigdata\project\grms\step8\
     文件        2441  2018-04-17 14:22  M00010_GRMS_0010\src\main\java\com\briup\bigdata\project\grms\step8\RecommendResultDB.java
     文件        2792  2018-04-18 14:45  M00010_GRMS_0010\src\main\java\com\briup\bigdata\project\grms\step8\SaveRecommendResultToDB.java
............此处省略11个文件信息

评论

共有 条评论