PrestoでHive Warehouseデータを分析する
このページではPrestoのHive Connectorを使用して、Hive data warehouseに保存されたデータを分析する方法をご説明します。
Reference Architecture
PrestoはInteractive Query 用途、HiveはBatch Query中心に使われます。Oozie, Airflowのようなアプリを使用して配置作業をスケジューリングできます。
PrestoはConnectorを使って多様なデータソースにアクセスできるだけでなく、一つのクエリで複数のデータソースに質疑できます。Hive Connectorを使用するとPrestoはHive metadataとwarehouseに保存されたデータのみ使用し、HiveQLまたはHiveのクエリの実行エンジン(MapReduce)は使いません。
Configuration
Ambari ServerのPresto > Configs > Advanced connectors.propertiesで connectorに関する設定を変更できます。
connectors.to.add
には追加する connector, connectors.to.delete
には削除するconnectorを入力します。
Prestoは使用する Connectorの個体ごとに /etc/presto/catalog
の下にconfigファイル(<connector-name>.properties
)が必要です。従って複数のHiveクラスタをPrestoと連動するためには、そのクラスタごとにそれぞれのconfig ファイルが必要です。
connector-name-1.properties
, connector-name-2.properties
ファイルを作成するためには、次のように connectors.to.add
に設定します。
{"connector-name-1":["key1=value1",
"key2=value2",
"key3=value3"],
"connector-name-2": ["key1=value1"]
}
ここではHive Connectorを追加する必要があるので、 connectors.to.add
に以下のように入力します。サービスをリスタートして新たな構成を反映します。
{"hive":["connector.name=hive-hadoop2",
"hive.metastore.uri=thrift://<METASTORE-HOST-IP>:9083",
"hive.config.resources=/etc/hadoop/conf/core-site.xml,/etc/hadoop/conf/hdfs-site.xml",
"hive.s3.use-instance-credentials=false",
"hive.s3.aws-access-key=<API-ACCESS-KEY>",
"hive.s3.aws-secret-key=<API-SECRET-KEY>",
"hive.s3.endpoint=https://kr.object.ncloudstorage.com"]
}
参考 Hadoopの構成ファイル(
/etc/hadoop/conf/core-site.xml
,/etc/hadoop/conf/hdfs-site.xml
)が Prestoを実行するノードに存在しなければなりません。
その他configuration項目は Presto Documentationで確認できます。
Querying Hive Tables
Presto CLI の実行
Presto CLI コンポーネントが設置されたノードにアクセスして以下のようにCLIを実行します。
/usr/lib/presto/bin/presto-cli --server <COORDINATOR-HOST-IP>:8285 --catalog hive --schema default
クエリの実行
Hiveのdefault データベース内にあるテーブルを対象にクエリを実行できます。