Hive数据表操作(增删改查)

一、创建表

  • 基本创建形式,没有指定分隔字符的形式,默认采用\001在文本编辑器中显示SOH,在vim中显示为^A

    
    create table test_tb(
    	id int
    )
    
  • 指定分隔符创建,row format delimited指定使用hive自带的方法类进行分隔,fields terminated by ‘,‘指定分隔方式为字段方式,符号是’,’

    create table test_tb_f(
    	id int,
        name string,
        age int,
        gender string
    )row format delimited
    fields terminated by ',';
    

二、查看数据表

  • 详情信息查看

    desc extended test_tb_f;
    
  • 详情信息格式化查看

    desc formatted test_tb_f;
    
  • 查看字段信息

    desc test_tb_f;
    
  • 查看建表语句

    show create table test_tb_f;
    

三、删除数据表

  • 删除整个表(删除整张表,包括元数据信息)

    drop table python.test_tb;
    
  • 删除表数据(删除表数据,不删除元数据)

    truncate table test_tb_f;
    

四、修改数据表

  • 修改表属性

    alter table test_tb_f set tblproperties('name'='EuropeanSheik');
    
  • 修改表名

    alter table test_tb_f rename to test_tb;
    
  • 修改表字段属性

    alter table test_tb change id id string;
    
  • 修改字段名

    alter table test_tb change name username string;
    
  • 添加新字段

    alter table test_tb add columns(address string);
    
  • 修改表的存储路径

    alter table test_tb set location '/ming';
    
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Hive和HBase是两个不同的数据存储系统,它们的询语言也不一样。Hive使用HQL(Hive Query Language)来询数据,而HBase使用Java API或HBase Shell来询数据。 下面是Hive中的常见操作示例: 1. 询数据 ``` SELECT * FROM table_name; ``` 2. 插入数据 ``` INSERT INTO TABLE table_name VALUES (value1, value2, ...); ``` 3. 更新数据 ``` UPDATE table_name SET column_name = new_value WHERE condition; ``` 4. 删除数据 ``` DELETE FROM table_name WHERE condition; ``` 下面是HBase中的常见操作示例: 1. 询数据 使用Java API: ``` Get get = new Get(Bytes.toBytes("row_key")); Result result = table.get(get); ``` 使用HBase Shell: ``` get 'table_name', 'row_key' ``` 2. 插入数据 使用Java API: ``` Put put = new Put(Bytes.toBytes("row_key")); put.addColumn(Bytes.toBytes("column_family"), Bytes.toBytes("column_name"), Bytes.toBytes("value")); table.put(put); ``` 使用HBase Shell: ``` put 'table_name', 'row_key', 'column_family:column_name', 'value' ``` 3. 更新数据 使用Java API: ``` Put put = new Put(Bytes.toBytes("row_key")); put.addColumn(Bytes.toBytes("column_family"), Bytes.toBytes("column_name"), Bytes.toBytes("new_value")); table.put(put); ``` 使用HBase Shell: ``` put 'table_name', 'row_key', 'column_family:column_name', 'new_value' ``` 4. 删除数据 使用Java API: ``` Delete delete = new Delete(Bytes.toBytes("row_key")); delete.addColumn(Bytes.toBytes("column_family"), Bytes.toBytes("column_name")); table.delete(delete); ``` 使用HBase Shell: ``` delete 'table_name', 'row_key', 'column_family:column_name' ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值