This is an automated email from the ASF dual-hosted git repository.
ngangam pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hive.git
The following commit(s) were added to refs/heads/master by this push:
new 1f77eb87d30 HIVE-28443: Add ifExists field to dropCatalogRequest
(#5395)
1f77eb87d30 is described below
commit 1f77eb87d30f4a8219f7515d0b90f1753ae10b64
Author: Hazel Jiang <[email protected]>
AuthorDate: Fri Aug 16 14:02:13 2024 -0700
HIVE-28443: Add ifExists field to dropCatalogRequest (#5395)
Co-authored-by: Jintong Jiang <[email protected]>
---
.../gen/thrift/gen-cpp/hive_metastore_types.cpp | 22 +++++
.../src/gen/thrift/gen-cpp/hive_metastore_types.h | 13 ++-
.../hive/metastore/api/DropCatalogRequest.java | 109 ++++++++++++++++++++-
.../gen-php/metastore/DropCatalogRequest.php | 24 +++++
.../src/gen/thrift/gen-py/hive_metastore/ttypes.py | 14 ++-
.../src/gen/thrift/gen-rb/hive_metastore_types.rb | 4 +-
.../hadoop/hive/metastore/HiveMetaStoreClient.java | 6 ++
.../hadoop/hive/metastore/IMetaStoreClient.java | 9 ++
.../src/main/thrift/hive_metastore.thrift | 3 +-
.../apache/hadoop/hive/metastore/HMSHandler.java | 13 ++-
.../metastore/HiveMetaStoreClientPreCatalog.java | 5 +
.../hadoop/hive/metastore/client/TestCatalogs.java | 7 ++
12 files changed, 218 insertions(+), 11 deletions(-)
diff --git
a/standalone-metastore/metastore-common/src/gen/thrift/gen-cpp/hive_metastore_types.cpp
b/standalone-metastore/metastore-common/src/gen/thrift/gen-cpp/hive_metastore_types.cpp
index 5be06e2b1f4..83028cf0727 100644
---
a/standalone-metastore/metastore-common/src/gen/thrift/gen-cpp/hive_metastore_types.cpp
+++
b/standalone-metastore/metastore-common/src/gen/thrift/gen-cpp/hive_metastore_types.cpp
@@ -7093,6 +7093,11 @@ DropCatalogRequest::~DropCatalogRequest() noexcept {
void DropCatalogRequest::__set_name(const std::string& val) {
this->name = val;
}
+
+void DropCatalogRequest::__set_ifExists(const bool val) {
+ this->ifExists = val;
+__isset.ifExists = true;
+}
std::ostream& operator<<(std::ostream& out, const DropCatalogRequest& obj)
{
obj.printTo(out);
@@ -7129,6 +7134,14 @@ uint32_t
DropCatalogRequest::read(::apache::thrift::protocol::TProtocol* iprot)
xfer += iprot->skip(ftype);
}
break;
+ case 2:
+ if (ftype == ::apache::thrift::protocol::T_BOOL) {
+ xfer += iprot->readBool(this->ifExists);
+ this->__isset.ifExists = true;
+ } else {
+ xfer += iprot->skip(ftype);
+ }
+ break;
default:
xfer += iprot->skip(ftype);
break;
@@ -7150,6 +7163,11 @@ uint32_t
DropCatalogRequest::write(::apache::thrift::protocol::TProtocol* oprot)
xfer += oprot->writeString(this->name);
xfer += oprot->writeFieldEnd();
+ if (this->__isset.ifExists) {
+ xfer += oprot->writeFieldBegin("ifExists",
::apache::thrift::protocol::T_BOOL, 2);
+ xfer += oprot->writeBool(this->ifExists);
+ xfer += oprot->writeFieldEnd();
+ }
xfer += oprot->writeFieldStop();
xfer += oprot->writeStructEnd();
return xfer;
@@ -7158,15 +7176,18 @@ uint32_t
DropCatalogRequest::write(::apache::thrift::protocol::TProtocol* oprot)
void swap(DropCatalogRequest &a, DropCatalogRequest &b) {
using ::std::swap;
swap(a.name, b.name);
+ swap(a.ifExists, b.ifExists);
swap(a.__isset, b.__isset);
}
DropCatalogRequest::DropCatalogRequest(const DropCatalogRequest& other242) {
name = other242.name;
+ ifExists = other242.ifExists;
__isset = other242.__isset;
}
DropCatalogRequest& DropCatalogRequest::operator=(const DropCatalogRequest&
other243) {
name = other243.name;
+ ifExists = other243.ifExists;
__isset = other243.__isset;
return *this;
}
@@ -7174,6 +7195,7 @@ void DropCatalogRequest::printTo(std::ostream& out) const
{
using ::apache::thrift::to_string;
out << "DropCatalogRequest(";
out << "name=" << to_string(name);
+ out << ", " << "ifExists="; (__isset.ifExists ? (out << to_string(ifExists))
: (out << "<null>"));
out << ")";
}
diff --git
a/standalone-metastore/metastore-common/src/gen/thrift/gen-cpp/hive_metastore_types.h
b/standalone-metastore/metastore-common/src/gen/thrift/gen-cpp/hive_metastore_types.h
index 10ea3edd674..d6882ba43c5 100644
---
a/standalone-metastore/metastore-common/src/gen/thrift/gen-cpp/hive_metastore_types.h
+++
b/standalone-metastore/metastore-common/src/gen/thrift/gen-cpp/hive_metastore_types.h
@@ -3472,8 +3472,9 @@ void swap(GetCatalogsResponse &a, GetCatalogsResponse &b);
std::ostream& operator<<(std::ostream& out, const GetCatalogsResponse& obj);
typedef struct _DropCatalogRequest__isset {
- _DropCatalogRequest__isset() : name(false) {}
+ _DropCatalogRequest__isset() : name(false), ifExists(false) {}
bool name :1;
+ bool ifExists :1;
} _DropCatalogRequest__isset;
class DropCatalogRequest : public virtual ::apache::thrift::TBase {
@@ -3482,20 +3483,28 @@ class DropCatalogRequest : public virtual
::apache::thrift::TBase {
DropCatalogRequest(const DropCatalogRequest&);
DropCatalogRequest& operator=(const DropCatalogRequest&);
DropCatalogRequest() noexcept
- : name() {
+ : name(),
+ ifExists(0) {
}
virtual ~DropCatalogRequest() noexcept;
std::string name;
+ bool ifExists;
_DropCatalogRequest__isset __isset;
void __set_name(const std::string& val);
+ void __set_ifExists(const bool val);
+
bool operator == (const DropCatalogRequest & rhs) const
{
if (!(name == rhs.name))
return false;
+ if (__isset.ifExists != rhs.__isset.ifExists)
+ return false;
+ else if (__isset.ifExists && !(ifExists == rhs.ifExists))
+ return false;
return true;
}
bool operator != (const DropCatalogRequest &rhs) const {
diff --git
a/standalone-metastore/metastore-common/src/gen/thrift/gen-javabean/org/apache/hadoop/hive/metastore/api/DropCatalogRequest.java
b/standalone-metastore/metastore-common/src/gen/thrift/gen-javabean/org/apache/hadoop/hive/metastore/api/DropCatalogRequest.java
index 970ece7faef..4b0a8f2026d 100644
---
a/standalone-metastore/metastore-common/src/gen/thrift/gen-javabean/org/apache/hadoop/hive/metastore/api/DropCatalogRequest.java
+++
b/standalone-metastore/metastore-common/src/gen/thrift/gen-javabean/org/apache/hadoop/hive/metastore/api/DropCatalogRequest.java
@@ -12,15 +12,18 @@ package org.apache.hadoop.hive.metastore.api;
private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new
org.apache.thrift.protocol.TStruct("DropCatalogRequest");
private static final org.apache.thrift.protocol.TField NAME_FIELD_DESC = new
org.apache.thrift.protocol.TField("name",
org.apache.thrift.protocol.TType.STRING, (short)1);
+ private static final org.apache.thrift.protocol.TField IF_EXISTS_FIELD_DESC
= new org.apache.thrift.protocol.TField("ifExists",
org.apache.thrift.protocol.TType.BOOL, (short)2);
private static final org.apache.thrift.scheme.SchemeFactory
STANDARD_SCHEME_FACTORY = new DropCatalogRequestStandardSchemeFactory();
private static final org.apache.thrift.scheme.SchemeFactory
TUPLE_SCHEME_FACTORY = new DropCatalogRequestTupleSchemeFactory();
private @org.apache.thrift.annotation.Nullable java.lang.String name; //
required
+ private boolean ifExists; // optional
/** The set of fields this struct contains, along with convenience methods
for finding and manipulating them. */
public enum _Fields implements org.apache.thrift.TFieldIdEnum {
- NAME((short)1, "name");
+ NAME((short)1, "name"),
+ IF_EXISTS((short)2, "ifExists");
private static final java.util.Map<java.lang.String, _Fields> byName = new
java.util.HashMap<java.lang.String, _Fields>();
@@ -38,6 +41,8 @@ package org.apache.hadoop.hive.metastore.api;
switch(fieldId) {
case 1: // NAME
return NAME;
+ case 2: // IF_EXISTS
+ return IF_EXISTS;
default:
return null;
}
@@ -79,11 +84,16 @@ package org.apache.hadoop.hive.metastore.api;
}
// isset id assignments
+ private static final int __IFEXISTS_ISSET_ID = 0;
+ private byte __isset_bitfield = 0;
+ private static final _Fields optionals[] = {_Fields.IF_EXISTS};
public static final java.util.Map<_Fields,
org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
static {
java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap =
new java.util.EnumMap<_Fields,
org.apache.thrift.meta_data.FieldMetaData>(_Fields.class);
tmpMap.put(_Fields.NAME, new
org.apache.thrift.meta_data.FieldMetaData("name",
org.apache.thrift.TFieldRequirementType.DEFAULT,
new
org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING)));
+ tmpMap.put(_Fields.IF_EXISTS, new
org.apache.thrift.meta_data.FieldMetaData("ifExists",
org.apache.thrift.TFieldRequirementType.OPTIONAL,
+ new
org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.BOOL)));
metaDataMap = java.util.Collections.unmodifiableMap(tmpMap);
org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(DropCatalogRequest.class,
metaDataMap);
}
@@ -102,9 +112,11 @@ package org.apache.hadoop.hive.metastore.api;
* Performs a deep copy on <i>other</i>.
*/
public DropCatalogRequest(DropCatalogRequest other) {
+ __isset_bitfield = other.__isset_bitfield;
if (other.isSetName()) {
this.name = other.name;
}
+ this.ifExists = other.ifExists;
}
public DropCatalogRequest deepCopy() {
@@ -114,6 +126,8 @@ package org.apache.hadoop.hive.metastore.api;
@Override
public void clear() {
this.name = null;
+ setIfExistsIsSet(false);
+ this.ifExists = false;
}
@org.apache.thrift.annotation.Nullable
@@ -140,6 +154,28 @@ package org.apache.hadoop.hive.metastore.api;
}
}
+ public boolean isIfExists() {
+ return this.ifExists;
+ }
+
+ public void setIfExists(boolean ifExists) {
+ this.ifExists = ifExists;
+ setIfExistsIsSet(true);
+ }
+
+ public void unsetIfExists() {
+ __isset_bitfield =
org.apache.thrift.EncodingUtils.clearBit(__isset_bitfield, __IFEXISTS_ISSET_ID);
+ }
+
+ /** Returns true if field ifExists is set (has been assigned a value) and
false otherwise */
+ public boolean isSetIfExists() {
+ return org.apache.thrift.EncodingUtils.testBit(__isset_bitfield,
__IFEXISTS_ISSET_ID);
+ }
+
+ public void setIfExistsIsSet(boolean value) {
+ __isset_bitfield =
org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __IFEXISTS_ISSET_ID,
value);
+ }
+
public void setFieldValue(_Fields field,
@org.apache.thrift.annotation.Nullable java.lang.Object value) {
switch (field) {
case NAME:
@@ -150,6 +186,14 @@ package org.apache.hadoop.hive.metastore.api;
}
break;
+ case IF_EXISTS:
+ if (value == null) {
+ unsetIfExists();
+ } else {
+ setIfExists((java.lang.Boolean)value);
+ }
+ break;
+
}
}
@@ -159,6 +203,9 @@ package org.apache.hadoop.hive.metastore.api;
case NAME:
return getName();
+ case IF_EXISTS:
+ return isIfExists();
+
}
throw new java.lang.IllegalStateException();
}
@@ -172,6 +219,8 @@ package org.apache.hadoop.hive.metastore.api;
switch (field) {
case NAME:
return isSetName();
+ case IF_EXISTS:
+ return isSetIfExists();
}
throw new java.lang.IllegalStateException();
}
@@ -198,6 +247,15 @@ package org.apache.hadoop.hive.metastore.api;
return false;
}
+ boolean this_present_ifExists = true && this.isSetIfExists();
+ boolean that_present_ifExists = true && that.isSetIfExists();
+ if (this_present_ifExists || that_present_ifExists) {
+ if (!(this_present_ifExists && that_present_ifExists))
+ return false;
+ if (this.ifExists != that.ifExists)
+ return false;
+ }
+
return true;
}
@@ -209,6 +267,10 @@ package org.apache.hadoop.hive.metastore.api;
if (isSetName())
hashCode = hashCode * 8191 + name.hashCode();
+ hashCode = hashCode * 8191 + ((isSetIfExists()) ? 131071 : 524287);
+ if (isSetIfExists())
+ hashCode = hashCode * 8191 + ((ifExists) ? 131071 : 524287);
+
return hashCode;
}
@@ -230,6 +292,16 @@ package org.apache.hadoop.hive.metastore.api;
return lastComparison;
}
}
+ lastComparison = java.lang.Boolean.compare(isSetIfExists(),
other.isSetIfExists());
+ if (lastComparison != 0) {
+ return lastComparison;
+ }
+ if (isSetIfExists()) {
+ lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.ifExists,
other.ifExists);
+ if (lastComparison != 0) {
+ return lastComparison;
+ }
+ }
return 0;
}
@@ -258,6 +330,12 @@ package org.apache.hadoop.hive.metastore.api;
sb.append(this.name);
}
first = false;
+ if (isSetIfExists()) {
+ if (!first) sb.append(", ");
+ sb.append("ifExists:");
+ sb.append(this.ifExists);
+ first = false;
+ }
sb.append(")");
return sb.toString();
}
@@ -277,6 +355,8 @@ package org.apache.hadoop.hive.metastore.api;
private void readObject(java.io.ObjectInputStream in) throws
java.io.IOException, java.lang.ClassNotFoundException {
try {
+ // it doesn't seem like you should have to do this, but java
serialization is wacky, and doesn't call the default constructor.
+ __isset_bitfield = 0;
read(new org.apache.thrift.protocol.TCompactProtocol(new
org.apache.thrift.transport.TIOStreamTransport(in)));
} catch (org.apache.thrift.TException te) {
throw new java.io.IOException(te);
@@ -309,6 +389,14 @@ package org.apache.hadoop.hive.metastore.api;
org.apache.thrift.protocol.TProtocolUtil.skip(iprot,
schemeField.type);
}
break;
+ case 2: // IF_EXISTS
+ if (schemeField.type == org.apache.thrift.protocol.TType.BOOL) {
+ struct.ifExists = iprot.readBool();
+ struct.setIfExistsIsSet(true);
+ } else {
+ org.apache.thrift.protocol.TProtocolUtil.skip(iprot,
schemeField.type);
+ }
+ break;
default:
org.apache.thrift.protocol.TProtocolUtil.skip(iprot,
schemeField.type);
}
@@ -327,6 +415,11 @@ package org.apache.hadoop.hive.metastore.api;
oprot.writeString(struct.name);
oprot.writeFieldEnd();
}
+ if (struct.isSetIfExists()) {
+ oprot.writeFieldBegin(IF_EXISTS_FIELD_DESC);
+ oprot.writeBool(struct.ifExists);
+ oprot.writeFieldEnd();
+ }
oprot.writeFieldStop();
oprot.writeStructEnd();
}
@@ -348,20 +441,30 @@ package org.apache.hadoop.hive.metastore.api;
if (struct.isSetName()) {
optionals.set(0);
}
- oprot.writeBitSet(optionals, 1);
+ if (struct.isSetIfExists()) {
+ optionals.set(1);
+ }
+ oprot.writeBitSet(optionals, 2);
if (struct.isSetName()) {
oprot.writeString(struct.name);
}
+ if (struct.isSetIfExists()) {
+ oprot.writeBool(struct.ifExists);
+ }
}
@Override
public void read(org.apache.thrift.protocol.TProtocol prot,
DropCatalogRequest struct) throws org.apache.thrift.TException {
org.apache.thrift.protocol.TTupleProtocol iprot =
(org.apache.thrift.protocol.TTupleProtocol) prot;
- java.util.BitSet incoming = iprot.readBitSet(1);
+ java.util.BitSet incoming = iprot.readBitSet(2);
if (incoming.get(0)) {
struct.name = iprot.readString();
struct.setNameIsSet(true);
}
+ if (incoming.get(1)) {
+ struct.ifExists = iprot.readBool();
+ struct.setIfExistsIsSet(true);
+ }
}
}
diff --git
a/standalone-metastore/metastore-common/src/gen/thrift/gen-php/metastore/DropCatalogRequest.php
b/standalone-metastore/metastore-common/src/gen/thrift/gen-php/metastore/DropCatalogRequest.php
index a1dc1848335..a8098e790bb 100644
---
a/standalone-metastore/metastore-common/src/gen/thrift/gen-php/metastore/DropCatalogRequest.php
+++
b/standalone-metastore/metastore-common/src/gen/thrift/gen-php/metastore/DropCatalogRequest.php
@@ -26,12 +26,21 @@ class DropCatalogRequest
'isRequired' => false,
'type' => TType::STRING,
),
+ 2 => array(
+ 'var' => 'ifExists',
+ 'isRequired' => false,
+ 'type' => TType::BOOL,
+ ),
);
/**
* @var string
*/
public $name = null;
+ /**
+ * @var bool
+ */
+ public $ifExists = null;
public function __construct($vals = null)
{
@@ -39,6 +48,9 @@ class DropCatalogRequest
if (isset($vals['name'])) {
$this->name = $vals['name'];
}
+ if (isset($vals['ifExists'])) {
+ $this->ifExists = $vals['ifExists'];
+ }
}
}
@@ -68,6 +80,13 @@ class DropCatalogRequest
$xfer += $input->skip($ftype);
}
break;
+ case 2:
+ if ($ftype == TType::BOOL) {
+ $xfer += $input->readBool($this->ifExists);
+ } else {
+ $xfer += $input->skip($ftype);
+ }
+ break;
default:
$xfer += $input->skip($ftype);
break;
@@ -87,6 +106,11 @@ class DropCatalogRequest
$xfer += $output->writeString($this->name);
$xfer += $output->writeFieldEnd();
}
+ if ($this->ifExists !== null) {
+ $xfer += $output->writeFieldBegin('ifExists', TType::BOOL, 2);
+ $xfer += $output->writeBool($this->ifExists);
+ $xfer += $output->writeFieldEnd();
+ }
$xfer += $output->writeFieldStop();
$xfer += $output->writeStructEnd();
return $xfer;
diff --git
a/standalone-metastore/metastore-common/src/gen/thrift/gen-py/hive_metastore/ttypes.py
b/standalone-metastore/metastore-common/src/gen/thrift/gen-py/hive_metastore/ttypes.py
index 04d6818e036..9f22c5a6358 100644
---
a/standalone-metastore/metastore-common/src/gen/thrift/gen-py/hive_metastore/ttypes.py
+++
b/standalone-metastore/metastore-common/src/gen/thrift/gen-py/hive_metastore/ttypes.py
@@ -4105,12 +4105,14 @@ class DropCatalogRequest(object):
"""
Attributes:
- name
+ - ifExists
"""
- def __init__(self, name=None,):
+ def __init__(self, name=None, ifExists=None,):
self.name = name
+ self.ifExists = ifExists
def read(self, iprot):
if iprot._fast_decode is not None and isinstance(iprot.trans,
TTransport.CReadableTransport) and self.thrift_spec is not None:
@@ -4126,6 +4128,11 @@ class DropCatalogRequest(object):
self.name = iprot.readString().decode('utf-8',
errors='replace') if sys.version_info[0] == 2 else iprot.readString()
else:
iprot.skip(ftype)
+ elif fid == 2:
+ if ftype == TType.BOOL:
+ self.ifExists = iprot.readBool()
+ else:
+ iprot.skip(ftype)
else:
iprot.skip(ftype)
iprot.readFieldEnd()
@@ -4140,6 +4147,10 @@ class DropCatalogRequest(object):
oprot.writeFieldBegin('name', TType.STRING, 1)
oprot.writeString(self.name.encode('utf-8') if sys.version_info[0]
== 2 else self.name)
oprot.writeFieldEnd()
+ if self.ifExists is not None:
+ oprot.writeFieldBegin('ifExists', TType.BOOL, 2)
+ oprot.writeBool(self.ifExists)
+ oprot.writeFieldEnd()
oprot.writeFieldStop()
oprot.writeStructEnd()
@@ -32155,6 +32166,7 @@ all_structs.append(DropCatalogRequest)
DropCatalogRequest.thrift_spec = (
None, # 0
(1, TType.STRING, 'name', 'UTF8', None, ), # 1
+ (2, TType.BOOL, 'ifExists', None, None, ), # 2
)
all_structs.append(Database)
Database.thrift_spec = (
diff --git
a/standalone-metastore/metastore-common/src/gen/thrift/gen-rb/hive_metastore_types.rb
b/standalone-metastore/metastore-common/src/gen/thrift/gen-rb/hive_metastore_types.rb
index ceda695d201..b7337b406e6 100644
---
a/standalone-metastore/metastore-common/src/gen/thrift/gen-rb/hive_metastore_types.rb
+++
b/standalone-metastore/metastore-common/src/gen/thrift/gen-rb/hive_metastore_types.rb
@@ -1756,9 +1756,11 @@ end
class DropCatalogRequest
include ::Thrift::Struct, ::Thrift::Struct_Union
NAME = 1
+ IFEXISTS = 2
FIELDS = {
- NAME => {:type => ::Thrift::Types::STRING, :name => 'name'}
+ NAME => {:type => ::Thrift::Types::STRING, :name => 'name'},
+ IFEXISTS => {:type => ::Thrift::Types::BOOL, :name => 'ifExists',
:optional => true}
}
def struct_fields; FIELDS; end
diff --git
a/standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java
b/standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java
index 32beb5831d0..4663def7cba 100644
---
a/standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java
+++
b/standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java
@@ -1083,6 +1083,12 @@ public class HiveMetaStoreClient implements
IMetaStoreClient, AutoCloseable {
client.drop_catalog(new DropCatalogRequest(catName));
}
+ public void dropCatalog(String catName, boolean ifExists) throws TException {
+ DropCatalogRequest rqst = new DropCatalogRequest(catName);
+ rqst.setIfExists(ifExists);
+ client.drop_catalog(rqst);
+ }
+
/**
* @param new_part
* @return the added partition
diff --git
a/standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/IMetaStoreClient.java
b/standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/IMetaStoreClient.java
index 2dd0e1c823f..c44a3edebed 100644
---
a/standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/IMetaStoreClient.java
+++
b/standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/IMetaStoreClient.java
@@ -143,6 +143,15 @@ public interface IMetaStoreClient extends AutoCloseable {
void dropCatalog(String catName)
throws NoSuchObjectException, InvalidOperationException, MetaException,
TException;
+ /**
+ * Drop a catalog. Catalogs must be empty to be dropped, there is no
cascade for dropping a
+ * catalog.
+ * @param catName name of the catalog to drop
+ * @param ifExists if true, do not throw an error if the catalog does not
exist.
+ * @throws TException general thrift exception.
+ */
+ void dropCatalog(String catName, boolean ifExists) throws TException;
+
/**
* Get the names of all databases in the default catalog that match the
given pattern.
* @param databasePattern pattern for the database name to patch
diff --git
a/standalone-metastore/metastore-common/src/main/thrift/hive_metastore.thrift
b/standalone-metastore/metastore-common/src/main/thrift/hive_metastore.thrift
index f292b210fca..6ab340cea93 100644
---
a/standalone-metastore/metastore-common/src/main/thrift/hive_metastore.thrift
+++
b/standalone-metastore/metastore-common/src/main/thrift/hive_metastore.thrift
@@ -417,7 +417,8 @@ struct GetCatalogsResponse {
}
struct DropCatalogRequest {
- 1: string name
+ 1: string name,
+ 2: optional bool ifExists
}
// namespace for tables
diff --git
a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HMSHandler.java
b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HMSHandler.java
index a88fa55af6e..39d5832ed81 100644
---
a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HMSHandler.java
+++
b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HMSHandler.java
@@ -1057,6 +1057,7 @@ public class HMSHandler extends FacebookBase implements
IHMSHandler {
public void drop_catalog(DropCatalogRequest rqst)
throws NoSuchObjectException, InvalidOperationException, MetaException {
String catName = rqst.getName();
+ boolean ifExists = rqst.isIfExists();
startFunction("drop_catalog", ": " + catName);
if (DEFAULT_CATALOG_NAME.equalsIgnoreCase(catName)) {
endFunction("drop_catalog", false, null);
@@ -1066,7 +1067,7 @@ public class HMSHandler extends FacebookBase implements
IHMSHandler {
boolean success = false;
Exception ex = null;
try {
- dropCatalogCore(catName);
+ dropCatalogCore(catName, ifExists);
success = true;
} catch (Exception e) {
ex = e;
@@ -1079,7 +1080,7 @@ public class HMSHandler extends FacebookBase implements
IHMSHandler {
}
- private void dropCatalogCore(String catName)
+ private void dropCatalogCore(String catName, boolean ifExists)
throws MetaException, NoSuchObjectException, InvalidOperationException {
boolean success = false;
Catalog cat = null;
@@ -1119,7 +1120,7 @@ public class HMSHandler extends FacebookBase implements
IHMSHandler {
}
}
- ms.dropCatalog(catName) ;
+ ms.dropCatalog(catName);
if (!transactionalListeners.isEmpty()) {
transactionalListenerResponses =
MetaStoreListenerNotifier.notifyEvent(transactionalListeners,
@@ -1128,6 +1129,12 @@ public class HMSHandler extends FacebookBase implements
IHMSHandler {
}
success = ms.commitTransaction();
+ } catch (NoSuchObjectException e) {
+ if (!ifExists) {
+ throw new NoSuchObjectException(e.getMessage());
+ } else {
+ ms.rollbackTransaction();
+ }
} finally {
if (success) {
wh.deleteDir(wh.getDnsPath(new Path(cat.getLocationUri())), false,
false, false);
diff --git
a/standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClientPreCatalog.java
b/standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClientPreCatalog.java
index 87da8b0127a..5d9ac21e0be 100644
---
a/standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClientPreCatalog.java
+++
b/standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClientPreCatalog.java
@@ -3199,6 +3199,11 @@ public class HiveMetaStoreClientPreCatalog implements
IMetaStoreClient, AutoClos
throw new UnsupportedOperationException();
}
+ @Override
+ public void dropCatalog(String catName, boolean ifExists) throws TException {
+ throw new UnsupportedOperationException();
+ }
+
@Override
public List<String> getDatabases(String catName, String databasePattern)
throws TException {
throw new UnsupportedOperationException();
diff --git
a/standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/client/TestCatalogs.java
b/standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/client/TestCatalogs.java
index 1f8e46ae6d3..89ddede4a26 100644
---
a/standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/client/TestCatalogs.java
+++
b/standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/client/TestCatalogs.java
@@ -200,6 +200,13 @@ public class TestCatalogs extends MetaStoreClientTest {
client.dropCatalog("noSuchCatalog");
}
+ @Test
+ public void dropNonExistentCatalogIfExists() throws TException {
+ client.dropCatalog("noSuchCatalog", true);
+ Assert.assertTrue("dropCatalog completed without throwing an exception",
true);
+ }
+
+
@Test(expected = MetaException.class)
public void dropHiveCatalog() throws TException {
client.dropCatalog(Warehouse.DEFAULT_CATALOG_NAME);