首页 > 编程语言 >datax修改 hdfsReader源码实现空文件及目录为空时,程序退出不抛出异常

datax修改 hdfsReader源码实现空文件及目录为空时,程序退出不抛出异常

时间:2024-06-03 14:34:29浏览次数:15  
标签:LOG hdfsReader List splitNumber 源码 datax 读取

最近在使用datax_202309时,有任务需要将hive的数据按天同步到mysql, 由于同步的表由业务生成,故可能有的表当天是没有数据产生,就会抛出出现下面的错误:

问题:datax读取hive分区表时,datax-hdfsReader 读取空目录报错
问题描述:
com.alibaba.datax.common.exception.DataXException: Code:[HdfsReader-08], Description:[您尝试读取的文件目录为空.]. - 未能找到待读取的文件,请确认您的配置项path: /user/hive/warehouse/dws.db/dws_index_business_xzkh/dt_date=2024-01-02

 

解决办法: 下载datax源码,修改源码,修改完后编译打包,上传并替换 datax安装${datax}/plugin/reader/hdfsreader/ 目录下面的 hdfsreader-0.0.1-SNAPSHOT.jar

 

 

 public List<Configuration> split(int adviceNumber) {

            LOG.info("split() begin...");
            List<Configuration> readerSplitConfigs = new ArrayList<Configuration>();
            // warn:每个slice拖且仅拖一个文件,
            // int splitNumber = adviceNumber;
            int splitNumber = this.sourceFiles.size();
            if (0 == splitNumber) {
            /*    throw DataXException.asDataXException(HdfsReaderErrorCode.EMPTY_DIR_EXCEPTION,
                        String.format("未能找到待读取的文件,请确认您的配置项path: %s", this.readerOriginConfig.getString(Key.PATH)));*/
                //异常处理逻辑修改
                LOG.warn(String.format("未能找到待读取的文件,请确认您的配置项path: %s", this.readerOriginConfig.getString(Key.PATH)));
                LOG.info("split() end");
                LOG.info("Task exited with return code 0");
                System.exit(0);
            }

            List<List<String>> splitedSourceFiles = this.splitSourceFiles(new ArrayList<String>(this.sourceFiles), splitNumber);
            for (List<String> files : splitedSourceFiles) {
                Configuration splitedConfig = this.readerOriginConfig.clone();
                splitedConfig.set(Constant.SOURCE_FILES, files);
                readerSplitConfigs.add(splitedConfig);
            }

            return readerSplitConfigs;
        }

  

 

展示效果:

 

标签:LOG,hdfsReader,List,splitNumber,源码,datax,读取
From: https://www.cnblogs.com/henyu/p/18228849

相关文章