Presto教程

Presto HIVE 连接器

Hive 连接器允许查询存储在 Hive 数据仓库中的数据。

先决条件

Hadoop 蜂巢
希望你已经在你的机器上安装了 Hadoop 和 Hive。在新终端中将所有服务一一启动。然后,使用以下命令启动 hive Metastore,
hive--service metastore
Presto 使用 Hive Metastore 服务获取 Hive 表的详细信息。

配置设置

"etc/catalog"目录下创建一个文件 "hive.properties"。使用以下命令。
$ cd etc 
$ cd catalog 
$ vi hive.properties  
connector.name = hive-cdh4 
hive.metastore.uri = thrift://localhost:9083
完成所有更改后,保存文件并退出终端。

创建数据库

使用以下查询在 Hive 中创建数据库-

查询

hive> CREATE SCHEMA tutorials; 
创建数据库后,您可以使用 "show databases"命令进行验证。

创建表

Create Table 是用于在 Hive 中创建表的语句。例如,使用以下查询。
hive> create table author(auth_id int, auth_name varchar(50), 
topic varchar(100) STORED AS SEQUENCEFILE;

插入表格

以下查询用于在 hive 的表中插入记录。
hive> insert into table author values (1,’ Doug Cutting’,Hadoop),
(2,’ James Gosling’,java),(3,’ Dennis Ritchie’,C);

启动 Presto CLI

您可以使用以下命令启动 Presto CLI 连接 Hive 存储插件。
$ ./presto--server localhost:8080--catalog hive —schema tutorials; 
您将收到以下回复。
presto:tutorials >

列出架构

要列出 Hive 连接器中的所有架构,请键入以下命令。

查询

presto:tutorials > show schemas from hive;

结果

default  
tutorials 

列出表格

要列出"tutorials"模式中的所有表,请使用以下查询。

查询

presto:tutorials > show tables from hive.tutorials; 

结果

author

获取表

以下查询用于从 hive 的表中获取所有记录。

查询

presto:tutorials > select * from hive.tutorials.author; 

结果

auth_id  |   auth_name    | topic 
---------+----------------+--------
       1 | Doug Cutting   | Hadoop 
       2 | James Gosling  | java 
       3 | Dennis Ritchie | C
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4