hive 数据定义

1:  CREATE DATABASE IF NOT EXISTS financials;

2: script:

  2.1: hive> SHOWDATABASES;

default

financials

hive> CREATEDATABASE human_resources;

hive> SHOWDATABASES;

default

financials

human_resources



  2.2:hive> SHOWDATABASES LIKE'h.*';

human_resources

hive> ...



  2.3: hive> CREATE DATABASE financials  LOCATION '/my/preferred/directory';  (now the table should be saved in the location  path )


hive> CREATEDATABASE financials  COMMENT 'Holds all financial tables';

hive> DESCRIBEDATABASE financials;

financials Holds all financial tables

hdfs://master-server/user/hive/warehouse/financials.db


2.4: hive> CREATE DATABASE financials  WITH DBPROPERTIES ('creator' = 'Mark Moneybags', 'date' = '2012-01-02');
hive> DESCRIBE DATABASE financials;
financials hdfs://master-server/user/hive/warehouse/financials.db
hive> DESCRIBE DATABASE EXTENDED financials;
financials hdfs://master-server/user/hive/warehouse/financials.db
{date=2012-01-02, creator=Mark Moneybags);


  2.5: 

hive> set hive.cli.print.current.db=true;
hive (financials)> USE default;
hive (default)> set hive.cli.print.current.db=false;
hive> ...
Finally, you can drop a database:
hive> DROP DATABASE IF EXISTS financials;


2.6: 

By default, Hive won’t permit you to drop a database if it contains tables. You can either drop the tables first or append the CASCADE keyword to the command, which will cause the Hive to drop the tables in the database first: 

hive> DROP DATABASE IF EXISTS financials CASCADE;


3: Alter Database

  3.1: hive> ALTER DATABASE financials SET DBPROPERTIES ('edited-by' = 'Joe Dba');


  3.2: Creating Tables

CREATE TABLE IFNOT EXISTS mydb.employees(

name STRING COMMENT 'Employee name',

salary FLOATCOMMENT 'Employeesalary',

subordinates ARRAY<STRING>COMMENT 'Namesof subordinates',

deductions MAP<STRING,FLOAT>

COMMENT 'Keys aredeductions names, values are percentages',

address STRUCT<street:STRING,city:STRING, state:STRING,zip:INT>

COMMENT 'Home address')

COMMENT 'Description of thetable'

TBLPROPERTIES ('creator'='me','created_at'='2012-01-0210:00:00', ...)

LOCATION'/user/hive/warehouse/mydb.db/employees';


  3.3: You can also copy the schema (but not the data) of anexisting table:

CREATE TABLE IF NOT EXISTS mydb.employees2

LIKE mydb.employees;


  3.4: 

hive> USE mydb;

hive> SHOWTABLES;

employees

table1

table2


3.5:

 

hive> USE mydb;

hive> SHOW TABLES  'empl.*';

employees


3.6:

hive> DESCRIBE EXTENDED mydb.employees;

name string Employee name

salary float Employee salary

subordinates array<string> Names of subordinates

deductions map<string,float> Keys are deductionsnames, values are percentages

addressstruct<street:string,city:string,state:string,zip:int> Home address

Detailed Table Information Table(tableName:employees,dbName:mydb, owner:me,

...

location:hdfs://master-server/user/hive/warehouse/mydb.db/employees,

parameters:{creator=me, created_at='2012-01-02 10:00:00',

last_modified_user=me, last_modified_time=1337544510,

comment:Description of the table, ...}, ...)


3.7: 

hive> DESCRIBE mydb.employees.salary;

salary float Employee salary




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值