Impala的简单使用

  • 创建表
create table if not exists touch.table_test(
  name string comment '姓名',
  age int not null comment '年龄',
  sex tinyint not null comment '性别',
  create_time timestamp not null comment '创建时间',
  primary key(name) 
  ) partition  by hash(name) partitions  10 
stored as kudu
  • 查看表定义
describe table_test
  • 修改表的指定列
ALTER TABLE table_test CHANGE name user_name String
  • 表的添加某些列
ALTER TABLE table_test ADD COLUMNS( update_time timestamp)
ALTER TABLE table_test ADD COLUMNS( email string,phone string)
  • 表的删除指定列
ALTER TABLE table_test drop sex
  • 表的插入数据
insert into table_test values('ggr',23,now(),now(),'[email protected]','17895642365');
  • 表的更新数据
insert overwrite table_test values('ggr',24,now(),now(),'[email protected]','17895642365');
//2.8版本之后
UPSERT INTO kudu_table (pk, c1, c2, c3) VALUES (0, 'hello', 50, true), (1, 'world', -1, false);

UPSERT INTO production_table SELECT * FROM staging_table;
 | Impala SQL Language Reference | 418
UPSERT INTO production_table SELECT * FROM staging_table WHERE c1 IS NOT
 NULL AND c2 > 0;

  • 表的查询数据
SELECT * FROM table_test;
SELECT user_name,age FROM table_test;   
  • 视图
Create View IF NOT EXISTS view_name as Select statement
DROP VIEW database_name.view_name;
ALTER VIEW database_name.view_name为Select语句
  • Order by 排序
select * from table_name ORDER BY col_name [ASC|DESC] [NULLS FIRST|NULLS LAST]
  • Group by分组
select data from table_name Group BY col_name;
  • Having 子句
    Impala中的Having子句允许您指定过滤哪些组结果显示在最终结果中的条件。
    一般来说,Having子句与group by子句一起使用; 它将条件放置在由GROUP BY子句创建的组上。
select * from table_name ORDER BY col_name [ASC|DESC] [NULLS FIRST|NULLS LAST]
  • DISTINCT运算符(去重)
select distinct columns… from table_name;
  • Union 使用
select * from customers order by id limit 3
 union select * from employee order by id limit 3;
  • 偏移量(offset) & 限制(limit)
    OFFSET 需要使用order by 条件语句配合。
select * from table_test order by create_time limit 2 offset 1

你可能感兴趣的:(Impala的简单使用)