Hive事务表转换为非事务表

环境:hive3.1.0

由于建表时默认会建为非事务表
CREATE TABLE bucket_text_table2(column1 string,column2 string,column3 int) CLUSTERED BY (column3) into 5 BUCKETS STORED AS TEXTFILE;

执行完成后,查看默认建表语句:

复制代码
+----------------------------------------------------+
|                   createtab_stmt                   |
+----------------------------------------------------+
| CREATE TABLE `bucket_text_table2`(                 |
|   `column1` string,                                |
|   `column2` string,                                |
|   `column3` int)                                   |
| CLUSTERED BY (                                     |
|   column3)                                         |
| INTO 5 BUCKETS                                     |
| ROW FORMAT SERDE                                   |
|   'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe'  |
| STORED AS INPUTFORMAT                              |
|   'org.apache.hadoop.mapred.TextInputFormat'       |
| OUTPUTFORMAT                                       |
|   'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat' |
| LOCATION                                           |
|   'hdfs://ambari-hadoop1:8020/warehouse/tablespace/managed/hive/test.db/bucket_text_table2' |
| TBLPROPERTIES (                                    |
|   'bucketing_version'='2',                         |
|   'transactional'='true',                          |
|   'transactional_properties'='insert_only',        |
|   'transient_lastDdlTime'='1704166322')            |
+----------------------------------------------------+

其中表的transactional被设置为true,代表表为事务表

尝试通过alter table set properties来进行修改

复制代码
0: jdbc:hive2://ambari-hadoop1:2181,ambari-ha> alter table bucket_text_table2 set tblproperties('transactional'='false');
INFO  : Compiling command(queryId=hive_20240102143335_121e893a-fb40-4853-876b-c6da7edf0ddd): alter table bucket_text_table2 set tblproperties('transactional'='false')
INFO  : Semantic Analysis Completed (retrial = false)
INFO  : Returning Hive schema: Schema(fieldSchemas:null, properties:null)
INFO  : Completed compiling command(queryId=hive_20240102143335_121e893a-fb40-4853-876b-c6da7edf0ddd); Time taken: 0.04 seconds
INFO  : Executing command(queryId=hive_20240102143335_121e893a-fb40-4853-876b-c6da7edf0ddd): alter table bucket_text_table2 set tblproperties('transactional'='false')
INFO  : Starting task [Stage-0:DDL] in serial mode
ERROR : FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. Cannot change 'transactional' without 'transactional_properties'
INFO  : Completed executing command(queryId=hive_20240102143335_121e893a-fb40-4853-876b-c6da7edf0ddd); Time taken: 0.033 seconds
Error: Error while processing statement: FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. Cannot change 'transactional' without 'transactional_properties' (state=08S01,code=1)

修改结果ERROR,看来需要同时修改transactional_properties属性值,重新调整

复制代码
0: jdbc:hive2://ambari-hadoop1:2181,ambari-ha> alter table bucket_text_table2 set tblproperties('transactional'='false','transactional_properties'='{}');
INFO  : Compiling command(queryId=hive_20240102143717_f10054c2-f69f-4d53-aa61-86fe98edaf64): alter table bucket_text_table2 set tblproperties('transactional'='false','transactional_properties'='{}')
INFO  : Semantic Analysis Completed (retrial = false)
INFO  : Returning Hive schema: Schema(fieldSchemas:null, properties:null)
INFO  : Completed compiling command(queryId=hive_20240102143717_f10054c2-f69f-4d53-aa61-86fe98edaf64); Time taken: 0.024 seconds
INFO  : Executing command(queryId=hive_20240102143717_f10054c2-f69f-4d53-aa61-86fe98edaf64): alter table bucket_text_table2 set tblproperties('transactional'='false','transactional_properties'='{}')
INFO  : Starting task [Stage-0:DDL] in serial mode
ERROR : FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. Cannot convert an ACID table to non-ACID
INFO  : Completed executing command(queryId=hive_20240102143717_f10054c2-f69f-4d53-aa61-86fe98edaf64); Time taken: 0.022 seconds
Error: Error while processing statement: FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. Cannot convert an ACID table to non-ACID (state=08S01,code=1)

Cannot convert an ACID table to non-ACID 很明显,不支持将事务表改变为非事务表。

我在以上表转换时,表中是有数据的,那么如果是空表是否还支持事务表转换至非事务表呢?测试后发现也不行,那么如果要将事务表转为非事务表怎么办呢?

  1. 创建一个新的非事务表。
  2. 将数据从原事务表导入到新的非事务表。
  3. 如果需要,你可以删除原事务表。
    cnblogs原文
相关推荐
viperrrrrrrrrr75 小时前
大数据学习(112)-HIVE中的窗口函数
hive·sql·学习
酷爱码11 小时前
如何通过python连接hive,并对里面的表进行增删改查操作
开发语言·hive·python
Debug_TheWorld13 小时前
Hive学习
hive
IT成长日记1 天前
【Hive入门】Hive数据导出完全指南:从HDFS到本地文件系统的专业实践
hive·hadoop·hdfs·数据导出
IT成长日记1 天前
【Hive入门】Hive概述:大数据时代的数据仓库桥梁
大数据·数据仓库·hive·sql优化·分布式计算
IT成长日记2 天前
【Hive入门】Hive查询语言(DQL)完全指南:从基础查询到高级分析
数据仓库·hive·hadoop·dql操作
IT成长日记2 天前
【Hive入门】Hive数据模型与存储格式深度解析:从理论到实践的最佳选择
数据仓库·hive·hadoop·数据模型·存储格式
IT成长日记2 天前
【Hive入门】Hive分区与分桶深度解析:优化查询性能的关键技术
数据仓库·hive·hadoop·分区·分桶
Faith_xzc2 天前
Hive 数据同步到 Doris 最佳实践方案:从场景适配到性能调优全解析
大数据·数据仓库·hive·hadoop·doris
酷爱码2 天前
hive默认的建表格式
数据仓库·hive·hadoop