【发布时间】:2021-07-27 22:53:50
【问题描述】:
我想配置 Presto 以在 AWS S3 中查询 ORC 文件。根据文档,必须配置 Hive Metastore。此元存储将收集表的所有模式。由于我有现有的 ORC 文件,有什么方法可以使用应该嵌入到 ORC 文件中的现有表的方案自动填充此元存储?
提前感谢您的帮助!
【问题讨论】:
标签: amazon-s3 hive presto orc metastore
我想配置 Presto 以在 AWS S3 中查询 ORC 文件。根据文档,必须配置 Hive Metastore。此元存储将收集表的所有模式。由于我有现有的 ORC 文件,有什么方法可以使用应该嵌入到 ORC 文件中的现有表的方案自动填充此元存储?
提前感谢您的帮助!
【问题讨论】:
标签: amazon-s3 hive presto orc metastore
这是完全可能的,但如果 ORC 编写器与 Trino 不兼容,它有时可能会失败 (formerly known as PrestoSQL)。这不太可能,但应该注意。
第一步是使架构正确。您可以通过使用 uber orc-tools.jar 和 meta 命令打印出 orc 模式来做到这一点。查看更多:https://orc.apache.org/docs/java-tools.html
java -jar orc-tools-1.6.7-uber.jar meta bucket_00001.orc
Processing data file bucket_00001.orc [length: 78511]
Structure for bucket_00001.orc
File Version: 0.12 with PRESTO_ORIGINAL
Rows: 1500
Compression: ZLIB
Compression size: 262144
Calendar: Julian/Gregorian
Type: struct<custkey:bigint,name:string,address:string,nationkey:bigint,phone:string,acctbal:double,mktsegment:string,comment:string>
您将需要使用输出中的 Type 结构。您还需要确保架构在所有 ORC 文件之间保持一致。
下一步是将 Type 结构体转换为 CREATE TABLE 语句,如下所示:
CREATE TABLE hive.default.customer (
custkey BIGINT,
name VARCHAR,
address VARCHAR,
nationkey BIGINT,
phone VARCHAR,
acctbal DOUBLE,
mktsegment VARCHAR,
comment VARCHAR
);
创建表后,您应该能够开始查询,除非您的表中有分区。如果是这种情况,您将需要同步 Hive 元存储(或可能是文件元存储)以将现有分区位置添加到元存储。
假设您在上面的nationkey 列上有一个分区,您的CREATE TABLE 语句将如下所示:
CREATE TABLE hive.default.customer (
custkey BIGINT,
name VARCHAR,
address VARCHAR,
phone VARCHAR,
acctbal DOUBLE,
mktsegment VARCHAR,
comment VARCHAR,
nationkey BIGINT
) WITH (
partitioned_by = ARRAY['nationkey']
);
然后您会想要同步,这可以通过 system.sync_partition_metadata procedure 完成。
这看起来像这样:
CALL system.sync_partition_metadata('default', 'customer', 'ADD');
还有a demo of doing this in the Trino Community Broadcast(当时 Trino 还叫 PrestoSQL)。
【讨论】: