-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hive_Assignment.txt
1263 lines (1023 loc) · 67.6 KB
/
Hive_Assignment.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Hive Query-create database hive_practice;
Query Output- Database has been created
Hive Query-show databases;
Query Output-
+---------------------+
| database_name |
+---------------------+
| default |
| foodmart |
| hive_practice |
| information_schema |
| sys |
+---------------------+
Hive Query-create database hive_custom location '/user/root/hive_practice/';
Query output-database has been created
Hive Query-describe database hive_custom;
Query output-
+--------------+----------+----------------------------------------------------+-------------+-------------+-------------+
| db_name | comment | location | owner_name | owner_type | parameters |
+--------------+----------+----------------------------------------------------+-------------+-------------+-------------+
| hive_custom | | hdfs://sandbox-hdp.hortonworks.com:8020/user/root/hive_practice | hive | USER | |
+--------------+----------+----------------------------------------------------+-------------+-------------+-------------+
Hive Query-show databases;
Query Output-
+---------------------+
| database_name |
+---------------------+
| default |
| foodmart |
| hive_custom |
| hive_practice |
| information_schema |
| sys |
+---------------------+
Hive Query-show databases like 'hive.*';
Query Output-
+----------------+
| database_name |
+----------------+
| hive_custom |
| hive_practice |
+----------------+
Hive Query-drop database hive_custom;
Query Output-database has been dropped;
Hive Query-show databases;
Query Output-
+---------------------+
| database_name |
+---------------------+
| default |
| foodmart |
| hive_practice |
| information_schema |
| sys |
+---------------------+
Hive Query-show tables;
Query Output-No Table has been created yet hence returns null
+-----------+
| tab_name |
+-----------+
+-----------+
Hive Query - create table emp_details ( emp_name string,unit string,exp int,location string) row format delimited fields terminated by ',' ;
Query Output-emp_details table has been created
Hive Query-show tables;
Query output-
+--------------+
| tab_name |
+--------------+
| emp_details |
+--------------+
Hive Query-alter table emp_details rename to employee_details;
Query output-Table name has been changed;
Hive Query-show tables;
Quer Output-
+-------------------+
| tab_name |
+-------------------+
| employee_details |
+-------------------+
Hive Query-create table india_captains (name string,unit string,id int,location string) row format delimited fields terminated by ',' stored as textfile;
Query output -Table is created with format as TextFormat
Hive Query-show create table india_captains;
Query Output-
+----------------------------------------------------+
| createtab_stmt |
+----------------------------------------------------+
| CREATE TABLE `india_captains`( |
| `name` string, |
| `unit` string, |
| `id` int, |
| `location` string) |
| ROW FORMAT SERDE |
| 'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe' |
| WITH SERDEPROPERTIES ( |
| 'field.delim'=',', |
| 'serialization.format'=',') |
| STORED AS INPUTFORMAT |
| 'org.apache.hadoop.mapred.TextInputFormat' |
| OUTPUTFORMAT |
| 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat' |
| LOCATION |
| 'hdfs://sandbox-hdp.hortonworks.com:8020/warehouse/tablespace/managed/hive/india_captains' |
| TBLPROPERTIES ( |
| 'bucketing_version'='2', |
| 'transactional'='true', |
| 'transactional_properties'='insert_only', |
| 'transient_lastDdlTime'='1626602567') |
+----------------------------------------------------+
Unix Command-vi Input.txt
Data present in Input.txt-
virat kohli,captain,1,INDIA
Dhoni,wicket keeper,2,INDIA
Warner,srh captain,1,SRH
williamson,srh,2,SRH
abd,wicket keeper,1,RCB
Hive Query-load data local inpath '/Hive_Practice/Input.txt' overwrite into table india_captains;
Query output-The data present in the Input.txt has been loaded into india_captains.
Hive Query-select * from india_captains;
Query output-
+----------------------+----------------------+--------------------+--------------------------+
| india_captains.name | india_captains.unit | india_captains.id | india_captains.location |
+----------------------+----------------------+--------------------+--------------------------+
| virat kohli | captain | 1 | INDIA |
| Dhoni | wicket keeper | 2 | INDIA |
| Warner | srh captain | 1 | SRH |
| williamson | srh | 2 | SRH |
| abd | wicket keeper | NULL | NULL |
+----------------------+----------------------+--------------------+--------------------------+
Hive Query-select * from india_captains limit 2;
Query Output-
+----------------------+----------------------+--------------------+--------------------------+
| india_captains.name | india_captains.unit | india_captains.id | india_captains.location |
+----------------------+----------------------+--------------------+--------------------------+
| virat kohli | captain | 1 | INDIA |
| Dhoni | wicket keeper | 2 | INDIA |
+----------------------+----------------------+--------------------+--------------------------+
Hive Query-create view india_captains_view select * from india_captains limit 3;
Query output-view has been created with the name india_captains_view;
Hive Query-show views;
Query Output-
+----------------------+
| tab_name |
+----------------------+
| india_captains_view |
+----------------------+
Hive Query-select * from india_captains order by id;
Query Output-
+----------------------+----------------------+--------------------+--------------------------+
| india_captains.name | india_captains.unit | india_captains.id | india_captains.location |
+----------------------+----------------------+--------------------+--------------------------+
| abd | wicket keeper | NULL | NULL |
| virat kohli | captain | 1 | INDIA |
| Warner | srh captain | 1 | SRH |
| Dhoni | wicket keeper | 2 | INDIA |
| williamson | srh | 2 | SRH |
+----------------------+----------------------+--------------------+--------------------------+
Hive Query-create external table cricket_players (name string,country string) row format delimited fields terminated by ',' stored as TEXTFILE
Query Output-External Table is created
Unix Command-vi Input_External.txt
Input Data present in Input_External.txt-
Kohli,IND
Dhoni,IND
WARNER,AUS
ABD,SA
Williamson,NZ
Hive Query-load data local inpath '/Hive_Practice/Input_External.txt' overwrite into table cricket_players;
Query output-Input Data is loaded into external table
Hive Query-select * from cricket_players limit 2;
Query output-
+-----------------------+--------------------------+
| cricket_players.name | cricket_players.country |
+-----------------------+--------------------------+
| Kohli | IND |
| Dhoni | IND |
+-----------------------+--------------------------+
**************************************SERDE Properties***********************
Unix Command- vi serde_csv_data.csv
Input Data present in serde_csv_data.csv -
Name,Location,Highest_Score
Kohli,IND,183
DHONI,IND,183
Clarke,AUS,104
****Loading CSV data into table using serde properties and tblproperties ******
Hive Query-create table tbl_csvserde (name string,country string,highest_score int) row format serde 'org.apache.hadoop.hive.serde2.OpenCSVSerde' with serdeproperties ('seperatorChar'=',') stored as TEXTFILE tblproperties('skip.header.line.count'='1');
Query Output-Table has been created with following properties
Hive Query-show create table tbl_csvserde;
Query Output-
+----------------------------------------------------+
| createtab_stmt |
+----------------------------------------------------+
| CREATE TABLE `tbl_csvserde`( |
| `name` string COMMENT 'from deserializer', |
| `country` string COMMENT 'from deserializer', |
| `highest_score` string COMMENT 'from deserializer') |
| ROW FORMAT SERDE |
| 'org.apache.hadoop.hive.serde2.OpenCSVSerde' |
| WITH SERDEPROPERTIES ( |
| 'seperatorChar'=',') |
| STORED AS INPUTFORMAT |
| 'org.apache.hadoop.mapred.TextInputFormat' |
| OUTPUTFORMAT |
| 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat' |
| LOCATION |
| 'hdfs://sandbox-hdp.hortonworks.com:8020/warehouse/tablespace/managed/hive/tbl_csvserde' |
| TBLPROPERTIES ( |
| 'bucketing_version'='2', |
| 'skip.header.line.count'='1', |
| 'transactional'='true', |
| 'transactional_properties'='insert_only', |
| 'transient_lastDdlTime'='1627139394') |
+----------------------------------------------------+
Hive Query-load data local inpath '/Hive_Practice/serde_csv_data.csv' overwrite into table tbl_csvserde;
Query Output-The Input file data is loaded into tbl_csvserde
Hive Query-select * from tbl_csvserde;
Query Output-
+--------------------+-----------------------+-----------------------------+
| tbl_csvserde.name | tbl_csvserde.country | tbl_csvserde.highest_score |
+--------------------+-----------------------+-----------------------------+
| Kohli | IND | 183 |
| DHONI | IND | 183 |
| Clarke | AUS | 104 |
+--------------------+-----------------------+-----------------------------+
Hive Query-select highest_score from tbl_csvserde;
Query Output-
+----------------+
| highest_score |
+----------------+
| 183 |
| 183 |
| 104 |
+----------------+
*****Loading JSON Data into table using serde properties*****
Unix Command-vi serde_json_data.json;
Input Data present in the serde_json_data.json-
{"name":"Kohli","country":"IND","role":["Batsman","Bowler"]}
{"name":"clarke","country":"AUS","role":["Batsman","Bowler"]}
{"name":"Dhoni","country":"IND","role":["Batsman","wicket-keeper"]}
Hive Query-create table tbl_jsonserde (name string,country string,role array<string>) row format serde 'org.apache.hive.hcatalog.data.JsonSerDe' stored as TEXTFILE;
Query output-Table is created
Hive Query-show create table tbl_jsonserde;
Query Output-
+----------------------------------------------------+
| createtab_stmt |
+----------------------------------------------------+
| CREATE TABLE `tbl_jsonserde`( |
| `name` string COMMENT 'from deserializer', |
| `country` string COMMENT 'from deserializer', |
| `role` array<string> COMMENT 'from deserializer') |
| ROW FORMAT SERDE |
| 'org.apache.hive.hcatalog.data.JsonSerDe' |
| STORED AS INPUTFORMAT |
| 'org.apache.hadoop.mapred.TextInputFormat' |
| OUTPUTFORMAT |
| 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat' |
| LOCATION |
| 'hdfs://sandbox-hdp.hortonworks.com:8020/warehouse/tablespace/managed/hive/tbl_jsonserde' |
| TBLPROPERTIES ( |
| 'bucketing_version'='2', |
| 'transactional'='true', |
| 'transactional_properties'='insert_only', |
| 'transient_lastDdlTime'='1627148204') |
+----------------------------------------------------+
Hive Query-load data local inpath '/Hive_Practice/serde_json_data.json' overwrite into table tbl_jsonserde;
Query Output- Input Data is loaded into tbl_jsonserde;
Hive Query-select * from tbl_jsonserde;
Query Output-
+---------------------+------------------------+------------------------------+
| tbl_jsonserde.name | tbl_jsonserde.country | tbl_jsonserde.role |
+---------------------+------------------------+------------------------------+
| Kohli | IND | ["Batsman","Bowler"] |
| clarke | AUS | ["Batsman","Bowler"] |
| Dhoni | IND | ["Batsman","wicket-keeper"] |
+---------------------+------------------------+------------------------------+
Hive Query-select role[1] from tbl_jsonserde;
Query Output-
+----------------+
| _c0 |
+----------------+
| Bowler |
| Bowler |
| wicket-keeper |
+----------------+
****Loading the data with regex patterns ****
Unix Command-vi regex_data.txt
Input Data present in the file-
host1/amit@gmail
host2/sumit@facebook
host3/raghav@gmail
host4/rohit@gmail
Hive Query-create table tbl_regexserde (host string,name string,domain string) row format serde 'org.apache.hadoop.hive.contrib.serde2.RegexSerDe' with serdeproperties('input.regex'='(.*)/(.*)@(.*)','output.string.format'='%1$s %2$s %3$s') stored as TEXTFILE;
Query Output-Table has been created
Hive Query-load data local inpath '/Hive_Practice/regex_data.txt' overwrite into table tbl_regexserde;
Query Output-Input Data has been loaded
Hive Query-show create table tbl_regexserde;
Query Output-
+----------------------------------------------------+
| createtab_stmt |
+----------------------------------------------------+
| CREATE TABLE `tbl_regexserde`( |
| `host` string COMMENT 'from deserializer', |
| `name` string COMMENT 'from deserializer', |
| `domain` string COMMENT 'from deserializer') |
| ROW FORMAT SERDE |
| 'org.apache.hadoop.hive.contrib.serde2.RegexSerDe' |
| WITH SERDEPROPERTIES ( |
| 'input.regex'='(.*)/(.*)@(.*)', |
| 'output.string.format'='%1 %2') |
| STORED AS INPUTFORMAT |
| 'org.apache.hadoop.mapred.TextInputFormat' |
| OUTPUTFORMAT |
| 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat' |
| LOCATION |
| 'hdfs://sandbox-hdp.hortonworks.com:8020/warehouse/tablespace/managed/hive/tbl_regexserde' |
| TBLPROPERTIES ( |
| 'bucketing_version'='2', |
| 'transactional'='true', |
| 'transactional_properties'='insert_only', |
| 'transient_lastDdlTime'='1627160837') |
+----------------------------------------------------+
Hive Query-select * from tbl_regexserde;
Query Output-
+----------------------+----------------------+------------------------+
| tbl_regexserde.host | tbl_regexserde.name | tbl_regexserde.domain |
+----------------------+----------------------+------------------------+
| host1 | amit | gmail |
| host2 | sumit | facebook |
| host3 | raghav | gmail |
| host4 | rohit | gmail |
+----------------------+----------------------+------------------------+
***************************************** File Formats*************************************
****Creation of Table in Sequence File Format*****
Hive Query-create table tbl_seq (day int,month int,year int) row format delimited fields terminated by ',' stored as SEQUENCEFILE;
Query Output-Table has been created as SEQUENCEFILE;
Hive Query-show create table tbl_seq;
Query Output-
+----------------------------------------------------+
| createtab_stmt |
+----------------------------------------------------+
| CREATE TABLE `tbl_seq`( |
| `day` int, |
| `month` int, |
| `year` int) |
| ROW FORMAT SERDE |
| 'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe' |
| WITH SERDEPROPERTIES ( |
| 'field.delim'=',', |
| 'serialization.format'=',') |
| STORED AS INPUTFORMAT |
| 'org.apache.hadoop.mapred.SequenceFileInputFormat' |
| OUTPUTFORMAT |
| 'org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat' |
| LOCATION |
| 'hdfs://sandbox-hdp.hortonworks.com:8020/warehouse/tablespace/managed/hive/tbl_seq' |
| TBLPROPERTIES ( |
| 'bucketing_version'='2', |
| 'transactional'='true', |
| 'transactional_properties'='insert_only', |
| 'transient_lastDdlTime'='1627288531') |
+----------------------------------------------------+
Hive Query-load data local inpath '/Hive_Practice/File_Formats_Data.txt' overwrite into table tbl_seq;
Query Output- Error while loading the data because the table is in sequence file format but loading the text data;
********Creation of Table with ORC Format********
Hive Query-create table tbl_orc (day int,month int,year int) row format delimited fields terminated by ',' stored as ORCFILE;
Query Output-Table has been created with ORCFILE Format;
Hive Query-show create table tbl_orc;
Query Output-
+----------------------------------------------------+
| createtab_stmt |
+----------------------------------------------------+
| CREATE TABLE `tbl_orc`( |
| `day` int, |
| `month` int, |
| `year` int) |
| ROW FORMAT SERDE |
| 'org.apache.hadoop.hive.ql.io.orc.OrcSerde' |
| WITH SERDEPROPERTIES ( |
| 'field.delim'=',', |
| 'serialization.format'=',') |
| STORED AS INPUTFORMAT |
| 'org.apache.hadoop.hive.ql.io.orc.OrcInputFormat' |
| OUTPUTFORMAT |
| 'org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat' |
| LOCATION |
| 'hdfs://sandbox-hdp.hortonworks.com:8020/warehouse/tablespace/managed/hive/tbl_orc' |
| TBLPROPERTIES ( |
| 'bucketing_version'='2', |
| 'transactional'='true', |
| 'transactional_properties'='default', |
| 'transient_lastDdlTime'='1627289813') |
+----------------------------------------------------+
*********Creation of Table with RC Format*********
Hive Query-create table tbl_rc (day int,month int,year int) row format delimited fields terminated by ',' stored as RCFILE;
Query Output-Table has been created with RC Format;
Hive Query-show create table tbl_rc;
Query Output-
+----------------------------------------------------+
| createtab_stmt |
+----------------------------------------------------+
| CREATE TABLE `tbl_rc`( |
| `day` int, |
| `month` int, |
| `year` int) |
| ROW FORMAT SERDE |
| 'org.apache.hadoop.hive.serde2.columnar.LazyBinaryColumnarSerDe' |
| WITH SERDEPROPERTIES ( |
| 'field.delim'=',', |
| 'serialization.format'=',') |
| STORED AS INPUTFORMAT |
| 'org.apache.hadoop.hive.ql.io.RCFileInputFormat' |
| OUTPUTFORMAT |
| 'org.apache.hadoop.hive.ql.io.RCFileOutputFormat' |
| LOCATION |
| 'hdfs://sandbox-hdp.hortonworks.com:8020/warehouse/tablespace/managed/hive/tbl_rc' |
| TBLPROPERTIES ( |
| 'bucketing_version'='2', |
| 'transactional'='true', |
| 'transactional_properties'='insert_only', |
| 'transient_lastDdlTime'='1627290117') |
+----------------------------------------------------+
******Creation of Table with PARQUET Format*************
Hive Query-create table tbl_parquet (day int,month int,year int) row format delimited fields terminated by ',' stored as PARQUETFILE;
Query Output-Table has been created with PARQUET Format
Hive Query-show create table tbl_parquet;
Query Output-
+----------------------------------------------------+
| createtab_stmt |
+----------------------------------------------------+
| CREATE TABLE `tbl_parquet`( |
| `day` int, |
| `month` int, |
| `year` int) |
| ROW FORMAT SERDE |
| 'org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe' |
| WITH SERDEPROPERTIES ( |
| 'field.delim'=',', |
| 'serialization.format'=',') |
| STORED AS INPUTFORMAT |
| 'org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat' |
| OUTPUTFORMAT |
| 'org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat' |
| LOCATION |
| 'hdfs://sandbox-hdp.hortonworks.com:8020/warehouse/tablespace/managed/hive/tbl_parquet' |
| TBLPROPERTIES ( |
| 'bucketing_version'='2', |
| 'transactional'='true', |
| 'transactional_properties'='insert_only', |
| 'transient_lastDdlTime'='1627290435') |
+----------------------------------------------------+
*************Describe all formats **************
Hive Query-describe formatted tbl_seq;
Query Output-
+-------------------------------+----------------------------------------------------+----------------------------------------------------+
| col_name | data_type | comment |
+-------------------------------+----------------------------------------------------+----------------------------------------------------+
| # col_name | data_type | comment |
| day | int | |
| month | int | |
| year | int | |
| | NULL | NULL |
| # Detailed Table Information | NULL | NULL |
| Database: | default | NULL |
| OwnerType: | USER | NULL |
| Owner: | hive | NULL |
| CreateTime: | Mon Jul 26 08:35:31 UTC 2021 | NULL |
| LastAccessTime: | UNKNOWN | NULL |
| Retention: | 0 | NULL |
| Location: | hdfs://sandbox-hdp.hortonworks.com:8020/warehouse/tablespace/managed/hive/tbl_seq | NULL |
| Table Type: | MANAGED_TABLE | NULL |
| Table Parameters: | NULL | NULL |
| | COLUMN_STATS_ACCURATE | {\"BASIC_STATS\":\"true\",\"COLUMN_STATS\":{\"day\":\"true\",\"month\":\"true\",\"year\":\"true\"}} |
| | bucketing_version | 2 |
| | numFiles | 0 |
| | numRows | 0 |
| | rawDataSize | 0 |
| | totalSize | 0 |
| | transactional | true |
| | transactional_properties | insert_only |
| | transient_lastDdlTime | 1627288531 |
| | NULL | NULL |
| # Storage Information | NULL | NULL |
| SerDe Library: | org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe | NULL |
| InputFormat: | org.apache.hadoop.mapred.SequenceFileInputFormat | NULL |
| OutputFormat: | org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat | NULL |
| Compressed: | No | NULL |
| Num Buckets: | -1 | NULL |
| Bucket Columns: | [] | NULL |
| Sort Columns: | [] | NULL |
| Storage Desc Params: | NULL | NULL |
| | field.delim | , |
| | serialization.format | , |
+-------------------------------+----------------------------------------------------+----------------------------------------------------+
Hive Query-describe formatted tbl_orc;
Query Output-
+-------------------------------+----------------------------------------------------+----------------------------------------------------+
| col_name | data_type | comment |
+-------------------------------+----------------------------------------------------+----------------------------------------------------+
| # col_name | data_type | comment |
| day | int | |
| month | int | |
| year | int | |
| | NULL | NULL |
| # Detailed Table Information | NULL | NULL |
| Database: | default | NULL |
| OwnerType: | USER | NULL |
| Owner: | hive | NULL |
| CreateTime: | Mon Jul 26 08:56:53 UTC 2021 | NULL |
| LastAccessTime: | UNKNOWN | NULL |
| Retention: | 0 | NULL |
| Location: | hdfs://sandbox-hdp.hortonworks.com:8020/warehouse/tablespace/managed/hive/tbl_orc | NULL |
| Table Type: | MANAGED_TABLE | NULL |
| Table Parameters: | NULL | NULL |
| | COLUMN_STATS_ACCURATE | {\"BASIC_STATS\":\"true\",\"COLUMN_STATS\":{\"day\":\"true\",\"month\":\"true\",\"year\":\"true\"}} |
| | bucketing_version | 2 |
| | numFiles | 0 |
| | numRows | 0 |
| | rawDataSize | 0 |
| | totalSize | 0 |
| | transactional | true |
| | transactional_properties | default |
| | transient_lastDdlTime | 1627289813 |
| | NULL | NULL |
| # Storage Information | NULL | NULL |
| SerDe Library: | org.apache.hadoop.hive.ql.io.orc.OrcSerde | NULL |
| InputFormat: | org.apache.hadoop.hive.ql.io.orc.OrcInputFormat | NULL |
| OutputFormat: | org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat | NULL |
| Compressed: | No | NULL |
| Num Buckets: | -1 | NULL |
| Bucket Columns: | [] | NULL |
| Sort Columns: | [] | NULL |
| Storage Desc Params: | NULL | NULL |
| | field.delim | , |
| | serialization.format | , |
+-------------------------------+----------------------------------------------------+----------------------------------------------------+
Hive Query-describe formatted tbl_rc;
Query Output-
+-------------------------------+----------------------------------------------------+----------------------------------------------------+
| col_name | data_type | comment |
+-------------------------------+----------------------------------------------------+----------------------------------------------------+
| # col_name | data_type | comment |
| day | int | |
| month | int | |
| year | int | |
| | NULL | NULL |
| # Detailed Table Information | NULL | NULL |
| Database: | default | NULL |
| OwnerType: | USER | NULL |
| Owner: | hive | NULL |
| CreateTime: | Mon Jul 26 09:01:57 UTC 2021 | NULL |
| LastAccessTime: | UNKNOWN | NULL |
| Retention: | 0 | NULL |
| Location: | hdfs://sandbox-hdp.hortonworks.com:8020/warehouse/tablespace/managed/hive/tbl_rc | NULL |
| Table Type: | MANAGED_TABLE | NULL |
| Table Parameters: | NULL | NULL |
| | COLUMN_STATS_ACCURATE | {\"BASIC_STATS\":\"true\",\"COLUMN_STATS\":{\"day\":\"true\",\"month\":\"true\",\"year\":\"true\"}} |
| | bucketing_version | 2 |
| | numFiles | 0 |
| | numRows | 0 |
| | rawDataSize | 0 |
| | totalSize | 0 |
| | transactional | true |
| | transactional_properties | insert_only |
| | transient_lastDdlTime | 1627290117 |
| | NULL | NULL |
| # Storage Information | NULL | NULL |
| SerDe Library: | org.apache.hadoop.hive.serde2.columnar.LazyBinaryColumnarSerDe | NULL |
| InputFormat: | org.apache.hadoop.hive.ql.io.RCFileInputFormat | NULL |
| OutputFormat: | org.apache.hadoop.hive.ql.io.RCFileOutputFormat | NULL |
| Compressed: | No | NULL |
| Num Buckets: | -1 | NULL |
| Bucket Columns: | [] | NULL |
| Sort Columns: | [] | NULL |
| Storage Desc Params: | NULL | NULL |
| | field.delim | , |
| | serialization.format | , |
+-------------------------------+----------------------------------------------------+----------------------------------------------------+
Hive Query-describe formatted tbl_parquet;
Query Output-
+-------------------------------+----------------------------------------------------+----------------------------------------------------+
| col_name | data_type | comment |
+-------------------------------+----------------------------------------------------+----------------------------------------------------+
| # col_name | data_type | comment |
| day | int | |
| month | int | |
| year | int | |
| | NULL | NULL |
| # Detailed Table Information | NULL | NULL |
| Database: | default | NULL |
| OwnerType: | USER | NULL |
| Owner: | hive | NULL |
| CreateTime: | Mon Jul 26 09:07:15 UTC 2021 | NULL |
| LastAccessTime: | UNKNOWN | NULL |
| Retention: | 0 | NULL |
| Location: | hdfs://sandbox-hdp.hortonworks.com:8020/warehouse/tablespace/managed/hive/tbl_parquet | NULL |
| Table Type: | MANAGED_TABLE | NULL |
| Table Parameters: | NULL | NULL |
| | COLUMN_STATS_ACCURATE | {\"BASIC_STATS\":\"true\",\"COLUMN_STATS\":{\"day\":\"true\",\"month\":\"true\",\"year\":\"true\"}} |
| | bucketing_version | 2 |
| | numFiles | 0 |
| | numRows | 0 |
| | rawDataSize | 0 |
| | totalSize | 0 |
| | transactional | true |
| | transactional_properties | insert_only |
| | transient_lastDdlTime | 1627290435 |
| | NULL | NULL |
| # Storage Information | NULL | NULL |
| SerDe Library: | org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe | NULL |
| InputFormat: | org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat | NULL |
| OutputFormat: | org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat | NULL |
| Compressed: | No | NULL |
| Num Buckets: | -1 | NULL |
| Bucket Columns: | [] | NULL |
| Sort Columns: | [] | NULL |
| Storage Desc Params: | NULL | NULL |
| | field.delim | , |
| | serialization.format | , |
+-------------------------------+----------------------------------------------------+----------------------------------------------------+
************************************Partitioning in Hive**********************************
**********Static Partitioning in Hive******************
Hive Query- select * from ind_players;(Main Table which contains loaded data)
Query Output-
+-------------------+--------------------+
| ind_players.name | ind_players.place |
+-------------------+--------------------+
| kohli | delhi |
| dhawan | delhi |
| dhoni | jharkand |
| kishan | jharkand |
| rahul | bangalore |
| manish | bangalore |
| iyer | mumbai |
| nair | bangalore |
| mayank | bangalore |
| tendulkar | mumbai |
+-------------------+--------------------+
Hive Query-show create table state_players_static;
Query Output-
+----------------------------------------------------+
| createtab_stmt |
+----------------------------------------------------+
| CREATE TABLE `state_players_static`( |
| `name` string) |
| PARTITIONED BY ( |
| `place` string) |
| ROW FORMAT SERDE |
| 'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe' |
| STORED AS INPUTFORMAT |
| 'org.apache.hadoop.mapred.TextInputFormat' |
| OUTPUTFORMAT |
| 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat' |
| LOCATION |
| 'hdfs://sandbox-hdp.hortonworks.com:8020/warehouse/tablespace/managed/hive/state_players_static' |
| TBLPROPERTIES ( |
| 'bucketing_version'='2', |
| 'transactional'='true', |
| 'transactional_properties'='insert_only', |
| 'transient_lastDdlTime'='1627759387') |
+----------------------------------------------------+
Hive Query-insert overwrite table state_players_static partition(place='delhi') select name from ind_players where place='delhi';
Query output- A seperate directory with place='delhi' is created in the table location in hdfs;
Hive Query-insert overwrite table state_players_static partition(place='mumbai') select name from ind_players where place='mumbai';
Query output-A seperate directory with place='mumbai' is created in the table location in hdfs;
Hive Query-insert overwrite table state_players_static partition(place='bangalore') select name from ind_players where place='bangalore';
Query output-A seperate directory with place='bangalore' is created in the table location in hdfs;
Hive Query-insert overwrite table state_players_mumbai partition(place='jharkand') select name from ind_players where place='jharkand';
Query Output-A seperate directory with place='jharkand' is created in the table location in hdfs;
Hive Query-select * from state_players_static;
Query Output-
+----------------------------+-----------------------------+
| state_players_static.name | state_players_static.place |
+----------------------------+-----------------------------+
| rahul | bangalore |
| manish | bangalore |
| nair | bangalore |
| mayank | bangalore |
| kohli | delhi |
| dhawan | delhi |
| dhoni | jharkand |
| kishan | jharkand |
| iyer | mumbai |
| tendulkar | mumbai |
+----------------------------+-----------------------------+
HDFS Command-hdfs dfs -ls /warehouse/tablespace/managed/hive/state_players_static
Command Output-
Found 4 items
drwxr-xr-x+ - hive hadoop 0 2021-07-31 20:09 /warehouse/tablespace/managed/hive/state_players_static/place=bangalore
drwxr-xr-x+ - hive hadoop 0 2021-07-31 19:51 /warehouse/tablespace/managed/hive/state_players_static/place=delhi
drwxr-xr-x+ - hive hadoop 0 2021-07-31 20:13 /warehouse/tablespace/managed/hive/state_players_static/place=jharkand
drwxr-xr-x+ - hive hadoop 0 2021-07-31 20:03 /warehouse/tablespace/managed/hive/state_players_static/place=mumbai
**********************Dynamic Partitioning in Hive *********************
Hive Query-select * from ind_players;(main table where input data is loaded)
Query Output-
+-------------------+--------------------+
| ind_players.name | ind_players.place |
+-------------------+--------------------+
| kohli | delhi |
| dhawan | delhi |
| dhoni | jharkand |
| kishan | jharkand |
| rahul | bangalore |
| manish | bangalore |
| iyer | mumbai |
| nair | bangalore |
| mayank | bangalore |
| tendulkar | mumbai |
+-------------------+--------------------+
Hive Query-show create table state_players;
Query Output-
+----------------------------------------------------+
| createtab_stmt |
+----------------------------------------------------+
| CREATE TABLE `state_players`( |
| `name` string) |
| PARTITIONED BY ( |
| `place` string) |
| ROW FORMAT SERDE |
| 'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe' |
| STORED AS INPUTFORMAT |
| 'org.apache.hadoop.mapred.TextInputFormat' |
| OUTPUTFORMAT |
| 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat' |
| LOCATION |
| 'hdfs://sandbox-hdp.hortonworks.com:8020/warehouse/tablespace/managed/hive/state_players' |
| TBLPROPERTIES ( |
| 'bucketing_version'='2', |
| 'transactional'='true', |
| 'transactional_properties'='insert_only', |
| 'transient_lastDdlTime'='1627167951') |
+----------------------------------------------------+
Hive Query- insert into table state_players partition(place) select * from ind_players;
Query Output- The Data is inserted into tables and created seperate directories in the table location;
Hive Query- select * from state_players;
Query Output-
+---------------------+----------------------+
| state_players.name | state_players.place |
+---------------------+----------------------+
| rahul | bangalore |
| manish | bangalore |
| nair | bangalore |
| mayank | bangalore |
| kohli | delhi |
| dhawan | delhi |
| dhoni | jharkand |
| kishan | jharkand |
| iyer | mumbai |
| tendulkar | mumbai |
+---------------------+----------------------+
HDFS Command- hdfs dfs -ls /warehouse/tablespace/managed/hive/state_players/
Command Output-
Found 4 items
drwxr-xr-x+ - hive hadoop 0 2021-07-31 17:27 /warehouse/tablespace/managed/hive/state_players/place=bangalore
drwxr-xr-x+ - hive hadoop 0 2021-07-31 17:27 /warehouse/tablespace/managed/hive/state_players/place=delhi
drwxr-xr-x+ - hive hadoop 0 2021-07-31 17:27 /warehouse/tablespace/managed/hive/state_players/place=jharkand
drwxr-xr-x+ - hive hadoop 0 2021-07-31 17:27 /warehouse/tablespace/managed/hive/state_players/place=mumbai
HDFS Command-hdfs dfs -ls /warehouse/tablespace/managed/hive/place=mumbai/
Command Output-
Found 1 items
drwxrwxrwx+ - hive hadoop 0 2021-07-31 17:27 /warehouse/tablespace/managed/hive/state_players/place=mumbai/delta_0000011_0000011_0000
HDFS Command-hdfs dfs -ls /warehouse/tablespace/managed/hive/state_players/place=mumbai/delta_0000011_0000011_0000/
Command Output-
Found 1 items
-rw-rw-rw-+ 1 hive hadoop 15 2021-07-31 17:28 /warehouse/tablespace/managed/hive/state_players/place=mumbai/delta_0000011_0000011_0000/000000_0
HDFS Command-hdfs dfs -ls /warehouse/tablespace/managed/hive/state_players/place=mumbai/delta_0000011_0000011_0000/000000_0
Command Output-
iyer
tendulkar
***************************Bucketing in Hive*******************************
Unix Command-vi Bucket_Input.csv
Input Data present in the file-
1,kohli,delhi
2,dhawan,delhi
3,dhoni,jharkand
4,kishan,jharkand
5,rahul,bangalore
6,manish,bangalore
7,mayank,bangalore
8,iyer,mumbai
9,nair,bangalore
10,tendulkar,mumbai
Hive Query-create table bucketing (id int,name string,place string) clustered by(id) into 2 buckets row format serde 'org.apache.hadoop.hive.serde2.OpenCSVSerde' with SERDEPROPERTIES ('seperatorChar'=',') stored as TEXTFILE;
Query Output -Table is created with following properties;
Hive Query-show create table bucketing;
Query Output -
+----------------------------------------------------+
| createtab_stmt |
+----------------------------------------------------+
| CREATE TABLE `bucketing`( |
| `id` string COMMENT 'from deserializer', |
| `name` string COMMENT 'from deserializer', |
| `place` string COMMENT 'from deserializer') |
| CLUSTERED BY ( |
| id) |
| INTO 2 BUCKETS |
| ROW FORMAT SERDE |
| 'org.apache.hadoop.hive.serde2.OpenCSVSerde' |
| WITH SERDEPROPERTIES ( |
| 'seperatorChar'=',') |
| STORED AS INPUTFORMAT |
| 'org.apache.hadoop.mapred.TextInputFormat' |
| OUTPUTFORMAT |
| 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat' |
| LOCATION |
| 'hdfs://sandbox-hdp.hortonworks.com:8020/warehouse/tablespace/managed/hive/bucketing' |
| TBLPROPERTIES ( |
| 'bucketing_version'='2', |
| 'transactional'='true', |
| 'transactional_properties'='insert_only', |
| 'transient_lastDdlTime'='1627764848') |
+----------------------------------------------------+
Hive Query-load data local inpath '/Hive_Practice/Bucket_Input.csv' overwrite into table bucketing;
Query Output- Data is loaded;
Hive Query-select * from bucketing;
Query Output-
+---------------+-----------------+------------------+
| bucketing.id | bucketing.name | bucketing.place |
+---------------+-----------------+------------------+