hadoop+海量数据面试题汇总(一)

hadoop面试题

Q1. Name the most common InputFormats defined in Hadoop? Which one is default ? 

Following 2 are most common InputFormats defined in Hadoop 

- TextInputFormat

- KeyValueInputFormat

- SequenceFileInputFormat

Q2. What is the difference between TextInputFormatand KeyValueInputFormat class 

TextInputFormat: It reads lines of text files and provides the offset of the line as key to the Mapper and actual line as Value to the mapper

KeyValueInputFormat: Reads text file and parses lines into key, val pairs. Everything up to the first tab character is sent as key to the Mapper and the remainder of the line is sent as value to the mapper.

 

Q3. What is InputSplit in Hadoop

When a hadoop job is run, it splits input files into chunks and assign each split to a mapper to process. This is called Input Split 

 

Q4. How is the splitting of file invoked in Hadoop Framework  

It is invoked by the Hadoop framework by running getInputSplit()method of the Input format class (like FileInputFormat) defined by the user 

 

Q5. Consider case scenario: In M/R system,

    - HDFS block size is 64 MB

    - Input format is FileInputFormat

    - We have 3 files of size 64K, 65Mb and 127Mb 

then how many input splits will be made by Hadoop framework?

Hadoop will make 5 splits as follows 

- 1 split for 64K files 

- 2  splits for 65Mb files 

- 2 splits for 127Mb file 

 

Q6. What is the purpose of RecordReader in Hadoop

The InputSplithas defined a slice of work, but does not describe how to access it. The RecordReaderclass actually loads the data from its source and converts it into (key, value) pairs suitable for reading by the Mapper. The RecordReader instance is defined by the InputFormat 

 

Q7. After the Map phase finishes, the hadoop framework does "Partitioning, Shuffle and sort". Explain what happens in this phase?

- Partitioning

Partitioning is the process of determining which reducer instance will receive which intermediate keys and values. Each mapper must determine for all of its output (key, value) pairs which reducer will receive them. It is necessary that for any key, regardless of which mapper instance generated it, the destination partition is the same

 

- Shuffle

After the first map tasks have completed, the nodes may still be performing several more map tasks each. But they also begin exchanging the intermediate outputs from the map tasks to where they are required by the reducers. This process of moving map outputs to the reducers is known as shuffling.

 

- Sort

Each reduce task is responsible for reducing the values associated with several intermediate keys. The set of intermediate keys on a single node is automatically sorted by Hadoop before they are presented to the Reducer 

 

Q9. If no custom partitioner is defined in the hadoop then how is data partitioned before its sent to the reducer  

The default partitioner computes a hash value for the key and assigns the partition based on this result 

 

Q10. What is a Combiner 

The Combiner is a "mini-reduce" process which operates only on data generated by a mapper. The Combiner will receive as input all data emitted by the Mapper instances on a given node. The output from the Combiner is then sent to the Reducers, instead of the output from the Mappers.

Q11. Give an example scenario where a cobiner can be used and where it cannot be used

There can be several examples following are the most common ones

- Scenario where you can use combiner

  Getting list of distinct words in a file

 

- Scenario where you cannot use a combiner

  Calculating mean of a list of numbers 

Q12. What is job tracker

Job Tracker is the service within Hadoop that runs Map Reduce jobs on the cluster

 

Q13. What are some typical functions of Job Tracker

The following are some typical tasks of Job Tracker

- Accepts jobs from clients

- It talks to the NameNode to determine the location of the data

- It locates TaskTracker nodes with available slots at or near the data

- It submits the work to the chosen Task Tracker nodes and monitors progress of each task by receiving heartbeat signals from Task tracker 

 

Q14. What is task tracker

Task Tracker is a node in the cluster that accepts tasks like Map, Reduce and Shuffle operations - from a JobTracker 

 

Q15. Whats the relationship between Jobs and Tasks in Hadoop

One job is broken down into one or many tasks in Hadoop. 

 

Q16. Suppose Hadoop spawned 100 tasks for a job and one of the task failed. What willhadoop do ?

It will restart the task again on some other task tracker and only if the task fails more than 4 (default setting and can be changed) times will it kill the job

 

Q17. Hadoop achieves parallelism by dividing the tasks across many nodes, it is possible for a few slow nodes to rate-limit the rest of the program and slow down the program. What mechanism Hadoop provides to combat this  

Speculative Execution 

 

Q18. How does speculative execution works in Hadoop  

Job tracker makes different task trackers process same input. When tasks complete, they announce this fact to the Job Tracker. Whichever copy of a task finishes first becomes the definitive copy. If other copies were executing speculatively, Hadoop tells the Task Trackers to abandon the tasks and discard their outputs. The Reducers then receive their inputs from whichever Mapper completed successfully, first. 

 

Q19. Using command line in Linux, how will you 

- see all jobs running in the hadoop cluster

- kill a job

- hadoop job -list

- hadoop job -kill jobid 

 

Q20. What is Hadoop Streaming  

Streaming is a generic API that allows programs written in virtually any language to be used asHadoop Mapper and Reducer implementations 

 

 

Q21. What is the characteristic of streaming API that makes it flexible run map reduce jobs in languages like perl, ruby, awk etc.  

Hadoop Streaming allows to use arbitrary programs for the Mapper and Reducer phases of a Map Reduce job by having both Mappers and Reducers receive their input on stdin and emit output (key, value) pairs on stdout.

Q22. Whats is Distributed Cache in Hadoop

Distributed Cache is a facility provided by the Map/Reduce framework to cache files (text, archives, jars and so on) needed by applications during execution of the job. The framework will copy the necessary files to the slave node before any tasks for the job are executed on that node.

Q23. What is the benifit of Distributed cache, why can we just have the file in HDFS and have the application read it  

This is because distributed cache is much faster. It copies the file to all trackers at the start of the job. Now if the task tracker runs 10 or 100 mappers or reducer, it will use the same copy of distributed cache. On the other hand, if you put code in file to read it from HDFS in the MR job then every mapper will try to access it from HDFS hence if a task tracker run 100 map jobs then it will try to read this file 100 times from HDFS. Also HDFS is not very efficient when used like this.

 

Q.24 What mechanism does Hadoop framework provides to synchronize changes made in Distribution Cache during runtime of the application  

This is a trick questions. There is no such mechanism. Distributed Cache by design is read only during the time of Job execution

 

Q25. Have you ever used Counters in Hadoop. Give us an example scenario 

Anybody who claims to have worked on a Hadoop project is expected to use counters

 

Q26. Is it possible to provide multiple input to Hadoop? If yes then how can you give multiple directories as input to the Hadoop job  

Yes, The input format class provides methods to add multiple directories as input to a Hadoop job

 

Q27. Is it possible to have Hadoop job output in multiple directories. If yes then how  

Yes, by using Multiple Outputs class

 

Q28. What will a hadoop job do if you try to run it with an output directory that is already present? Will it

- overwrite it

- warn you and continue

- throw an exception and exit

The hadoop job will throw an exception and exit.

 

Q29. How can you set an arbitary number of mappers to be created for a job in Hadoop  

This is a trick question. You cannot set it

 

Q30. How can you set an arbitary number of reducers to be created for a job in Hadoop  

You can either do it progamatically by using method setNumReduceTasksin the JobConfclass or set it up as a configuration setting

 

32、设计一套系统,使之能够从不断增加的不同的数据源中,提取指定格式的数据。
要求:1、运行结果要能大致得知提取效果,并可据此持续改进提取方法;
            2、由于数据来源的差异性,请给出可弹性配置的程序框架;
            3、数据来源可能有Mysql,sqlserver等;
            4、该系统具备持续挖掘的能力,即,可重复提取更多信息;

33. 经典的一道题:

现有1亿个整数均匀分布,如果要得到前1K个最大的数,求最优的算法。­
(先不考虑内存的限制,也不考虑读写外存,时间复杂度最少的算法即为最优算法)­

              我先说下我的想法:分块,比如分1W块,每块1W个,然后分别找出每块最大值,从这最大的1W个值中找最大                  1K个,那么其他的9K个最大值所在的块即可扔掉,从剩下的最大的1K个值所在的块中找前1K个即可。那么                       原问题的规模就缩小到了1/10。­

              问题:­
               1.这种分块方法的最优时间复杂度。­
               2.如何分块达到最优。比如也可分10W块,每块1000个数。则问题规模可降到原来1/100。但事实上复杂度并没                降低。­
               3.还有没更好更优的方法解决这个问题。­

34. MapReduce大致流程?

35. combiner, partition作用?

36.用mapreduce实现sql语句 select count(x) from a group by b?

36. 用mapreduce如何实现两张表连接,有哪些方法?

1、MapReduce中排序发生在哪几个阶段??这些排序是否可以避免,为什么??

答:一个MapReduce作业由Map阶段和Reduce阶段两部分组成,这两阶段会对数据排序,从这个意义上说,MapReduce框架本质就 是一个Distributed Sort。在Map阶段,在Map阶段,Map Task会在本地磁盘输出一个按照key排序(采用的是快速排序)的文件(中间可能产生多个文件,但最终会合并成一个),在Reduce阶段,每个 Reduce Task会对收到的数据排序,这样,数据便按照Key分成了若干组,之后以组为单位交给reduce()处理。很多人的误解在Map阶段,如果不使用 Combiner便不会排序,这是错误的,不管你用不用Combiner,Map Task均会对产生的数据排序(如果没有Reduce Task,则不会排序, 实际上Map阶段的排序就是为了减轻Reduce端排序负载)。由于这些排序是MapReduce自动完成的,用户无法控制,因此,在hadoop 1.x中无法避免,也不可以关闭,但hadoop2.x是可以关闭的。

2、编写MapReduce作业时,如何做到在Reduce阶段,先对Key排序,再对Value排序??

答:该问题通常称为”二次排序“,最常用的方法是将Value放到Key中,实现一个组合Key,然后自定义Key排序规则(为Key实现一个WritableComparable)

3、如何使用MapReduce实现两个表join,可以考虑一下几种情况:(1)一个表大,一个表小(可放到内存中);(2)两个表都是大表

答:第一种情况比较简单,只需将小表放到DistributedCache中即可;第二种情况常用的方法有:map-side join(要求输入数据有序,通常用户Hbase中的数据表连接),reduce-side join,semi join(半连接),具体资料可网上查询

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

hadoop面试题

面试hadoop可能被问到的问题,你能回答出几个 ?

 

1、hadoop运行的原理?

 

2、mapreduce的原理?

 

3、HDFS存储的机制?

 

4、举一个简单的例子说明mapreduce是怎么来运行的 ?

 

5、面试的人给你出一些问题,让你用mapreduce来实现?

 

      比如:现在有10个文件夹,每个文件夹都有1000000个url.现在让你找出top1000000url。

 

6、hadoop中Combiner的作用?

 

 

 

 

一、作用

1、combiner最基本是实现本地key的聚合,对map输出的key进行排序,value进行迭代。如下所示:

map: (K1, V1) → list(K2, V2) 

combine: (K2, list(V2)) → list(K2, V2) 

reduce: (K2, list(V2)) → list(K3, V3)

 

2、combiner还具有类似本地的reduce功能.

例如hadoop自带的wordcount的例子和找出value的最大值的程序,combiner和reduce完全一致。如下所示:

map: (K1, V1) → list(K2, V2) 

combine: (K2, list(V2)) → list(K3, V3) ,减轻reduce的负担!reduce: (K3, list(V3)) → list(K4, V4) 

 

3、如果不用combiner,那么,所有的结果都是reduce完成,效率会相对低下。使用combiner,先完成的map会在本地聚合,提升速度。

 

举一个hadoop自带的wordcount例子说明。

value就是一个叠加的数字,所以map一结束就可以进行reduce的value叠加,而不必要等到所有的map结束再去进行reduce的value叠加。

 

二、总结

1、combiner使用的合适,可以在满足业务的情况下提升job的速度,如果不合适,则将导致输出的结果不正确,上面7楼说的很对,不是所有的场合都适合combiner。根据自己的业务来使用。、

 

 

 

 

、hadoop就是map 和 reduce的过程。服务器上一个目录节点+多个数据节点。将程序传送到各个节点,在数据节点上进行计算

2、将数据存储到不同节点,用map方式对应管理,在各个节点进行计算,采用reduce进行合并结果集

3、就是通过java程序和目录节点配合,将数据存放到不同数据节点上

4、看上边的2.注意,分布式注重的是计算,不是每个场景都适合

5、将文件存放到不同的数据节点,然后每个节点计算出前十个进行reduce的计算

 

 

 

补充:

loudcomputing 理论测试题目答案

1.     请问在 Hadoop 体系结构中,按照由下到上顺序,排列正确的是() 

B.    Common MapReduce Pig 

2.     关于 Datanode 的描述错误的是() 

D.    文件的副本系数由 Datanode 储存

5.     配置 hbase 过程中,下面那个文件没有改动。 

A.    hbase-default.xml 

7.     客户端发现域服务器崩溃之后与__交互来处理问题. 

B.    hbasemaster 

9.     hbase 中存储的数据类型是__。 

B.    byte 

11.     Hive 提供了基于 SQL 并使得熟悉 SQL 的用户能够查询数据的__。 

A.    QL 

12.     下面哪一个对于 Hive 查询语言的命令的描述是错误的__。

C.    SHOW PARTITIONS page_view:列出表格 page_view 的所有的分隔。如果该表格没有

被分隔,那么什么也不做。

13.     注意到 Hive 只支持等值连接。最好把最大的表格放在连接的__端以得到最好的表

现。

C.    最右

版权所有人:王方舟    盗版必究

14.     Ubuntu 安装后默认 root 密码是多少? 

D.    默认 root 密码每次开机是随机的

15.     在 Ubuntu 上安装 Cassandra 的命令是什么? 

C.    sudo apt-get install Cassandra 

18.     下列哪项在 Cassandra 中充当排序因子的角色? 

C.    row

19.     下面是一些命令,这些命令都是使用这些配置启动服务器/客户端的,其中哪项是

错误的?

B.    glusterfs -start /../client.vol(启动客户端) 

20.     从这些配置文件,你可以看出,这个结构具有什么的功能? 

C.    镜像特征的卷,服务器 1 和服务器 2 互作备份 

1.     ___执行文件系统命名空间操作()

B.    Namenode

2.     关于 Datanode 的描述错误的是()

D.    文件的副本系数由 Datanode 储存

4.     Hadoop 的优势不包括()

D.    实时的

5.     下列哪项不是 HDFS 的设计目标() 

版权所有人:王方舟    盗版必究

D.    “多次写入多次读取”的文件访问模型

6.     下列哪项不是 HDFS 命令()

D.    ls

7.     hbase 体系架构中,由__完成域分配任务。

B.    hbasemaster

9.     hbase 中锁定__之后才能进行写操作。

B.    行

11.     Hive 是建立在__之上的一个数据仓库。

D.    Hadoop

12.     Hive 提供了基于 SQL 并使得熟悉 SQL 的用户能够查询数据的__。

A.    QL

13.     为了启动 hive,我们必须在路径里安装有 hadoop 或者__。

A.    export HADOOP_HOME=hadoop-install-dir

15.     在 Ubuntu 上安装 Cassandra 的命令是什么?

C.    sudo apt-get install Cassandra

16.     Cassandra 的安装包中哪个文件夹是放置启动和测试脚本文件的?

C.    bin

18.     关于这个平台你还需要知道一些其他的事情,比如以下这些,下列哪项是错的 

版权所有人:王方舟    盗版必究

B.    当一个存储节点发生故障时,我可以直接把他从服务器列表中移除

19.     作为数据管理者,你也许非常需要了解数据的存储形式,服务器的工作状态等等内

容。Gluster 为你提供了以下的功能:

A.    卷管理,资源管理,硬盘/服务器管理,日志管理 

14.    Cassandra 中的存储模型为:

A.  Keyspace1--row007--Standard1

2.     下列说法错误的是()

D.    Common 没有提供文件系统

3.     Hadoop 的优势不包括()

D.    实时的

4.     下列说法错误的是()

D.    HDFS 不是一个高度容错性的系统

6.     配置 hbase 过程中,下面那个文件没有改动。

A.    hbase-default.xml

7.     hbase 中锁定__之后才能进行写操作。

B.    行

8.     下面那个操作完成了投影操作。

A.    Scan s = new Scan();s.addColumn(String columns);

9.     Hive 默认的构造是存储在(install-dir)/conf/__. 

版权所有人:王方舟    盗版必究

B.    hive-default.xml

10.     Hive 查询语言中的算术操作符的返回结果是__类型的。

A.    Number

13.     在 Ubuntu 上安装 Cassandra 的命令是什么?

C.    sudo apt-get install Cassandra

15.     在 Cassandra 里,相同的 ColumnFamily 中什么的名字必须唯一?

不选 B:keyspace

16.     在 Cassandra 中最小的组织单元是:

D.    Column

17.     Gluster 平台在 3.0 版本之后加入了新的功能?自愈功能,作为一个数据管理者,

你应该非常欢迎这个功能,同时你也需要了解这项新功能,下面那个不是自愈功能的特点:

B.    难以处理细节事件 

19.     客户端连接的远程卷的名字是什么?

A.    locker

1.     关于 Datanode 的描述错误的是()

D.    文件的副本系数由 Datanode 储存

2.     关于基于 Hadoop 的 MapReduce 编程的环境配置,下面哪一步是不必要的() 

C.    配置 Eclipse

3.     下列说法错误的是() 

版权所有人:王方舟    盗版必究

D.    IsolationRunner 是用于编译 Hadoop 程序的工具

5.     下列说法错误的是()

A.    MapReduce 中 maper conbiner reducer 缺一不可

6.     hbase 是建立在__之上的分布式数据库。

C.    hadoop

7.     下面那个选项正确配置了 HBASE 的分布式环境。

B.    在 hbase-site.xml 文件中设置 hbase.cluster.distributed 为 true

8.     性能方面,hbase 与关系数据库相比__。

A.    查询效率高

10.     为了启动 hive,我们必须在路径里安装有 hadoop 或者__。 

A.    export HADOOP_HOME=hadoop-install-dir

11.     我们必须创建__和__,并在 Hive 中创建一个表格之前,在 HDFS 中把他们的权限设

置为 g+w。

A.    /tmp and /user/hive/warehouse

12.     下面哪种操作是不被 Hive 查询语言所支持的__。、

C.    在一个表格中添加索引。

13.     下面哪一项不是目前 hive 查询语言的特征__。

D.    索引

16.     在 Cassandra 中最大的组织单元是: 

版权所有人:王方舟    盗版必究

A.    Keyspace

17.     在这次学习开始前,你需要知道你如何安装 Gluster Storage Platform,想想你

知道多少种安装方式,并挑选出下面哪项是错的? 

D.    按源码方式安装 Gluster 平台前,我需要安装 java 的编译环境(可以不是 sun 公司

的)

18.     作为一款分布式存储平台,你知道客户是如何通过客户端与服务器连接的吗?

A.    是通过把分布在多台(或一台)服务器上卷挂载到客户端上的文件夹的方式实现客户

端与服务器相连 

19.     下面是一些命令,这些命令都是使用这些配置启动服务器/客户端的,其中哪项是

错误的?

B.    glusterfs -start /../client.vol(启动客户端)

20.     从这些配置文件,你可以看出,这个结构具有什么的功能?

C.    镜像特征的卷,服务器 1 和服务器 2 互作备份

4.     关于基于 Hadoop 的 MapReduce 编程的环境配置,下面哪一步是不必要的()

C.    安装 Eclipse

6.     下面那个选项正确配置了 HBASE 的分布式环境。

B.    在 hbase-site.xml 文件中设置 hbase.cluster.distributed 为 true

9.     对于最小粒度的任务,Hive 查询的反应时间约为 ___。

D.    几分钟

10.     下面哪种操作是不被 Hive 查询语言所支持的__。 

版权所有人:王方舟    盗版必究

C.    在一个表格中添加索引。

12.     下面哪个操作是不可复原的__。

D.    ALTER TABLE pv_users DROP PARTITION (ds="2008-08-08")

13.     在 Cassandra 上编译 Java 的 jar 时,需要用到是什么?

C.    ant

14.     一般在哪个文件中配置 Cassandra 集群的信息?

C.    storage-conf.xml

15.     作为一个熟练的 Linux 用户,你决定采用源码编译方式安装 Gluster 平台(基于

fuse 的客户端),安装前,你需要先安装什么?

C.    fuse,Flex,Gun bison,gcc

17.     关于这个平台你还需要知道一些其他的事情,比如以下这些,下列哪项是错的

B.    当一个存储节点发生故障时,我可以直接把他从服务器列表中移除

18.     看下段内容: volume server type protocol/server option tran sport-type 

tcp/server option bind-address 192.168.4.190 # Default is to listen on all 

interfaces option listen-port 6996 # Default is 6996 subvolumes locker option 

auth.addr.brick.allow * option auth.addr.locker.allow * end -volume 这段内容中,

option 可以看做语法标识符。后面给出的是函数执行时所需的参数,如果把 type 结构可以

看做是类的结构,option 用来给出这个“类”中的参数。想想看,下面哪项是错误的?

C.    option transport-type tcp/server 后的参数表示服务器使用 TCP 协议与 Internet

连接

19.     下面是一些命令,这些命令都是使用这些配置启动服务器/客户端的,其中哪项是

错误的?

B.    glusterfs -start /../client.vol(启动客户端)

16.    下列哪项在 Cassandra 中概念最接近关系型数据库中的表?

A.  columnFamily

12.     按粒度大小的顺序,Hive 数据被组成为:数据库,表格,__和桶。

C.    分隔

 

 

 

 





  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值