Apache Presto - HIVE连接器

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

先决条件

  • Hadoop

  • Hive

希望您已在机器上安装Hadoop和Hive.在新终端中逐个启动所有服务.然后,使用以下命令启动hive Metastore,

hive --service metastore

Presto使用Hive Metastore服务获取hive表的详细信息.

配置设置

创建文件"hive.properties " "etc/catalog"目录下.使用以下命令.

$ cd etc 
$ cd catalog 
$ vi hive.properties  

connector.name = hive-cdh4 
hive.metastore.uri = thrift://localhost:9083

完成所有更改后,保存文件并退出终端.

创建数据库

使用以下查询 :

$ b在Hive中创建数据库$ b

查询

hive> CREATE SCHEMA tutorials;

创建数据库后,您可以使用"show databases"命令对其进行验证.

创建表

创建表是用于在Hive中创建表的语句.例如,使用以下查询.

hive> create table author(auth_id int, auth_name varchar(50), 
topic varchar(100) STORED AS SEQUENCEFILE;

Insert Table

以下查询用于在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 >

List Schemas

要列出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