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

ExpediaGroup / beekeeper / #814

07 Apr 2026 07:33PM UTC coverage: 87.706% (-0.07%) from 87.774%
#814

Pull #201

ninhomilton
Clean up
Pull Request #201: Upgrade to Java 21 and Spring Boot 3.2.12

10 of 12 new or added lines in 3 files covered. (83.33%)

115 existing lines in 33 files now uncovered.

1541 of 1757 relevant lines covered (87.71%)

0.88 hits per line

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

92.68
/beekeeper-cleanup/src/main/java/com/expediagroup/beekeeper/cleanup/hive/HiveClient.java
1
/**
2
 * Copyright (C) 2019-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.expediagroup.beekeeper.cleanup.hive;
17

18
import java.util.HashMap;
19
import java.util.Map;
20

21
import org.apache.hadoop.hive.metastore.api.NoSuchObjectException;
22
import org.apache.hadoop.hive.metastore.api.Table;
23
import org.apache.thrift.TException;
24
import org.slf4j.Logger;
25
import org.slf4j.LoggerFactory;
26

27
import com.expediagroup.beekeeper.cleanup.metadata.CleanerClient;
28
import com.expediagroup.beekeeper.core.error.BeekeeperException;
29

30
import com.hotels.hcommon.hive.metastore.client.api.CloseableMetaStoreClient;
31

32
public class HiveClient implements CleanerClient {
1✔
33

34
  private static final Logger log = LoggerFactory.getLogger(HiveClient.class);
35

36
  private CloseableMetaStoreClient client;
37
  private final boolean dryRunEnabled;
1✔
38

1✔
39
  public HiveClient(CloseableMetaStoreClient client, boolean dryRunEnabled) {
1✔
40
    this.client = client;
1✔
41
    this.dryRunEnabled = dryRunEnabled;
42
  }
43

44
  /**
45
   * Will drop the table from the database if it exists.
46
   *
47
   * @param databaseName
48
   * @param tableName
49
   */
50
  @Override
1✔
51
  public void dropTable(String databaseName, String tableName) {
1✔
52
    if (dryRunEnabled) {
53
      log.info("Dry run - dropping table \"{}.{}\"", databaseName, tableName);
54
    } else {
1✔
55
      try {
1✔
56
        log.info("Dropping table \"{}.{}\"", databaseName, tableName);
1✔
57
        client.dropTable(databaseName, tableName);
1✔
58
      } catch (NoSuchObjectException e) {
1✔
59
        log.info("Could not drop table: table not found: \"{}.{}\"", databaseName, tableName);
1✔
60
      } catch (TException e) {
61
        throw new BeekeeperException(
62
            "Unexpected exception when dropping table: \"" + databaseName + "." + tableName + "\".",
1✔
63
            e);
64
      }
1✔
65
    }
66
  }
67

68
  /**
69
   * Will drop the partition from the table if it exists.
70
   *
71
   * @param databaseName
72
   * @param tableName
73
   * @param partitionName expected format: "event_date=2020-01-01/event_hour=0/event_type=A"
74
   */
75
  @Override
1✔
76
  public boolean dropPartition(String databaseName, String tableName, String partitionName) {
1✔
77
    boolean partitionDeleted = true;
1✔
78
    if (dryRunEnabled) {
79
      log.info("Dry run - dropping partition \"{}\" from table \"{}.{}\"", partitionName, databaseName, tableName);
80
    } else {
81
      try {
82
        log.info("Dropping partition \"{}\" from table \"{}.{}\"", partitionName, databaseName, tableName);
83
        client.dropPartition(databaseName, tableName, partitionName, false);
84
      } catch (NoSuchObjectException e) {
1✔
85
        log
86
            .info("Could not drop partition \"{}\" from table \"{}.{}\". Partition does not exist.", partitionName,
87
                databaseName, tableName);
88
        partitionDeleted = false;
89
      } catch (TException e) {
1✔
90
        throw new BeekeeperException("Unexpected exception when dropping partition \""
1✔
91
            + partitionName
1✔
92
            + "\" from table: \""
93
            + databaseName
94
            + "."
95
            + tableName
96
            + "\".", e);
1✔
97
      }
1✔
98
    }
1✔
99
    return partitionDeleted;
100
  }
101

102
  @Override
103
  public boolean tableExists(String databaseName, String tableName) {
104
    try {
105
      return client.tableExists(databaseName, tableName);
106
    } catch (TException e) {
107
      throw new BeekeeperException(
1✔
108
          "Unexpected exception when checking if table \"" + databaseName + "." + tableName + "\" exists.", e);
109
    }
1✔
110
  }
111

112
  @Override
113
  public Map<String, String> getTableProperties(String databaseName, String tableName) {
114
    try {
UNCOV
115
      Table table = client.getTable(databaseName, tableName);
×
116
      if (table.getParameters() == null) {
1✔
117
        return new HashMap<>();
1✔
118
      }
119
      return table.getParameters();
120
    } catch (NoSuchObjectException e) {
121
      log.warn("The table {}.{} does not exist", databaseName, tableName);
122
      return new HashMap<>();
123
    } catch (TException e) {
124
      throw new BeekeeperException(
125
          "Unexpected exception when getting table properties for \"" + databaseName + "." + tableName + ".", e);
126
    }
127
  }
128

129
  @Override
130
  public void close() {
1✔
131
    client.close();
1✔
132
  }
1✔
133
}
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