show databases; show tables; 系统自带的函数 1)查看系统自带的函数 hive> show functions; 2)显示自带的函数的用法 hive> desc function upper; 3)详细显示自带的函数的用法 hive> desc function extended upper; use qhtest; -- 创建表 create table qhtest.S_test_table (id int, name string, age int) row format delimited fields terminated by ',' lines terminated by '\n' stored as parquetfile; -- 创建表 表结构一致,没有数据 create table if not exists ioczxk_s.S_LS_GZW_sgyzctjxx108800 like iocgjk.O_LS_GZW_sgyzctjxx108800; -- 创建表 表结构一致,复制数据,分区表复制过去后变成字段 create table user_table1 as table_2; -- 创建表指定存储格式 create table if not exists qhtest.S_test_table ( id int , name string , age int ) row format delimited fields terminated by ',' lines terminated by '\n' stored as parquetfile; -- 插入数据 -- 删除表 drop table qhtest.S_test_table; -- 查看表类型 desc formatted qhtest.S_test_table; -- 清空表 truncate table qhtest.S_test_table; 文件加载到hive表中 上传文件到hdfs hdfs dfs -put test_data.txt /user/qh_test_hive/; hdfs加载到hive表 test_data.txt load data local inpath '/opt/qh_ioc/test_data.txt' overwrite into table qhtest.S_test_table; load命令详解: ================================= 1、load本地数据 //相当于上传或者复制,源文件不变 load data local inpath '/home/centos/employee.txt' into table employee; 2、load hdfs数据 load data inpath '/duowan_user.txt' into table duowan; //相当于移动 3、load本地数据 + 覆盖原始数据 load data local inpath '/home/centos/employee.txt' overwrite into table employee; 4、load hdfs数据 + 覆盖原始数据 load data inpath '/duowan_user.txt' overwrite into table duowan; describe 表名; 表的详细信息
创建分区表
-- 添加注释 create table tb_test ( id varchar(100) comment '用户id', -- 用户id age varchar(100) comment '年龄' -- 年龄 ) PARTITIONED BY (occur_period string) row format delimited fields terminated by '\001' lines terminated by '\n' stored as parquetfile comment '测试表';
注意:字段分隔符和 存储格式指定只能在hive下使用,spark客户端不支持,会报错
Error: org.apache.spark.sql.catalyst.parser.ParseException: Operation not allowed: ROW FORMAT DELIMITED is only compatible with 'textfile', not 'rcfile'(line 1, pos 0)
spark 不为 parquet文件提供DELIMITERS。
禁止 ROW FORMAT 和 STORED AS (parquet | orc | avro etc.)
https://blog.csdn.net/zhangshenghang/article/details/102459033/
hive下
-- 按月occur_period_month创建分区表 分区字段不能出现在表字段中 create table mydb.tb_test( rid int COMMENT '行id' ,id varchar(100) comment '用户id' ,age varchar(100) comment '年龄' ,creat_time string comment '创建时间' )PARTITIONED BY (occur_period string) row format delimited fields terminated by '\001' lines terminated by '\n' stored as parquetfile; -- 添加表注释 ALTER TABLE mydb.tb_test SET TBLPROPERTIES ('comment' = '测试表');