03_matrixdb通过pxf读写hdfs文件

2023-12-03 08:48
文章标签 读写 03 hdfs matrixdb pxf

本文主要是介绍03_matrixdb通过pxf读写hdfs文件,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

matrixdb视频教程 - 03matrixdb通过pxf读写hdfs文件

作者

shidb

日期

2021-05-11

标签

matrixdb视频教程 - 03matrixdb通过pxf读写hdfs文件

环境介绍

sdw5 namenode hive
sdw3 matrixdb集群

matrixdb通过pxf读取hdfs文件

在hdfs上创建文件夹

[hdfs@sdw5 ~]$ hdfs dfs -mkdir /matrixdb/pxf

上传文件

echo 'Prague,Jan,101,4875.33
> Rome,Mar,87,1557.39
> Bangalore,May,317,8936.99
> Beijing,Jul,411,11600.67' > pxf_hdfs_simple.txt[hdfs@sdw5 ~]$ ls
pxf_hdfs_simple.txt[hdfs@sdw5 ~]$ hdfs dfs -put pxf_hdfs_simple.txt /matrixdb/pxf/
hdfs dfs -cat /matrixdb/pxf/pxf_hdfs_simple.txt
Prague,Jan,101,4875.33
Rome,Mar,87,1557.39
Bangalore,May,317,8936.99
Beijing,Jul,411,11600.67

cdh配置proxyuser

hdfs->配置->core-site.xml
core-site.xml的集群范围高级配置添加
hadoop.proxyuser.shidb.host 
*
hadoop.proxyuser.shidb.group 
*

配置pxf

将hdfs下的core-site.xml、hdfs-site.xml拷贝到

[root@sdw5 ~]# cp /etc/hadoop/conf.cloudera.hdfs/core-site.xml .
[root@sdw5 ~]# cp /etc/hadoop/conf.cloudera.hdfs/hdfs-site.xml .拷贝到所有matrixdb pxf节点的如下路径
cp core-site.xml /usr/local/pxf-matrixdb3/conf/servers/cdh_hdfs/
cp hdfs-site.xml /usr/local/pxf-matrixdb3/conf/servers/cdh_hdfs/

如果之前已经配置过,需要重置

停止pxf

[shidb@sdw3 ~]$ pxf cluster stop
Stopping PXF on 1 segment host…
PXF stopped successfully on 1 out of 1 host

重置pxf配置

[shidb@sdw3 ~]$ pxf cluster reset
Ensure your PXF cluster is stopped before continuing. This is a destructive action. Press y to continue:
y
Resetting PXF on master host and 0 segment hosts...
PXF has been reset on 1 out of 1 host

初始化pxf

[shidb@sdw3 ~]$ pxf cluster init
Initializing PXF on master host and 0 segment hosts...
PXF initialized successfully on 1 out of 1 host

pxf同步

[shidb@sdw3 ~]$ pxf cluster sync
Syncing PXF configuration files from master host to 1 segment host...
PXF configs synced successfully on 1 out of 1 host

启动PXF

[shidb@sdw3 ~]$ pxf cluster start
Starting PXF on 1 segment host...
PXF started successfully on 1 out of 1 host

查看pxf状态

[shidb@sdw3 ~]$ pxf cluster status
Checking status of PXF servers on 1 segment host...
PXF is running on 1 out of 1 host

master上单独也需要启动

[shidb@sdw3 ~]$ pxf start
Using CATALINA_BASE:   /usr/local/pxf-matrixdb3/pxf-service
Using CATALINA_HOME:   /usr/local/pxf-matrixdb3/pxf-service
Using CATALINA_TMPDIR: /usr/local/pxf-matrixdb3/pxf-service/temp
Using JRE_HOME:        /usr/local/jdk1805/jre
Using CLASSPATH:       /usr/local/pxf-matrixdb3/pxf-service/bin/bootstrap.jar:/usr/local/pxf-matrixdb3/pxf-service/bin/tomcat-juli.jar
Using CATALINA_PID:    /usr/local/pxf-matrixdb3/run/catalina.pid
Existing PID file found during start.
Tomcat appears to still be running with PID 763115. Start aborted.
If the following process is not a Tomcat process, remove the PID file and try again:
UID         PID   PPID  C STIME TTY          TIME CMD
shidb    763115      1 99 12:27 pts/178  00:00:28 /usr/local/jdk1805/jre/bin/java -Djava.util.logging.config.file=/usr/local/pxf-matrixdb3/pxf-service/conf/logging.properties -Djava.util.logg
[shidb@sdw3 ~]$

matrixdb操作

创建插件

CREATE EXTENSION pxf_fdw ;

创建FDW Server

DROP SERVER hdfs_svr FOREIGN DATA WRAPPER hdfs_pxf_fdw;
CREATE SERVER hdfs_svr FOREIGN DATA WRAPPER hdfs_pxf_fdw OPTIONS ( config 'single_hdfs' );

创建用户名admin的FDW User mapping

CREATE USER MAPPING FOR shidb SERVER hdfs_svr;
drop USER MAPPING FOR shidb SERVER hdfs_svr;CREATE USER MAPPING FOR hdfs SERVER hdfs_svr;
drop USER MAPPING FOR hdfs SERVER hdfs_svr;

创建FDW Foreign Table,指向对应的HDFS文件

DROP FOREIGN TABLE pxf_hdfs_table;
CREATE FOREIGN TABLE pxf_hdfs_table (
location text,
month text,
num_orders int,
total_sales float8) SERVER hdfs_svr OPTIONS ( resource '/matrixdb/pxf/pxf_hdfs_simple.txt', format 'text',delimiter ',');

9.查询Foreign Table获取数据

SELECT * FROM pxf_hdfs_table ;
postgres=# select * from pxf_hdfs_table ;location  | month | num_orders | total_sales
-----------+-------+------------+-------------Prague    | Jan   |        101 |     4875.33Rome      | Mar   |         87 |     1557.39Bangalore | May   |        317 |     8936.99Beijing   | Jul   |        411 |    11600.67
(4 rows)

matrixdb读写hdfs

drop FOREIGN TABLE pxf_hdfs_dir;
CREATE FOREIGN TABLE pxf_hdfs_dir (
location text,
month text,
num_orders int,
total_sales float8) SERVER hdfs_svr OPTIONS ( resource '/matrixdb/pxf/', format 'text',delimiter ',');postgres=# select * from pxf_hdfs_dir;location  | month | num_orders | total_sales 
-----------+-------+------------+-------------Prague    | Jan   |        101 |     4875.33Rome      | Mar   |         87 |     1557.39Bangalore | May   |        317 |     8936.99Beijing   | Jul   |        411 |    11600.67

如需入群沟通交流,请扫码添加好友
在这里插入图片描述

这篇关于03_matrixdb通过pxf读写hdfs文件的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/448835

相关文章

在SpringBoot+MyBatis项目中实现MySQL读写分离的实战指南

《在SpringBoot+MyBatis项目中实现MySQL读写分离的实战指南》在SpringBoot和MyBatis项目中实现MySQL读写分离,主要有两种思路:一种是在应用层通过代码和配置手动控制... 目录如何选择实现方案核心实现:应用层手动分离实施中的关键问题与解决方案总结在Spring Boot和

MySQL数据库读写分离与负载均衡的实现逻辑

《MySQL数据库读写分离与负载均衡的实现逻辑》读写分离与负载均衡是数据库优化的关键策略,读写分离的核心是将数据库的读操作与写操作分离,本文给大家介绍MySQL数据库读写分离与负载均衡的实现方式,感兴... 目录读写分离与负载均衡的核心概念与目的读写分离的必要性与实现逻辑读写分离的实现方式及优缺点读负载均衡

C++读写word文档(.docx)DuckX库的使用详解

《C++读写word文档(.docx)DuckX库的使用详解》DuckX是C++库,用于创建/编辑.docx文件,支持读取文档、添加段落/片段、编辑表格,解决中文乱码需更改编码方案,进阶功能含文本替换... 目录一、基本用法1. 读取文档3. 添加段落4. 添加片段3. 编辑表格二、进阶用法1. 文本替换2

ShardingProxy读写分离之原理、配置与实践过程

《ShardingProxy读写分离之原理、配置与实践过程》ShardingProxy是ApacheShardingSphere的数据库中间件,通过三层架构实现读写分离,解决高并发场景下数据库性能瓶... 目录一、ShardingProxy技术定位与读写分离核心价值1.1 技术定位1.2 读写分离核心价值二

MySQL中读写分离方案对比分析与选型建议

《MySQL中读写分离方案对比分析与选型建议》MySQL读写分离是提升数据库可用性和性能的常见手段,本文将围绕现实生产环境中常见的几种读写分离模式进行系统对比,希望对大家有所帮助... 目录一、问题背景介绍二、多种解决方案对比2.1 原生mysql主从复制2.2 Proxy层中间件:ProxySQL2.3

C#读写文本文件的多种方式详解

《C#读写文本文件的多种方式详解》这篇文章主要为大家详细介绍了C#中各种常用的文件读写方式,包括文本文件,二进制文件、CSV文件、JSON文件等,有需要的小伙伴可以参考一下... 目录一、文本文件读写1. 使用 File 类的静态方法2. 使用 StreamReader 和 StreamWriter二、二进

MySQL主从复制与读写分离的用法解读

《MySQL主从复制与读写分离的用法解读》:本文主要介绍MySQL主从复制与读写分离的用法,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、主从复制mysql主从复制原理实验案例二、读写分离实验案例安装并配置mycat 软件设置mycat读写分离验证mycat读

Redis分片集群、数据读写规则问题小结

《Redis分片集群、数据读写规则问题小结》本文介绍了Redis分片集群的原理,通过数据分片和哈希槽机制解决单机内存限制与写瓶颈问题,实现分布式存储和高并发处理,但存在通信开销大、维护复杂及对事务支持... 目录一、分片集群解android决的问题二、分片集群图解 分片集群特征如何解决的上述问题?(与哨兵模

ShardingSphere之读写分离方式

《ShardingSphere之读写分离方式》:本文主要介绍ShardingSphere之读写分离方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录ShardingSphere-读写分离读写分离mysql主从集群创建 user 表主节点执行见表语句项目代码读写分

SpringBoot实现数据库读写分离的3种方法小结

《SpringBoot实现数据库读写分离的3种方法小结》为了提高系统的读写性能和可用性,读写分离是一种经典的数据库架构模式,在SpringBoot应用中,有多种方式可以实现数据库读写分离,本文将介绍三... 目录一、数据库读写分离概述二、方案一:基于AbstractRoutingDataSource实现动态