Skip to content

Commit 6b14eee

Browse files
hive changes
1 parent f173fee commit 6b14eee

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

hadoop/edw/cloudera/hive/02hive_ddl.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,34 @@ PARTITIONED BY (order_month string)
6767
ROW FORMAT DELIMITED FIELDS TERMINATED BY '|'
6868
STORED AS TEXTFILE;
6969

70+
CREATE TABLE orders_part_avro (
71+
order_id int,
72+
order_date string,
73+
order_customer_id int,
74+
order_status string
75+
)
76+
PARTITIONED BY (order_month string)
77+
STORED AS AVRO
78+
LOCATION 'hdfs:///user/hive/warehouse/retail_stage.db/orders_part_avro'
79+
TBLPROPERTIES ('avro.schema.url'='hdfs://quickstart.cloudera/user/cloudera/retail_stage/orders_part_avro.avsc');
80+
81+
-- Adding partition manually
82+
alter table orders_part_avro add partition (order_month='2014-01');
83+
84+
-- Inserting data to a partition
85+
insert into table orders_part_avro partition (order_month='2014-01')
86+
select * from orders where from_unixtime(cast(substr(order_date, 1, 10) as int)) like '2014-01%';
87+
88+
-- Drop table and recreate to test dynamic insert
89+
-- Dynamic insert
90+
set hive.exec.dynamic.partition.mode=nonstrict;
91+
insert into table orders_part_avro partition (order_month)
92+
select order_id, order_date, order_customer_id, order_status, from_unixtime(cast(substr(order_date, 1, 10) as int)) order_month from orders;
93+
94+
--validate
95+
dfs -ls /user/hive/warehouse/retail_stage.db/orders_part_avro/*
96+
dfs -ls /user/hive/warehouse/retail_stage.db/orders_part_avro/
97+
7098
CREATE TABLE order_items (
7199
order_item_id int,
72100
order_item_order_id int,

0 commit comments

Comments
 (0)