You need to enable JavaScript to run this app.
导航

Impala 基础操作

最近更新时间2022.10.24 14:21:05

首次发布时间2022.10.24 14:21:05

本文描述对 Impala 的创建数据库,创建表,写入数据,查询表等基本操作。

1 前提条件

  1. 已创建包含 Impala 组件服务的 E-MapReduce(EMR)集群,详情请参见 创建集群

  2. 使用 SSH 方式登录到集群 master-1 节点,即 statestored 和 catalogd 所在的节点,详情请参见使用 SSH连接主节点

  3. 目前 Impala 组件是白名单开放,您可通过 创建工单 的方式,申请使用。

2 创建数据库

  1. 登录集群节点后,您可以使用 impala-shell 命令,进入到 impala:
root@emr-4nw5w1f78f3xxx-master-1:~# impala-shell 
/opt/emr/2.0.0/impala-3.4.1/shell/impala-shell-3.4.1-RELEASE/ext-py2/bitarray-0.9.0-py2.7-linux-x86_64.egg/bitarray/_bitarray.py:3: UserWarning: Module backports was already imported from None, but /usr/lib/python2.7/dist-packages is being added to sys.path
Starting Impala Shell without Kerberos authentication
Opened TCP connection to emr-4nw5w1f78f3xxx-master-1:21000
Connected to emr-4nw5w1f78f3xxx-master-1:21000
Server version: impalad version 3.4.1-RELEASE RELEASE (build eb1ed66fa435a722fa8c6a7c58ff53edc10c572e)
***********************************************************************************
Welcome to the Impala shell.
(Impala Shell v3.4.1-RELEASE (eb1ed66) built on Fri Sep 16 15:03:38 CST 2022)
 
Want to know what version of Impala you're connected to? Run the VERSION command to
find out!
***********************************************************************************
[emr-4nw5w1f78f3xxx-master-1:21000] default>
  1. 创建数据库
[emr-4nw5w1f78f3xxx-master-1:21000] default> create database first_db;
Query: create database first_db
+----------------------------+
| summary                    |
+----------------------------+
| Database has been created. |
+----------------------------+
Fetched 1 row(s) in 5.36s

3 创建表

  1. 选择数据库
[emr-4nw5w1f78f3xxx-master-1:21000] default> use first_db;
Query: use first_db
  1. 创建 parquet 格式表
[emr-4nw5w1f78f3xxx-master-1:21000] first_db> CREATE TABLE parquet_table ( id INT) STORED AS PARQUET;
Query: CREATE TABLE parquet_table ( id INT) STORED AS PARQUET
+-------------------------+
| summary                 |
+-------------------------+
| Table has been created. |
+-------------------------+
Fetched 1 row(s) in 5.26s

4 写入数据

[emr-4nw5w1f78f3xxx-master-1:21000] first_db> insert into parquet_table values(1);
Query: insert into parquet_table values(1)
Query submitted at: 2022-10-17 16:52:34 (Coordinator: http://emr-4nw5w1f78f3xxx-core-1:25000)
Query progress can be monitored at: http://emr-4nw5w1f78f3xxx-core-1:25000/query_plan?query_id=8549b1a1cd09d63d:f8d8828f00000000
Modified 1 row(s) in 15.70s

5 查询数据

[emr-4nw5w1f78f3xxx-master-1:21000] first_db> select * from parquet_table;
Query: select * from parquet_table
Query submitted at: 2022-10-17 16:53:10 (Coordinator: http://emr-4nw5w1f78f3xxx-core-1:25000)
Query progress can be monitored at: http://emr-4nw5w1f78f3xxx-core-1:25000/query_plan?query_id=5744559c2307a8b9:a411428400000000
+----+
| id |
+----+
| 1  |
+----+
Fetched 1 row(s) in 0.26s

6 删除表

[emr-4nw5w1f78f3xxx-master-1:21000] first_db> drop table parquet_table;
Query: drop table parquet_table
+-------------------------+
| summary                 |
+-------------------------+
| Table has been dropped. |
+-------------------------+
Fetched 1 row(s) in 5.23s