Impala(一) 基本使用

Impala DEMO

impala shell

[root@flinkhadoop ~]# impala-shell 
Starting Impala Shell without Kerberos authentication
Opened TCP connection to flinkhadoop:21000
Connected to flinkhadoop:21000
Server version: impalad version 3.2.0-cdh6.3.0 RELEASE (build 495397101e5807c701df71ea288f4815d69c2c8a)
***********************************************************************************
Welcome to the Impala shell.
(Impala Shell v3.2.0-cdh6.3.0 (4953971) built on Thu Jul 18 10:24:11 PDT 2019)

Run the PROFILE command after a query has finished to see a comprehensive summary
of all the performance and diagnostic information that Impala gathered for that
query. Be warned, it can be very long!
***********************************************************************************

HUE

SELECT * FROM student;

insert into student values(2, "s2");
insert into student values(3, "s3");
insert into student values(4, "s4");

數據類型

image-20200510134111653

注意:Impala 雖然支持 array,map,struct 複雜數據類型,但是支持並不完全,一般處理方 法,將複雜類型轉化爲基本類型,通過 hive 創建表。

DML & DDL

DDL

CREATE DATABASE [IF NOT EXISTS] database_name
[COMMENT database_comment]
[LOCATION hdfs_path];

數據庫管理

#------------------------ 創建數據庫 ——---------------------
create database hive_db;
 
 show databases;

 show databases like 'hive*';


 describe database hive_db;


#---------------------------- 刪除數據庫 ---------------------
 drop database hive_db;
 ## 級聯刪除,會將表刪除
 drop database hive_db cascade;

注:

Impala 不支持 alter database 語法

當數據庫被 USE 語句選中時,無法刪除

表管理

內部表
drop table if exists student2;
create table if not exists student2(
id int, name string
)
row format delimited fields terminated by '\t'
stored as textfile
location '/user/hive/warehouse/student2';
#--------------------------
describe formatted student2;


外部表
create external table stu_external(
 id int,
 name string)
 row format delimited fields terminated by '\t' ;
分區表
create table stu_par(id int, name string)
 partitioned by (month string)
 row format delimited
 fields terminated by '\t';
 
 #----------------------  加載數據 ---------------------------------------
alter table stu_par add partition (month='201810');

load data inpath '/user/admin/student.txt' into table stu_par partition(month='201810');

insert into table stu_par partition (month = '201811') select * from student;
 
 #----------------------  查詢分區表裏面的數據 ----------------------------
 select * from stu_par where month = '201811';
 
 #------------------------ 增加多個分區 ----------------------------------
alter table stu_par add partition (month='201812') partition (month='201813');

#-------------------------------刪除分區---------------------------------
alter table stu_par drop partition (month='201812');

#-------------------------------查看分區---------------------------------
show partitions stu_par;

image-20200510134820317

DML 數據操作

與hive基本一致

數據導入

impala 不支持 load data local inpath…

數據導出

  1. impala 不支持 insert overwrite…語法導出數據

​ 2. impala 數據導出一般使用 impala -o

  1. Impala 不支持 export 和 import 命令

查詢

  1. 基本的語法跟 hive 的查詢語句大體一樣

  2. Impala 不支持 CLUSTER BY, DISTRIBUTE BY, SORT BY

  3. Impala 中不支持分桶表

  4. Impala 不支持 COLLECT_SET(col)和 explode(col)函數

  5. Impala 支持開窗函數

存儲和壓縮

image-20200510132635240

Impala 附錄

impala shell 命令

image-20200510131346457

impala 操作命令

image-20200510131431311

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章