一、基础DDL练习
SHOW DATABASES; CREATE DATABASE IF NOT EXISTS db1 COMMENT 'Our database db1'; SHOW DATABASES; DESCRIBE DATABASE db1; CREATE TABLE db1.table1 (word STRING, count INT); SHOW TABLES in db1; DESCRIBE db1.table1; USE db1; SHOW TABLES; SELECT * FROM db1.table1; DROP TABLE table1; DROP DATABASE db1; USE default;
二、基础DML语句
创建表 create table if not exists user_dimension ( uid STRING, name STRING, gender STRING, birth DATE, province STRING )ROW FORMAT DELIMITED //按行切分的意思 FIELDS TERMINATED BY ',' //按逗号分隔的 查看表信息 describe user_dimension; show create table user_dimension; 查看所有表 show tables; 载入本地数据 load data local inpath '/home/orco/tempdata/user.data' overwrite into table user_dimension; 载入HDFS上的数据 load data inpath '/user/orco/practice_1/user.data' overwrite into table user_dimension; 验证 select * from user_dimension; 查看hive在hdfs上的存储目录 hadoop fs -ls /warehouse/ hadoop fs -ls /warehouse/user_dimension
三、复杂数据类型
示例2: CREATE TABLE IF NOT EXISTS employees ( name STRING, salary FLOAT, subordinates ARRAY<STRING>, deductions MAP<STRING, FLOAT>, address STRUCT<street:STRING, city:STRING, state:STRING, zip:INT> ) ROW FORMAT DELIMITED FIELDS TERMINATED BY '