Presto連線Hive
版權宣告:本文為博主原創文章,未經博主允許不得轉載。https://blog.csdn.net/kongxx/article/details/83409435
接前一篇文章,這裡只說怎樣連線Hive。
配置 Hive Connector
- etc/catalog/hive.properties
connector.name=hive-hadoop2 hive.metastore.uri=thrift://<hive_metastore_ip>:9083 hive.config.resources=/opt/presto-server-0.211/etc/cluster/core-site.xml,/opt/presto-server-0.211/etc/cluster/hdfs-site.xml
其中 hive.metastore.uri 可以從 hive-site.xml 檔案中獲取。
將配置複製到其它節點的相同目錄下。
hdfs 配置檔案
從 hdfs 的環境中複製 core-site.xml 和 hdfs-site.xml 檔案到 presto 的 etc/cluster 目錄下。
將配置複製到其它節點的相同目錄下。
啟動 Prestore
分別在兩個節點上重新啟動 Presto 服務。
在 Hive 中建立資料庫、資料表和資料
$ hive # 建立資料庫 hive> create schema test; # 查詢資料庫 hive> show databases; +---------------------+ |database_name| +---------------------+ | default| | information_schema| | sys| | test| +---------------------+ # 顯示資料庫中的表 hive> show tables from test; +-----------+ | tab_name| +-----------+ +-----------+ # 建立資料表 hive> CREATE TABLE test.users(id int, username string, password string) ROW FORMAT DELIMITED FIELDS TERMINATED BY ','; ... # 插入資料 hive> insert into table test.users values (1, 'user1', 'password1'), (2, 'user2', 'password2'), (3, 'user3', 'password3'); ... # 查詢資料 hive> select * from test.users; +-----------+-----------------+-----------------+ | users.id| users.username| users.password| +-----------+-----------------+-----------------+ | 1| user1| password1| | 2| user2| password2| | 3| user3| password3| +-----------+-----------------+-----------------+
通過 Presto 查詢資料
# 啟動 presto 命令列 $ ./presto --server bd1:8080 --catalog hive --schema test # 查詢資料庫 presto:test> show schemas from hive; Schema -------------------- default information_schema sys test (4 rows) # 查詢資料表 presto:test> show tables from hive.test; Table -------- users users2 (2 rows) # 查詢資料 presto:test> select * from hive.test.users; id | username | password ----+----------+---------- (0 rows)