Impala 简明教程

Impala - Shell

在前面的章节中,我们已经学习了使用 Cloudera 安装 Impala 及其架构。

  1. Impala shell (command prompt)

  2. Hue (User Interface)

  3. ODBC 和 JDBC(第三方库)

本章说明了如何启动 Impala Shell 以及 Shell 的各种选项。

Impala Shell Command Reference

Impala Shell 的命令分为 general commands, query specific optionstable and database specific options ,如下所示。

General Commands

  1. help

  2. version

  3. history

  4. shell (or) !

  5. connect

  6. exit | quit

Query specific options

  1. Set/unset

  2. Profile

  3. Explain

Table and Database specific options

  1. Alter

  2. describe

  3. drop

  4. insert

  5. select

  6. show

  7. use

Starting Impala Shell

打开 Cloudera 终端,以超级用户身份登录,然后键入 cloudera 作为密码,如下所示。

[cloudera@quickstart ~]$ su
Password: cloudera
[root@quickstart cloudera]#

键入以下命令启动 Impala Shell −

[root@quickstart cloudera] # impala-shell
Starting Impala Shell without Kerberos authentication
Connected to quickstart.cloudera:21000
Server version: impalad version 2.3.0-cdh5.5.0 RELEASE
(build 0c891d79aa38f297d244855a32f1e17280e2129b)
*********************************************************************

Welcome to the Impala shell. Copyright (c) 2015 Cloudera, Inc. All rights reserved.
(Impala Shell v2.3.0-cdh5.5.0 (0c891d7) built on Mon Nov 9 12:18:12 PST 2015)

Want to know what version of Impala you're connected to? Run the VERSION command to
find out!
*********************************************************************
[quickstart.cloudera:21000] >

Impala – General Purpose Commands

以下详解 Impala 的通用命令 −

help command

Impala shell 的 help 命令提供 Impala 中可用命令的列表 −

[quickstart.cloudera:21000] > help;

Documented commands (type help <topic>):
========================================================
compute  describe  insert  set     unset  with  version
connect  explain   quit    show    values use
exit     history   profile select  shell  tip

Undocumented commands:
=========================================
alter create desc drop help load summary

version command

version 命令提供当前的 Impala 版本,如下所示。

[quickstart.cloudera:21000] > version;
Shell version: Impala Shell v2.3.0-cdh5.5.0 (0c891d7) built on Mon Nov 9
12:18:12 PST 2015

Server version: impalad version 2.3.0-cdh5.5.0 RELEASE (build
0c891d79aa38f297d244855a32f1e17280e2129b)

history command

Impala 的 history 命令显示在 shell 中执行的最后 10 条命令。以下是 history 命令的示例。在此例中,我们执行了 5 个命令:版本、帮助、显示、使用和历史记录。

[quickstart.cloudera:21000] > history;
[1]:version;
[2]:help;
[3]:show databases;
[4]:use my_db;
[5]:history;

quit/exit command

你可以使用 quitexit 命令退出 Impala shell,如下所示。

[quickstart.cloudera:21000] > exit;
Goodbye cloudera

connect command

connect 命令用于连接到 Impala 的特定实例。如果你未指定任何实例,则会连接到默认端口 21000 ,如下所示。

[quickstart.cloudera:21000] > connect;
Connected to quickstart.cloudera:21000
Server version: impalad version 2.3.0-cdh5.5.0 RELEASE (build
0c891d79aa38f297d244855a32f1e17280e2129b)

Impala Query Specific Options

Impala 的查询特定命令接受查询。它们如下所示 −

Explain

explain 命令返回给定查询的执行计划。

[quickstart.cloudera:21000] > explain select * from sample;
Query: explain select * from sample
+------------------------------------------------------------------------------------+
| Explain String                                                                     |
+------------------------------------------------------------------------------------+
| Estimated Per-Host Requirements: Memory = 48.00MB VCores = 1                       |
| WARNING: The following tables are missing relevant table and/or column statistics. |
| my_db.customers                                                                    |
| 01:EXCHANGE [UNPARTITIONED]                                                        |
| 00:SCAN HDFS [my_db.customers]                                                     |
| partitions = 1/1 files = 6 size = 148B                                             |
+------------------------------------------------------------------------------------+
Fetched 7 row(s) in 0.17s

Profile

profile 命令显示有关最近查询的底层信息。此命令用于诊断和执行查询性能调优。以下是 profile 命令的示例。在此场景中, profile 命令返回 explain 查询的底层信息。

[quickstart.cloudera:21000] > profile;

Query Runtime Profile:
Query (id=164b1294a1049189:a67598a6699e3ab6):

   Summary:
      Session ID: e74927207cd752b5:65ca61e630ad3ad
      Session Type: BEESWAX
      Start Time: 2016-04-17 23:49:26.08148000 End Time: 2016-04-17 23:49:26.2404000
      Query Type: EXPLAIN
      Query State: FINISHED
      Query Status: OK
      Impala Version: impalad version 2.3.0-cdh5.5.0 RELEASE (build 0c891d77280e2129b)
      User: cloudera
      Connected User: cloudera
      Delegated User:
      Network Address:10.0.2.15:43870
      Default Db: my_db
      Sql Statement: explain select * from sample
      Coordinator: quickstart.cloudera:22000
      : 0ns
      Query Timeline: 167.304ms
         - Start execution: 41.292us (41.292us) - Planning finished: 56.42ms (56.386ms)
         - Rows available: 58.247ms (1.819ms)
         - First row fetched: 160.72ms (101.824ms)
         - Unregister query: 166.325ms (6.253ms)

   ImpalaServer:
      - ClientFetchWaitTimer: 107.969ms
      - RowMaterializationTimer: 0ns

Table and Database Specific Options

下表列出了 Impala 中的表和数据特定选项。

Sr.No

Command & Explanation

1

Alter The alter 命令用于更改 Impala 中表的结构和名称。

2

Impala 的 Describe 命令提供表的元数据。它包含列及其数据类型等信息。 describe 命令的简写为 desc

3

Drop 命令用于从 Impala 中删除构造,其中构造可以是表、视图或数据库函数。

4

Impala 的 insert 命令用于将数据(列)追加到表中。覆盖现有表的数据。覆盖现有表的数据。

5

select 语句用于对特定数据集执行所需的操作。它指定要完成某个操作的数据集。你可以打印或存储(在文件中)select 语句的结果。

6

Impala 的 show 语句用于显示各种构造(例如表、数据库和表)的元存储。

7

Impala 的 use 语句用于将当前上下文更改为所需数据库。