Mapreduce如何获取读取文件夹下文件的名字

如何在Amazon Elastic MapReduce(EMR)上运行MapReduce程序 这个问题其实是挺简单的,但是网上真的很不好找教程,尤其对于一些细节,就没人说过。估计大家可能也会一次次试验,我试了好多次终于成功,权当初学者一点帮助吧。 第一步自然是去Amazon注册账号。这里给的是EC2的地址,不过一样。 http://aws.amazon.com/ec2/    现在Amazon提供了很多不同种类的云服务,存储的有S3,就和DropBox一个原理,不过没那么方便易用,主要用 阅读详情

 需要注意的导包的时候导这两个包

                    import org.apache.hadoop.mapreduce.InputSplit;

                    import org.apache.hadoop.mapreduce.lib.input.FileSplit;
--------------------- 
作者:闻雷
来源:CSDN 
原文:https://blog.csdn.net/qq_41950069/article/details/80446912 
 

    只需要获得文件的名字:

     InputSplit inputSplit=(InputSplit)context.getInputSplit();
 
    String filename=((FileSplit)inputSplit).getPath().getName();
 

简化后:String filename=((FileSplit)context.getInputSplit()).getPath().getName();
    System.out.println(filename);

如果需要获得在hdfs上的绝对路径,可以用以下代码实现:

String filepath = ((FileSplit)context.getInputSplit()).getPath().toString();
  • 1

获取文件名的大致流程为:Context(map函数里) → InputSplit → FileSplit → Path → String(file name)。

 

 

04 分布式文件系统以及MapReduce入门程序 文章目录04 分布式文件系统以及MapReduce入门程序1.分布式文件系统hdfs详细介绍2.HDFS分布式文件系统设计目标3.HDFS的来源4.hdfs的架构图5.hdfs的架构之文件的文件副本机制以及block块存储6.HDFS的元数据信息FSimage以及edits和secondaryNN的作用6.1、FSImage与edits详解6.2、FSimage文件当中的文件信息查看6.3、edi... 阅读详情

相关推荐

MIT 6.5840 Lab1 - MapReduce

2023年的叫做6.5840,名字改了,不过区别不大,直接用这个就行,大家还是习惯称呼他6.824。我是根据课程表来的,所以上完了前四节课就开始做实验了。下面就正式开始吧。

JehanRio's Private Blog 5784

Mapreduce中获取输入文件名及路径的方法

在map函数中想要获取当前split所读取的文件名,方法如下: 1 不通用方法 1 如果读入的文件类型为 TextInputFormat,则获取文件名如下: String filePath = context.getConfiguration().get("mapreduce.map.input.file"); Path tmpFilePath = new Path(filePath)...

YF_Li123的博客 3734

第六课HDFS+MapReduce

Hadoop Distributed File System,是一个文件系统,用于存储文件,通过目录树来定位文件;其次,它是分布式的,由很多服务器联合起来实现其功能,集群中的服务器有各自的角色。HDFS的使用场景:适合一次写入,多次读出的场景,且不支持文件的修改。适合用来做数据分析,并不适合用来做网盘应用。

2403_90029703的博客 278

MapReduce> Java代码获取文件名称

获取文件名称 在Map中加入以下代码,即可获取读取的文件名称 //通过context可以获取这行文本所属的文件名称 FileSplit inputSplit = (FileSplit)context.getInputSplit(); String filename= inputSplit.getPath().getName(); 代码 MoreFileMappe...

qq_44509920的博客 292

JAVA大数据(二) Hadoop 分布式文件系统HDFS 架构,MapReduce介绍,Yarn资源调度

文章目录1.分布式文件系统HDFS1.HDFS的来源2.HDFS的架构图之基础架构2.1 master/slave 架构2.2 名字空间(NameSpace)2.3 文件操作2.4副本机制2.5心跳机制2.6 一次写入,多次读出3.NameNode与Datanode的总结概述3.1namenode 元数据管理3.2 Datanode 数据存储4.文件副本机制以及block块存储5.元文件FSImage与edits6、HDFS的文件写入过程7、HDFS的文件读取过程8.HDFS基本Shell操作9.HDFS的

m0_58818478的博客 541

18、MapReduce的计数器与通过MapReduce读取/写入数据库示例

在执行MapReduce程序的时候,控制台输出日志中通常有下面所示片段内容Hadoop内置的计数器可以收集、统计程序运行中核心信息,帮助用户理解程序的运行情况,辅助用户诊断故障下面是示例性日志,介绍了计数器。

alanchanchn的专栏 8万+

MapReduce程序获取文件名

在maper类中 Path path = ((FileSplit) context.getInputSplit()).getPath() .getParent();  String fileName = path.getParent().toString(); 引用类为  import org.apache.hadoop.fs.Path; import org.apache.

momo的专栏 1196

【胡学长 带你学 Global Mapper 】如何将影像地图转换为国家2000坐标系

多部门联合开展工作坐标数据不匹配怎么办?Hi,我是胡学长!今天教大家如何利用Global Mapper将谷歌影像数据转换为国家2000坐标系影像数据 。

一起来交流学习吧 1万+

hadoop_mapreduce_Map中获取文件名

Mapreduce的map输入的是文件的每一行值,即V1为文件的行。hadoop jar xxx.jar /input /output当input为一个文件名时,v1为文件的行;当input为一个目录时,v1为此目录下各文件的行。 因此在某些情况下在map中获取v1对应的文件名就很有必要了,获取方法://路径:/myindexdata/data01.txtString path = ((FileS...

子龙修仙的博客 1434

VS2022 LNK1168无法打开进行写入 解决办法

C语言编程---VS---错误和警告---链接器工具错误---LNK1168--无法打开进行写入

weixin_67166415的博客 7171

机器视觉学习(七)—— 卷积、边缘和滤波器

卷积运算、垂直边缘与水平边缘、滤波器

歆歆~黯了 2745

MapReduce之自定义输入

1.驱动类 Drive代码 package RecordWrite; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.NullWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.

qq_45769990的博客 335

superpowers-中文使用说明

《obra/superpowers:AI辅助开发的流程纪律工具集》 摘要:obra/superpowers是一套面向AI辅助软件开发的系统化流程规范,包含14个核心技能,强调"先理解后行动"的纪律性开发方法。该工具集定义了从头脑风暴到代码评审的完整工作流,要求严格遵循测试驱动开发、子代理隔离执行等原则。核心特色包括:1) 任何实现前必须完成设计和评审;2) 采用红-绿-重构的TDD循环;3) 复杂任务通过独立子代理串行处理;4) 所有产出需经过双重验证(规格合规+代码质量)。该工具集特别注重文档化和可验证性

qq_22786633的博客 775

HDFS、MapReduce、Yarn学习

文章目录1.HDFS入门介绍1.1 HDFS 介绍1.2 HDFS的特性1.2.1 master/slave 架构1.2.2 分块存储1.2.3 名字空间(NameSpace)1.2.4 namenode 元数据管理1.2.5 Datanode 数据存储1.2.6 副本机制1.2.7 一次写入,多次读出2.分布式文件系统HDFS1.HDFS的来源2.HDFS的架构图之基础架构2.1 master/slave 架构2.2 名字空间(NameSpace)2.3 文件操作2.4副本机制2.5心跳机制2.6 一次写

望山。 3684

自动驾驶感知融合算法拆解:从华为MDC案例看前融合与大融合的工程实现

本文深度解析了华为MDC平台在自动驾驶感知融合算法中的前沿工程实践,重点探讨了Camera-Lidar前融合与多传感器大融合的架构设计。通过异构融合架构、数据流优化和场景化应用,华为MDC平台实现了高效、安全的感知能力,显著提升了自动驾驶系统的性能与可靠性。

weixin_29198045的博客 549

金蝶Apusic应用服务器 未授权目录遍历漏洞复现

由于金蝶Apusic应用服务器/admin/protected/selector/server_file/files、/admin/protected/selector/server_file/folders 等接口没有进行校验和过滤,直接将参数拼接到文件操作中,导致出现目录遍历漏洞,未经身份验证的远程攻击者可通过此漏洞读取系统内部系统文件路径及信息,导致信息泄露,系统处于极不安全状态。

0xSec 2185

02.分布式文件系统HDFS、MapReduce、Yarn介绍

文章目录1.分布式文件系统HDFS1.HDFS的来源2.HDFS的架构图之基础架构2.1 master/slave 架构2.2 名字空间(NameSpace)2.3 文件操作2.4副本机制2.5心跳机制2.6 一次写入,多次读出3.NameNode与Datanode的总结概述3.1namenode 元数据管理3.2 Datanode 数据存储4.文件副本机制以及block块存储5.元文件FSImage与edits6、HDFS的文件写入过程7、HDFS的文件读取过程8.HDFS基本Shell操作9.HDFS的

qq_43102730的博客 1737

5.4 GTT BO的内存分配分析

本文分析了AMD GPU驱动中的GTT技术实现。GTT作为GPU页表,负责管理主机内存与GPU虚拟地址的映射,支持大容量内存访问和统一寻址。文章详细介绍了GTT的核心数据结构amdgpu_gtt_mgr、初始化流程,以及BO(Buffer Object)创建时GTT区间的分配与释放机制。GTT管理通过TTM框架实现分层设计,提供内存统计、兼容性检查等接口,并支持动态迁移、多进程隔离等高级特性。该机制为AMD GPU提供了高效灵活的内存管理基础。

图形/计算GPU的驱动与虚拟化技术分享园地 3773

wordcount程序中,输出文件夹中为空

ShuffleError: error in shuffle in localfetcher#1问题解决办法 问题 WIndows10 下使用IDEA本地调试wordcount出现如下错误 2021-03-05 11:11:41,311 WARN [org.apache.hadoop.mapred.LocalJobRunner] - job_local1291814541_0001 java.lang.Exception: org.apache.hadoop.mapreduce.task.reduce.Sh

小李的博客 1836

Unity 面试篇|(六)数据结构和算法篇 【全面总结 | 持续更新】

先拿10000个数建堆,然后一次添加剩余元素,如果大于堆顶的数(10000中最小的),将这个数替换堆顶,并调整结构使之仍然是一个最小堆,这样遍历完后,堆中的10000个数就是所需的最大的10000个。桶排序是计数排序的升级版。它的工作原理:首先在未排序序列中找到最小(大)元素,存放到排序序列的起始位置,然后,再从剩余未排序元素中继续寻找最小(大)元素,然后放到已排序序列的末尾。这样处理就可以分别在每个文件的10^6个数据中找出最大的10000个数,合并到一起在再找出1000*10000中的最终的结果。

游戏开发小Y的博客 12万+

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

7 ,hbaseAPI 操作 : 连接 mapreduce

一 ,连接 mapreduce : 1 ,介绍 : 简介 : hbase 可以和 mr 勾搭上。 详细 : 通过 HBase 的相关 JavaAPI,我们可以实现伴随 HBase 操作的 MapReduce 过程,比如使用MapReduce 将数据从本地文件系统导入到 HBase 的表中,比如我们从 HBase 中读取一些原始数据后使用 MapReduce 做数据分析。 2 , ...

孙砚秋的博客 675

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

MapReduce 和 Hadoop 的工作原理

Hadoop 是一个开源框架,主要用于可靠、高效地处理大规模数据集。它由多个组件构成,其中最核心的是和。

Davina_yu的博客 1061

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Eclipse-MapReduce

三个类 map package com.lizijun.test; import java.io.IOException; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.Text; import org.apache.h...

CSDN_bird的博客 750

MapReduce编程:单词计数--《大数据基础教程》

MapReduce编程:单词计数 1、实验描述 使用mapreduce编程,完成单词计数 实验时长:90分钟 主要步骤: 启动Hadoop集群 编写代码 打包程序,并提交至HDFS运行 查看实验结果文件 2、实验环境 虚拟机数量:3 系统版本:Centos 7.5 Hadoop版本:Apache Hadoop 2.7.3 Eclipse版本:Neon.3 4.6.3 3、相关技能 JavaSE基础 MapReduce编程 4、相关知识点 配置开发环境 编写Mapper类 编写Reduce

一顿吃不饱的博客 6521
下一篇: 什么是hive?
风一样不问归期
博客等级 码龄9年 2粉丝 14原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值