多表关联处理获取结果,大致意思把数据切割成左右表
package org.apache.hadoop.examples; import java.io.IOException; import java.util.Iterator; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.Mapper; import org.apache.hadoop.mapreduce.Reducer; import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; import org.apache.hadoop.util.GenericOptionsParser; public class STjoin { public static int time = 0; public static class Map extends Mapper<Object, Text, Text, Text> { public void map(Object key, Text value, Context context) throws IOException, InterruptedException { String childname = new String(); String parentname = new String(); String type = new String(); String line = value.toString(); int i = 0; while (line.charAt(i) != ' ') { i++; } String[] values = { line.substring(0, i), line.substring(i + 1) }; if (values[0].compareTo("child") != 0) { childname = values[0]; parentname = values[1]; type = "1"; context.write(new Text(values[1]), new Text(type + "+" + childname + "+" + parentname)); type = "2"; context.write(new Text(values[0]), new Text(type + "+" + childname + "+" + parentname)); } } } public static class IntSumReducer extends Reducer<Text, Text, Text, Text> { public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException { if (time == 0) { context.write(new Text("grandchild"), new Text("grandparent")); time++; } int grandchildnum = 0; String grandchild[] = new String[10]; int grandparentnum = 0; String grandparent[] = new String[10]; Iterator ite = values.iterator(); while (ite.hasNext()) { String record = ite.next().toString(); int len = record.length(); int i = 2; if (len == 0) continue; char type = record.charAt(0); String childname = new String(); String parentname = new String(); System.out.println("------------------" + record); while (record.charAt(i) != '+') { childname = childname + record.charAt(i); i++; // System.out.println("childname" + childname); } i = i + 1; while (i < len) { parentname = parentname + record.charAt(i); i++; // System.out.println("parentname" + parentname); } if (type == '1') { grandchild[grandchildnum] = childname; grandchildnum++; } else { grandparent[grandparentnum] = parentname; grandparentnum++; } } if (grandparentnum != 0 && grandchildnum != 0) { for (int i = 0; i < grandchildnum; i++) { for (int j = 0; j < grandparentnum; j++) { context.write(new Text(grandchild[i]), new Text( grandparent[j])); } } } } } public static void main(String[] args) throws Exception { Configuration conf = new Configuration(); String[] otherArgs = new GenericOptionsParser(conf, args) .getRemainingArgs(); if (otherArgs.length != 2) { System.err.println("Usage: wordcount <in> <out>"); System.exit(2); } Job job = new Job(conf, "stsort"); job.setJarByClass(STjoin.class); job.setMapperClass(Map.class); job.setReducerClass(IntSumReducer.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(Text.class); FileInputFormat.addInputPath(job, new Path(otherArgs[0])); FileOutputFormat.setOutputPath(job, new Path(otherArgs[1])); System.exit(job.waitForCompletion(true) ? 0 : 1); } }
相关推荐
《Hadoop MapReduce实战手册》是一本专注于大数据处理技术的专著,主要针对Apache Hadoop中的MapReduce框架进行了深入的探讨。MapReduce是Hadoop生态系统中的核心组件之一,用于处理和生成大规模数据集。该书旨在...
本部分主要介绍Hadoop在实战应用开发中的相关知识点。 首先,Hadoop系统的基础组件HDFS是一种分布式文件系统,支持高吞吐量的数据访问,特别适合大规模数据集的存储。HDFS具有高容错性的特点,能够检测并快速恢复...
《Hadoop Spark大数据巨量分析与机器学习整合开发实战》一书由林大贵编著,主要讲解了如何将大数据分析技术和机器学习技术结合起来进行实战开发。本书的重点是Hadoop和Spark这两个在大数据处理领域占据重要地位的...
综上,基于Hadoop的商品推荐系统课程设计涵盖了大数据处理、推荐系统理论、Hadoop实战等多个重要知识点。通过这个项目,学习者不仅能掌握Hadoop的基本操作,还能了解到推荐系统的设计与优化,从而具备解决实际问题的...
### Hadoop深度实战知识点 #### 一、Linux虚拟环境搭建 **1. 安装VmWare** - **目的**:创建一个稳定可靠的虚拟环境来模拟真实服务器环境,用于Hadoop的部署与测试。 - **步骤**: - 下载VmWare安装包。 - 按照...
每行文本被分割成单词,并与一个计数值1关联。这个过程产生了许多键值对,键是单词,值是1。例如,输入文本"Hello World Hello"会被处理成以下键值对:("Hello", 1), ("World", 1), ("Hello", 1)。 接下来,Reducer...
4. **算法应用**:结合实际案例,展示如何在Hadoop和Spark上实现各种数据挖掘算法,如聚类、分类、关联规则等。 5. **实战项目**:提供实际的大数据项目实践,帮助读者将理论知识应用于解决实际问题。 6. **性能...
HDFS是Hadoop的基础,它是一个分布式文件系统,能将大型数据集分布在多台廉价硬件上,提供高容错性和高吞吐量的数据访问。MapReduce则是处理这些数据的计算模型,通过将大任务拆解为无数小的“映射”和“归约”任务...
标题中的“hadoop,spark,linux,机器学习,数据挖掘等大数据全套视频.rar”表明这是一个包含多方面大数据技术的综合教程资源,涵盖了Hadoop、Spark、Linux、机器学习以及数据挖掘等多个关键领域。这些主题都是现代信息...
Hadoop生态还包括多个关联项目,如Hive用于SQL-like查询,Pig提供高级数据分析语言,HBase是基于HDFS的NoSQL数据库,Zookeeper用于集群协调,YARN作为资源管理系统,等等。 6. **Hadoop安装与配置**: 学习Hadoop...
第五章可能涵盖Hadoop的实战应用和案例,例如在互联网日志分析、推荐系统、社交网络分析等场景下,Hadoop如何发挥其威力。 通过深入学习Hadoop集群,不仅可以理解大数据处理的基本原理,还能掌握实际操作技巧,为在...
描述中提到的“基于Python和Hadoop集群的项目实战报告”揭示了分析过程的核心技术。Python是一种强大的编程语言,尤其在数据分析和科学计算领域,拥有丰富的库如Pandas、Numpy和Matplotlib等,适合进行数据处理和...
在Hive中,我们同样会创建一个`user`表,利用HQL(Hive Query Language)进行数据清洗、聚合和关联操作,比如找出活跃用户的特征,或者分析用户行为模式。 Hadoop是大数据处理的基础框架,它提供了分布式存储(HDFS...
整套大数据课程从hadoop入门开始,由浅入深,内置“hadoop源码解析与企业应用开发实战”,“Hive开发实战”,“Hbase开发实战”,“Spark,mahout,sqoop,storm诸模块开发实战”,“数据挖掘基础。这个系列课程有几...
通过这个课程,学员不仅能够深入理解Hadoop平台的核心组件,还能掌握Pig这一强大的数据分析工具,从而在大数据处理领域具备实战能力。这对于从事云计算和大数据分析工作的专业人士来说,是非常宝贵的知识和技能。
《Hadoop项目实战:新闻离线项目分析》是一门针对大数据处理与分析的实践课程,主要聚焦于如何利用Hadoop框架解决实际中的新闻数据分析问题。课程不仅深入剖析了Hadoop的相关理论,还通过具体的新闻数据集,让学习者...
在实际应用中,经常需要对多个表进行关联查询,以获取更丰富的信息。本案例将演示如何进行不同的表关联查询。 **内连接(`INNER JOIN`)** ``` SELECT stu.name, stu.id, course.courseName FROM stu JOIN ...
同时,社区不断优化其性能和功能,如支持更丰富的查询语言,提升多表关联操作的效率。 总之,《大数据云计算技术系列:Hadoop之HBase从入门到精通》涵盖了从基础理论到实践应用的全面内容,是学习和掌握HBase的宝贵...
【标题】:“Hadoop MapReduce实现基于ItemCF的协同过滤物品推荐系统” 在这个项目中,我们探讨了如何利用Hadoop MapReduce框架来...同时,对于学习和研究Hadoop以及协同过滤技术的人员来说,也是一个宝贵的实战案例。
《大数据分析与挖掘实战》这本书深入探讨了大数据技术在实际业务场景中的应用,特别是通过Hadoop平台进行数据处理和分析的实战经验。大数据是当前信息技术领域的重要趋势,它涉及海量、高速、多样的数据集,这些数据...