[$host] transwarp> CREATE DATABASE test_db;
[$host] transwarp> DESCRIBE DATABASE test_db; test_db hdfs://ns/inceptor1/user/hive/warehouse/test_db.db Inceptor提供WITH DBPROPERTIES让用户可以通过键值对来添加数据库的元数据。DESCRIBE DATABASE EXTENDED命令可以查看用户自定义的DBPROPERTIES:
[$host] transwarp> CREATE DATABASE test_db WITH DBPROPERTIES ('owner'='zhang san');
[$host] transwarp> DESCRIBE DATABASE EXTENDED test_db;
test_db hdfs://ns/inceptor1/user/hive/warehouse/test_db.db {owner=zhang san}
[$host]transwarp> SHOW DATABASES; default my_db test test_db
Location 'hdfs_path'指令指定外部表在HDFS中的路径。
[$host] transwarp> CREATE TABLE test_table (col INT, col2 STRING COMMENT 'this is a comment on col2') COMMENT 'this is a comment on test_table' PARTITIONED BY (col3 DOUBLE); [$host] transwarp> DESCRIBE test_table; col int None col2 string this is a comment on col2 col3 double None # Partition Information # col_name data_type comment col3 double NoneInceptor提供TBLPROPERTIES让用户以键值对的形式添加自定义的元数据。DESCRIBE EXTENDED 或者 DESCRIBE FORMATTED 可以显示TBLPROPERTIES和其他的schema信息:
[$host] transwarp> CREATE TABLE test_table (col1 INT, col2 STRING COMMENT 'this is a comment on col2') COMMENT 'this is a comment on test_table' PARTITIONED BY (col3 DOUBLE) TBLPROPERTIES ('owner'='Zhang San');
[$host] transwarp> DESCRIBE EXTENDED test_table;
col1 int None
col2 string this is a comment on col2
col3 double None
# Partition Information
# col_name data_type comment
col3 double None
Detailed Table Information Table(tableName:test_table, dbName:default, owner:yarn, createTime:1417790881, lastAccessTime:0, retention:0, sd:StorageDescriptor(cols:[FieldSchema(name:col1, type:int, comment:null), FieldSchema(name:col2, type:string, comment:this is a comment on col2), FieldSchema(name:col3, type:double, comment:null)], location:hdfs://ns/inceptor1/user/hive/warehouse/test_table, inputFormat:org.apache.hadoop.mapred.TextInputFormat, outputFormat:org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat, compressed:false, numBuckets:-1, serdeInfo:SerDeInfo(name:null, serializationLib:org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe, parameters:{serialization.format=1}), bucketCols:[], sortCols:[], parameters:{}, skewedInfo:SkewedInfo(skewedColNames:[], skewedColValues:[], skewedColValueLocationMaps:{}), storedAsSubDirectories:false), partitionKeys:[FieldSchema(name:col3, type:double, comment:null)], parameters:{owner=Zhang San, transient_lastDdlTime=1417790881, comment=this is a comment on test_table}, viewOriginalText:null, viewExpandedText:null, tableType:MANAGED_TABLE, isRangePartitioned:false)
[$host] transwarp> SHOW TABLES; test_table如果想要显示一个其他数据库下的表,使用SHOW TABLES IN db_name指令。比如,我们来查看exchange_platform下的所有表:
[$host] transwarp> SHOW TABLES IN exchange_platform; nonsecure_user_info part_user_info empty_user_info user_info
[$host] transwarp> SELECT DISTINCT name FROM (SELECT name FROM user_info JOIN transactions ON acc_num = acc_num); 邱坤 管淑艳 李韩瑶 潘营泽 祝韩恒 魏向卉 马从筠 华微我们可以把子查询
SELECT name FROM user_info JOIN transactions ON acc_num = acc_num封装进一个VIEW,然后再查询:
[$host] transwarp> CREATE VIEW name_view AS SELECT name FROM user_info JOIN transactions ON acc_num = acc_num; [$host] transwarp> SELECT DISTINCT name FROM name_view; 祝韩恒 魏向卉 马从筠 华微 邱坤 管淑艳 李韩瑶 潘营泽
[$host] transwarp> CREATE VIEW secure_info AS SELECT name, acc_num, reg_date, acc_level from user_info; [$host] transwarp> SELECT * FROM secure_info; 马从筠 6513065 20110101 A 祝韩恒 6670192 20100101 C 华微 5224133 20080214 B 魏向卉 3912384 20091202 A 宁新瑶 4580952 20081031 D 邱坤 0700735 20121024 A 李平 8725869 20130702 E 潘营泽 6600641 20110430 C 李韩瑶 2755506 20110916 D 管淑艳 2394923 20141003 C