我有以下現有的表emp,磁區列為as_of_date(current_date -1)。
創建外部表IF NOT EXISTS emp(
student_ID INT,
name STRING)
通過(as_of_date日期)進行磁區
行的格式劃定
欄位以','結尾
存盤為文本檔案
LOCATION '/user/emp';
下面是現有的磁區路徑
user/emp/as_of_date=2021-09-02
user/emp/as_of_date=2021-09-03
user/emp/as_of_date=2021-09-04
在emp表中,我必須添加新的磁區列作為businessdate(current_date),并將磁區列(as_of_date)改為非磁區列。
預期的輸出應該如下所示。
描述表emp。
CREATE EXTERNAL TABLE IF NOT EXISTS emp(
student_ID INT,
Name STRING,
as_of_date date)
磁區為(businessdate date)
行的格式劃定
欄位以','結尾
存盤為文本檔案
LOCATION '/user/emp'。
更新后,下面將是hdfs的路徑
。user/emp/buinessdate=2021-09-03
user/emp/buinessdate=2021-09-04
user/emp/businessdate=2021-09-05
預期輸出表:
|student_ID |name |as_of_date | business_date |
|--| --- | --- |----|
|1 |Sta |2021-09-02| 2021-09-03 |
|2 |Danny|2021-09-03| 2021-09-04 |
|3 |Elle |2021-09-04| 2021-09-05 |
uj5u.com熱心網友回復:
創建新表,從舊表加載資料,洗掉舊表,重命名新表。
--1 創建新表emp1
創建外部表emp1(
student_ID INT,
Name STRING,
as_of_date date)
磁區為(businessdate date)
行的格式劃定
欄位以','結尾
存盤為文本檔案
LOCATION '/user/emp1'。
-2 從emp中加載資料到emp1,并計算出新的磁區列
。--動態磁區模式
SET hive.exec.dynamic.partition=true;
SET hive.exec.dynamic.partition.mode=nonstrict;
插入覆寫表emp1的磁區(business_date)
選擇
student_ID,
名稱。
as_of_date,
date_add(as_of_date,1) as business_date
from emp;
現在你可以丟棄舊表(讓它先管理好丟棄的位置),并在必要時重命名新表。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/318964.html
標籤:
上一篇:404NotFoundforindex.htmlinGoogleAppEngine-如何讓頁面顯示?
下一篇:即使我在GoogleAppEngine中設定了{"type":"module"},“無法在模塊外使用匯入陳述句”錯誤
