3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[Oracle Cloud] Presto から Object Storage のデータを参照する

Last updated at Posted at 2020-05-02

はじめに

Presto から、OCI Object Storage へ参照するための手順を確認します。Object Storage には、S3互換API があり、これを使用してアクセスが出来ます。

Hive/Hadoop や Hive Metastore(MySQL) の環境は、こちらの記事で構築しています。
Presto の環境は、こちらの記事で構築しています。

Customer Secret Keys 生成

Object Storage を S3 API でアクセスするためには、OCI IAM ユーザー上で、Customer Secret Key を生成する必要があります。Customer Secret Key を生成することで、Access Key と Secret Key が生成されます。この2種類の Key が必要です。

OCI Console の右上のユーザー名を選択して、ユーザーの詳細画面へ移動します。

1581848373047.png

Customer Secret Keys のメニューに移動して、Generate Secret Key を押します

1581848412021.png

適当に NAME を指定して、Generate Secret Key を押します。

  • NAME : s3 compat

1581848435665.png

Key が表示されます。これは Secret Key です (画像のものは、現在無効化しています)

1581848454945.png

画面を戻すと、Access Key が表示されています。

1581848491080.png

Object Storage の Endpoint

OCI 上で次の2つの情報を確認すると、Endpoint を把握することが出来ます

  • Region Identifier
  • Bucket の Namespace

Region Identifier は、次の Document に書かれています

1584623537839.png

Bucket の Namespaceは、OCI Console で詳細を開くと確認できます。

1584623605964.png

これを、以下の書式にあてはめると、S3互換APIのEndpointがわかります

https://<Namespace>.compat.objectstorage.<Region Identifier>.oraclecloud.com

Hive Connector の設定

Hive Connector の設定を行い、Hive Metastore や OCI Object Storage (S3互換API) を参照するための設定をします

  • hive.s3.use-instance-credentials : IAM Role は使えないため false
  • hive.s3.aws-access-key : 67f023eb4fe062a937922730caf4d6485c078bea
  • hive.s3.aws-secret-key : tDMuNoytFCLE4ol25lW159x8582oPO2s+gBuSexnrHa=
  • hive.s3.endpoint : https://nryjxkqe0mhq.compat.objectstorage.ap-tokyo-1.oraclecloud.com
  • hive.s3.path-style-access : true
  • hive.s3.ssl.enabled : false
cat <<'EOF' > ~/presto/presto-server-0.227/etc/catalog/hive.properties
connector.name=hive-hadoop2
hive.metastore.uri=thrift://10.0.0.12:9083
hive.s3.use-instance-credentials=false
hive.s3.aws-access-key=67f023eb4fe062a937922730caf4d6485c078bea
hive.s3.aws-secret-key=tDMuNoytFCLE4ol25lW159x8582oPO2s+gBuSexnrHa=
hive.s3.endpoint=https://nryjxkqe0mhq.compat.objectstorage.ap-tokyo-1.oraclecloud.com
hive.s3.path-style-access=true
EOF

Hive 側で Metastore 用サービス起動

Hive を構成しているサーバーにSSHログインして、Metastore に接続するためのサービスを起動します。いわゆる、リモートメタストアと言われる接続方式らしいです。

フォアグラウンドで起動

$HIVE_HOME/bin/hive --service metastore

バックグラウンド起動

nohup $HIVE_HOME/bin/hive --service metastore &

Hive側で、External Table の指定

次のURLに書かれている内容を、既にHive側で実施しています。実施してない場合は、実施します。

https://qiita.com/sugimount/items/80e2b201c43856f74166#hive-%E3%82%B3%E3%83%9E%E3%83%B3%E3%83%89%E3%81%A7-object-storage-%E3%81%AB%E6%8E%A5%E7%B6%9A

動作確認

それでは、Presto を使用して、S3互換のObject Storageへアクセスしてみます。まずは、presto cli を起動します。

~/presto/presto-server-0.227/bin/presto --server localhost:8080 --catalog hive

use で、hive.<データベース名> を指定します。

use hive.sugi;

Hive側で定義済みの External Table の定義を使用して、Select します。

select * from test1 limit 20;

実行例
次のように、Object Storage 上のデータを確認できます。

presto:sugi> select * from test1 limit 20;
 rank |   name   
------+----------
    1 | satou
    2 | suzuki
    3 | tanaka
    4 | sugiyama
    5 | kato
(5 rows)

Query 20200502_161051_00012_y7m8a, FINISHED, 1 node
Splits: 19 total, 19 done (100.00%)
0:00 [5 rows, 71B] [13 rows/s, 196B/s]

presto:sugi>

参考URL

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?