hdfs_fdw
hdfs 外部数据包装器
概览
| 扩展包名 | 版本 | 分类 | 许可证 | 语言 |
|---|---|---|---|---|
hdfs_fdw | 2.3.3 | FDW | BSD 3-Clause | C |
| ID | 扩展名 | Bin | Lib | Load | Create | Trust | Reloc | 模式 |
|---|---|---|---|---|---|---|---|---|
| 8740 | hdfs_fdw | 否 | 是 | 否 | 是 | 否 | 否 | - |
| 相关扩展 | pg_parquet mongo_fdw kafka_fdw wrappers multicorn jdbc_fdw aws_s3 duckdb_fdw |
|---|
版本
| 类型 | 仓库 | 版本 | PG 大版本 | 包名 | 依赖 |
|---|---|---|---|---|---|
| EXT | PGDG | 2.3.3 | 1817161514 | hdfs_fdw | - |
| RPM | PGDG | 2.3.3 | 1817161514 | hdfs_fdw_$v | - |
安装
您可以直接安装 hdfs_fdw 扩展包的预置二进制包,首先确保 PGDG 仓库已经添加并启用:
pig repo add pgdg -u # 添加 PGDG 仓库并更新缓存
使用 pig 或者是 apt/yum/dnf 安装扩展:
pig install hdfs_fdw; # 当前活跃 PG 版本安装
pig ext install -y hdfs_fdw -v 18 # PG 18
pig ext install -y hdfs_fdw -v 17 # PG 17
pig ext install -y hdfs_fdw -v 16 # PG 16
pig ext install -y hdfs_fdw -v 15 # PG 15
pig ext install -y hdfs_fdw -v 14 # PG 14
dnf install -y hdfs_fdw_18 # PG 18
dnf install -y hdfs_fdw_17 # PG 17
dnf install -y hdfs_fdw_16 # PG 16
dnf install -y hdfs_fdw_15 # PG 15
dnf install -y hdfs_fdw_14 # PG 14
创建扩展:
CREATE EXTENSION hdfs_fdw;
用法
创建服务器
CREATE EXTENSION hdfs_fdw;
CREATE SERVER hdfs_server FOREIGN DATA WRAPPER hdfs_fdw
OPTIONS (host '127.0.0.1', port '10000', client_type 'hiveserver2');
服务器选项: host(默认 localhost)、port(默认 10000)、client_type(hiveserver2 或 spark,默认 hiveserver2)、auth_type(NOSASL 或 LDAP)、connect_timeout(默认 300)、fetch_size(默认 10000)、log_remote_sql(默认 false)、use_remote_estimate(默认 false)、enable_join_pushdown(默认 true)、enable_aggregate_pushdown(默认 true)、enable_order_by_pushdown(默认 true)。
创建用户映射
CREATE USER MAPPING FOR postgres SERVER hdfs_server
OPTIONS (username 'hive_user', password 'hive_password');
对于 NOSASL 认证,完全省略 OPTIONS 子句。
创建外部表
CREATE FOREIGN TABLE weblogs (
client_ip text,
http_status_code text,
uri text,
request_count bigint
)
SERVER hdfs_server
OPTIONS (dbname 'default', table_name 'weblogs');
表选项: dbname(默认 default)、table_name(默认为外部表名)、enable_join_pushdown、enable_aggregate_pushdown、enable_order_by_pushdown。
查询
SELECT client_ip, count(*) FROM weblogs GROUP BY client_ip ORDER BY count(*) DESC LIMIT 10;
Spark 示例
CREATE SERVER spark_server FOREIGN DATA WRAPPER hdfs_fdw
OPTIONS (host '127.0.0.1', port '10000', client_type 'spark');
CREATE USER MAPPING FOR postgres SERVER spark_server
OPTIONS (username 'spark_user', password 'spark_pass');
CREATE FOREIGN TABLE spark_table (
id int,
name text,
value double precision
)
SERVER spark_server
OPTIONS (dbname 'default', table_name 'my_table');
下推特性
hdfs_fdw 将 WHERE 子句、JOIN、聚合函数、ORDER BY 和 LIMIT/OFFSET 下推到远程 Hive/Spark 服务器。在会话级别控制下推:
SET hdfs_fdw.enable_join_pushdown = on;
SET hdfs_fdw.enable_aggregate_pushdown = on;
SET hdfs_fdw.enable_order_by_pushdown = on;
SET hdfs_fdw.enable_limit_pushdown = on;