• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

HotelsDotCom / waggle-dance / #318

pending completion
#318

push

web-flow
Feature/upgrade springboot (#268)

* update springboot to 2.1.18

* update springboot to 2.2.13

* Upgrade to srping boot 2.7.11

* Update changelog

* Update changelog

* fix version

3 of 3 new or added lines in 2 files covered. (100.0%)

132 of 3058 relevant lines covered (4.32%)

0.04 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/waggle-dance-core/src/main/java/com/hotels/bdp/waggledance/server/FederatedHMSHandler.java
1
/**
×
2
 * Copyright (C) 2016-2022 Expedia, Inc.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 * http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package com.hotels.bdp.waggledance.server;
17

18
import java.io.IOException;
19
import java.util.ArrayList;
20
import java.util.List;
21
import java.util.Map;
22

23
import org.apache.hadoop.conf.Configuration;
24
import org.apache.hadoop.hive.metastore.api.*;
25
import org.apache.thrift.TException;
26
import org.slf4j.Logger;
27
import org.slf4j.LoggerFactory;
28
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
29
import org.springframework.context.annotation.Scope;
30
import org.springframework.stereotype.Component;
31

32
import com.facebook.fb303.FacebookBase;
33
import com.facebook.fb303.fb_status;
34
import com.jcabi.aspects.Loggable;
35

36
import com.hotels.bdp.waggledance.conf.WaggleDanceConfiguration;
37
import com.hotels.bdp.waggledance.mapping.model.DatabaseMapping;
38
import com.hotels.bdp.waggledance.mapping.service.MappingEventListener;
39
import com.hotels.bdp.waggledance.mapping.service.impl.NotifyingFederationService;
40
import com.hotels.bdp.waggledance.metrics.Monitored;
41

42
@Monitored
43
@Component
44
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
45
class FederatedHMSHandler extends FacebookBase implements CloseableIHMSHandler {
46

47
  private static final Logger LOG = LoggerFactory.getLogger(FederatedHMSHandler.class);
48

49
  private static final String INVOCATION_LOG_NAME = "com.hotels.bdp.waggledance.server.invocation-log";
50
  private final MappingEventListener databaseMappingService;
51
  private final NotifyingFederationService notifyingFederationService;
52
  private final WaggleDanceConfiguration waggleDanceConfiguration;
53
  private Configuration conf;
54

55
  FederatedHMSHandler(
56
      MappingEventListener databaseMappingService,
57
      NotifyingFederationService notifyingFederationService,
58
      WaggleDanceConfiguration waggleDanceConfiguration) {
59
    super("waggle-dance-handler");
×
60
    this.databaseMappingService = databaseMappingService;
×
61
    this.notifyingFederationService = notifyingFederationService;
×
62
    this.waggleDanceConfiguration = waggleDanceConfiguration;
×
63
    this.notifyingFederationService.subscribe(databaseMappingService);
×
64
  }
×
65

66
  private ThriftHiveMetastore.Iface getPrimaryClient() throws TException {
67
    return databaseMappingService.primaryDatabaseMapping().getClient();
×
68
  }
69

70
  private DatabaseMapping checkWritePermissions(String databaseName) throws TException {
71
    DatabaseMapping mapping = databaseMappingService.databaseMapping(databaseName);
×
72
    mapping.checkWritePermissions(databaseName);
×
73
    return mapping;
×
74
  }
75

76
  private DatabaseMapping getDbMappingAndCheckTableAllowed(String dbName, String tblName) throws NoSuchObjectException {
77
    DatabaseMapping mapping = databaseMappingService.databaseMapping(dbName);
×
78
    databaseMappingService.checkTableAllowed(dbName, tblName, mapping);
×
79
    return mapping;
×
80
  }
81

82
  private DatabaseMapping checkWritePermissionsAndCheckTableAllowed(String dbName, String tblName) throws TException {
83
    DatabaseMapping mapping = checkWritePermissions(dbName);
×
84
    databaseMappingService.checkTableAllowed(dbName, tblName, mapping);
×
85
    return mapping;
×
86
  }
87

88
  private void checkWritePermissionsAndCheckTableAllowed(
89
      String dest_db,
90
      String dest_table_name,
91
      DatabaseMapping mapping)
92
    throws NoSuchObjectException {
93
    mapping.checkWritePermissions(dest_db);
×
94
    databaseMappingService.checkTableAllowed(dest_db, dest_table_name, mapping);
×
95
  }
×
96

97
  @Override
98
  public void close() throws IOException {
×
99
    shutdown();
100
  }
101

102
  @Override
103
  public void shutdown() {
×
104
    super.shutdown();
105
    try {
106
      notifyingFederationService.unsubscribe(databaseMappingService);
107
      databaseMappingService.close();
108
    } catch (IOException e) {
109
      LOG.warn("Error shutting down federated handler", e);
110
    }
111
  }
112

113
  //////////////////////////////
114

115
  @Override
116
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
117
  public String getMetaConf(String key) throws MetaException, TException {
×
118
    return getPrimaryClient().getMetaConf(key);
119
  }
120

121
  @Override
122
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
123
  public void setMetaConf(String key, String value) throws MetaException, TException {
×
124
    getPrimaryClient().setMetaConf(key, value);
125
  }
126

127
  @Override
128
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
129
  public void create_database(Database database)
×
130
    throws AlreadyExistsException, InvalidObjectException, MetaException, TException {
131
    DatabaseMapping mapping = databaseMappingService.primaryDatabaseMapping();
132
    mapping.createDatabase(mapping.transformInboundDatabase(database));
133
  }
134

135
  @Override
136
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
137
  public Database get_database(String name) throws NoSuchObjectException, MetaException, TException {
×
138
    LOG.info("Fetching database {}", name);
139
    DatabaseMapping mapping = databaseMappingService.databaseMapping(name);
140
    LOG.info("Mapping is '{}'", mapping.getDatabasePrefix());
141
    Database result = mapping.getClient().get_database(mapping.transformInboundDatabaseName(name));
142
    return mapping.transformOutboundDatabase(mapping.getMetastoreFilter().filterDatabase(result));
143
  }
144

145
  @Override
146
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
147
  public void drop_database(String name, boolean deleteData, boolean cascade)
×
148
    throws NoSuchObjectException, InvalidOperationException, MetaException, TException {
149
    DatabaseMapping mapping = checkWritePermissions(name);
150
    mapping.getClient().drop_database(mapping.transformInboundDatabaseName(name), deleteData, cascade);
151
  }
152

153
  @Override
154
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
155
  public List<String> get_databases(String pattern) throws MetaException, TException {
×
156
    return databaseMappingService.getPanopticOperationHandler().getAllDatabases(pattern);
157
  }
158

159
  @Override
160
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
161
  public List<String> get_all_databases() throws MetaException, TException {
×
162
    return databaseMappingService.getPanopticOperationHandler().getAllDatabases();
163
  }
164

165
  @Override
166
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
167
  public void alter_database(String dbname, Database db) throws MetaException, NoSuchObjectException, TException {
×
168
    DatabaseMapping mapping = checkWritePermissions(dbname);
169
    mapping.checkWritePermissions(db.getName());
170
    mapping
171
        .getClient()
172
        .alter_database(mapping.transformInboundDatabaseName(dbname), mapping.transformInboundDatabase(db));
173
  }
174

175
  @Override
176
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
177
  public Type get_type(String name) throws MetaException, NoSuchObjectException, TException {
×
178
    return getPrimaryClient().get_type(name);
179
  }
180

181
  @Override
182
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
183
  public boolean create_type(Type type)
×
184
    throws AlreadyExistsException, InvalidObjectException, MetaException, TException {
185
    return getPrimaryClient().create_type(type);
186
  }
187

188
  @Override
189
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
190
  public boolean drop_type(String type) throws MetaException, NoSuchObjectException, TException {
×
191
    return getPrimaryClient().drop_type(type);
192
  }
193

194
  @Override
195
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
196
  public Map<String, Type> get_type_all(String name) throws MetaException, TException {
×
197
    return getPrimaryClient().get_type_all(name);
198
  }
199

200
  @Override
201
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
202
  public List<FieldSchema> get_fields(String db_name, String table_name)
×
203
    throws MetaException, UnknownTableException, UnknownDBException, TException {
204
    DatabaseMapping mapping = getDbMappingAndCheckTableAllowed(db_name, table_name);
205
    return mapping.getClient().get_fields(mapping.transformInboundDatabaseName(db_name), table_name);
206
  }
207

208
  @Override
209
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
210
  public List<FieldSchema> get_schema(String db_name, String table_name)
×
211
    throws MetaException, UnknownTableException, UnknownDBException, TException {
212
    DatabaseMapping mapping = getDbMappingAndCheckTableAllowed(db_name, table_name);
213
    return mapping.getClient().get_schema(mapping.transformInboundDatabaseName(db_name), table_name);
214
  }
215

216
  @Override
217
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
218
  public void create_table(Table tbl)
×
219
    throws AlreadyExistsException, InvalidObjectException, MetaException, NoSuchObjectException, TException {
220
    DatabaseMapping mapping = checkWritePermissions(tbl.getDbName());
221
    mapping.getClient().create_table(mapping.transformInboundTable(tbl));
222
  }
223

224
  @Override
225
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
226
  public void create_table_with_environment_context(Table tbl, EnvironmentContext environment_context)
×
227
    throws AlreadyExistsException, InvalidObjectException, MetaException, NoSuchObjectException, TException {
228
    DatabaseMapping mapping = checkWritePermissions(tbl.getDbName());
229
    mapping.getClient().create_table_with_environment_context(mapping.transformInboundTable(tbl), environment_context);
230
  }
231

232
  @Override
233
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
234
  public void drop_table(String dbname, String name, boolean deleteData)
×
235
    throws NoSuchObjectException, MetaException, TException {
236
    DatabaseMapping mapping = checkWritePermissionsAndCheckTableAllowed(dbname, name);
237
    mapping.getClient().drop_table(mapping.transformInboundDatabaseName(dbname), name, deleteData);
238
  }
239

240
  @Override
241
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
242
  public void drop_table_with_environment_context(
×
243
      String dbname,
244
      String name,
245
      boolean deleteData,
246
      EnvironmentContext environment_context)
247
    throws NoSuchObjectException, MetaException, TException {
248
    DatabaseMapping mapping = checkWritePermissionsAndCheckTableAllowed(dbname, name);
249
    mapping
250
        .getClient()
251
        .drop_table_with_environment_context(mapping.transformInboundDatabaseName(dbname), name, deleteData,
252
            environment_context);
253
  }
254

255
  @Override
256
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
257
  public List<String> get_tables(String db_name, String pattern) throws MetaException, TException {
×
258
    DatabaseMapping mapping = databaseMappingService.databaseMapping(db_name);
259
    List<String> resultTables = mapping.getClient().get_tables(mapping.transformInboundDatabaseName(db_name), pattern);
260
    resultTables = databaseMappingService.filterTables(db_name, resultTables, mapping);
261
    return mapping.getMetastoreFilter().filterTableNames(db_name, resultTables);
262
  }
263

264
  @Override
265
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
266
  public List<String> get_all_tables(String db_name) throws MetaException, TException {
×
267
    DatabaseMapping mapping = databaseMappingService.databaseMapping(db_name);
268
    List<String> resultTables = mapping.getClient().get_all_tables(mapping.transformInboundDatabaseName(db_name));
269
    resultTables = databaseMappingService.filterTables(db_name, resultTables, mapping);
270
    return mapping.getMetastoreFilter().filterTableNames(db_name, resultTables);
271
  }
272

273
  @Override
274
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
275
  public Table get_table(String dbname, String tbl_name) throws MetaException, NoSuchObjectException, TException {
×
276
    DatabaseMapping mapping = getDbMappingAndCheckTableAllowed(dbname, tbl_name);
277
    Table table = mapping.getClient().get_table(mapping.transformInboundDatabaseName(dbname), tbl_name);
278
    return mapping.transformOutboundTable(mapping.getMetastoreFilter().filterTable(table));
279
  }
280

281
  @Override
282
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
283
  public List<Table> get_table_objects_by_name(String dbname, List<String> tbl_names)
×
284
    throws MetaException, InvalidOperationException, UnknownDBException, TException {
285
    DatabaseMapping mapping = databaseMappingService.databaseMapping(dbname);
286
    List<String> filteredTables = databaseMappingService.filterTables(dbname, tbl_names, mapping);
287
    List<Table> tables = mapping
288
        .getClient()
289
        .get_table_objects_by_name(mapping.transformInboundDatabaseName(dbname), filteredTables);
290
    tables = mapping.getMetastoreFilter().filterTables(tables);
291
    List<Table> outboundTables = new ArrayList<>(tables.size());
292
    for (Table table : tables) {
293
      outboundTables.add(mapping.transformOutboundTable(table));
294
    }
295
    return outboundTables;
296
  }
297

298
  @Override
299
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
300
  public List<String> get_table_names_by_filter(String dbname, String filter, short max_tables)
×
301
    throws MetaException, InvalidOperationException, UnknownDBException, TException {
302
    DatabaseMapping mapping = databaseMappingService.databaseMapping(dbname);
303
    List<String> resultTables = mapping
304
        .getClient()
305
        .get_table_names_by_filter(mapping.transformInboundDatabaseName(dbname), filter, max_tables);
306
    List<String> result = databaseMappingService.filterTables(dbname, resultTables, mapping);
307
    return mapping.getMetastoreFilter().filterTableNames(dbname, result);
308
  }
309

310
  @Override
311
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
312
  public void alter_table(String dbname, String tbl_name, Table new_tbl)
×
313
    throws InvalidOperationException, MetaException, TException {
314
    DatabaseMapping mapping = checkWritePermissionsAndCheckTableAllowed(dbname, tbl_name);
315
    mapping.checkWritePermissions(new_tbl.getDbName());
316
    databaseMappingService.checkTableAllowed(new_tbl.getDbName(), new_tbl.getTableName(), mapping);
317
    mapping
318
        .getClient()
319
        .alter_table(mapping.transformInboundDatabaseName(dbname), tbl_name, mapping.transformInboundTable(new_tbl));
320
  }
321

322
  @Override
323
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
324
  public void alter_table_with_environment_context(
×
325
      String dbname,
326
      String tbl_name,
327
      Table new_tbl,
328
      EnvironmentContext environment_context)
329
    throws InvalidOperationException, MetaException, TException {
330
    DatabaseMapping mapping = checkWritePermissionsAndCheckTableAllowed(dbname, tbl_name);
331
    checkWritePermissionsAndCheckTableAllowed(new_tbl.getDbName(), new_tbl.getTableName(), mapping);
332
    mapping
333
        .getClient()
334
        .alter_table_with_environment_context(mapping.transformInboundDatabaseName(dbname), tbl_name,
335
            mapping.transformInboundTable(new_tbl), environment_context);
336
  }
337

338
  @Override
339
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
340
  public Partition add_partition(Partition new_part)
×
341
    throws InvalidObjectException, AlreadyExistsException, MetaException, TException {
342
    DatabaseMapping mapping = checkWritePermissionsAndCheckTableAllowed(new_part.getDbName(), new_part.getTableName());
343
    Partition result = mapping.getClient().add_partition(mapping.transformInboundPartition(new_part));
344
    return mapping.transformOutboundPartition(result);
345
  }
346

347
  @Override
348
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
349
  public Partition add_partition_with_environment_context(Partition new_part, EnvironmentContext environment_context)
×
350
    throws InvalidObjectException, AlreadyExistsException, MetaException, TException {
351
    DatabaseMapping mapping = checkWritePermissionsAndCheckTableAllowed(new_part.getDbName(), new_part.getTableName());
352
    Partition result = mapping
353
        .getClient()
354
        .add_partition_with_environment_context(mapping.transformInboundPartition(new_part), environment_context);
355
    return mapping.transformOutboundPartition(result);
356
  }
357

358
  @Override
359
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
360
  public int add_partitions(List<Partition> new_parts)
×
361
    throws InvalidObjectException, AlreadyExistsException, MetaException, TException {
362
    if (!new_parts.isEmpty()) {
363
      // Need to pick one mapping and use that for permissions and getting the client.
364
      // If the partitions added are for different databases in different clients that won't work with waggle-dance
365
      DatabaseMapping mapping = databaseMappingService.databaseMapping(new_parts.get(0).getDbName());
366
      for (Partition partition : new_parts) {
367
        checkWritePermissionsAndCheckTableAllowed(partition.getDbName(), partition.getTableName(), mapping);
368
      }
369
      return mapping.getClient().add_partitions(mapping.transformInboundPartitions(new_parts));
370
    }
371
    return 0;
372
  }
373

374
  @Override
375
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
376
  public int add_partitions_pspec(List<PartitionSpec> new_parts)
×
377
    throws InvalidObjectException, AlreadyExistsException, MetaException, TException {
378
    if (!new_parts.isEmpty()) {
379
      // Need to pick one mapping and use that for permissions and getting the client.
380
      // If the partitions added are for different databases in different clients that won't work with waggle-dance
381
      DatabaseMapping mapping = databaseMappingService.databaseMapping(new_parts.get(0).getDbName());
382
      for (PartitionSpec partitionSpec : new_parts) {
383
        checkWritePermissionsAndCheckTableAllowed(partitionSpec.getDbName(), partitionSpec.getTableName(), mapping);
384
      }
385
      return mapping.getClient().add_partitions_pspec(mapping.transformInboundPartitionSpecs(new_parts));
386
    }
387
    return 0;
388
  }
389

390
  @Override
391
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
392
  public Partition append_partition(String db_name, String tbl_name, List<String> part_vals)
×
393
    throws InvalidObjectException, AlreadyExistsException, MetaException, TException {
394
    DatabaseMapping mapping = checkWritePermissionsAndCheckTableAllowed(db_name, tbl_name);
395
    Partition result = mapping
396
        .getClient()
397
        .append_partition(mapping.transformInboundDatabaseName(db_name), tbl_name, part_vals);
398
    return mapping.transformOutboundPartition(result);
399
  }
400

401
  @Override
402
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
403
  public AddPartitionsResult add_partitions_req(AddPartitionsRequest request)
×
404
    throws InvalidObjectException, AlreadyExistsException, MetaException, TException {
405
    DatabaseMapping mapping = checkWritePermissionsAndCheckTableAllowed(request.getDbName(), request.getTblName());
406
    for (Partition partition : request.getParts()) {
407
      checkWritePermissionsAndCheckTableAllowed(partition.getDbName(), partition.getTableName(), mapping);
408
    }
409
    AddPartitionsResult result = mapping
410
        .getClient()
411
        .add_partitions_req(mapping.transformInboundAddPartitionsRequest(request));
412
    result.setPartitions(mapping.getMetastoreFilter().filterPartitions(result.getPartitions()));
413
    return mapping.transformOutboundAddPartitionsResult(result);
414
  }
415

416
  @Override
417
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
418
  public Partition append_partition_with_environment_context(
×
419
      String db_name,
420
      String tbl_name,
421
      List<String> part_vals,
422
      EnvironmentContext environment_context)
423
    throws InvalidObjectException, AlreadyExistsException, MetaException, TException {
424
    DatabaseMapping mapping = checkWritePermissionsAndCheckTableAllowed(db_name, tbl_name);
425
    Partition partition = mapping
426
        .getClient()
427
        .append_partition_with_environment_context(mapping.transformInboundDatabaseName(db_name), tbl_name, part_vals,
428
            environment_context);
429
    return mapping.transformOutboundPartition(partition);
430
  }
431

432
  @Override
433
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
434
  public Partition append_partition_by_name(String db_name, String tbl_name, String part_name)
×
435
    throws InvalidObjectException, AlreadyExistsException, MetaException, TException {
436
    DatabaseMapping mapping = checkWritePermissionsAndCheckTableAllowed(db_name, tbl_name);
437
    Partition partition = mapping
438
        .getClient()
439
        .append_partition_by_name(mapping.transformInboundDatabaseName(db_name), tbl_name, part_name);
440
    return mapping.transformOutboundPartition(partition);
441
  }
442

443
  @Override
444
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
445
  public Partition append_partition_by_name_with_environment_context(
×
446
      String db_name,
447
      String tbl_name,
448
      String part_name,
449
      EnvironmentContext environment_context)
450
    throws InvalidObjectException, AlreadyExistsException, MetaException, TException {
451
    DatabaseMapping mapping = checkWritePermissionsAndCheckTableAllowed(db_name, tbl_name);
452
    Partition partition = mapping
453
        .getClient()
454
        .append_partition_by_name_with_environment_context(mapping.transformInboundDatabaseName(db_name), tbl_name,
455
            part_name, environment_context);
456
    return mapping.transformOutboundPartition(partition);
457
  }
458

459
  @Override
460
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
461
  public boolean drop_partition(String db_name, String tbl_name, List<String> part_vals, boolean deleteData)
×
462
    throws NoSuchObjectException, MetaException, TException {
463
    DatabaseMapping mapping = checkWritePermissionsAndCheckTableAllowed(db_name, tbl_name);
464
    return mapping
465
        .getClient()
466
        .drop_partition(mapping.transformInboundDatabaseName(db_name), tbl_name, part_vals, deleteData);
467
  }
468

469
  @Override
470
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
471
  public boolean drop_partition_with_environment_context(
×
472
      String db_name,
473
      String tbl_name,
474
      List<String> part_vals,
475
      boolean deleteData,
476
      EnvironmentContext environment_context)
477
    throws NoSuchObjectException, MetaException, TException {
478
    DatabaseMapping mapping = checkWritePermissionsAndCheckTableAllowed(db_name, tbl_name);
479
    return mapping
480
        .getClient()
481
        .drop_partition_with_environment_context(mapping.transformInboundDatabaseName(db_name), tbl_name, part_vals,
482
            deleteData, environment_context);
483
  }
484

485
  @Override
486
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
487
  public boolean drop_partition_by_name(String db_name, String tbl_name, String part_name, boolean deleteData)
×
488
    throws NoSuchObjectException, MetaException, TException {
489
    DatabaseMapping mapping = checkWritePermissionsAndCheckTableAllowed(db_name, tbl_name);
490
    return mapping
491
        .getClient()
492
        .drop_partition_by_name(mapping.transformInboundDatabaseName(db_name), tbl_name, part_name, deleteData);
493
  }
494

495
  @Override
496
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
497
  public boolean drop_partition_by_name_with_environment_context(
×
498
      String db_name,
499
      String tbl_name,
500
      String part_name,
501
      boolean deleteData,
502
      EnvironmentContext environment_context)
503
    throws NoSuchObjectException, MetaException, TException {
504
    DatabaseMapping mapping = checkWritePermissionsAndCheckTableAllowed(db_name, tbl_name);
505
    return mapping
506
        .getClient()
507
        .drop_partition_by_name_with_environment_context(mapping.transformInboundDatabaseName(db_name), tbl_name,
508
            part_name, deleteData, environment_context);
509
  }
510

511
  @Override
512
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
513
  public DropPartitionsResult drop_partitions_req(DropPartitionsRequest req)
×
514
    throws NoSuchObjectException, MetaException, TException {
515
    DatabaseMapping mapping = checkWritePermissionsAndCheckTableAllowed(req.getDbName(), req.getTblName());
516
    DropPartitionsResult result = mapping
517
        .getClient()
518
        .drop_partitions_req(mapping.transformInboundDropPartitionRequest(req));
519
    return mapping.transformOutboundDropPartitionsResult(result);
520
  }
521

522
  @Override
523
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
524
  public Partition get_partition(String db_name, String tbl_name, List<String> part_vals)
×
525
    throws MetaException, NoSuchObjectException, TException {
526
    DatabaseMapping mapping = getDbMappingAndCheckTableAllowed(db_name, tbl_name);
527
    Partition partition = mapping
528
        .getClient()
529
        .get_partition(mapping.transformInboundDatabaseName(db_name), tbl_name, part_vals);
530
    return mapping.transformOutboundPartition(mapping.getMetastoreFilter().filterPartition(partition));
531
  }
532

533
  @Override
534
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
535
  public Partition exchange_partition(
×
536
      Map<String, String> partitionSpecs,
537
      String source_db,
538
      String source_table_name,
539
      String dest_db,
540
      String dest_table_name)
541
    throws MetaException, NoSuchObjectException, InvalidObjectException, InvalidInputException, TException {
542
    DatabaseMapping mapping = checkWritePermissionsAndCheckTableAllowed(source_db, source_table_name);
543
    checkWritePermissionsAndCheckTableAllowed(dest_db, dest_table_name, mapping);
544
    Partition result = mapping
545
        .getClient()
546
        .exchange_partition(partitionSpecs, mapping.transformInboundDatabaseName(source_db), source_table_name,
547
            mapping.transformInboundDatabaseName(dest_db), dest_table_name);
548
    return mapping.transformOutboundPartition(result);
549
  }
550

551
  @Override
552
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
553
  public Partition get_partition_with_auth(
×
554
      String db_name,
555
      String tbl_name,
556
      List<String> part_vals,
557
      String user_name,
558
      List<String> group_names)
559
    throws MetaException, NoSuchObjectException, TException {
560
    DatabaseMapping mapping = getDbMappingAndCheckTableAllowed(db_name, tbl_name);
561
    Partition partition = mapping
562
        .getClient()
563
        .get_partition_with_auth(mapping.transformInboundDatabaseName(db_name), tbl_name, part_vals, user_name,
564
            group_names);
565
    return mapping.transformOutboundPartition(mapping.getMetastoreFilter().filterPartition(partition));
566
  }
567

568
  @Override
569
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
570
  public Partition get_partition_by_name(String db_name, String tbl_name, String part_name)
×
571
    throws MetaException, NoSuchObjectException, TException {
572
    DatabaseMapping mapping = getDbMappingAndCheckTableAllowed(db_name, tbl_name);
573
    Partition partition = mapping
574
        .getClient()
575
        .get_partition_by_name(mapping.transformInboundDatabaseName(db_name), tbl_name, part_name);
576
    return mapping.transformOutboundPartition(mapping.getMetastoreFilter().filterPartition(partition));
577
  }
578

579
  @Override
580
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME, prepend = true)
581
  public List<Partition> get_partitions(String db_name, String tbl_name, short max_parts)
×
582
    throws NoSuchObjectException, MetaException, TException {
583
    DatabaseMapping mapping = getDbMappingAndCheckTableAllowed(db_name, tbl_name);
584
    List<Partition> partitions = mapping
585
        .getClient()
586
        .get_partitions(mapping.transformInboundDatabaseName(db_name), tbl_name, max_parts);
587
    return mapping.transformOutboundPartitions(mapping.getMetastoreFilter().filterPartitions(partitions));
588
  }
589

590
  @Override
591
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME, prepend = true)
592
  public List<Partition> get_partitions_with_auth(
×
593
      String db_name,
594
      String tbl_name,
595
      short max_parts,
596
      String user_name,
597
      List<String> group_names)
598
    throws NoSuchObjectException, MetaException, TException {
599
    DatabaseMapping mapping = getDbMappingAndCheckTableAllowed(db_name, tbl_name);
600
    List<Partition> partitions = mapping
601
        .getClient()
602
        .get_partitions_with_auth(mapping.transformInboundDatabaseName(db_name), tbl_name, max_parts, user_name,
603
            group_names);
604
    return mapping.transformOutboundPartitions(mapping.getMetastoreFilter().filterPartitions(partitions));
605
  }
606

607
  @Override
608
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME, prepend = true)
609
  public List<PartitionSpec> get_partitions_pspec(String db_name, String tbl_name, int max_parts)
×
610
    throws NoSuchObjectException, MetaException, TException {
611
    DatabaseMapping mapping = getDbMappingAndCheckTableAllowed(db_name, tbl_name);
612
    List<PartitionSpec> partitionSpecs = mapping
613
        .getClient()
614
        .get_partitions_pspec(mapping.transformInboundDatabaseName(db_name), tbl_name, max_parts);
615
    return mapping.transformOutboundPartitionSpecs(mapping.getMetastoreFilter().filterPartitionSpecs(partitionSpecs));
616
  }
617

618
  @Override
619
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
620
  public List<String> get_partition_names(String db_name, String tbl_name, short max_parts)
×
621
    throws MetaException, TException {
622
    DatabaseMapping mapping = getDbMappingAndCheckTableAllowed(db_name, tbl_name);
623
    List<String> result = mapping
624
        .getClient()
625
        .get_partition_names(mapping.transformInboundDatabaseName(db_name), tbl_name, max_parts);
626
    return mapping.getMetastoreFilter().filterPartitionNames(db_name, tbl_name, result);
627
  }
628

629
  @Override
630
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME, prepend = true)
631
  public List<Partition> get_partitions_ps(String db_name, String tbl_name, List<String> part_vals, short max_parts)
×
632
    throws MetaException, NoSuchObjectException, TException {
633
    DatabaseMapping mapping = getDbMappingAndCheckTableAllowed(db_name, tbl_name);
634
    List<Partition> partitions = mapping
635
        .getClient()
636
        .get_partitions_ps(mapping.transformInboundDatabaseName(db_name), tbl_name, part_vals, max_parts);
637
    return mapping.transformOutboundPartitions(mapping.getMetastoreFilter().filterPartitions(partitions));
638
  }
639

640
  @Override
641
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME, prepend = true)
642
  public List<Partition> get_partitions_ps_with_auth(
×
643
      String db_name,
644
      String tbl_name,
645
      List<String> part_vals,
646
      short max_parts,
647
      String user_name,
648
      List<String> group_names)
649
    throws NoSuchObjectException, MetaException, TException {
650
    DatabaseMapping mapping = getDbMappingAndCheckTableAllowed(db_name, tbl_name);
651
    List<Partition> partitions = mapping
652
        .getClient()
653
        .get_partitions_ps_with_auth(mapping.transformInboundDatabaseName(db_name), tbl_name, part_vals, max_parts,
654
            user_name, group_names);
655
    return mapping.transformOutboundPartitions(mapping.getMetastoreFilter().filterPartitions(partitions));
656
  }
657

658
  @Override
659
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
660
  public List<String> get_partition_names_ps(String db_name, String tbl_name, List<String> part_vals, short max_parts)
×
661
    throws MetaException, NoSuchObjectException, TException {
662
    DatabaseMapping mapping = getDbMappingAndCheckTableAllowed(db_name, tbl_name);
663
    List<String> result = mapping
664
        .getClient()
665
        .get_partition_names_ps(mapping.transformInboundDatabaseName(db_name), tbl_name, part_vals, max_parts);
666
    return mapping.getMetastoreFilter().filterPartitionNames(db_name, tbl_name, result);
667
  }
668

669
  @Override
670
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME, prepend = true)
671
  public List<Partition> get_partitions_by_filter(String db_name, String tbl_name, String filter, short max_parts)
×
672
    throws MetaException, NoSuchObjectException, TException {
673
    DatabaseMapping mapping = getDbMappingAndCheckTableAllowed(db_name, tbl_name);
674
    List<Partition> partitions = mapping
675
        .getClient()
676
        .get_partitions_by_filter(mapping.transformInboundDatabaseName(db_name), tbl_name, filter, max_parts);
677
    return mapping.transformOutboundPartitions(mapping.getMetastoreFilter().filterPartitions(partitions));
678
  }
679

680
  @Override
681
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME, prepend = true)
682
  public List<PartitionSpec> get_part_specs_by_filter(String db_name, String tbl_name, String filter, int max_parts)
×
683
    throws MetaException, NoSuchObjectException, TException {
684
    DatabaseMapping mapping = getDbMappingAndCheckTableAllowed(db_name, tbl_name);
685
    List<PartitionSpec> partitionSpecs = mapping
686
        .getClient()
687
        .get_part_specs_by_filter(mapping.transformInboundDatabaseName(db_name), tbl_name, filter, max_parts);
688
    return mapping.transformOutboundPartitionSpecs(mapping.getMetastoreFilter().filterPartitionSpecs(partitionSpecs));
689
  }
690

691
  @Override
692
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
693
  public PartitionsByExprResult get_partitions_by_expr(PartitionsByExprRequest req)
×
694
    throws MetaException, NoSuchObjectException, TException {
695
    DatabaseMapping mapping = getDbMappingAndCheckTableAllowed(req.getDbName(), req.getTblName());
696
    PartitionsByExprResult result = mapping
697
        .getClient()
698
        .get_partitions_by_expr(mapping.transformInboundPartitionsByExprRequest(req));
699
    result.setPartitions(mapping.getMetastoreFilter().filterPartitions(result.getPartitions()));
700
    return mapping.transformOutboundPartitionsByExprResult(result);
701
  }
702

703
  @Override
704
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME, prepend = true)
705
  public List<Partition> get_partitions_by_names(String db_name, String tbl_name, List<String> names)
×
706
    throws MetaException, NoSuchObjectException, TException {
707
    DatabaseMapping mapping = getDbMappingAndCheckTableAllowed(db_name, tbl_name);
708
    List<Partition> partitions = mapping
709
        .getClient()
710
        .get_partitions_by_names(mapping.transformInboundDatabaseName(db_name), tbl_name, names);
711
    return mapping.transformOutboundPartitions(mapping.getMetastoreFilter().filterPartitions(partitions));
712
  }
713

714
  @Override
715
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
716
  public void alter_partition(String db_name, String tbl_name, Partition new_part)
×
717
    throws InvalidOperationException, MetaException, TException {
718
    DatabaseMapping mapping = checkWritePermissionsAndCheckTableAllowed(db_name, tbl_name);
719
    checkWritePermissionsAndCheckTableAllowed(new_part.getDbName(), new_part.getTableName());
720
    mapping
721
        .getClient()
722
        .alter_partition(mapping.transformInboundDatabaseName(db_name), tbl_name,
723
            mapping.transformInboundPartition(new_part));
724
  }
725

726
  @Override
727
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
728
  public void alter_partitions(String db_name, String tbl_name, List<Partition> new_parts)
×
729
    throws InvalidOperationException, MetaException, TException {
730
    DatabaseMapping mapping = checkWritePermissionsAndCheckTableAllowed(db_name, tbl_name);
731
    for (Partition newPart : new_parts) {
732
      checkWritePermissionsAndCheckTableAllowed(newPart.getDbName(), newPart.getTableName(), mapping);
733
    }
734
    mapping
735
        .getClient()
736
        .alter_partitions(mapping.transformInboundDatabaseName(db_name), tbl_name,
737
            mapping.transformInboundPartitions(new_parts));
738
  }
739

740
  @Override
741
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
742
  public void alter_partition_with_environment_context(
×
743
      String db_name,
744
      String tbl_name,
745
      Partition new_part,
746
      EnvironmentContext environment_context)
747
    throws InvalidOperationException, MetaException, TException {
748
    DatabaseMapping mapping = checkWritePermissionsAndCheckTableAllowed(db_name, tbl_name);
749
    checkWritePermissionsAndCheckTableAllowed(new_part.getDbName(), new_part.getTableName(), mapping);
750
    mapping
751
        .getClient()
752
        .alter_partition_with_environment_context(mapping.transformInboundDatabaseName(db_name), tbl_name,
753
            mapping.transformInboundPartition(new_part), environment_context);
754
  }
755

756
  @Override
757
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
758
  public void rename_partition(String db_name, String tbl_name, List<String> part_vals, Partition new_part)
×
759
    throws InvalidOperationException, MetaException, TException {
760
    DatabaseMapping mapping = checkWritePermissionsAndCheckTableAllowed(db_name, tbl_name);
761
    checkWritePermissionsAndCheckTableAllowed(new_part.getDbName(), new_part.getTableName(), mapping);
762
    mapping.getClient().rename_partition(mapping.transformInboundDatabaseName(db_name), tbl_name, part_vals, new_part);
763
  }
764

765
  @Override
766
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
767
  public boolean partition_name_has_valid_characters(List<String> part_vals, boolean throw_exception)
×
768
    throws MetaException, TException {
769
    return getPrimaryClient().partition_name_has_valid_characters(part_vals, throw_exception);
770
  }
771

772
  @Override
773
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
774
  public String get_config_value(String name, String defaultValue) throws ConfigValSecurityException, TException {
×
775
    return getPrimaryClient().get_config_value(name, defaultValue);
776
  }
777

778
  @Override
779
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
780
  public List<String> partition_name_to_vals(String part_name) throws MetaException, TException {
×
781
    return getPrimaryClient().partition_name_to_vals(part_name);
782
  }
783

784
  @Override
785
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
786
  public Map<String, String> partition_name_to_spec(String part_name) throws MetaException, TException {
×
787
    return getPrimaryClient().partition_name_to_spec(part_name);
788
  }
789

790
  @Override
791
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
792
  public void markPartitionForEvent(
×
793
      String db_name,
794
      String tbl_name,
795
      Map<String, String> part_vals,
796
      PartitionEventType eventType)
797
    throws MetaException, NoSuchObjectException, UnknownDBException, UnknownTableException, UnknownPartitionException,
798
    InvalidPartitionException, TException {
799
    DatabaseMapping mapping = checkWritePermissionsAndCheckTableAllowed(db_name, tbl_name);
800
    mapping
801
        .getClient()
802
        .markPartitionForEvent(mapping.transformInboundDatabaseName(db_name), tbl_name, part_vals, eventType);
803
  }
804

805
  @Override
806
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
807
  public boolean isPartitionMarkedForEvent(
×
808
      String db_name,
809
      String tbl_name,
810
      Map<String, String> part_vals,
811
      PartitionEventType eventType)
812
    throws MetaException, NoSuchObjectException, UnknownDBException, UnknownTableException, UnknownPartitionException,
813
    InvalidPartitionException, TException {
814
    DatabaseMapping mapping = getDbMappingAndCheckTableAllowed(db_name, tbl_name);
815
    return mapping
816
        .getClient()
817
        .isPartitionMarkedForEvent(mapping.transformInboundDatabaseName(db_name), tbl_name, part_vals, eventType);
818
  }
819

820
  @Override
821
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
822
  public Index add_index(Index new_index, Table index_table)
×
823
    throws InvalidObjectException, AlreadyExistsException, MetaException, TException {
824
    DatabaseMapping mapping = checkWritePermissionsAndCheckTableAllowed(new_index.getDbName(),
825
        new_index.getOrigTableName());
826
    checkWritePermissionsAndCheckTableAllowed(index_table.getDbName(), index_table.getTableName(), mapping);
827
    Index result = mapping
828
        .getClient()
829
        .add_index(mapping.transformInboundIndex(new_index), mapping.transformInboundTable(index_table));
830
    return mapping.transformOutboundIndex(result);
831
  }
832

833
  @Override
834
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
835
  public void alter_index(String dbname, String base_tbl_name, String idx_name, Index new_idx)
×
836
    throws InvalidOperationException, MetaException, TException {
837
    DatabaseMapping mapping = checkWritePermissionsAndCheckTableAllowed(dbname, base_tbl_name);
838
    checkWritePermissionsAndCheckTableAllowed(new_idx.getDbName(), new_idx.getOrigTableName(), mapping);
839
    mapping
840
        .getClient()
841
        .alter_index(mapping.transformInboundDatabaseName(dbname), base_tbl_name, idx_name,
842
            mapping.transformInboundIndex(new_idx));
843
  }
844

845
  @Override
846
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
847
  public boolean drop_index_by_name(String db_name, String tbl_name, String index_name, boolean deleteData)
×
848
    throws NoSuchObjectException, MetaException, TException {
849
    DatabaseMapping mapping = checkWritePermissionsAndCheckTableAllowed(db_name, tbl_name);
850
    return mapping
851
        .getClient()
852
        .drop_index_by_name(mapping.transformInboundDatabaseName(db_name), tbl_name, index_name, deleteData);
853
  }
854

855
  @Override
856
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
857
  public Index get_index_by_name(String db_name, String tbl_name, String index_name)
×
858
    throws MetaException, NoSuchObjectException, TException {
859
    DatabaseMapping mapping = getDbMappingAndCheckTableAllowed(db_name, tbl_name);
860
    Index result = mapping
861
        .getClient()
862
        .get_index_by_name(mapping.transformInboundDatabaseName(db_name), tbl_name, index_name);
863
    return mapping.transformOutboundIndex(mapping.getMetastoreFilter().filterIndex(result));
864
  }
865

866
  @Override
867
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
868
  public List<Index> get_indexes(String db_name, String tbl_name, short max_indexes)
×
869
    throws NoSuchObjectException, MetaException, TException {
870
    DatabaseMapping mapping = getDbMappingAndCheckTableAllowed(db_name, tbl_name);
871
    List<Index> indexes = mapping
872
        .getClient()
873
        .get_indexes(mapping.transformInboundDatabaseName(db_name), tbl_name, max_indexes);
874
    return mapping.transformOutboundIndexes(mapping.getMetastoreFilter().filterIndexes(indexes));
875
  }
876

877
  @Override
878
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
879
  public List<String> get_index_names(String db_name, String tbl_name, short max_indexes)
×
880
    throws MetaException, TException {
881
    DatabaseMapping mapping = getDbMappingAndCheckTableAllowed(db_name, tbl_name);
882
    List<String> result = mapping
883
        .getClient()
884
        .get_index_names(mapping.transformInboundDatabaseName(db_name), tbl_name, max_indexes);
885
    return mapping.getMetastoreFilter().filterIndexNames(db_name, tbl_name, result);
886
  }
887

888
  @Override
889
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
890
  public boolean update_table_column_statistics(ColumnStatistics stats_obj)
×
891
    throws NoSuchObjectException, InvalidObjectException, MetaException, InvalidInputException, TException {
892
    String dbName = stats_obj.getStatsDesc().getDbName();
893
    String tblName = stats_obj.getStatsDesc().getTableName();
894
    DatabaseMapping mapping = checkWritePermissionsAndCheckTableAllowed(dbName, tblName);
895
    return mapping.getClient().update_table_column_statistics(mapping.transformInboundColumnStatistics(stats_obj));
896
  }
897

898
  @Override
899
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
900
  public boolean update_partition_column_statistics(ColumnStatistics stats_obj)
×
901
    throws NoSuchObjectException, InvalidObjectException, MetaException, InvalidInputException, TException {
902
    DatabaseMapping mapping = checkWritePermissions(stats_obj.getStatsDesc().getDbName());
903
    return mapping.getClient().update_partition_column_statistics(mapping.transformInboundColumnStatistics(stats_obj));
904
  }
905

906
  @Override
907
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
908
  public ColumnStatistics get_table_column_statistics(String db_name, String tbl_name, String col_name)
×
909
    throws NoSuchObjectException, MetaException, InvalidInputException, InvalidObjectException, TException {
910
    DatabaseMapping mapping = getDbMappingAndCheckTableAllowed(db_name, tbl_name);
911
    ColumnStatistics result = mapping
912
        .getClient()
913
        .get_table_column_statistics(mapping.transformInboundDatabaseName(db_name), tbl_name, col_name);
914
    return mapping.transformOutboundColumnStatistics(result);
915
  }
916

917
  @Override
918
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
919
  public ColumnStatistics get_partition_column_statistics(
×
920
      String db_name,
921
      String tbl_name,
922
      String part_name,
923
      String col_name)
924
    throws NoSuchObjectException, MetaException, InvalidInputException, InvalidObjectException, TException {
925
    DatabaseMapping mapping = getDbMappingAndCheckTableAllowed(db_name, tbl_name);
926
    ColumnStatistics result = mapping
927
        .getClient()
928
        .get_partition_column_statistics(mapping.transformInboundDatabaseName(db_name), tbl_name, part_name, col_name);
929
    return mapping.transformOutboundColumnStatistics(result);
930
  }
931

932
  @Override
933
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
934
  public TableStatsResult get_table_statistics_req(TableStatsRequest request)
×
935
    throws NoSuchObjectException, MetaException, TException {
936
    DatabaseMapping mapping = getDbMappingAndCheckTableAllowed(request.getDbName(), request.getTblName());
937
    return mapping.getClient().get_table_statistics_req(mapping.transformInboundTableStatsRequest(request));
938
  }
939

940
  @Override
941
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
942
  public PartitionsStatsResult get_partitions_statistics_req(PartitionsStatsRequest request)
×
943
    throws NoSuchObjectException, MetaException, TException {
944
    DatabaseMapping mapping = getDbMappingAndCheckTableAllowed(request.getDbName(), request.getTblName());
945
    return mapping.getClient().get_partitions_statistics_req(mapping.transformInboundPartitionsStatsRequest(request));
946
  }
947

948
  @Override
949
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
950
  public AggrStats get_aggr_stats_for(PartitionsStatsRequest request)
×
951
    throws NoSuchObjectException, MetaException, TException {
952
    DatabaseMapping mapping = getDbMappingAndCheckTableAllowed(request.getDbName(), request.getTblName());
953
    return mapping.getClient().get_aggr_stats_for(mapping.transformInboundPartitionsStatsRequest(request));
954
  }
955

956
  @Override
957
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
958
  public boolean set_aggr_stats_for(SetPartitionsStatsRequest request)
×
959
    throws NoSuchObjectException, InvalidObjectException, MetaException, InvalidInputException, TException {
960
    if (!request.getColStats().isEmpty()) {
961
      DatabaseMapping mapping = databaseMappingService
962
          .databaseMapping(request.getColStats().get(0).getStatsDesc().getDbName());
963
      for (ColumnStatistics stats : request.getColStats()) {
964
        checkWritePermissionsAndCheckTableAllowed(stats.getStatsDesc().getDbName(), stats.getStatsDesc().getTableName(),
965
            mapping);
966
      }
967
      return mapping.getClient().set_aggr_stats_for(mapping.transformInboundSetPartitionStatsRequest(request));
968
    }
969
    return false;
970
  }
971

972
  @Override
973
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
974
  public boolean delete_partition_column_statistics(String db_name, String tbl_name, String part_name, String col_name)
×
975
    throws NoSuchObjectException, MetaException, InvalidObjectException, InvalidInputException, TException {
976
    DatabaseMapping mapping = checkWritePermissionsAndCheckTableAllowed(db_name, tbl_name);
977
    return mapping
978
        .getClient()
979
        .delete_partition_column_statistics(mapping.transformInboundDatabaseName(db_name), tbl_name, part_name,
980
            col_name);
981
  }
982

983
  @Override
984
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
985
  public boolean delete_table_column_statistics(String db_name, String tbl_name, String col_name)
×
986
    throws NoSuchObjectException, MetaException, InvalidObjectException, InvalidInputException, TException {
987
    DatabaseMapping mapping = checkWritePermissionsAndCheckTableAllowed(db_name, tbl_name);
988
    return mapping
989
        .getClient()
990
        .delete_table_column_statistics(mapping.transformInboundDatabaseName(db_name), tbl_name, col_name);
991
  }
992

993
  @Override
994
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
995
  public void create_function(Function func)
×
996
    throws AlreadyExistsException, InvalidObjectException, MetaException, NoSuchObjectException, TException {
997
    DatabaseMapping mapping = checkWritePermissions(func.getDbName());
998
    mapping.getClient().create_function(mapping.transformInboundFunction(func));
999
  }
1000

1001
  @Override
1002
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1003
  public void drop_function(String dbName, String funcName) throws NoSuchObjectException, MetaException, TException {
×
1004
    DatabaseMapping mapping = checkWritePermissions(dbName);
1005
    mapping.getClient().drop_function(mapping.transformInboundDatabaseName(dbName), funcName);
1006
  }
1007

1008
  @Override
1009
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1010
  public void alter_function(String dbName, String funcName, Function newFunc)
×
1011
    throws InvalidOperationException, MetaException, TException {
1012
    DatabaseMapping mapping = checkWritePermissions(dbName);
1013
    mapping.checkWritePermissions(newFunc.getDbName());
1014
    mapping
1015
        .getClient()
1016
        .alter_function(mapping.transformInboundDatabaseName(dbName), funcName,
1017
            mapping.transformInboundFunction(newFunc));
1018
  }
1019

1020
  @Override
1021
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1022
  public List<String> get_functions(String dbName, String pattern) throws MetaException, TException {
×
1023
    DatabaseMapping mapping = databaseMappingService.databaseMapping(dbName);
1024
    return mapping.getClient().get_functions(mapping.transformInboundDatabaseName(dbName), pattern);
1025
  }
1026

1027
  @Override
1028
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1029
  public Function get_function(String dbName, String funcName) throws MetaException, NoSuchObjectException, TException {
×
1030
    DatabaseMapping mapping = databaseMappingService.databaseMapping(dbName);
1031
    return mapping
1032
        .transformOutboundFunction(
1033
            mapping.getClient().get_function(mapping.transformInboundDatabaseName(dbName), funcName));
1034
  }
1035

1036
  @Override
1037
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1038
  public boolean create_role(Role role) throws MetaException, TException {
×
1039
    return getPrimaryClient().create_role(role);
1040
  }
1041

1042
  @Override
1043
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1044
  public boolean drop_role(String role_name) throws MetaException, TException {
×
1045
    return getPrimaryClient().drop_role(role_name);
1046
  }
1047

1048
  @Override
1049
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1050
  public List<String> get_role_names() throws MetaException, TException {
×
1051
    return getPrimaryClient().get_role_names();
1052
  }
1053

1054
  @Override
1055
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1056
  public boolean grant_role(
×
1057
      String role_name,
1058
      String principal_name,
1059
      PrincipalType principal_type,
1060
      String grantor,
1061
      PrincipalType grantorType,
1062
      boolean grant_option)
1063
    throws MetaException, TException {
1064
    return getPrimaryClient().grant_role(role_name, principal_name, principal_type, grantor, grantorType, grant_option);
1065
  }
1066

1067
  @Override
1068
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1069
  public boolean revoke_role(String role_name, String principal_name, PrincipalType principal_type)
×
1070
    throws MetaException, TException {
1071
    return getPrimaryClient().revoke_role(role_name, principal_name, principal_type);
1072
  }
1073

1074
  @Override
1075
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1076
  public List<Role> list_roles(String principal_name, PrincipalType principal_type) throws MetaException, TException {
×
1077
    return getPrimaryClient().list_roles(principal_name, principal_type);
1078
  }
1079

1080
  @Override
1081
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1082
  public GrantRevokeRoleResponse grant_revoke_role(GrantRevokeRoleRequest request) throws MetaException, TException {
×
1083
    return getPrimaryClient().grant_revoke_role(request);
1084
  }
1085

1086
  @Override
1087
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1088
  public GetPrincipalsInRoleResponse get_principals_in_role(GetPrincipalsInRoleRequest request)
×
1089
    throws MetaException, TException {
1090
    return getPrimaryClient().get_principals_in_role(request);
1091
  }
1092

1093
  @Override
1094
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1095
  public GetRoleGrantsForPrincipalResponse get_role_grants_for_principal(GetRoleGrantsForPrincipalRequest request)
×
1096
    throws MetaException, TException {
1097
    return getPrimaryClient().get_role_grants_for_principal(request);
1098
  }
1099

1100
  @Override
1101
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1102
  public PrincipalPrivilegeSet get_privilege_set(HiveObjectRef hiveObject, String user_name, List<String> group_names)
×
1103
    throws MetaException, TException {
1104
    DatabaseMapping mapping;
1105
    if (hiveObject.getDbName() == null) {
1106
      mapping = databaseMappingService.primaryDatabaseMapping();
1107
    } else {
1108
      mapping = databaseMappingService.databaseMapping(hiveObject.getDbName());
1109
    }
1110
    return mapping
1111
        .getClient()
1112
        .get_privilege_set(mapping.transformInboundHiveObjectRef(hiveObject), user_name, group_names);
1113
  }
1114

1115
  @Override
1116
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1117
  public List<HiveObjectPrivilege> list_privileges(
×
1118
      String principal_name,
1119
      PrincipalType principal_type,
1120
      HiveObjectRef hiveObject)
1121
    throws MetaException, TException {
1122
    DatabaseMapping mapping = databaseMappingService.databaseMapping(hiveObject.getDbName());
1123
    List<HiveObjectPrivilege> privileges = mapping
1124
        .getClient()
1125
        .list_privileges(principal_name, principal_type, mapping.transformInboundHiveObjectRef(hiveObject));
1126
    return mapping.transformOutboundHiveObjectPrivileges(privileges);
1127
  }
1128

1129
  @Override
1130
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1131
  public boolean grant_privileges(PrivilegeBag privileges) throws MetaException, TException {
×
1132
    if (privileges.isSetPrivileges() && !privileges.getPrivileges().isEmpty()) {
1133
      DatabaseMapping mapping = checkWritePermissionsForPrivileges(privileges);
1134
      return mapping.getClient().grant_privileges(mapping.transformInboundPrivilegeBag(privileges));
1135
    }
1136
    return false;
1137
  }
1138

1139
  @Override
1140
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1141
  public boolean revoke_privileges(PrivilegeBag privileges) throws MetaException, TException {
×
1142
    if (privileges.isSetPrivileges() && !privileges.getPrivileges().isEmpty()) {
1143
      DatabaseMapping mapping = checkWritePermissionsForPrivileges(privileges);
1144
      return mapping.getClient().revoke_privileges(mapping.transformInboundPrivilegeBag(privileges));
1145
    }
1146
    return false;
1147
  }
1148

1149
  @Override
1150
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1151
  public GrantRevokePrivilegeResponse grant_revoke_privileges(GrantRevokePrivilegeRequest request)
×
1152
    throws MetaException, TException {
1153
    PrivilegeBag privilegesBag = request.getPrivileges();
1154
    if (privilegesBag.isSetPrivileges() && !privilegesBag.getPrivileges().isEmpty()) {
1155
      DatabaseMapping mapping = checkWritePermissionsForPrivileges(privilegesBag);
1156
      return mapping.getClient().grant_revoke_privileges(mapping.transformInboundGrantRevokePrivilegesRequest(request));
1157
    }
1158
    return getPrimaryClient().grant_revoke_privileges(request);
1159
  }
1160

1161
  private DatabaseMapping checkWritePermissionsForPrivileges(PrivilegeBag privileges) throws NoSuchObjectException {
1162
    DatabaseMapping mapping = databaseMappingService
×
1163
        .databaseMapping(privileges.getPrivileges().get(0).getHiveObject().getDbName());
×
1164
    for (HiveObjectPrivilege privilege : privileges.getPrivileges()) {
×
1165
      HiveObjectRef obj = privilege.getHiveObject();
×
1166
      mapping.checkWritePermissions(obj.getDbName());
×
1167
      if (obj.getObjectType() == HiveObjectType.DATABASE) {
×
1168
        mapping.checkWritePermissions(obj.getObjectName());
×
1169
      }
1170
    }
1171
    return mapping;
×
1172
  }
1173

1174
  @Override
1175
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1176
  public List<String> set_ugi(String user_name, List<String> group_names) throws MetaException, TException {
×
1177
    List<DatabaseMapping> mappings = databaseMappingService.getAllDatabaseMappings();
1178
    return databaseMappingService.getPanopticOperationHandler().setUgi(user_name, group_names, mappings);
1179
  }
1180

1181
  @Override
1182
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1183
  public String get_delegation_token(String token_owner, String renewer_kerberos_principal_name)
×
1184
    throws MetaException, TException {
1185
    return getPrimaryClient().get_delegation_token(token_owner, renewer_kerberos_principal_name);
1186
  }
1187

1188
  @Override
1189
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1190
  public long renew_delegation_token(String token_str_form) throws MetaException, TException {
×
1191
    return getPrimaryClient().renew_delegation_token(token_str_form);
1192
  }
1193

1194
  @Override
1195
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1196
  public void cancel_delegation_token(String token_str_form) throws MetaException, TException {
×
1197
    getPrimaryClient().cancel_delegation_token(token_str_form);
1198
  }
1199

1200
  @Override
1201
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1202
  public GetOpenTxnsResponse get_open_txns() throws TException {
×
1203
    return getPrimaryClient().get_open_txns();
1204
  }
1205

1206
  @Override
1207
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1208
  public GetOpenTxnsInfoResponse get_open_txns_info() throws TException {
×
1209
    return getPrimaryClient().get_open_txns_info();
1210
  }
1211

1212
  @Override
1213
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1214
  public OpenTxnsResponse open_txns(OpenTxnRequest rqst) throws TException {
×
1215
    return getPrimaryClient().open_txns(rqst);
1216
  }
1217

1218
  @Override
1219
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1220
  public void abort_txn(AbortTxnRequest rqst) throws NoSuchTxnException, TException {
×
1221
    getPrimaryClient().abort_txn(rqst);
1222
  }
1223

1224
  @Override
1225
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1226
  public void commit_txn(CommitTxnRequest rqst) throws NoSuchTxnException, TxnAbortedException, TException {
×
1227
    getPrimaryClient().commit_txn(rqst);
1228
  }
1229

1230
  @Override
1231
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1232
  public LockResponse lock(LockRequest rqst) throws NoSuchTxnException, TxnAbortedException, TException {
×
1233
    DatabaseMapping mapping = databaseMappingService.primaryDatabaseMapping();
1234
    List<LockComponent> components = rqst.getComponent();
1235
    for (LockComponent component : components) {
1236
      checkWritePermissionsAndCheckTableAllowed(component.getDbname(), component.getTablename());
1237
    }
1238
    return mapping.getClient().lock(mapping.transformInboundLockRequest(rqst));
1239
  }
1240

1241
  @Override
1242
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1243
  public LockResponse check_lock(CheckLockRequest rqst)
×
1244
    throws NoSuchTxnException, TxnAbortedException, NoSuchLockException, TException {
1245
    return getPrimaryClient().check_lock(rqst);
1246
  }
1247

1248
  @Override
1249
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1250
  public void unlock(UnlockRequest rqst) throws NoSuchLockException, TxnOpenException, TException {
×
1251
    getPrimaryClient().unlock(rqst);
1252
  }
1253

1254
  @Override
1255
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1256
  public ShowLocksResponse show_locks(ShowLocksRequest rqst) throws TException {
×
1257
    return getPrimaryClient().show_locks(rqst);
1258
  }
1259

1260
  @Override
1261
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1262
  public void heartbeat(HeartbeatRequest ids)
×
1263
    throws NoSuchLockException, NoSuchTxnException, TxnAbortedException, TException {
1264
    getPrimaryClient().heartbeat(ids);
1265
  }
1266

1267
  @Override
1268
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1269
  public HeartbeatTxnRangeResponse heartbeat_txn_range(HeartbeatTxnRangeRequest txns) throws TException {
×
1270
    return getPrimaryClient().heartbeat_txn_range(txns);
1271
  }
1272

1273
  @Override
1274
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1275
  public void compact(CompactionRequest rqst) throws TException {
×
1276
    DatabaseMapping mapping = databaseMappingService.primaryDatabaseMapping();
1277
    checkWritePermissionsAndCheckTableAllowed(rqst.getDbname(), rqst.getTablename(), mapping);
1278
    mapping.getClient().compact(mapping.transformInboundCompactionRequest(rqst));
1279
  }
1280

1281
  @Override
1282
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1283
  public ShowCompactResponse show_compact(ShowCompactRequest rqst) throws TException {
×
1284
    return getPrimaryClient().show_compact(rqst);
1285
  }
1286

1287
  @Override
1288
  public String getCpuProfile(int arg0) throws TException {
×
1289
    return getPrimaryClient().getCpuProfile(arg0);
1290
  }
1291

1292
  @Override
1293
  public String getVersion() throws TException {
×
1294
    return getPrimaryClient().getVersion();
1295
  }
1296

1297
  @Override
1298
  public fb_status getStatus() {
×
1299
    try {
1300
      return getPrimaryClient().getStatus();
1301
    } catch (TException e) {
1302
      LOG.error("Cannot getStatus() from client: ", e);
1303
      return fb_status.DEAD;
1304
    }
1305
  }
1306

1307
  @Override
1308
  public Configuration getConf() {
×
1309
    return conf;
1310
  }
1311

1312
  @Override
1313
  public void setConf(Configuration conf) {
×
1314
    this.conf = conf;
1315
  }
1316

1317
  @Override
1318
  public void init() throws MetaException {}
×
1319

1320
  // Hive 2.1.0 methods
1321
  @Override
1322
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1323
  public void abort_txns(AbortTxnsRequest rqst) throws NoSuchTxnException, TException {
×
1324
    getPrimaryClient().abort_txns(rqst);
1325
  }
1326

1327
  @Override
1328
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1329
  public void add_dynamic_partitions(AddDynamicPartitions rqst)
×
1330
    throws NoSuchTxnException, TxnAbortedException, TException {
1331
    DatabaseMapping mapping = checkWritePermissionsAndCheckTableAllowed(rqst.getDbname(), rqst.getTablename());
1332
    mapping.getClient().add_dynamic_partitions(mapping.transformInboundAddDynamicPartitions(rqst));
1333
  }
1334

1335
  @Override
1336
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1337
  public void add_foreign_key(AddForeignKeyRequest req) throws NoSuchObjectException, MetaException, TException {
×
1338
    getPrimaryClient().add_foreign_key(req);
1339
  }
1340

1341
  @Override
1342
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1343
  public int add_master_key(String key) throws MetaException, TException {
×
1344
    return getPrimaryClient().add_master_key(key);
1345
  }
1346

1347
  @Override
1348
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1349
  public void add_primary_key(AddPrimaryKeyRequest req) throws NoSuchObjectException, MetaException, TException {
×
1350
    getPrimaryClient().add_primary_key(req);
1351
  }
1352

1353
  @Override
1354
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1355
  public boolean add_token(String token_identifier, String delegation_token) throws TException {
×
1356
    return getPrimaryClient().add_token(token_identifier, delegation_token);
1357
  }
1358

1359
  @Override
1360
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1361
  public void alter_partitions_with_environment_context(
×
1362
      String db_name,
1363
      String tbl_name,
1364
      List<Partition> new_parts,
1365
      EnvironmentContext environment_context)
1366
    throws InvalidOperationException, MetaException, TException {
1367
    DatabaseMapping mapping = checkWritePermissionsAndCheckTableAllowed(db_name, tbl_name);
1368
    for (Partition newPart : new_parts) {
1369
      checkWritePermissionsAndCheckTableAllowed(newPart.getDbName(), newPart.getTableName(), mapping);
1370
    }
1371
    mapping
1372
        .getClient()
1373
        .alter_partitions_with_environment_context(mapping.transformInboundDatabaseName(db_name), tbl_name,
1374
                mapping.transformInboundPartitions(new_parts), environment_context);
1375
  }
1376

1377
  @Override
1378
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1379
  public void alter_table_with_cascade(String dbname, String tbl_name, Table new_tbl, boolean cascade)
×
1380
    throws InvalidOperationException, MetaException, TException {
1381
    DatabaseMapping mapping = checkWritePermissionsAndCheckTableAllowed(dbname, tbl_name);
1382
    checkWritePermissionsAndCheckTableAllowed(new_tbl.getDbName(), new_tbl.getTableName(), mapping);
1383
    mapping
1384
        .getClient()
1385
        .alter_table_with_cascade(mapping.transformInboundDatabaseName(dbname), tbl_name,
1386
                mapping.transformInboundTable(new_tbl), cascade);
1387
  }
1388

1389
  @Override
1390
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1391
  public CacheFileMetadataResult cache_file_metadata(CacheFileMetadataRequest req) throws TException {
×
1392
    DatabaseMapping mapping = databaseMappingService.primaryDatabaseMapping();
1393
    checkWritePermissionsAndCheckTableAllowed(req.getDbName(), req.getTblName());
1394
    return mapping.getClient().cache_file_metadata(mapping.transformInboundCacheFileMetadataRequest(req));
1395
  }
1396

1397
  @Override
1398
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1399
  public ClearFileMetadataResult clear_file_metadata(ClearFileMetadataRequest req) throws TException {
×
1400
    return getPrimaryClient().clear_file_metadata(req);
1401
  }
1402

1403
  @Override
1404
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1405
  public void create_table_with_constraints(Table tbl, List<SQLPrimaryKey> primaryKeys, List<SQLForeignKey> foreignKeys)
×
1406
    throws AlreadyExistsException, InvalidObjectException, MetaException, NoSuchObjectException, TException {
1407
    DatabaseMapping mapping = checkWritePermissions(tbl.getDbName());
1408
    mapping.getClient().create_table_with_constraints(mapping.transformInboundTable(tbl), primaryKeys, foreignKeys);
1409
  }
1410

1411
  @Override
1412
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1413
  public void drop_constraint(DropConstraintRequest req) throws NoSuchObjectException, MetaException, TException {
×
1414
    DatabaseMapping mapping = checkWritePermissionsAndCheckTableAllowed(req.getDbname(), req.getTablename());
1415
    mapping.getClient().drop_constraint(mapping.transformInboundDropConstraintRequest(req));
1416
  }
1417

1418
  @Override
1419
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1420
  public List<Partition> exchange_partitions(
×
1421
      Map<String, String> partitionSpecs,
1422
      String source_db,
1423
      String source_table_name,
1424
      String dest_db,
1425
      String dest_table_name)
1426
    throws MetaException, NoSuchObjectException, InvalidObjectException, InvalidInputException, TException {
1427
    DatabaseMapping mapping = checkWritePermissionsAndCheckTableAllowed(source_db, source_table_name);
1428
    checkWritePermissionsAndCheckTableAllowed(dest_db, dest_table_name, mapping);
1429
    List<Partition> result = mapping
1430
        .getClient()
1431
        .exchange_partitions(partitionSpecs, mapping.transformInboundDatabaseName(source_db), source_table_name,
1432
            mapping.transformInboundDatabaseName(dest_db), dest_table_name);
1433
    return mapping.transformOutboundPartitions(result);
1434
  }
1435

1436
  @Override
1437
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1438
  public FireEventResponse fire_listener_event(FireEventRequest rqst) throws TException {
×
1439
    DatabaseMapping mapping = databaseMappingService.databaseMapping(rqst.getDbName());
1440
    return mapping.getClient().fire_listener_event(mapping.transformInboundFireEventRequest(rqst));
1441
  }
1442

1443
  @Override
1444
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1445
  public void flushCache() throws TException {
×
1446
    getPrimaryClient().flushCache();
1447
  }
1448

1449
  @Override
1450
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1451
  public GetAllFunctionsResponse get_all_functions() throws TException {
×
1452
    if (waggleDanceConfiguration.isQueryFunctionsAcrossAllMetastores()) {
1453
      return databaseMappingService
1454
          .getPanopticOperationHandler()
1455
          .getAllFunctions(databaseMappingService.getAvailableDatabaseMappings());
1456
    } else {
1457
      return getPrimaryClient().get_all_functions();
1458
    }
1459
  }
1460

1461
  @Override
1462
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1463
  public List<String> get_all_token_identifiers() throws TException {
×
1464
    return getPrimaryClient().get_all_token_identifiers();
1465
  }
1466

1467
  @Override
1468
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1469
  public CurrentNotificationEventId get_current_notificationEventId() throws TException {
×
1470
    return getPrimaryClient().get_current_notificationEventId();
1471
  }
1472

1473
  @Override
1474
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1475
  public List<FieldSchema> get_fields_with_environment_context(
×
1476
      String db_name,
1477
      String table_name,
1478
      EnvironmentContext environment_context)
1479
    throws MetaException, UnknownTableException, UnknownDBException, TException {
1480
    DatabaseMapping mapping = getDbMappingAndCheckTableAllowed(db_name, table_name);
1481
    return mapping
1482
        .getClient()
1483
        .get_fields_with_environment_context(mapping.transformInboundDatabaseName(db_name), table_name,
1484
            environment_context);
1485
  }
1486

1487
  @Override
1488
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1489
  public GetFileMetadataResult get_file_metadata(GetFileMetadataRequest req) throws TException {
×
1490
    return getPrimaryClient().get_file_metadata(req);
1491
  }
1492

1493
  @Override
1494
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1495
  public GetFileMetadataByExprResult get_file_metadata_by_expr(GetFileMetadataByExprRequest req) throws TException {
×
1496
    return getPrimaryClient().get_file_metadata_by_expr(req);
1497
  }
1498

1499
  @Override
1500
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1501
  public ForeignKeysResponse get_foreign_keys(ForeignKeysRequest request)
×
1502
    throws MetaException, NoSuchObjectException, TException {
1503
    DatabaseMapping mapping = getDbMappingAndCheckTableAllowed(request.getForeign_db_name(),
1504
        request.getForeign_tbl_name());
1505
    return mapping
1506
        .transformOutboundForeignKeysResponse(
1507
            mapping.getClient().get_foreign_keys(mapping.transformInboundForeignKeysRequest(request)));
1508
  }
1509

1510
  @Override
1511
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1512
  public List<String> get_master_keys() throws TException {
×
1513
    return getPrimaryClient().get_master_keys();
1514
  }
1515

1516
  @Override
1517
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1518
  public NotificationEventResponse get_next_notification(NotificationEventRequest rqst) throws TException {
×
1519
    return getPrimaryClient().get_next_notification(rqst);
1520
  }
1521

1522
  @Override
1523
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1524
  public int get_num_partitions_by_filter(String db_name, String tbl_name, String filter)
×
1525
    throws MetaException, NoSuchObjectException, TException {
1526
    DatabaseMapping mapping = getDbMappingAndCheckTableAllowed(db_name, tbl_name);
1527
    return mapping
1528
        .getClient()
1529
        .get_num_partitions_by_filter(mapping.transformInboundDatabaseName(db_name), tbl_name, filter);
1530
  }
1531

1532
  @Override
1533
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1534
  public PrimaryKeysResponse get_primary_keys(PrimaryKeysRequest request)
×
1535
    throws MetaException, NoSuchObjectException, TException {
1536
    DatabaseMapping mapping = getDbMappingAndCheckTableAllowed(request.getDb_name(), request.getTbl_name());
1537
    return mapping
1538
        .transformOutboundPrimaryKeysResponse(
1539
            mapping.getClient().get_primary_keys(mapping.transformInboundPrimaryKeysRequest(request)));
1540
  }
1541

1542
  @Override
1543
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1544
  public List<FieldSchema> get_schema_with_environment_context(
×
1545
      String db_name,
1546
      String table_name,
1547
      EnvironmentContext environment_context)
1548
    throws MetaException, UnknownTableException, UnknownDBException, TException {
1549
    DatabaseMapping mapping = getDbMappingAndCheckTableAllowed(db_name, table_name);
1550
    return mapping
1551
        .getClient()
1552
        .get_schema_with_environment_context(mapping.transformInboundDatabaseName(db_name), table_name,
1553
            environment_context);
1554
  }
1555

1556
  @Override
1557
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1558
  public List<TableMeta> get_table_meta(String db_patterns, String tbl_patterns, List<String> tbl_types)
×
1559
    throws MetaException {
1560
    return databaseMappingService.getPanopticOperationHandler().getTableMeta(db_patterns, tbl_patterns, tbl_types);
1561
  }
1562

1563
  @Override
1564
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1565
  public String get_token(String token_identifier) throws TException {
×
1566
    return getPrimaryClient().get_token(token_identifier);
1567
  }
1568

1569
  @Override
1570
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1571
  public PutFileMetadataResult put_file_metadata(PutFileMetadataRequest req) throws TException {
×
1572
    return getPrimaryClient().put_file_metadata(req);
1573
  }
1574

1575
  @Override
1576
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1577
  public boolean remove_master_key(int key_seq) throws TException {
×
1578
    return getPrimaryClient().remove_master_key(key_seq);
1579
  }
1580

1581
  @Override
1582
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1583
  public boolean remove_token(String token_identifier) throws TException {
×
1584
    return getPrimaryClient().remove_token(token_identifier);
1585
  }
1586

1587
  @Override
1588
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1589
  public void update_master_key(int seq_number, String key) throws NoSuchObjectException, MetaException, TException {
×
1590
    getPrimaryClient().update_master_key(seq_number, key);
1591
  }
1592

1593
  // Hive 2.3.0 methods
1594
  @Override
1595
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1596
  public List<String> get_tables_by_type(String db_name, String pattern, String tableType)
×
1597
    throws MetaException, TException {
1598
    DatabaseMapping mapping = databaseMappingService.databaseMapping(db_name);
1599
    List<String> resultTables = mapping
1600
        .getClient()
1601
        .get_tables_by_type(mapping.transformInboundDatabaseName(db_name), pattern, tableType);
1602
    List<String> result = databaseMappingService.filterTables(db_name, resultTables, mapping);
1603
    return mapping.getMetastoreFilter().filterTableNames(db_name, result);
1604
  }
1605

1606
  @Override
1607
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1608
  public GetTableResult get_table_req(GetTableRequest req) throws MetaException, NoSuchObjectException, TException {
×
1609
    DatabaseMapping mapping = getDbMappingAndCheckTableAllowed(req.getDbName(), req.getTblName());
1610
    GetTableResult result = mapping.getClient().get_table_req(mapping.transformInboundGetTableRequest(req));
1611
    result.setTable(mapping.getMetastoreFilter().filterTable(result.getTable()));
1612
    return mapping.transformOutboundGetTableResult(result);
1613
  }
1614

1615
  @Override
1616
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1617
  public GetTablesResult get_table_objects_by_name_req(GetTablesRequest req)
×
1618
    throws MetaException, InvalidOperationException, UnknownDBException, TException {
1619
    DatabaseMapping mapping = databaseMappingService.databaseMapping(req.getDbName());
1620
    List<String> filteredTables = databaseMappingService.filterTables(req.getDbName(), req.getTblNames(), mapping);
1621
    req.setTblNames(filteredTables);
1622
    GetTablesResult result = mapping
1623
        .getClient()
1624
        .get_table_objects_by_name_req(mapping.transformInboundGetTablesRequest(req));
1625
    result.setTables(mapping.getMetastoreFilter().filterTables(result.getTables()));
1626
    return mapping.transformOutboundGetTablesResult(result);
1627
  }
1628

1629
  @Override
1630
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1631
  public CompactionResponse compact2(CompactionRequest rqst) throws TException {
×
1632
    DatabaseMapping mapping = databaseMappingService.primaryDatabaseMapping();
1633
    checkWritePermissionsAndCheckTableAllowed(rqst.getDbname(), rqst.getTablename(), mapping);
1634
    return mapping.getClient().compact2(mapping.transformInboundCompactionRequest(rqst));
1635
  }
1636

1637
  // Hive 2.3.6 methods
1638

1639
  @Override
1640
  @Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
1641
  public PartitionValuesResponse get_partition_values(PartitionValuesRequest req)
×
1642
    throws MetaException, NoSuchObjectException, TException {
1643
    DatabaseMapping mapping = getDbMappingAndCheckTableAllowed(req.getDbName(), req.getTblName());
1644
    return mapping.getClient().get_partition_values(mapping.transformInboundPartitionValuesRequest(req));
1645
  }
1646

1647
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc