一.問題重現(xiàn)
SQL 錯誤 [2] [08S01]: Error while processing statement: FAILED: Execution Error, return code 2 from org.apache.hadoop.hive.ql.exec.mr.MapRedTask
Error while processing statement: FAILED: Execution Error, return code 2 from org.apache.hadoop.hive.ql.exec.mr.MapRedTask
Error while processing statement: FAILED: Execution Error, return code 2 from org.apache.hadoop.hive.ql.exec.mr.MapRedTask
二.問題分析
這個錯誤代碼表明 Hive 作業(yè)由于某種原因失敗。
? ?1.資源問題: 這個錯誤可能發(fā)生在集群上存在資源約束的情況下,例如內(nèi)存或 CPU 資源不足以完成 Hive 作業(yè)。
? ?2.數(shù)據(jù)問題: 它可能與數(shù)據(jù)本身相關。例如,數(shù)據(jù)可能損壞,或者數(shù)據(jù)格式或模式存在問題,Hive 無法處理。
? ?3.配置問題: 不正確的 Hive 或 Hadoop 配置設置可能導致作業(yè)失敗。
? ?4.查詢錯誤: 可能是與你嘗試執(zhí)行的 SQL 查詢相關的問題。例如,它可能存在語法錯誤,或者嘗試執(zhí)行 Hive 不支持的操作。
? ?5.權限問題: 你可能沒有執(zhí)行你嘗試執(zhí)行的操作所需的權限。
? ?6.版本沖突:hive和Hadoop版本不兼容。
三.問題解決
為了解決這個問題我們可以嘗試以下步驟:
-
檢查 Hive 日志以獲取有關問題性質(zhì)的更多詳細錯誤消息。這些日志可以提供有關問題的額外信息。
-
檢查你的 SQL 查詢,確保它是正確的,并適用于你正在處理的數(shù)據(jù)和模式。
-
驗證你是否具有訪問和操作數(shù)據(jù)所需的權限。
-
確保你的 Hive 和 Hadoop 配置正確設置。
-
如果錯誤與數(shù)據(jù)有關,請檢查數(shù)據(jù)是否存在問題,如損壞、缺失值或不正確的格式。
- 考慮咨詢你的 Hadoop 或 Hive 管理員以獲取進一步的故障排除幫助。
- 檢查集群的資源利用情況,看集群資源是否充足。例如CPU和內(nèi)存
? ? ? ? 如果確定是集群資源不足,可以在hadoop/etc/hadoop/下yarn-site.sh配置文件添加以下內(nèi)容
<!--yarn單個容器允許分配的最大最小內(nèi)存 -->
<property>
<name>yarn.scheduler.minimum-allocation-mb</name>
<value>512</value>
</property>
<property>
<name>yarn.scheduler.maximum-allocation-mb</name>
<value>4096</value>
</property>
<!-- yarn容器允許管理的物理內(nèi)存大小 -->
<property>
<name>yarn.nodemanager.resource.memory-mb</name>
<value>4096</value>
</property>
<!-- 關閉yarn對物理內(nèi)存和虛擬內(nèi)存的限制檢查 -->
<property>
<name>yarn.nodemanager.pmem-check-enabled</name>
<value>true</value>
</property>
<property>
<name>yarn.nodemanager.vmem-check-enabled</name>
<value>false</value>
</property>
排除以上問題之后問題沒有解決,如果你插入數(shù)據(jù)是很多字段,可以嘗試減少字段插入數(shù)據(jù)
例如
? ? 這是我原本插入的數(shù)據(jù)的SQL語句
-- 插入數(shù)據(jù)
insert overwrite table dw_didi.t_user_order_wide partition(dt='2020-04-12')
select
orderid,telephone,lng,lat,province,city,es_money,gender,profession,age_range,tip,subscribe,
case when subscribe = 0 then '非預約'
when subscribe = 1 then '預約'
end as subscribe_name,sub_time,is_agent,
case when is_agent = 0 then '本人'
when is_agent = 1 then '代叫'
end as is_agent_name,
agent_telephone,
date_format(concat(order_time,':00'),'yyyy-MM-dd') as order_date,
year(date_format(concat(order_time,':00'),'yyyy-MM-dd:ss')) as order_year,
month(date_format(concat(order_time,':00'),'yyyy-MM-dd:ss'))as order_month,
day(date_format(concat(order_time,':00'),'yyyy-MM-dd:ss'))as order_day,
hour(date_format(concat(order_time,':00'),'yyyy-MM-dd HH:mm:ss'))as order_hour,
case when hour(date_format(concat(order_time,':00'),'yyyy-MM-dd HH:mm:ss')) > 1 and hour (date_format(concat(order_time,':00'),'yyyy-MM-dd HH:mm:ss')) <= 5 then '凌晨'
when hour(date_format(concat(order_time,':00'),'yyyy-MM-dd HH:mm:ss')) > 5 and hour (date_format(concat(order_time,':00'),'yyyy-MM-dd HH:mm:ss')) <= 8 then '早上'
when hour(date_format(concat(order_time,':00'),'yyyy-MM-dd HH:mm:ss')) > 8 and hour (date_format(concat(order_time,':00'),'yyyy-MM-dd HH:mm:ss')) <= 11 then '上午'
when hour(date_format(concat(order_time,':00'),'yyyy-MM-dd HH:mm:ss')) > 11 and hour (date_format(concat(order_time,':00'),'yyyy-MM-dd HH:mm:ss')) <= 13 then '中午'
when hour(date_format(concat(order_time,':00'),'yyyy-MM-dd HH:mm:ss')) > 13 and hour (date_format(concat(order_time,':00'),'yyyy-MM-dd HH:mm:ss')) <= 17 then '下午'
when hour(date_format(concat(order_time,':00'),'yyyy-MM-dd HH:mm:ss')) > 17 and hour (date_format(concat(order_time,':00'),'yyyy-MM-dd HH:mm:ss')) <= 19 then '晚上'
when hour(date_format(concat(order_time,':00'),'yyyy-MM-dd HH:mm:ss')) > 19 and hour (date_format(concat(order_time,':00'),'yyyy-MM-dd HH:mm:ss')) <= 20 then '半夜'
when hour(date_format(concat(order_time,':00'),'yyyy-MM-dd HH:mm:ss')) > 20 and hour (date_format(concat(order_time,':00'),'yyyy-MM-dd HH:mm:ss')) <= 24 then '深夜'
when hour(date_format(concat(order_time,':00'),'yyyy-MM-dd HH:mm:ss')) > 0 and hour (date_format(concat(order_time,':00'),'yyyy-MM-dd HH:mm:ss')) <= 1 then '深夜'
else 'N/A'
end as order_time_range,
date_format(concat(concat(order_time,':00'),':00'),'yyyy-MM-dd HH:mm:ss') as order_time
from ods_didi.t_user_order WHERE dt = '2020-04-12' and length(order_time) > 8;
SELECT * from dw_didi.t_user_order_wide
現(xiàn)在改為
insert overwrite table dw_didi.wide1 partition(dt='2020-04-12')
select
orderid
from ods_didi.t_user_order WHERE dt = '2020-04-12' and length(order_time) > 8;
SELECT * from dw_didi.wide1
如果嘗試運行之后還是報相同錯誤
就可以基本判定是hive配置文件的錯誤
檢查配置文件后,如果還是報錯,我們可以嘗試設置hive的執(zhí)行引擎
1.下載tez的依賴包:http://tez.apache.org
2.拷貝apache-tez-0.9.1-bin.tar.gz到hadoop102的/export/software目錄
3.解壓縮apache-tez-0.9.1-bin.tar.gz
tar -zxvf apache-tez-0.9.1-bin.tar.gz -C /export/servers
4.進入到Hive的配置目錄
/hive/conf
5.在hive-env.sh文件中添加tez環(huán)境變量配置和依賴包環(huán)境變量配置
vim hive-env.sh
export TEZ_HOME=/export/servers/tez-0.9.1 #是你的tez的解壓目錄
export TEZ_JARS=""
for jar in `ls $TEZ_HOME |grep jar`; do
export TEZ_JARS=$TEZ_JARS:$TEZ_HOME/$jar
done
for jar in `ls $TEZ_HOME/lib`; do
export TEZ_JARS=$TEZ_JARS:$TEZ_HOME/lib/$jar
done
export HIVE_AUX_JARS_PATH=/export/servers/hadoop-2.7.7/share/hadoop/common/hadoop-lzo-0.4.20.jar$TEZ_JARS
6.在hive-site.xml文件中添加如下配置,更改hive計算引擎
<property>
<name>hive.execution.engine</name>
<value>tez</value>
</property>
7.在Hive的/export/servers/hive/conf下面創(chuàng)建一個tez-site.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
<name>tez.lib.uris</name> <value>${fs.defaultFS}/tez/tez-0.9.1,${fs.defaultFS}/tez/tez-0.9.1/lib</value>
</property>
<property>
<name>tez.lib.uris.classpath</name> <value>${fs.defaultFS}/tez/tez-0.9.1,${fs.defaultFS}/tez/tez-0.9.1/lib</value>
</property>
<property>
<name>tez.use.cluster.hadoop-libs</name>
<value>true</value>
</property>
<property>
<name>tez.history.logging.service.class</name> <value>org.apache.tez.dag.history.logging.ats.ATSHistoryLoggingService</value>
</property>
</configuration>
8.將/export/servers/tez-0.9.1上傳到HDFS的/tez路徑
hadoop fs -mkdir /tez
hadoop fs -put /export/servers/tez-0.9.1/ /tez
hadoop fs -ls /tez查看結果是這個
/tez/tez-0.9.1
運行Tez時檢查到用過多內(nèi)存而被NodeManager殺死進程問題:文章來源:http://www.zghlxwxcb.cn/news/detail-753482.html
Caused by: org.apache.tez.dag.api.SessionNotRunning: TezSession has already shutdown. Application application_1546781144082_0005 failed 2 times due to AM Container for appattempt_1546781144082_0005_000002 exited with exitCode: -103
For more detailed output, check application tracking page:http://hadoop102:8088/cluster/app/application_1546781144082_0005Then, click on links to logs of each attempt.
Diagnostics: Container [pid=11116,containerID=container_1546781144082_0005_02_000001] is running beyond virtual memory limits. Current usage: 216.3 MB of 1 GB physical memory used; 2.6 GB of 2.1 GB virtual memory used. Killing container.
解決方法:文章來源地址http://www.zghlxwxcb.cn/news/detail-753482.html
<property>
<name>yarn.nodemanager.vmem-check-enabled</name>
<value>false</value>
</property>
到了這里,關于在hive插入數(shù)據(jù)時出現(xiàn)“Execution Error, return code 2 from org.apache.hadoop.hive.ql.exec.mr.MapRedTask”報錯的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!