大数据Hadoop之ApacheHudi与PrestoTri
一、概述
ApacheHudi是一个快速增长的数据湖存储系统,可帮助组织构建和管理PB级数据湖。Hudi通过引入诸如升序、删除和增量查询之类的原语,将流式处理引入到批处理式大数据中。这些功能有助于在统一服务层上更快、更新鲜的数据。Hudi表可以存储在Hadoop分布式文件系统(HDFS)或云存储上,并与流行的查询引擎(如Presto(Trino)、ApacheHive、ApacheSpark和ApacheImpala)集成良好。鉴于Hudi开创了一种新的模型,它不仅仅是将文件写入到一个更受管理的存储层,该存储层可以与所有主要的查询引擎进行互操作,因此在集成点是如何演变的方面有了有趣的经验。
使用presto或者trino分析hudi表数据,最终将结果存储到mysql表中。
Hive中创建表,关联Hudi表Presto集成Hive,加载Hive表数据Presto集成MySQL,读取或者保存数据二、Trino环境部署
关于trino或者presto的介绍,可以参考我这篇文章:大数据Hadoop之基于内存型SQL查询引擎Presto(PrestoTrino环境部署),这里部署trino单机版进行测试。1)安装JDK
【注意】Trino不同的版本要求的JDK版本也不一样的。这里我安装Trino最新版,JDK也安装最新版本。wgethttps:cdn。azul。comzulubinzulu19。30。11cajdk19。0。1linuxx64。zipunzipzulu19。30。11cajdk19。0。1linuxx64。zip
配置环境变量etcprofile文件中追加如下内容:exportJAVAHOMEoptbigdatatrinozulu19。30。11cajdk19。0。1linuxx64exportPATHJAVAHOMEbin:PATHexportCLASSPATH。:JAVAHOMElibdt。jar:JAVAHOMElibtools。jar加载生效sourceetcprofile2)安装pythonversion2。6。x,2。7。x,or3。xyumyinstallpython3python3versionlnsusrbinpython3usrbinpython3)安装Trino
这里部署单机版,Coordinator和Worker同进程。1、下载解压并配置环境变量wgethttps:repo1。maven。orgmaven2iotrinotrinoserver401trinoserver401。tar。gztarxftrinoserver401。tar。gz配置环境变量etcprofileexportTRINOHOMEoptbigdatatrinotrinoserver401exportPATHTRINOHOMEbin:PATH2、修改配置
首先创建etc和data目录,后面配置文件需要用到cdTRINOHOMEmkdirpdataetccatalognode。propertiescatEOFTRINOHOMEetcnode。properties环境的名字。集群中所有的Trino节点必须具有相同的环境名称。node。environmentdev此Trino安装的唯一标识符。这对于每个节点都必须是唯一的。node。idtrinoworker数据目录的位置(文件系统路径)。Trino在这里存储ahrefhttps:www。bs178。comrizhitargetblankclassinfotextkey日志a和其他数据。node。datadiroptbigdatatrinotrinoserver401dataEOFjvm。configcatEOFTRINOHOMEetcjvm。configserverXmx2GXX:UseG1GCXX:G1HeapRegionSize32MXX:ExplicitGCInvokesConcurrentXX:ExitOnOutOfMemoryErrorXX:HeapDumpOnOutOfMemoryErrorXX:OmitStackTraceInFastThrowXX:ReservedCodeCacheSize512MXX:PerMethodRecompilationCutoff10000XX:PerBytecodeRecompilationCutoff10000Djdk。attach。allowAttachSelftrueDjdk。nio。maxCachedBufferSize2000000EOFconfig。propertiescatEOFTRINOHOMEetcconfig。properties设置该节点为coordinator节点coordinatortrue允许在协调器上调度工作,也就是coordinator节点又充当worker节点用nodescheduler。includecoordinatortrue指定HTTP服务器的端口。Trino使用HTTP进行内部和外部web的所有通信。httpserver。http。port9000查询可以使用的最大分布式内存。【注意】不能配置超过jvm配置的最大堆栈内存大小query。maxmemory1GB查询可以在任何一台机器上使用的最大用户内存。【注意】也是不能配置超过jvm配置的最大堆栈内存大小query。maxmemorypernode1GBhadoopnode1也可以是IPdiscovery。urihttp:local168182130:9000EOFlog。propertiescatEOFTRINOHOMEetclog。properties设置ahrefhttps:www。bs178。comrizhitargetblankclassinfotextkey日志a级别,有四个级别:DEBUG,INFO,WARNandERRORio。trinoINFOEOF配置hive数据源,hive。propertiescatEOFTRINOHOMEetccataloghive。propertiesconnector。namehivehive。metastore。urithrift:local168182130:9083hive。config。resourcesoptbigdatahadoophadoop3。3。2etchadoopcoresite。xml,optbigdatahadoophadoop3。3。2etchadoophdfssite。xmlEOF配置mysql数据源,mysql。properties所有节点都得添加catEOFTRINOHOMEetccatalogmysql。propertiesconnector。namemysqlconnectionurljdbc:mysql:local168182130:3306connectionuserrootconnectionpassword123456EOF3、启动服务TRINOHOMEbinlauncherstart查看ahrefhttps:www。bs178。comrizhitargetblankclassinfotextkey日志atailfTRINOHOMEdatavarlogserver。lognetstattnlpgrep:90004、测试验证
web访问验证:http:local168182130:9000
下载对应trino版本的客户端进行连接测试cdTRINOHOMEbinwgethttps:repo1。maven。orgmaven2iotrinotrinocli401trinocli401executable。jar改名,加执行权限mvtrinocli401executable。jartrinochmodxtrino非交互式连接操作TRINOHOMEbintrinoserverlocal168182130:9000executeselectfromsystem。runtime。nodes;交互式连接测试TRINOHOMEbintrinoserverlocal168182130:9000命令不区分大小写showcatalogs;查库showschemasfromsystem;查表showtablesfromsystem。runtime;查具体记录,查看当前node节点记录selectfromsystem。runtime。nodes;
三、在Hive中创建表关联Hudi表
hive查询hudi数据主要是在hive中建立外部表,数据路径指向hdfs路径,同时hudi重写了inputformat和outpurtformat。因为hudi在读的数据的时候会读元数据来决定我要加载那些parquet文件,而在写的时候会写入新的元数据信息到hdfs路径下。所以hive要集成hudi查询要把编译的jar包放到HIVEHOMElib下面。否则查询时找不到inputformat和outputformat的类。1)添加jar包cphudihudi0。12。0packaginghudihivesyncbundletargethudihivesyncbundle0。12。0。jarHIVEHOMElib重启metastore服务nohuphiveservicemetastore重启hiverserver2nohuphiveservicehiveserver2devnull21查看ahrefhttps:www。bs178。comrizhitargetblankclassinfotextkey日志atailftmproothive。log连接beelineujdbc:hive2:local168182130:10000nroot2)创建库表关联Hudi1、创建数据库CREATEDATABASEIFNOTEXISTShudihive;USEhudihive;2、创建hive表,指定数据存储路径,关联hudi表路径。beelineujdbc:hive2:local168182130:10000nrootCREATEEXTERNALTABLEhudihive。tblcustomer(idstring,customerrelationshipidstring,createdatetimestring,updatedatetimestring,deletedstring,namestring,idcardstring,birthyearstring,genderstring,phonestring,wechatstring,qqstring,emailstring,areastring,leaveschooldatestring,graduationdatestring,bxgstudentidstring,creatorstring,origintypestring,originchannelstring,tenantstring,mdidstring)PARTITIONEDBY(daystrstring)ROWFORMATSERDEorg。apache。hadoop。hive。ql。io。parquet。serde。ParquetHiveSerDeSTOREDASINPUTFORMATorg。apache。hudi。hadoop。HoodieParquetInputFormatOUTPUTFORMATorg。apache。hadoop。hive。ql。io。parquet。MapredParquetOutputFormatLOCATIONhudihivecustomerhudi;
就会在DFS上创建相关的目录
数据来源可以是flink或者spark任务去写数据,根据具体场景而定。四、Hudi与Trino集成
trino集成hudi是基于hivecatalog,同样是访问hive外表进行查询,如果要集成,需要把huditrinojar包copy到trinopluginhive插件下面。cphudihudi0。12。0packaginghuditrinobundletargethuditrinobundle0。12。0。jarTRINOHOMEpluginhive
查询TRINOHOMEbintrinoserverlocal168182130:9000showschemasfromhive;showtablesfromhive。hudihive;selectfromhive。hudihive。tblcustomer;
trino或者presto将需要查询的数据进行统计写入到其它数据源,这是trinopresto的优势,因为trinopresto本身支持很多种数据源(catalog)。
Hudi与Trino(Presto)的集成讲解就先到这里了,有任何疑问欢迎给我留言,后面会持续更新【大数据云原生】相关的文章,请小伙伴耐心等待