hiveQL資料定義

2021-08-07 03:20:20 字數 2246 閱讀 1118

hive不支援行級插入操作、更新操作、刪除操作,hive也不支援事物。

1,建立資料庫

create database ***;

show databases;

use ***database;

hive 會為每個資料庫建立乙個目錄,資料庫中的表將會以這個資料庫目錄的子目錄形式儲存。有乙個例外就是default資料庫中的表,因為這個資料庫本身沒有自己的目錄。

目錄位置位於屬性hive.metastore.warehouse.dir所指定的目錄之後,預設是/user/hive/warehouse(指的是hdfs上的路徑)。

改變這個路徑可以在建立表的時候指定location '/***/***x';

使用者檢視路徑:

describe database xxdatabase;

建立資料庫時可以增加一些和其相關的鍵值對屬性資訊

create database ***database

with dbproperties ('creator' = 'mark', 'date' = '2017-08-14');

提示符裡顯示當前使用資料庫。

set hive.cli.print.current.db=true;

刪除資料庫:

drop database if exists ***database;

hive不能刪除包含有表的資料庫,所以可以在命令後加上cascade

drop database if exists ***database cascade;

2,修改資料庫

hive的資料庫的元資料是不能修改的,只能改屬性資訊,比如:

alter database financials set dbproperties ('creator2'='ady');

3,建立表

create table if not exists zhangtest.employees(

home string comment 'employee name',

salary float comment 'employee salary',

subordinates arraycomment 'names of subordinates',

deductions map

comment 'keys are deductions names, values are percentages',

adress struct

comment 'home adress')

comment 'description of the table'

location '/user/hive/warehouse/

zhangtest

.db/employee'

tblproperties ('creator'='me', 'data'='2017');

可以使用desc formatted zhangtest.employees;

檢視表的格式化資訊。

管理表也叫內部表,目前為止我們建立的表都是這種表,hive控制著資料的宣告週期。

當我們刪除乙個表時,hive也會刪除這個表中的資料。

外部表create external table if not exists taobaoaccount333 (

email string)

row format delimited fields terminated by ''

location '

/input/333/';

關鍵字external告訴hive這個表是外部表,而location告訴hive資料位於哪個路徑下。

刪除外部表時,並不會刪除資料,而是刪除元資料資訊。

使用desc extended tabblename 來檢視是否內部表或外部表。

分割槽表create table *** (************x)

partitioned by(xx, yy);

hive將會建立好反映分割槽結構的子目錄。例如:/xx=xx/yy=yy

show partitions tablename;檢視表中存在的所有分割槽。

刪除表drop table if exists taobaoaccount333;

如果使用者開啟了hadoop**站功能,那麼被刪除的資料會被移到使用者目錄下的.trash目錄下。

對於外部表,表的元資料資訊會被刪除。

修改表重新命名表

alter table *** rename to yyy

修改表還有好多。。。。

HiveQL 資料定義

一.資料庫部分 1.建立資料庫 create database dw 或者create database ifnot exists dw create database dw comment this is a test database create database dw location my...

HiveQL 資料定義

掌握應用hiveql建立資料庫 掌握應用hiveql建立表 掌握應用hiveql建立檢視 硬體環境要求 pc機至少4g記憶體,硬碟至少預留50g空間。軟體要求 已安裝並啟動hadoop 已安裝並啟動hive 應用hiveql建立資料庫 應用hiveql建立表 應用hiveql建立檢視 第5章 hiv...

Hive學習 HiveQL 資料定義

hiveql可能和mysql語句接近,但是兩者還是存在顯著差異。hive不支援行級插入操作 更新操作和刪除操作。hive也不支援事務。建立資料庫 create database financials 檢視hive中包含的資料庫 show databases 使用正則匹配篩選出需要的資料庫 show ...