FAILED: SemanticException Unable to determine if hdfs://tmaster:8020/user/root/words.db/test_t2 is encrypted

使用hive时,建立数据库,建表,写数据;

读数据:select *  from test_t2;

报错SemanticException

原因:建表时使用了其他路径,或者在另一个路径的数据库(建立数据库时指定了location参数:create database words_db location 'hdfs://tmaster:8020/user/root/words.db')中建表test_t2,也就是因为在建表时没有在默认路径下建立,默认路径是:/user/hive/warehouse/databasename.db/tablename/partition_name (注意要建立分区)

解决方法:

1. 方法一:重新在默认路径下建表,也就是不显式指定location参数,直接默认即可;

例如:建立外部分区表(指定location参数)--- (create table ...)

CREATE EXTERNAL TABLE IF NOT EXISTS test_t1(
   column_1 string
  ,column_2 string
  ,column_3 string
 )PARTITIONED BY (day_time string)
 ROW FORMAT DELIMITED FIELDS TERMINATED BY ','
 STORED AS TEXTFILE
 LOCATION '/user/root/test';

默认建表(不指定location参数):

create table test_t1(column_1 string,column_2 string) partitioned by (day_time string) row format delimited fields terminated by '1';

其中:row format delimited fields terminated by '1' 表示行内的列分隔符是'1'。

2. 方法二:修改设置参数location,参考:https://blog.csdn.net/ggwxk1990/article/details/78067803

建立分区:当设置partitioned by (day_time string)时,表示以day_time来进行分区 --- (alter table ...)

alter table test_t1 add IF NOT EXISTS partition (day_time='20191031');

#或者 (同样可加也可不加:IF NOT EXISTS)
alter table database_name.test_t1 add IF NOT EXISTS partition (day_time='20191031')

一般的流程:建表--->建立分区--->写数据

注意:建数据库和建表时,均有location参数

参考:

https://blog.csdn.net/Thomson617/article/details/86153924

https://blog.csdn.net/qq_36743482/article/details/78383964

## 欢迎交流

原文地址:https://www.cnblogs.com/qi-yuan-008/p/11772121.html