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实现数据库读写分离的3种方法小结

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

Redis中高并发读写性能的深度解析与优化

《Redis中高并发读写性能的深度解析与优化》Redis作为一款高性能的内存数据库,广泛应用于缓存、消息队列、实时统计等场景,本文将深入探讨Redis的读写并发能力,感兴趣的小伙伴可以了解下... 目录引言一、Redis 并发能力概述1.1 Redis 的读写性能1.2 影响 Redis 并发能力的因素二、

Python实现高效地读写大型文件

《Python实现高效地读写大型文件》Python如何读写的是大型文件,有没有什么方法来提高效率呢,这篇文章就来和大家聊聊如何在Python中高效地读写大型文件,需要的可以了解下... 目录一、逐行读取大型文件二、分块读取大型文件三、使用 mmap 模块进行内存映射文件操作(适用于大文件)四、使用 pand

C# 读写ini文件操作实现

《C#读写ini文件操作实现》本文主要介绍了C#读写ini文件操作实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧... 目录一、INI文件结构二、读取INI文件中的数据在C#应用程序中,常将INI文件作为配置文件,用于存储应用程序的

SpringBoot操作spark处理hdfs文件的操作方法

《SpringBoot操作spark处理hdfs文件的操作方法》本文介绍了如何使用SpringBoot操作Spark处理HDFS文件,包括导入依赖、配置Spark信息、编写Controller和Ser... 目录SpringBoot操作spark处理hdfs文件1、导入依赖2、配置spark信息3、cont

C#实现文件读写到SQLite数据库

《C#实现文件读写到SQLite数据库》这篇文章主要为大家详细介绍了使用C#将文件读写到SQLite数据库的几种方法,文中的示例代码讲解详细,感兴趣的小伙伴可以参考一下... 目录1. 使用 BLOB 存储文件2. 存储文件路径3. 分块存储文件《文件读写到SQLite数据库China编程的方法》博客中,介绍了文

HDFS—存储优化(纠删码)

纠删码原理 HDFS 默认情况下,一个文件有3个副本,这样提高了数据的可靠性,但也带来了2倍的冗余开销。 Hadoop3.x 引入了纠删码,采用计算的方式,可以节省约50%左右的存储空间。 此种方式节约了空间,但是会增加 cpu 的计算。 纠删码策略是给具体一个路径设置。所有往此路径下存储的文件,都会执行此策略。 默认只开启对 RS-6-3-1024k

HDFS—集群扩容及缩容

白名单:表示在白名单的主机IP地址可以,用来存储数据。 配置白名单步骤如下: 1)在NameNode节点的/opt/module/hadoop-3.1.4/etc/hadoop目录下分别创建whitelist 和blacklist文件 (1)创建白名单 [lytfly@hadoop102 hadoop]$ vim whitelist 在whitelist中添加如下主机名称,假如集群正常工作的节

10. 文件的读写

10.1 文本文件 操作文件三大类: ofstream:写操作ifstream:读操作fstream:读写操作 打开方式解释ios::in为了读文件而打开文件ios::out为了写文件而打开文件,如果当前文件存在则清空当前文件在写入ios::app追加方式写文件ios::trunc如果文件存在先删除,在创建ios::ate打开文件之后令读写位置移至文件尾端ios::binary二进制方式

cross-plateform 跨平台应用程序-03-如果只选择一个框架,应该选择哪一个?

跨平台系列 cross-plateform 跨平台应用程序-01-概览 cross-plateform 跨平台应用程序-02-有哪些主流技术栈? cross-plateform 跨平台应用程序-03-如果只选择一个框架,应该选择哪一个? cross-plateform 跨平台应用程序-04-React Native 介绍 cross-plateform 跨平台应用程序-05-Flutte