Hive Learning
HIVEQL和MYSQL最为接近
数据操作
SHOW TABLES IN crm_integration
Show tables 'dim_con*'
DESCRIBE EXTENDED crm_integration.itg_fact_sales_order
DESCRIBE FORMATTED crm_integration.itg_fact_sales_order
show partitions crm_integration.itg_fact_sales_order --查看表中所有分区
DELETE TABLE
DROP TABLE IF EXSTS employees
.Trash(需要开启回收站功能)
ALTER TABLE log_MESSAGES RENAME TO logmsgs;
ALTER TABLE table ADD PARTITION…
ALTER TABLE logmessages DROP IF EXISTS PARTITION (year = 2011, month =12, _day =2 )
ALTER TABLE log ADD COLUMNS(app_name STRING COMMENT ‘application name’)
替换列:REPLACE
ARCHIVE PARTITION
保护:
ALTER TABLE logmessages DROP IF EXISTS PARTITION (year = 2011, month =12, day =2 ) ENABLE NO_DROP
ALTER TABLE logmessages DROP IF EXISTS PARTITION (year = 2011, month =12, day =2 ) ENABLE OFFLINE
装载数据
Load data local
Overwrite
集合数据类型中的元素提取:
SELECT name, subordinates[0] FROM employees;
SELECT name, deductions[“State Taxes”] FROM EMPLOYEES;
这里deductions列是一个map,jason格式。
引用struct中的元素,可以用点。
SELEFCT name, ADDRESS.CITY FROM EMPLOYEES;
正则表达式:
LIKE, RLIKE
LIMIT 2
谓词:
A<> B
A !=B
A is null
A IS NOT NULL
A LIKE B
A NOT LIKE B
A RLIKE B
A REGEXP B
JOIN(笛卡尔积) --消耗资源,不建议
LEFT OUTER JOIN
LEFT SEMI-JOIN:
返回左边表的记录,前提是记录对于右边表满足ON语句中的判定条件。Sql回通过IN…EXISTS结构来处理这种情况。
HIVE不支持RIGHT SEMI-JOIN
SEMI-JOIN比inner join要更高效。
SORT BY –每个reducer中对数据排序,局部排序过程
ORDER BY—全局有序
DISTRIBUTE BY –写在SORT BY 前面。
CLUSTER BY
数据类型:
CAST(SALARY AS FLOAT)
6.9 抽样查询:
RAND()
数据块抽样:
SELECT * FROM numbersflat TABLESAMPLE (0.1 PERCENT) s;
CREATE TABLE shipments2 LIKE shipment
索引:
Show FORMATTED INDEX ON employess
调优
EXPLAIN
EXPLAIN SELECT SUM(NUMBER) FROM onecol;
EXPLAIN EXTENDED
标签:PARTITION,JOIN,name,HIVEQL,DROP,笔记,HIVE,TABLE,ALTER From: https://www.cnblogs.com/watermarks/p/17127997.html