本页面展示了将 Apache Hive 与 Dataproc Metastore 服务搭配使用的示例。在此示例中,您将在 Managed Service for Apache Spark 集群上启动 Hive 会话,然后运行示例命令来创建数据库和表。
准备工作
连接到 Apache Hive
如需开始使用 Hive,请使用 SSH 连接到与您的 Dataproc Metastore 服务关联的 Managed Service for Apache Spark 集群。连接后,您可以在浏览器中使用 SSH 终端窗口运行 Hive 命令来管理元数据。
连接到 Hive
- 在 Google Cloud 控制台中,前往虚拟机实例页面。
- 在虚拟机实例列表中,点击要连接的 Managed Service for Apache Spark 虚拟机实例所在行中的 SSH。
此时会打开一个浏览器窗口,并显示节点上的主目录,其中包含类似于以下内容的输出:
Connected, host fingerprint: ssh-rsa ...
Linux cluster-1-m 3.16.0-0.bpo.4-amd64 ...
...
example-cluster@cluster-1-m:~$
如需启动 Hive 并创建数据库和表,请在 SSH 会话中运行以下命令:
启动 Hive。
hive创建一个名为
myDatabase的数据库。create database myDatabase;显示您创建的数据库。
show databases;使用您创建的数据库。
use myDatabase;创建一个名为
myTable的表。create table myTable(id int,name string);列出
myDatabase下的表格。show tables;在您创建的表格中显示表格行。
desc myTable;
运行以下命令会生成类似于以下内容的输出:
$hive
hive> show databases;
OK
default
hive> create database myDatabase;
OK
hive> use myDatabase;
OK
hive> create table myTable(id int,name string);
OK
hive> show tables;
OK
myTable
hive> desc myTable;
OK
id int
name string