-
Notifications
You must be signed in to change notification settings - Fork 118
/
AWSCatalogMetastoreClient.java
2455 lines (2106 loc) · 99.9 KB
/
AWSCatalogMetastoreClient.java
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
package com.amazonaws.glue.catalog.metastore;
import com.amazonaws.AmazonServiceException;
import com.amazonaws.glue.catalog.converters.CatalogToHiveConverter;
import com.amazonaws.glue.catalog.converters.GlueInputConverter;
import com.amazonaws.glue.catalog.converters.Hive3CatalogToHiveConverter;
import com.amazonaws.glue.catalog.util.BatchDeletePartitionsHelper;
import com.amazonaws.glue.catalog.util.ExpressionHelper;
import com.amazonaws.glue.catalog.util.LoggingHelper;
import com.amazonaws.glue.catalog.util.MetastoreClientUtils;
import com.amazonaws.glue.shims.AwsGlueHiveShims;
import com.amazonaws.glue.shims.ShimsLoader;
import com.amazonaws.services.glue.AWSGlue;
import com.amazonaws.services.glue.model.AlreadyExistsException;
import com.amazonaws.services.glue.model.EntityNotFoundException;
import com.amazonaws.services.glue.model.GetDatabaseRequest;
import com.amazonaws.services.glue.model.Partition;
import com.amazonaws.services.glue.model.UpdatePartitionRequest;
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hive.common.FileUtils;
import org.apache.hadoop.hive.common.StatsSetupConst;
import org.apache.hadoop.hive.common.ValidTxnList;
import org.apache.hadoop.hive.common.ValidWriteIdList;
import org.apache.hadoop.hive.metastore.HiveMetaHookLoader;
import org.apache.hadoop.hive.metastore.IMetaStoreClient;
import org.apache.hadoop.hive.metastore.PartitionDropOptions;
import org.apache.hadoop.hive.metastore.TableType;
import org.apache.hadoop.hive.metastore.Warehouse;
import org.apache.hadoop.hive.metastore.api.AggrStats;
import org.apache.hadoop.hive.metastore.api.Catalog;
import org.apache.hadoop.hive.metastore.api.CheckConstraintsRequest;
import org.apache.hadoop.hive.metastore.api.CmRecycleRequest;
import org.apache.hadoop.hive.metastore.api.CmRecycleResponse;
import org.apache.hadoop.hive.metastore.api.ColumnStatisticsObj;
import org.apache.hadoop.hive.metastore.api.CompactionResponse;
import org.apache.hadoop.hive.metastore.api.CompactionType;
import org.apache.hadoop.hive.metastore.api.ConfigValSecurityException;
import org.apache.hadoop.hive.metastore.api.CreationMetadata;
import org.apache.hadoop.hive.metastore.api.CurrentNotificationEventId;
import org.apache.hadoop.hive.metastore.api.DataOperationType;
import org.apache.hadoop.hive.metastore.api.Database;
import org.apache.hadoop.hive.metastore.api.DefaultConstraintsRequest;
import org.apache.hadoop.hive.metastore.api.EnvironmentContext;
import org.apache.hadoop.hive.metastore.api.FieldSchema;
import org.apache.hadoop.hive.metastore.api.FindSchemasByColsResp;
import org.apache.hadoop.hive.metastore.api.FindSchemasByColsRqst;
import org.apache.hadoop.hive.metastore.api.FireEventRequest;
import org.apache.hadoop.hive.metastore.api.FireEventResponse;
import org.apache.hadoop.hive.metastore.api.ForeignKeysRequest;
import org.apache.hadoop.hive.metastore.api.Function;
import org.apache.hadoop.hive.metastore.api.GetAllFunctionsResponse;
import org.apache.hadoop.hive.metastore.api.GetOpenTxnsInfoResponse;
import org.apache.hadoop.hive.metastore.api.GetRoleGrantsForPrincipalRequest;
import org.apache.hadoop.hive.metastore.api.GetRoleGrantsForPrincipalResponse;
import org.apache.hadoop.hive.metastore.api.HeartbeatTxnRangeResponse;
import org.apache.hadoop.hive.metastore.api.HiveObjectPrivilege;
import org.apache.hadoop.hive.metastore.api.HiveObjectRef;
import org.apache.hadoop.hive.metastore.api.HiveObjectType;
import org.apache.hadoop.hive.metastore.api.ISchema;
import org.apache.hadoop.hive.metastore.api.InvalidInputException;
import org.apache.hadoop.hive.metastore.api.InvalidObjectException;
import org.apache.hadoop.hive.metastore.api.InvalidOperationException;
import org.apache.hadoop.hive.metastore.api.InvalidPartitionException;
import org.apache.hadoop.hive.metastore.api.LockRequest;
import org.apache.hadoop.hive.metastore.api.LockResponse;
import org.apache.hadoop.hive.metastore.api.Materialization;
import org.apache.hadoop.hive.metastore.api.MetaException;
import org.apache.hadoop.hive.metastore.api.MetadataPpdResult;
import org.apache.hadoop.hive.metastore.api.NoSuchLockException;
import org.apache.hadoop.hive.metastore.api.NoSuchObjectException;
import org.apache.hadoop.hive.metastore.api.NoSuchTxnException;
import org.apache.hadoop.hive.metastore.api.NotNullConstraintsRequest;
import org.apache.hadoop.hive.metastore.api.NotificationEventResponse;
import org.apache.hadoop.hive.metastore.api.NotificationEventsCountRequest;
import org.apache.hadoop.hive.metastore.api.NotificationEventsCountResponse;
import org.apache.hadoop.hive.metastore.api.OpenTxnsResponse;
import org.apache.hadoop.hive.metastore.api.PartitionEventType;
import org.apache.hadoop.hive.metastore.api.PartitionValuesRequest;
import org.apache.hadoop.hive.metastore.api.PartitionValuesResponse;
import org.apache.hadoop.hive.metastore.api.PrimaryKeysRequest;
import org.apache.hadoop.hive.metastore.api.PrivilegeBag;
import org.apache.hadoop.hive.metastore.api.RuntimeStat;
import org.apache.hadoop.hive.metastore.api.SQLCheckConstraint;
import org.apache.hadoop.hive.metastore.api.SQLDefaultConstraint;
import org.apache.hadoop.hive.metastore.api.SQLForeignKey;
import org.apache.hadoop.hive.metastore.api.SQLNotNullConstraint;
import org.apache.hadoop.hive.metastore.api.SQLPrimaryKey;
import org.apache.hadoop.hive.metastore.api.SQLUniqueConstraint;
import org.apache.hadoop.hive.metastore.api.SchemaVersion;
import org.apache.hadoop.hive.metastore.api.SchemaVersionState;
import org.apache.hadoop.hive.metastore.api.SerDeInfo;
import org.apache.hadoop.hive.metastore.api.ShowCompactResponse;
import org.apache.hadoop.hive.metastore.api.ShowLocksRequest;
import org.apache.hadoop.hive.metastore.api.ShowLocksResponse;
import org.apache.hadoop.hive.metastore.api.Table;
import org.apache.hadoop.hive.metastore.api.TableMeta;
import org.apache.hadoop.hive.metastore.api.TableValidWriteIds;
import org.apache.hadoop.hive.metastore.api.TxnAbortedException;
import org.apache.hadoop.hive.metastore.api.TxnOpenException;
import org.apache.hadoop.hive.metastore.api.TxnToWriteId;
import org.apache.hadoop.hive.metastore.api.UniqueConstraintsRequest;
import org.apache.hadoop.hive.metastore.api.UnknownDBException;
import org.apache.hadoop.hive.metastore.api.UnknownPartitionException;
import org.apache.hadoop.hive.metastore.api.UnknownTableException;
import org.apache.hadoop.hive.metastore.api.WMFullResourcePlan;
import org.apache.hadoop.hive.metastore.api.WMMapping;
import org.apache.hadoop.hive.metastore.api.WMNullablePool;
import org.apache.hadoop.hive.metastore.api.WMNullableResourcePlan;
import org.apache.hadoop.hive.metastore.api.WMPool;
import org.apache.hadoop.hive.metastore.api.WMResourcePlan;
import org.apache.hadoop.hive.metastore.api.WMTrigger;
import org.apache.hadoop.hive.metastore.api.WMValidateResourcePlanResponse;
import org.apache.hadoop.hive.metastore.api.hive_metastoreConstants;
import org.apache.hadoop.hive.metastore.conf.MetastoreConf;
import org.apache.hadoop.hive.metastore.partition.spec.PartitionSpecProxy;
import org.apache.hadoop.hive.metastore.utils.MetaStoreUtils;
import org.apache.hadoop.hive.metastore.utils.ObjectPair;
import org.apache.log4j.Logger;
import org.apache.thrift.TException;
import java.io.IOException;
import java.net.URI;
import java.nio.ByteBuffer;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.regex.Pattern;
import static com.amazonaws.glue.catalog.util.MetastoreClientUtils.isExternalTable;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.apache.hadoop.hive.metastore.Warehouse.DEFAULT_DATABASE_COMMENT;
import static org.apache.hadoop.hive.metastore.Warehouse.DEFAULT_DATABASE_NAME;
public class AWSCatalogMetastoreClient implements IMetaStoreClient {
// TODO "hook" into Hive logging (hive or hive.metastore)
private static final Logger logger = Logger.getLogger(AWSCatalogMetastoreClient.class);
private final Configuration conf;
private final AWSGlue glueClient;
private final Warehouse wh;
private final GlueMetastoreClientDelegate glueMetastoreClientDelegate;
private final String catalogId;
private final CatalogToHiveConverter catalogToHiveConverter;
private static final int BATCH_DELETE_PARTITIONS_PAGE_SIZE = 25;
private static final int BATCH_DELETE_PARTITIONS_THREADS_COUNT = 5;
static final String BATCH_DELETE_PARTITIONS_THREAD_POOL_NAME_FORMAT = "batch-delete-partitions-%d";
private static final ExecutorService BATCH_DELETE_PARTITIONS_THREAD_POOL = Executors.newFixedThreadPool(
BATCH_DELETE_PARTITIONS_THREADS_COUNT,
new ThreadFactoryBuilder()
.setNameFormat(BATCH_DELETE_PARTITIONS_THREAD_POOL_NAME_FORMAT)
.setDaemon(true).build()
);
private Map<String, String> currentMetaVars;
private final AwsGlueHiveShims hiveShims = ShimsLoader.getHiveShims();
public AWSCatalogMetastoreClient(Configuration conf, HiveMetaHookLoader hook) throws MetaException {
this.conf = conf;
catalogId = MetastoreClientUtils.getCatalogId(conf);
glueClient = new AWSGlueClientFactory(this.conf).newClient();
catalogToHiveConverter = new Hive3CatalogToHiveConverter();
// TODO preserve existing functionality for HiveMetaHook
wh = new Warehouse(this.conf);
AWSGlueMetastore glueMetastore = new AWSGlueMetastoreFactory().newMetastore(conf);
glueMetastoreClientDelegate = new GlueMetastoreClientDelegate(this.conf, glueMetastore, wh);
snapshotActiveConf();
if (!doesDefaultDBExist()) {
createDefaultDatabase();
}
}
/**
* Currently used for unit tests
*/
public static class Builder {
private Configuration conf;
private Warehouse wh;
private GlueClientFactory clientFactory;
private AWSGlueMetastoreFactory metastoreFactory;
private boolean createDefaults = true;
private String catalogId;
private GlueMetastoreClientDelegate glueMetastoreClientDelegate;
public Builder withConf(Configuration conf) {
this.conf = conf;
return this;
}
public Builder withClientFactory(GlueClientFactory clientFactory) {
this.clientFactory = clientFactory;
return this;
}
public Builder withMetastoreFactory(AWSGlueMetastoreFactory metastoreFactory) {
this.metastoreFactory = metastoreFactory;
return this;
}
public Builder withWarehouse(Warehouse wh) {
this.wh = wh;
return this;
}
public Builder withCatalogId(String catalogId) {
this.catalogId = catalogId;
return this;
}
public Builder withGlueMetastoreClientDelegate(GlueMetastoreClientDelegate clientDelegate) {
this.glueMetastoreClientDelegate = clientDelegate;
return this;
}
public AWSCatalogMetastoreClient build() throws MetaException {
return new AWSCatalogMetastoreClient(this);
}
public Builder createDefaults(boolean createDefaultDB) {
this.createDefaults = createDefaultDB;
return this;
}
}
private AWSCatalogMetastoreClient(Builder builder) throws MetaException {
catalogToHiveConverter = new Hive3CatalogToHiveConverter();
conf = MoreObjects.firstNonNull(builder.conf, MetastoreConf.newMetastoreConf());
if (builder.wh != null) {
this.wh = builder.wh;
} else {
this.wh = new Warehouse(conf);
}
if (builder.catalogId != null) {
this.catalogId = builder.catalogId;
} else {
this.catalogId = null;
}
GlueClientFactory clientFactory = MoreObjects.firstNonNull(builder.clientFactory, new AWSGlueClientFactory(conf));
AWSGlueMetastoreFactory metastoreFactory = MoreObjects.firstNonNull(builder.metastoreFactory,
new AWSGlueMetastoreFactory());
glueClient = clientFactory.newClient();
AWSGlueMetastore glueMetastore = metastoreFactory.newMetastore(conf);
glueMetastoreClientDelegate = new GlueMetastoreClientDelegate(this.conf, glueMetastore, wh);
/**
* It seems weird to create databases as part of client construction. This
* part should probably be moved to the section in hive code right after the
* metastore client is instantiated. For now, simply copying the
* functionality in the thrift server
*/
if(builder.createDefaults && !doesDefaultDBExist()) {
createDefaultDatabase();
}
}
private boolean doesDefaultDBExist() throws MetaException {
try {
GetDatabaseRequest getDatabaseRequest = new GetDatabaseRequest().withName(DEFAULT_DATABASE_NAME).withCatalogId(
catalogId);
glueClient.getDatabase(getDatabaseRequest);
} catch (EntityNotFoundException e) {
return false;
} catch (AmazonServiceException e) {
String msg = "Unable to verify existence of default database: ";
logger.error(msg, e);
throw new MetaException(msg + e);
}
return true;
}
private void createDefaultDatabase() throws MetaException {
Database defaultDB = new Database();
defaultDB.setName(DEFAULT_DATABASE_NAME);
defaultDB.setDescription(DEFAULT_DATABASE_COMMENT);
defaultDB.setLocationUri(wh.getDefaultDatabasePath(DEFAULT_DATABASE_NAME).toString());
org.apache.hadoop.hive.metastore.api.PrincipalPrivilegeSet principalPrivilegeSet
= new org.apache.hadoop.hive.metastore.api.PrincipalPrivilegeSet();
principalPrivilegeSet.setRolePrivileges(Maps.<String, List<org.apache.hadoop.hive.metastore.api.PrivilegeGrantInfo>>newHashMap());
defaultDB.setPrivileges(principalPrivilegeSet);
/**
* TODO: Grant access to role PUBLIC after role support is added
*/
try {
createDatabase(defaultDB);
} catch (org.apache.hadoop.hive.metastore.api.AlreadyExistsException e) {
logger.warn("database - default already exists. Ignoring..");
} catch (Exception e) {
logger.error("Unable to create default database", e);
}
}
@Override
public void createDatabase(Database database) throws InvalidObjectException,
org.apache.hadoop.hive.metastore.api.AlreadyExistsException, MetaException, TException {
glueMetastoreClientDelegate.createDatabase(database);
}
@Override
public Database getDatabase(String name) throws NoSuchObjectException, MetaException, TException {
return glueMetastoreClientDelegate.getDatabase(name);
}
@Override
public Database getDatabase(String catalogName, String dbName) throws NoSuchObjectException, MetaException, TException {
return glueMetastoreClientDelegate.getDatabase(dbName);
}
@Override
public List<String> getDatabases(String pattern) throws MetaException, TException {
return glueMetastoreClientDelegate.getDatabases(pattern);
}
@Override
public List<String> getDatabases(String catalogName, String dbPattern) throws MetaException, TException {
return glueMetastoreClientDelegate.getDatabases(dbPattern);
}
@Override
public List<String> getAllDatabases() throws MetaException, TException {
return getDatabases(".*");
}
@Override
public List<String> getAllDatabases(String catalogName) throws MetaException, TException {
return getDatabases(".*");
}
@Override
public void alterDatabase(String databaseName, Database database) throws NoSuchObjectException, MetaException,
TException {
glueMetastoreClientDelegate.alterDatabase(databaseName, database);
}
@Override
public void alterDatabase(String catalogName, String databaseName, Database database) throws NoSuchObjectException, MetaException, TException {
glueMetastoreClientDelegate.alterDatabase(databaseName, database);
}
@Override
public void dropDatabase(String name) throws NoSuchObjectException, InvalidOperationException, MetaException,
TException {
dropDatabase(name, true, false, false);
}
@Override
public void dropDatabase(String name, boolean deleteData, boolean ignoreUnknownDb) throws NoSuchObjectException,
InvalidOperationException, MetaException, TException {
dropDatabase(name, deleteData, ignoreUnknownDb, false);
}
@Override
public void dropDatabase(String name, boolean deleteData, boolean ignoreUnknownDb, boolean cascade)
throws NoSuchObjectException, InvalidOperationException, MetaException, TException {
glueMetastoreClientDelegate.dropDatabase(name, deleteData, ignoreUnknownDb, cascade);
}
@Override
public void dropDatabase(String catalogName, String dbName, boolean deleteData, boolean ignoreUnknownDb, boolean cascade) throws NoSuchObjectException, InvalidOperationException, MetaException, TException {
glueMetastoreClientDelegate.dropDatabase(dbName, deleteData, ignoreUnknownDb, cascade);
}
@Override
public org.apache.hadoop.hive.metastore.api.Partition add_partition(org.apache.hadoop.hive.metastore.api.Partition partition)
throws InvalidObjectException, org.apache.hadoop.hive.metastore.api.AlreadyExistsException, MetaException,
TException {
glueMetastoreClientDelegate.addPartitions(Lists.newArrayList(partition), false, true);
return partition;
}
@Override
public int add_partitions(List<org.apache.hadoop.hive.metastore.api.Partition> partitions)
throws InvalidObjectException, org.apache.hadoop.hive.metastore.api.AlreadyExistsException, MetaException,
TException {
return glueMetastoreClientDelegate.addPartitions(partitions, false, true).size();
}
@Override
public List<org.apache.hadoop.hive.metastore.api.Partition> add_partitions(
List<org.apache.hadoop.hive.metastore.api.Partition> partitions,
boolean ifNotExists,
boolean needResult
) throws TException {
return glueMetastoreClientDelegate.addPartitions(partitions, ifNotExists, needResult);
}
@Override
public int add_partitions_pspec(
PartitionSpecProxy pSpec
) throws InvalidObjectException, org.apache.hadoop.hive.metastore.api.AlreadyExistsException,
MetaException, TException {
return glueMetastoreClientDelegate.addPartitionsSpecProxy(pSpec);
}
@Override
public void alterFunction(String dbName, String functionName, org.apache.hadoop.hive.metastore.api.Function newFunction) throws InvalidObjectException,
MetaException, TException {
glueMetastoreClientDelegate.alterFunction(dbName, functionName, newFunction);
}
@Override
public void alterFunction(String catalogName, String dbName, String functionName, Function newFunction) throws InvalidObjectException, MetaException, TException {
glueMetastoreClientDelegate.alterFunction(dbName, functionName, newFunction);
}
@Override
public void alter_partition(
String dbName,
String tblName,
org.apache.hadoop.hive.metastore.api.Partition partition
) throws InvalidOperationException, MetaException, TException {
glueMetastoreClientDelegate.alterPartitions(dbName, tblName, Lists.newArrayList(partition));
}
@Override
public void alter_partition(
String dbName,
String tblName,
org.apache.hadoop.hive.metastore.api.Partition partition,
EnvironmentContext environmentContext
) throws InvalidOperationException, MetaException, TException {
glueMetastoreClientDelegate.alterPartitions(dbName, tblName, Lists.newArrayList(partition));
}
@Override
public void alter_partition(
String catalogName,
String dbName,
String tblName,
org.apache.hadoop.hive.metastore.api.Partition partition,
EnvironmentContext environmentContext
) throws InvalidOperationException, MetaException, TException {
glueMetastoreClientDelegate.alterPartitions(dbName, tblName, Lists.newArrayList(partition));
}
@Override
public void alter_partitions(
String dbName,
String tblName,
List<org.apache.hadoop.hive.metastore.api.Partition> partitions
) throws InvalidOperationException, MetaException, TException {
glueMetastoreClientDelegate.alterPartitions(dbName, tblName, partitions);
}
@Override
public void alter_partitions(
String dbName,
String tblName,
List<org.apache.hadoop.hive.metastore.api.Partition> partitions,
EnvironmentContext environmentContext
) throws InvalidOperationException, MetaException, TException {
glueMetastoreClientDelegate.alterPartitions(dbName, tblName, partitions);
}
@Override
public void alter_partitions(
String catalogName,
String dbName,
String tblName,
List<org.apache.hadoop.hive.metastore.api.Partition> partitions,
EnvironmentContext environmentContext
) throws InvalidOperationException, MetaException, TException {
glueMetastoreClientDelegate.alterPartitions(dbName, tblName, partitions);
}
@Override
public void alter_table(String dbName, String tblName, Table table)
throws InvalidOperationException, MetaException, TException {
glueMetastoreClientDelegate.alterTable(dbName, tblName, table, null);
}
@Override
public void alter_table(String catalogName, String dbName, String tblName, Table table, EnvironmentContext environmentContext)
throws InvalidOperationException, MetaException, TException {
glueMetastoreClientDelegate.alterTable(dbName, tblName, table, null);
}
@Override
public void alter_table(String dbName, String tblName, Table table, boolean cascade)
throws InvalidOperationException, MetaException, TException {
EnvironmentContext environmentContext = null;
if (cascade) {
environmentContext = new EnvironmentContext();
environmentContext.putToProperties("CASCADE", StatsSetupConst.TRUE);
}
glueMetastoreClientDelegate.alterTable(dbName, tblName, table, environmentContext);
}
@Override
public void alter_table_with_environmentContext(
String dbName,
String tblName,
Table table,
EnvironmentContext environmentContext
) throws InvalidOperationException, MetaException, TException {
glueMetastoreClientDelegate.alterTable(dbName, tblName, table, environmentContext);
}
@Override
public org.apache.hadoop.hive.metastore.api.Partition appendPartition(String dbName, String tblName, List<String> values)
throws InvalidObjectException, org.apache.hadoop.hive.metastore.api.AlreadyExistsException, MetaException, TException {
return glueMetastoreClientDelegate.appendPartition(dbName, tblName, values);
}
@Override
public org.apache.hadoop.hive.metastore.api.Partition appendPartition(String catalogName, String dbName, String tblName, List<String> values)
throws InvalidObjectException, org.apache.hadoop.hive.metastore.api.AlreadyExistsException, MetaException, TException {
return glueMetastoreClientDelegate.appendPartition(dbName, tblName, values);
}
@Override
public org.apache.hadoop.hive.metastore.api.Partition appendPartition(String dbName, String tblName, String partitionName) throws InvalidObjectException,
org.apache.hadoop.hive.metastore.api.AlreadyExistsException, MetaException, TException {
List<String> partVals = partitionNameToVals(partitionName);
return glueMetastoreClientDelegate.appendPartition(dbName, tblName, partVals);
}
@Override
public org.apache.hadoop.hive.metastore.api.Partition appendPartition(String catalogName, String dbName, String tblName, String partitionName)
throws InvalidObjectException, org.apache.hadoop.hive.metastore.api.AlreadyExistsException, MetaException, TException {
List<String> partVals = partitionNameToVals(partitionName);
return glueMetastoreClientDelegate.appendPartition(dbName, tblName, partVals);
}
@Override
public boolean create_role(org.apache.hadoop.hive.metastore.api.Role role) throws MetaException, TException {
return glueMetastoreClientDelegate.createRole(role);
}
@Override
public boolean drop_role(String roleName) throws MetaException, TException {
return glueMetastoreClientDelegate.dropRole(roleName);
}
@Override
public List<org.apache.hadoop.hive.metastore.api.Role> list_roles(
String principalName, org.apache.hadoop.hive.metastore.api.PrincipalType principalType
) throws MetaException, TException {
return glueMetastoreClientDelegate.listRoles(principalName, principalType);
}
@Override
public List<String> listRoleNames() throws MetaException, TException {
return glueMetastoreClientDelegate.listRoleNames();
}
@Override
public org.apache.hadoop.hive.metastore.api.GetPrincipalsInRoleResponse get_principals_in_role(
org.apache.hadoop.hive.metastore.api.GetPrincipalsInRoleRequest request) throws MetaException, TException {
return glueMetastoreClientDelegate.getPrincipalsInRole(request);
}
@Override
public GetRoleGrantsForPrincipalResponse get_role_grants_for_principal(
GetRoleGrantsForPrincipalRequest request) throws MetaException, TException {
return glueMetastoreClientDelegate.getRoleGrantsForPrincipal(request);
}
@Override
public boolean grant_role(
String roleName,
String userName,
org.apache.hadoop.hive.metastore.api.PrincipalType principalType,
String grantor, org.apache.hadoop.hive.metastore.api.PrincipalType grantorType,
boolean grantOption
) throws MetaException, TException {
return glueMetastoreClientDelegate.grantRole(roleName, userName, principalType, grantor, grantorType, grantOption);
}
@Override
public boolean revoke_role(
String roleName,
String userName,
org.apache.hadoop.hive.metastore.api.PrincipalType principalType,
boolean grantOption
) throws MetaException, TException {
return glueMetastoreClientDelegate.revokeRole(roleName, userName, principalType, grantOption);
}
@Override
public void cancelDelegationToken(String tokenStrForm) throws MetaException, TException {
glueMetastoreClientDelegate.cancelDelegationToken(tokenStrForm);
}
@Override
public String getTokenStrForm() throws IOException {
return glueMetastoreClientDelegate.getTokenStrForm();
}
@Override
public boolean addToken(String tokenIdentifier, String delegationToken) throws TException {
return glueMetastoreClientDelegate.addToken(tokenIdentifier, delegationToken);
}
@Override
public boolean removeToken(String tokenIdentifier) throws TException {
return glueMetastoreClientDelegate.removeToken(tokenIdentifier);
}
@Override
public String getToken(String tokenIdentifier) throws TException {
return glueMetastoreClientDelegate.getToken(tokenIdentifier);
}
@Override
public List<String> getAllTokenIdentifiers() throws TException {
return glueMetastoreClientDelegate.getAllTokenIdentifiers();
}
@Override
public int addMasterKey(String key) throws MetaException, TException {
return glueMetastoreClientDelegate.addMasterKey(key);
}
@Override
public void updateMasterKey(Integer seqNo, String key) throws NoSuchObjectException, MetaException, TException {
glueMetastoreClientDelegate.updateMasterKey(seqNo, key);
}
@Override
public boolean removeMasterKey(Integer keySeq) throws TException {
return glueMetastoreClientDelegate.removeMasterKey(keySeq);
}
@Override
public String[] getMasterKeys() throws TException {
return glueMetastoreClientDelegate.getMasterKeys();
}
@Override
public LockResponse checkLock(long lockId)
throws NoSuchTxnException, TxnAbortedException, NoSuchLockException, TException {
return glueMetastoreClientDelegate.checkLock(lockId);
}
@Override
public void close() {
currentMetaVars = null;
}
@Override
public void commitTxn(long txnId) throws NoSuchTxnException, TxnAbortedException, TException {
glueMetastoreClientDelegate.commitTxn(txnId);
}
@Override
public void replCommitTxn(long srcTxnid, String replPolicy) throws NoSuchTxnException, TxnAbortedException, TException {
glueMetastoreClientDelegate.replCommitTxn(srcTxnid, replPolicy);
}
@Override
public void abortTxns(List<Long> txnIds) throws TException {
glueMetastoreClientDelegate.abortTxns(txnIds);
}
@Override
public long allocateTableWriteId(long txnId, String dbName, String tableName) throws TException {
throw new UnsupportedOperationException("allocateTableWriteId is not supported.");
}
@Override
public void replTableWriteIdState(String validWriteIdList, String dbName, String tableName, List<String> partNames) throws TException {
throw new UnsupportedOperationException("replTableWriteIdState is not supported.");
}
@Override
public List<TxnToWriteId> allocateTableWriteIdsBatch(List<Long> txnIds, String dbName, String tableName) throws TException {
throw new UnsupportedOperationException("allocateTableWriteIdsBatch is not supported.");
}
@Override
public List<TxnToWriteId> replAllocateTableWriteIdsBatch(String dbName, String tableName, String replPolicy,
List<TxnToWriteId> srcTxnToWriteIdList) throws TException {
throw new UnsupportedOperationException("replAllocateTableWriteIdsBatch is not supported.");
}
@Deprecated
public void compact(
String dbName,
String tblName,
String partitionName,
CompactionType compactionType
) throws TException {
glueMetastoreClientDelegate.compact(dbName, tblName, partitionName, compactionType);
}
@Deprecated
public void compact(
String dbName,
String tblName,
String partitionName,
CompactionType compactionType,
Map<String, String> tblProperties
) throws TException {
glueMetastoreClientDelegate.compact(dbName, tblName, partitionName, compactionType, tblProperties);
}
@Override
public CompactionResponse compact2(
String dbName,
String tblName,
String partitionName,
CompactionType compactionType,
Map<String, String> tblProperties
) throws TException {
return glueMetastoreClientDelegate.compact2(dbName, tblName, partitionName, compactionType, tblProperties);
}
@Override
public void createFunction(org.apache.hadoop.hive.metastore.api.Function function) throws InvalidObjectException, MetaException, TException {
glueMetastoreClientDelegate.createFunction(function);
}
@Override
public void createTable(Table tbl) throws org.apache.hadoop.hive.metastore.api.AlreadyExistsException, InvalidObjectException, MetaException,
NoSuchObjectException, TException {
glueMetastoreClientDelegate.createTable(tbl);
}
@Override
public boolean deletePartitionColumnStatistics(
String dbName, String tableName, String partName, String colName
) throws NoSuchObjectException, MetaException, InvalidObjectException,
TException, org.apache.hadoop.hive.metastore.api.InvalidInputException {
return glueMetastoreClientDelegate.deletePartitionColumnStatistics(dbName, tableName, partName, colName);
}
@Override
public boolean deletePartitionColumnStatistics(String catalogName, String dbName, String tableName, String partName, String colName)
throws NoSuchObjectException, MetaException, InvalidObjectException, TException, InvalidInputException {
return glueMetastoreClientDelegate.deletePartitionColumnStatistics(dbName, tableName, partName, colName);
}
@Override
public boolean deleteTableColumnStatistics(
String dbName, String tableName, String colName
) throws NoSuchObjectException, MetaException, InvalidObjectException,
TException, org.apache.hadoop.hive.metastore.api.InvalidInputException {
return glueMetastoreClientDelegate.deleteTableColumnStatistics(dbName, tableName, colName);
}
@Override
public boolean deleteTableColumnStatistics(String catalogName, String dbName, String tableName, String colName)
throws NoSuchObjectException, MetaException, InvalidObjectException, TException, InvalidInputException {
return glueMetastoreClientDelegate.deleteTableColumnStatistics(dbName, tableName, colName);
}
@Override
public void dropFunction(String dbName, String functionName) throws MetaException, NoSuchObjectException,
InvalidObjectException, org.apache.hadoop.hive.metastore.api.InvalidInputException, TException {
glueMetastoreClientDelegate.dropFunction(dbName, functionName);
}
@Override
public void dropFunction(String catalogName, String dbName, String functionName)
throws MetaException, NoSuchObjectException, InvalidObjectException, InvalidInputException, TException {
glueMetastoreClientDelegate.dropFunction(dbName, functionName);
}
private void deleteParentRecursive(Path parent, int depth, boolean mustPurge) throws IOException, MetaException {
if (depth > 0 && parent != null && wh.isWritable(parent) && wh.isEmpty(parent)) {
wh.deleteDir(parent, true, mustPurge, true);
deleteParentRecursive(parent.getParent(), depth - 1, mustPurge);
}
}
// This logic is taken from HiveMetaStore#isMustPurge
private boolean isMustPurge(Table table, boolean ifPurge) {
return (ifPurge || "true".equalsIgnoreCase(table.getParameters().get("auto.purge")));
}
@Override
public boolean dropPartition(String dbName, String tblName, List<String> values, boolean deleteData)
throws NoSuchObjectException, MetaException, TException {
return glueMetastoreClientDelegate.dropPartition(dbName, tblName, values, false, deleteData, false);
}
@Override
public boolean dropPartition(String catalogName, String dbName, String tblName, List<String> values, boolean deleteData)
throws NoSuchObjectException, MetaException, TException {
return glueMetastoreClientDelegate.dropPartition(dbName, tblName, values, false, deleteData, false);
}
@Override
public boolean dropPartition(String dbName, String tblName, List<String> values, PartitionDropOptions options) throws TException {
return glueMetastoreClientDelegate.dropPartition(dbName, tblName, values, options.ifExists, options.deleteData, options.purgeData);
}
@Override
public boolean dropPartition(String catalogName, String dbName, String tblName, List<String> values, PartitionDropOptions options)
throws NoSuchObjectException, MetaException, TException {
return glueMetastoreClientDelegate.dropPartition(dbName, tblName, values, options.ifExists, options.deleteData, options.purgeData);
}
@Override
public List<org.apache.hadoop.hive.metastore.api.Partition> dropPartitions(
String dbName,
String tblName,
List<ObjectPair<Integer, byte[]>> partExprs,
boolean deleteData,
boolean ifExists
) throws NoSuchObjectException, MetaException, TException {
//use defaults from PartitionDropOptions for purgeData
return dropPartitions_core(dbName, tblName, partExprs, deleteData, false);
}
@Override
public List<org.apache.hadoop.hive.metastore.api.Partition> dropPartitions(
String dbName,
String tblName,
List<ObjectPair<Integer, byte[]>> partExprs,
boolean deleteData,
boolean ifExists,
boolean needResults
) throws NoSuchObjectException, MetaException, TException {
return dropPartitions_core(dbName, tblName, partExprs, deleteData, false);
}
@Override
public List<org.apache.hadoop.hive.metastore.api.Partition> dropPartitions(
String dbName,
String tblName,
List<ObjectPair<Integer, byte[]>> partExprs,
PartitionDropOptions options
) throws NoSuchObjectException, MetaException, TException {
return dropPartitions_core(dbName, tblName, partExprs, options.deleteData, options.purgeData);
}
@Override
public List<org.apache.hadoop.hive.metastore.api.Partition> dropPartitions(
String catalogName,
String dbName,
String tblName,
List<ObjectPair<Integer, byte[]>> partExprs,
PartitionDropOptions options
) throws NoSuchObjectException, MetaException, TException {
return dropPartitions_core(dbName, tblName, partExprs, options.deleteData, options.purgeData);
}
@Override
public boolean dropPartition(String dbName, String tblName, String partitionName, boolean deleteData)
throws NoSuchObjectException, MetaException, TException {
List<String> values = partitionNameToVals(partitionName);
return glueMetastoreClientDelegate.dropPartition(dbName, tblName, values, false, deleteData, false);
}
@Override
public boolean dropPartition(String catalogName, String dbName, String tblName, String partitionName, boolean deleteData)
throws NoSuchObjectException, MetaException, TException {
List<String> values = partitionNameToVals(partitionName);
return glueMetastoreClientDelegate.dropPartition(dbName, tblName, values, false, deleteData, false);
}
private List<org.apache.hadoop.hive.metastore.api.Partition> dropPartitions_core(
String databaseName,
String tableName,
List<ObjectPair<Integer, byte[]>> partExprs,
boolean deleteData,
boolean purgeData
) throws TException {
List<org.apache.hadoop.hive.metastore.api.Partition> deleted = Lists.newArrayList();
for (ObjectPair<Integer, byte[]> expr : partExprs) {
byte[] tmp = expr.getSecond();
String exprString = ExpressionHelper.convertHiveExpressionToCatalogExpression(tmp);
List<Partition> catalogPartitionsToDelete = glueMetastoreClientDelegate.getCatalogPartitions(databaseName, tableName, exprString, -1);
deleted.addAll(batchDeletePartitions(databaseName, tableName, catalogPartitionsToDelete, deleteData, purgeData));
}
return deleted;
}
/**
* Delete all partitions in the list provided with BatchDeletePartitions request. It doesn't use transaction,
* so the call may result in partial failure.
* @param dbName
* @param tableName
* @param partitionsToDelete
* @return the partitions successfully deleted
* @throws TException
*/
private List<org.apache.hadoop.hive.metastore.api.Partition> batchDeletePartitions(
final String dbName, final String tableName, final List<Partition> partitionsToDelete,
final boolean deleteData, final boolean purgeData) throws TException {
List<org.apache.hadoop.hive.metastore.api.Partition> deleted = Lists.newArrayList();
if (partitionsToDelete == null) {
return deleted;
}
validateBatchDeletePartitionsArguments(dbName, tableName, partitionsToDelete);
List<Future<BatchDeletePartitionsHelper>> batchDeletePartitionsFutures = Lists.newArrayList();
int numOfPartitionsToDelete = partitionsToDelete.size();
for (int i = 0; i < numOfPartitionsToDelete; i += BATCH_DELETE_PARTITIONS_PAGE_SIZE) {
int j = Math.min(i + BATCH_DELETE_PARTITIONS_PAGE_SIZE, numOfPartitionsToDelete);
final List<Partition> partitionsOnePage = partitionsToDelete.subList(i, j);
batchDeletePartitionsFutures.add(BATCH_DELETE_PARTITIONS_THREAD_POOL.submit(new Callable<BatchDeletePartitionsHelper>() {
@Override
public BatchDeletePartitionsHelper call() throws Exception {
return new BatchDeletePartitionsHelper(glueClient, dbName, tableName, catalogId, partitionsOnePage).deletePartitions();
}
}));
}
TException tException = null;
for (Future<BatchDeletePartitionsHelper> future : batchDeletePartitionsFutures) {
try {
BatchDeletePartitionsHelper batchDeletePartitionsHelper = future.get();
for (Partition partition : batchDeletePartitionsHelper.getPartitionsDeleted()) {
org.apache.hadoop.hive.metastore.api.Partition hivePartition =
catalogToHiveConverter.convertPartition(partition);
try {
performDropPartitionPostProcessing(dbName, tableName, hivePartition, deleteData, purgeData);
} catch (TException e) {
logger.error("Drop partition directory failed.", e);
tException = tException == null ? e : tException;
}
deleted.add(hivePartition);
}
tException = tException == null ? batchDeletePartitionsHelper.getFirstTException() : tException;
} catch (Exception e) {
logger.error("Exception thrown by BatchDeletePartitions thread pool. ", e);
}
}
if (tException != null) {
throw tException;
}
return deleted;
}
private void validateBatchDeletePartitionsArguments(final String dbName, final String tableName,
final List<Partition> partitionsToDelete) {
Preconditions.checkArgument(dbName != null, "Database name cannot be null");
Preconditions.checkArgument(tableName != null, "Table name cannot be null");
for (Partition partition : partitionsToDelete) {
Preconditions.checkArgument(dbName.equals(partition.getDatabaseName()), "Database name cannot be null");
Preconditions.checkArgument(tableName.equals(partition.getTableName()), "Table name cannot be null");
Preconditions.checkArgument(partition.getValues() != null, "Partition values cannot be null");
}
}
// Preserve the logic from Hive metastore
private void performDropPartitionPostProcessing(String dbName, String tblName,
org.apache.hadoop.hive.metastore.api.Partition partition, boolean deleteData, boolean ifPurge)
throws MetaException, NoSuchObjectException, TException {
if (deleteData && partition.getSd() != null && partition.getSd().getLocation() != null) {
Path partPath = new Path(partition.getSd().getLocation());
Table table = getTable(dbName, tblName);
if (isExternalTable(table)){
//Don't delete external table data
return;
}
boolean mustPurge = isMustPurge(table, ifPurge);
wh.deleteDir(partPath, true, mustPurge, true);
try {
List<String> values = partition.getValues();
deleteParentRecursive(partPath.getParent(), values.size() - 1, mustPurge);
} catch (IOException e) {
throw new MetaException(e.getMessage());
}
}
}
@Deprecated
public void dropTable(String tableName, boolean deleteData) throws MetaException, UnknownTableException, TException,
NoSuchObjectException {
dropTable(DEFAULT_DATABASE_NAME, tableName, deleteData, false);
}
@Override
public void dropTable(String dbname, String tableName) throws MetaException, TException, NoSuchObjectException {