Apache Presto - HIVE 聯結器



Hive 聯結器允許查詢儲存在 Hive 資料倉庫中的資料。

先決條件

  • Hadoop
  • Hive

希望您已在您的機器上安裝了 Hadoop 和 Hive。在新終端中逐個啟動所有服務。然後,使用以下命令啟動 Hive 元儲存,

hive --service metastore

Presto 使用 Hive 元儲存服務來獲取 Hive 表的詳細資訊。

配置設定

在“etc/catalog”目錄下建立檔案“hive.properties”。使用以下命令。

$ cd etc 
$ cd catalog 
$ vi hive.properties  

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

完成所有更改後,儲存檔案並退出終端。

建立資料庫

使用以下查詢在 Hive 中建立一個數據庫 −

查詢

hive> CREATE SCHEMA tutorials; 

建立資料庫後,您可以使用“show databases”命令對其進行驗證。

建立表

建立表是一個用於在 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
廣告
© . All rights reserved.