hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ser...@apache.org
Subject [1/6] hive git commit: HIVE-20793 : add RP namespacing to workload management (Sergey Shelukhin, reviewed by Prasanth Jayachandran)
Date Tue, 30 Oct 2018 20:01:13 GMT
Repository: hive
Updated Branches:
  refs/heads/master b701720f5 -> 5258c67e9


http://git-wip-us.apache.org/repos/asf/hive/blob/5258c67e/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java
----------------------------------------------------------------------
diff --git a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java
index 0755483..03e3a2d 100644
--- a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java
+++ b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java
@@ -11593,13 +11593,15 @@ public class ObjectStore implements RawStore, Configurable {
     } else {
       rp = new MWMResourcePlan(rpName, null, Status.DISABLED);
     }
+    rp.setNs(resourcePlan.getNs());
     try {
       openTransaction();
       pm.makePersistent(rp);
       if (copyFromName != null) {
-        MWMResourcePlan copyFrom = getMWMResourcePlan(copyFromName, false);
+        String ns = getNsOrDefault(resourcePlan.getNs());
+        MWMResourcePlan copyFrom = getMWMResourcePlan(copyFromName, ns, false);
         if (copyFrom == null) {
-          throw new NoSuchObjectException(copyFromName);
+          throw new NoSuchObjectException(copyFromName + " in " + ns);
         }
         copyRpContents(rp, copyFrom);
       } else {
@@ -11627,6 +11629,7 @@ public class ObjectStore implements RawStore, Configurable {
 
   private void copyRpContents(MWMResourcePlan dest, MWMResourcePlan src) {
     dest.setQueryParallelism(src.getQueryParallelism());
+    dest.setNs(src.getNs());
     Map<String, MWMPool> pools = new HashMap<>();
     Map<String, Set<MWMPool>> triggersToPools = new HashMap<>();
     for (MWMPool copyPool : src.getPools()) {
@@ -11686,6 +11689,7 @@ public class ObjectStore implements RawStore, Configurable {
     }
     WMResourcePlan rp = new WMResourcePlan();
     rp.setName(mplan.getName());
+    rp.setNs(mplan.getNs());
     rp.setStatus(WMResourcePlanStatus.valueOf(mplan.getStatus().name()));
     if (mplan.getQueryParallelism() != null) {
       rp.setQueryParallelism(mplan.getQueryParallelism());
@@ -11724,6 +11728,7 @@ public class ObjectStore implements RawStore, Configurable {
     assert mPool.getQueryParallelism() != null;
     result.setQueryParallelism(mPool.getQueryParallelism());
     result.setSchedulingPolicy(mPool.getSchedulingPolicy());
+    result.setNs(mPool.getResourcePlan().getNs());
     return result;
   }
 
@@ -11736,15 +11741,24 @@ public class ObjectStore implements RawStore, Configurable {
     if (mMapping.getOrdering() != null) {
       result.setOrdering(mMapping.getOrdering());
     }
+    result.setNs(mMapping.getResourcePlan().getNs());
     return result;
   }
 
+  private final String getNsOrDefault(String ns) {
+    // This is only needed for old clients not setting NS in requests.
+    // Not clear how to handle this... this is properly a HS2 config but metastore needs its default
+    // value for backward compat, and we don't want it configurable separately because it's also
+    // used in upgrade scripts, were it cannot be configured.
+     return normalizeIdentifier(ns == null ? "default" : ns);
+  }
+
   @Override
-  public WMFullResourcePlan getResourcePlan(String name) throws NoSuchObjectException {
+  public WMFullResourcePlan getResourcePlan(String name, String ns) throws NoSuchObjectException {
     boolean commited = false;
     try {
       openTransaction();
-      WMFullResourcePlan fullRp = fullFromMResourcePlan(getMWMResourcePlan(name, false));
+      WMFullResourcePlan fullRp = fullFromMResourcePlan(getMWMResourcePlan(name, ns, false));
       commited = commitTransaction();
       return fullRp;
     } catch (InvalidOperationException e) {
@@ -11755,12 +11769,12 @@ public class ObjectStore implements RawStore, Configurable {
     }
   }
 
-  private MWMResourcePlan getMWMResourcePlan(String name, boolean editCheck)
+  private MWMResourcePlan getMWMResourcePlan(String name, String ns, boolean editCheck)
       throws NoSuchObjectException, InvalidOperationException {
-    return getMWMResourcePlan(name, editCheck, true);
+    return getMWMResourcePlan(name, ns, editCheck, true);
   }
 
-  private MWMResourcePlan getMWMResourcePlan(String name, boolean editCheck, boolean mustExist)
+  private MWMResourcePlan getMWMResourcePlan(String name, String ns, boolean editCheck, boolean mustExist)
       throws NoSuchObjectException, InvalidOperationException {
     MWMResourcePlan resourcePlan;
     boolean commited = false;
@@ -11768,18 +11782,16 @@ public class ObjectStore implements RawStore, Configurable {
 
     name = normalizeIdentifier(name);
     try {
-      openTransaction();
-      query = pm.newQuery(MWMResourcePlan.class, "name == rpname");
-      query.declareParameters("java.lang.String rpname");
-      query.setUnique(true);
-      resourcePlan = (MWMResourcePlan) query.execute(name);
+      query = createGetResourcePlanQuery();
+      ns = getNsOrDefault(ns);
+      resourcePlan = (MWMResourcePlan) query.execute(name, ns);
       pm.retrieve(resourcePlan);
       commited = commitTransaction();
     } finally {
       rollbackAndCleanup(commited, query);
     }
     if (mustExist && resourcePlan == null) {
-      throw new NoSuchObjectException("There is no resource plan named: " + name);
+      throw new NoSuchObjectException("There is no resource plan named: " + name + " in " + ns);
     }
     if (editCheck && resourcePlan != null
         && resourcePlan.getStatus() != MWMResourcePlan.Status.DISABLED) {
@@ -11788,15 +11800,24 @@ public class ObjectStore implements RawStore, Configurable {
     return resourcePlan;
   }
 
+  private Query createGetResourcePlanQuery() {
+    openTransaction();
+    Query query = pm.newQuery(MWMResourcePlan.class, "name == rpname && ns == nsname");
+    query.declareParameters("java.lang.String rpname, java.lang.String nsname");
+    query.setUnique(true);
+    return query;
+  }
+
   @Override
-  public List<WMResourcePlan> getAllResourcePlans() throws MetaException {
+  public List<WMResourcePlan> getAllResourcePlans(String ns) throws MetaException {
     List<WMResourcePlan> resourcePlans = new ArrayList();
     boolean commited = false;
     Query query = null;
     try {
       openTransaction();
-      query = pm.newQuery(MWMResourcePlan.class);
-      List<MWMResourcePlan> mplans = (List<MWMResourcePlan>) query.execute();
+      query = pm.newQuery(MWMResourcePlan.class, "ns == nsname");
+      query.declareParameters("java.lang.String nsname");
+      List<MWMResourcePlan> mplans = (List<MWMResourcePlan>) query.execute(getNsOrDefault(ns));
       pm.retrieveAll(mplans);
       commited = commitTransaction();
       if (mplans != null) {
@@ -11811,7 +11832,7 @@ public class ObjectStore implements RawStore, Configurable {
   }
 
   @Override
-  public WMFullResourcePlan alterResourcePlan(String name, WMNullableResourcePlan changes,
+  public WMFullResourcePlan alterResourcePlan(String name, String ns, WMNullableResourcePlan changes,
       boolean canActivateDisabled, boolean canDeactivate, boolean isReplace)
     throws AlreadyExistsException, NoSuchObjectException, InvalidOperationException, MetaException {
     name = name == null ? null : normalizeIdentifier(name);
@@ -11827,9 +11848,9 @@ public class ObjectStore implements RawStore, Configurable {
     try {
       openTransaction();
       if (isReplace) {
-        result = handleAlterReplace(name, changes);
+        result = handleAlterReplace(name, ns, changes);
       } else {
-        result = handleSimpleAlter(name, changes, canActivateDisabled, canDeactivate);
+        result = handleSimpleAlter(name, ns, changes, canActivateDisabled, canDeactivate);
       }
 
       commited = commitTransaction();
@@ -11842,11 +11863,16 @@ public class ObjectStore implements RawStore, Configurable {
     }
   }
 
-  private WMFullResourcePlan handleSimpleAlter(String name, WMNullableResourcePlan changes,
+  private WMFullResourcePlan handleSimpleAlter(String name, String ns, WMNullableResourcePlan changes,
       boolean canActivateDisabled, boolean canDeactivate)
           throws InvalidOperationException, NoSuchObjectException, MetaException {
-    MWMResourcePlan plan = name == null ? getActiveMWMResourcePlan()
-        : getMWMResourcePlan(name, !changes.isSetStatus());
+    MWMResourcePlan plan = name == null ? getActiveMWMResourcePlan(ns)
+        : getMWMResourcePlan(name, ns, !changes.isSetStatus());
+    boolean hasNsChange = changes.isSetNs() && !changes.getNs().equals(getNsOrDefault(plan.getNs()));
+    if (hasNsChange) {
+      throw new InvalidOperationException("Cannot change ns; from " + getNsOrDefault(plan.getNs())
+          + " to " + changes.getNs());
+    }
     boolean hasNameChange = changes.isSetName() && !changes.getName().equals(name);
     // Verify that field changes are consistent with what Hive does. Note: we could handle this.
     if (changes.isSetIsSetQueryParallelism()
@@ -11895,7 +11921,7 @@ public class ObjectStore implements RawStore, Configurable {
     return null;
   }
 
-  private WMFullResourcePlan handleAlterReplace(String name, WMNullableResourcePlan changes)
+  private WMFullResourcePlan handleAlterReplace(String name, String ns, WMNullableResourcePlan changes)
           throws InvalidOperationException, NoSuchObjectException, MetaException {
     // Verify that field changes are consistent with what Hive does. Note: we could handle this.
     if (changes.isSetQueryParallelism() || changes.isSetDefaultPoolPath()) {
@@ -11911,19 +11937,26 @@ public class ObjectStore implements RawStore, Configurable {
     if (name == null) {
       throw new InvalidOperationException("Invalid replace - no name specified");
     }
+    ns = getNsOrDefault(ns);
     MWMResourcePlan replacedPlan = isReplacingSpecific
-        ? getMWMResourcePlan(changes.getName(), false) : getActiveMWMResourcePlan();
-    MWMResourcePlan plan = getMWMResourcePlan(name, false);
+        ? getMWMResourcePlan(changes.getName(), ns, false) : getActiveMWMResourcePlan(ns);
+    MWMResourcePlan plan = getMWMResourcePlan(name, ns, false);
 
     if (replacedPlan.getName().equals(plan.getName())) {
       throw new InvalidOperationException("A plan cannot replace itself");
     }
+    String oldNs = getNsOrDefault(replacedPlan.getNs()), newNs = getNsOrDefault(plan.getNs());
+    if (!oldNs.equals(newNs)) {
+      throw new InvalidOperationException("Cannot change the namespace; replacing "
+          + oldNs + " with " + newNs);
+    }
+
     // We will inherit the name and status from the plan we are replacing.
     String newName = replacedPlan.getName();
     int i = 0;
     String copyName = generateOldPlanName(newName, i);
     while (true) {
-      MWMResourcePlan dup = getMWMResourcePlan(copyName, false, false);
+      MWMResourcePlan dup = getMWMResourcePlan(copyName, ns, false, false);
       if (dup == null) {
         break;
       }
@@ -11950,18 +11983,16 @@ public class ObjectStore implements RawStore, Configurable {
   }
 
   @Override
-  public WMFullResourcePlan getActiveResourcePlan() throws MetaException {
+  public WMFullResourcePlan getActiveResourcePlan(String ns) throws MetaException {
     // Note: fullFromMResroucePlan needs to be called inside the txn, otherwise we could have
     //       deduplicated this with getActiveMWMResourcePlan.
     boolean commited = false;
     Query query = null;
     WMFullResourcePlan result = null;
     try {
-      openTransaction();
-      query = pm.newQuery(MWMResourcePlan.class, "status == activeStatus");
-      query.declareParameters("java.lang.String activeStatus");
-      query.setUnique(true);
-      MWMResourcePlan mResourcePlan = (MWMResourcePlan) query.execute(Status.ACTIVE.toString());
+      query = createActivePlanQuery();
+      MWMResourcePlan mResourcePlan = (MWMResourcePlan) query.execute(
+          Status.ACTIVE.toString(), getNsOrDefault(ns));
       if (mResourcePlan != null) {
         result = fullFromMResourcePlan(mResourcePlan);
       }
@@ -11972,16 +12003,14 @@ public class ObjectStore implements RawStore, Configurable {
     return result;
   }
 
-  private MWMResourcePlan getActiveMWMResourcePlan() throws MetaException {
+  private MWMResourcePlan getActiveMWMResourcePlan(String ns) throws MetaException {
     boolean commited = false;
     Query query = null;
     MWMResourcePlan result = null;
     try {
-      openTransaction();
-      query = pm.newQuery(MWMResourcePlan.class, "status == activeStatus");
-      query.declareParameters("java.lang.String activeStatus");
-      query.setUnique(true);
-      result = (MWMResourcePlan) query.execute(Status.ACTIVE.toString());
+      query = createActivePlanQuery();
+      result = (MWMResourcePlan) query.execute(
+          Status.ACTIVE.toString(), getNsOrDefault(ns));
       pm.retrieve(result);
       commited = commitTransaction();
     } finally {
@@ -11990,6 +12019,14 @@ public class ObjectStore implements RawStore, Configurable {
     return result;
   }
 
+  private Query createActivePlanQuery() {
+    openTransaction();
+    Query query = pm.newQuery(MWMResourcePlan.class, "status == activeStatus && ns == nsname");
+    query.declareParameters("java.lang.String activeStatus, java.lang.String nsname");
+    query.setUnique(true);
+    return query;
+  }
+
   private WMFullResourcePlan switchStatus(String name, MWMResourcePlan mResourcePlan, String status,
       boolean canActivateDisabled, boolean canDeactivate) throws InvalidOperationException {
     Status currentStatus = mResourcePlan.getStatus();
@@ -12018,7 +12055,7 @@ public class ObjectStore implements RawStore, Configurable {
         doValidate = true;
         doActivate = (newStatus == Status.ACTIVE);
         if (doActivate && !canActivateDisabled) {
-          throw new InvalidOperationException("Resource plan " +name
+          throw new InvalidOperationException("Resource plan " + name
               + " is disabled and should be enabled before activation (or in the same command)");
         }
         break;
@@ -12043,7 +12080,7 @@ public class ObjectStore implements RawStore, Configurable {
     }
     if (doActivate) {
       // Deactivate currently active resource plan.
-      deactivateActiveResourcePlan();
+      deactivateActiveResourcePlan(mResourcePlan.getNs());
       mResourcePlan.setStatus(newStatus);
       return fullFromMResourcePlan(mResourcePlan);
     } else {
@@ -12052,14 +12089,13 @@ public class ObjectStore implements RawStore, Configurable {
     return null;
   }
 
-  private void deactivateActiveResourcePlan() {
+  private void deactivateActiveResourcePlan(String ns) {
     boolean commited = false;
     Query query = null;
     try {
-      openTransaction();
-      query = pm.newQuery(MWMResourcePlan.class, "status == \"ACTIVE\"");
-      query.setUnique(true);
-      MWMResourcePlan mResourcePlan = (MWMResourcePlan) query.execute();
+      query = createActivePlanQuery();
+      MWMResourcePlan mResourcePlan = (MWMResourcePlan) query.execute(
+          Status.ACTIVE.toString(), getNsOrDefault(ns));
       // We may not have an active resource plan in the start.
       if (mResourcePlan != null) {
         mResourcePlan.setStatus(Status.ENABLED);
@@ -12130,7 +12166,8 @@ public class ObjectStore implements RawStore, Configurable {
         poolData.found = true;
         if (!poolData.hasChildren) {
           response.addToErrors("Root has no children");
-        } else if (Math.abs(1.0 - poolData.totalChildrenAllocFraction) > 0.001) {
+          // TODO: change fractions to use decimal? somewhat brittle
+        } else if (Math.abs(1.0 - poolData.totalChildrenAllocFraction) > 0.00001) {
           response.addToErrors("Sum of root children pools' alloc fraction should be 1.0 got: " +
               poolData.totalChildrenAllocFraction + " for pool: " + entry.getKey());
         }
@@ -12139,7 +12176,8 @@ public class ObjectStore implements RawStore, Configurable {
         response.addToErrors("Pool does not exists but has children: " + entry.getKey());
       }
       if (poolData.hasChildren) {
-        if (!isRoot && 1.0 <= poolData.totalChildrenAllocFraction) {
+
+        if (!isRoot && (poolData.totalChildrenAllocFraction - 1.0) > 0.00001) {
           response.addToErrors("Sum of children pools' alloc fraction should be less than 1 got: "
               + poolData.totalChildrenAllocFraction + " for pool: " + entry.getKey());
         }
@@ -12151,39 +12189,36 @@ public class ObjectStore implements RawStore, Configurable {
   }
 
   @Override
-  public WMValidateResourcePlanResponse validateResourcePlan(String name)
+  public WMValidateResourcePlanResponse validateResourcePlan(String name, String ns)
       throws NoSuchObjectException, InvalidObjectException, MetaException {
     name = normalizeIdentifier(name);
+    boolean committed = false;
     Query query = null;
     try {
-      query = pm.newQuery(MWMResourcePlan.class, "name == rpName");
-      query.declareParameters("java.lang.String rpName");
-      query.setUnique(true);
-      MWMResourcePlan mResourcePlan = (MWMResourcePlan) query.execute(name);
+      query = createGetResourcePlanQuery();
+      MWMResourcePlan mResourcePlan = (MWMResourcePlan) query.execute(name, ns);
       if (mResourcePlan == null) {
-        throw new NoSuchObjectException("Cannot find resourcePlan: " + name);
+        throw new NoSuchObjectException("Cannot find resourcePlan: " + name + " in " + ns);
       }
-      // Validate resource plan.
-      return getResourcePlanErrors(mResourcePlan);
+      WMValidateResourcePlanResponse result = getResourcePlanErrors(mResourcePlan);
+      committed = commitTransaction();
+      return result;
     } finally {
-      rollbackAndCleanup(true, query);
+      rollbackAndCleanup(committed, query);
     }
   }
 
   @Override
-  public void dropResourcePlan(String name) throws NoSuchObjectException, MetaException {
+  public void dropResourcePlan(String name, String ns) throws NoSuchObjectException, MetaException {
     name = normalizeIdentifier(name);
     boolean commited = false;
     Query query = null;
     try {
-      openTransaction();
-      query = pm.newQuery(MWMResourcePlan.class, "name == rpname");
-      query.declareParameters("java.lang.String rpname");
-      query.setUnique(true);
-      MWMResourcePlan resourcePlan = (MWMResourcePlan) query.execute(name);
-      pm.retrieve(resourcePlan);
+      query = createGetResourcePlanQuery();
+      MWMResourcePlan resourcePlan = (MWMResourcePlan) query.execute(name, getNsOrDefault(ns));
+      pm.retrieve(resourcePlan); // TODO: why do some codepaths call retrieve and some don't?
       if (resourcePlan == null) {
-        throw new NoSuchObjectException("There is no resource plan named: " + name);
+        throw new NoSuchObjectException("There is no resource plan named: " + name + " in " + ns);
       }
       if (resourcePlan.getStatus() == Status.ACTIVE) {
         throw new MetaException("Cannot drop an active resource plan");
@@ -12207,7 +12242,8 @@ public class ObjectStore implements RawStore, Configurable {
     boolean commited = false;
     try {
       openTransaction();
-      MWMResourcePlan resourcePlan = getMWMResourcePlan(trigger.getResourcePlanName(), true);
+      MWMResourcePlan resourcePlan = getMWMResourcePlan(
+          trigger.getResourcePlanName(), trigger.getNs(), true);
       MWMTrigger mTrigger = new MWMTrigger(resourcePlan,
           normalizeIdentifier(trigger.getTriggerName()), trigger.getTriggerExpression(),
           trigger.getActionExpression(), null,
@@ -12229,7 +12265,8 @@ public class ObjectStore implements RawStore, Configurable {
     Query query = null;
     try {
       openTransaction();
-      MWMResourcePlan resourcePlan = getMWMResourcePlan(trigger.getResourcePlanName(), true);
+      MWMResourcePlan resourcePlan = getMWMResourcePlan(
+          trigger.getResourcePlanName(), trigger.getNs(), true);
       MWMTrigger mTrigger = getTrigger(resourcePlan, trigger.getTriggerName());
       // Update the object.
       if (trigger.isSetTriggerExpression()) {
@@ -12271,7 +12308,7 @@ public class ObjectStore implements RawStore, Configurable {
   }
 
   @Override
-  public void dropWMTrigger(String resourcePlanName, String triggerName)
+  public void dropWMTrigger(String resourcePlanName, String triggerName, String ns)
       throws NoSuchObjectException, InvalidOperationException, MetaException  {
     resourcePlanName = normalizeIdentifier(resourcePlanName);
     triggerName = normalizeIdentifier(triggerName);
@@ -12280,7 +12317,7 @@ public class ObjectStore implements RawStore, Configurable {
     Query query = null;
     try {
       openTransaction();
-      MWMResourcePlan resourcePlan = getMWMResourcePlan(resourcePlanName, true);
+      MWMResourcePlan resourcePlan = getMWMResourcePlan(resourcePlanName, ns, true);
       query = pm.newQuery(MWMTrigger.class, "resourcePlan == rp && name == triggerName");
       query.declareParameters("MWMResourcePlan rp, java.lang.String triggerName");
       if (query.deletePersistentAll(resourcePlan, triggerName) != 1) {
@@ -12293,7 +12330,7 @@ public class ObjectStore implements RawStore, Configurable {
   }
 
   @Override
-  public List<WMTrigger> getTriggersForResourcePlan(String resourcePlanName)
+  public List<WMTrigger> getTriggersForResourcePlan(String resourcePlanName, String ns)
       throws NoSuchObjectException, MetaException {
     List<WMTrigger> triggers = new ArrayList();
     boolean commited = false;
@@ -12302,7 +12339,7 @@ public class ObjectStore implements RawStore, Configurable {
       openTransaction();
       MWMResourcePlan resourcePlan;
       try {
-        resourcePlan = getMWMResourcePlan(resourcePlanName, false);
+        resourcePlan = getMWMResourcePlan(resourcePlanName, ns, false);
       } catch (InvalidOperationException e) {
         // Should not happen, edit check is false.
         throw new RuntimeException(e);
@@ -12330,6 +12367,7 @@ public class ObjectStore implements RawStore, Configurable {
     trigger.setTriggerExpression(mTrigger.getTriggerExpression());
     trigger.setActionExpression(mTrigger.getActionExpression());
     trigger.setIsInUnmanaged(mTrigger.getIsInUnmanaged());
+    trigger.setNs(mTrigger.getResourcePlan().getNs());
     return trigger;
   }
 
@@ -12339,7 +12377,8 @@ public class ObjectStore implements RawStore, Configurable {
     boolean commited = false;
     try {
       openTransaction();
-      MWMResourcePlan resourcePlan = getMWMResourcePlan(pool.getResourcePlanName(), true);
+      MWMResourcePlan resourcePlan = getMWMResourcePlan(
+          pool.getResourcePlanName(), pool.getNs(), true);
 
       if (!poolParentExists(resourcePlan, pool.getPoolPath())) {
         throw new NoSuchObjectException("Pool path is invalid, the parent does not exist");
@@ -12366,7 +12405,8 @@ public class ObjectStore implements RawStore, Configurable {
     boolean commited = false;
     try {
       openTransaction();
-      MWMResourcePlan resourcePlan = getMWMResourcePlan(pool.getResourcePlanName(), true);
+      MWMResourcePlan resourcePlan = getMWMResourcePlan(
+          pool.getResourcePlanName(), pool.getNs(), true);
       MWMPool mPool = getPool(resourcePlan, poolPath);
       pm.retrieve(mPool);
       if (pool.isSetAllocFraction()) {
@@ -12463,20 +12503,20 @@ public class ObjectStore implements RawStore, Configurable {
   }
 
   @Override
-  public void dropWMPool(String resourcePlanName, String poolPath)
+  public void dropWMPool(String resourcePlanName, String poolPath, String ns)
       throws NoSuchObjectException, InvalidOperationException, MetaException {
     poolPath = normalizeIdentifier(poolPath);
     boolean commited = false;
     Query query = null;
     try {
       openTransaction();
-      MWMResourcePlan resourcePlan = getMWMResourcePlan(resourcePlanName, true);
+      MWMResourcePlan resourcePlan = getMWMResourcePlan(resourcePlanName, ns, true);
       if (resourcePlan.getDefaultPool() != null &&
           resourcePlan.getDefaultPool().getPath().equals(poolPath)) {
         throw new InvalidOperationException("Cannot drop default pool of a resource plan");
       }
       if (poolHasChildren(resourcePlan, poolPath)) {
-        throw new InvalidOperationException("Pool has children cannot drop.");
+        throw new InvalidOperationException("Cannot drop a pool that has child pools");
       }
       query = pm.newQuery(MWMPool.class, "resourcePlan == rp && path.startsWith(poolPath)");
       query.declareParameters("MWMResourcePlan rp, java.lang.String poolPath");
@@ -12521,7 +12561,8 @@ public class ObjectStore implements RawStore, Configurable {
     Query query = null;
     try {
       openTransaction();
-      MWMResourcePlan resourcePlan = getMWMResourcePlan(mapping.getResourcePlanName(), true);
+      MWMResourcePlan resourcePlan = getMWMResourcePlan(
+          mapping.getResourcePlanName(), mapping.getNs(), true);
       MWMPool pool = null;
       if (mapping.isSetPoolPath()) {
         pool = getPool(resourcePlan, mapping.getPoolPath());
@@ -12555,7 +12596,8 @@ public class ObjectStore implements RawStore, Configurable {
     Query query = null;
     try {
       openTransaction();
-      MWMResourcePlan resourcePlan = getMWMResourcePlan(mapping.getResourcePlanName(), true);
+      MWMResourcePlan resourcePlan = getMWMResourcePlan(
+          mapping.getResourcePlanName(), mapping.getNs(), true);
       query = pm.newQuery(MWMMapping.class,
           "resourcePlan == rp && entityType == type && entityName == name");
       query.declareParameters("MWMResourcePlan rp, java.lang.String type, java.lang.String name");
@@ -12570,12 +12612,12 @@ public class ObjectStore implements RawStore, Configurable {
 
   @Override
   public void createWMTriggerToPoolMapping(String resourcePlanName, String triggerName,
-      String poolPath) throws AlreadyExistsException, NoSuchObjectException,
+      String poolPath, String ns) throws AlreadyExistsException, NoSuchObjectException,
       InvalidOperationException, MetaException {
     boolean commited = false;
     try {
       openTransaction();
-      MWMResourcePlan resourcePlan = getMWMResourcePlan(resourcePlanName, true);
+      MWMResourcePlan resourcePlan = getMWMResourcePlan(resourcePlanName, ns, true);
       MWMPool pool = getPool(resourcePlan, poolPath);
       MWMTrigger trigger = getTrigger(resourcePlan, triggerName);
       pool.getTriggers().add(trigger);
@@ -12590,11 +12632,11 @@ public class ObjectStore implements RawStore, Configurable {
 
   @Override
   public void dropWMTriggerToPoolMapping(String resourcePlanName, String triggerName,
-      String poolPath) throws NoSuchObjectException, InvalidOperationException, MetaException {
+      String poolPath, String ns) throws NoSuchObjectException, InvalidOperationException, MetaException {
     boolean commited = false;
     try {
       openTransaction();
-      MWMResourcePlan resourcePlan = getMWMResourcePlan(resourcePlanName, true);
+      MWMResourcePlan resourcePlan = getMWMResourcePlan(resourcePlanName, ns, true);
       MWMPool pool = getPool(resourcePlan, poolPath);
       MWMTrigger trigger = getTrigger(resourcePlan, triggerName);
       pool.getTriggers().remove(trigger);

http://git-wip-us.apache.org/repos/asf/hive/blob/5258c67e/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/RawStore.java
----------------------------------------------------------------------
diff --git a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/RawStore.java b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/RawStore.java
index c3914b6..209e92a 100644
--- a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/RawStore.java
+++ b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/RawStore.java
@@ -20,12 +20,6 @@ package org.apache.hadoop.hive.metastore;
 
 import org.apache.hadoop.hive.common.TableName;
 import org.apache.hadoop.hive.metastore.api.*;
-import org.apache.hadoop.hive.metastore.api.CreationMetadata;
-import org.apache.hadoop.hive.metastore.api.ISchemaName;
-import org.apache.hadoop.hive.metastore.api.Partition;
-import org.apache.hadoop.hive.metastore.api.SchemaVersionDescriptor;
-import org.apache.hadoop.hive.metastore.api.WMFullResourcePlan;
-import org.apache.hadoop.hive.metastore.api.WriteEventInfo;
 
 import java.lang.annotation.ElementType;
 import java.lang.annotation.Retention;
@@ -1546,21 +1540,21 @@ public interface RawStore extends Configurable {
   void createResourcePlan(WMResourcePlan resourcePlan, String copyFrom, int defaultPoolSize)
       throws AlreadyExistsException, MetaException, InvalidObjectException, NoSuchObjectException;
 
-  WMFullResourcePlan getResourcePlan(String name) throws NoSuchObjectException, MetaException;
+  WMFullResourcePlan getResourcePlan(String name, String string) throws NoSuchObjectException, MetaException;
 
-  List<WMResourcePlan> getAllResourcePlans() throws MetaException;
+  List<WMResourcePlan> getAllResourcePlans(String string) throws MetaException;
 
-  WMFullResourcePlan alterResourcePlan(String name, WMNullableResourcePlan resourcePlan,
+  WMFullResourcePlan alterResourcePlan(String name, String ns, WMNullableResourcePlan resourcePlan,
       boolean canActivateDisabled, boolean canDeactivate, boolean isReplace)
       throws AlreadyExistsException, NoSuchObjectException, InvalidOperationException,
           MetaException;
 
-  WMFullResourcePlan getActiveResourcePlan() throws MetaException;
+  WMFullResourcePlan getActiveResourcePlan(String ns) throws MetaException;
 
-  WMValidateResourcePlanResponse validateResourcePlan(String name)
+  WMValidateResourcePlanResponse validateResourcePlan(String name, String ns)
       throws NoSuchObjectException, InvalidObjectException, MetaException;
 
-  void dropResourcePlan(String name) throws NoSuchObjectException, MetaException;
+  void dropResourcePlan(String name, String ns) throws NoSuchObjectException, MetaException;
 
   void createWMTrigger(WMTrigger trigger)
       throws AlreadyExistsException, NoSuchObjectException, InvalidOperationException,
@@ -1569,10 +1563,10 @@ public interface RawStore extends Configurable {
   void alterWMTrigger(WMTrigger trigger)
       throws NoSuchObjectException, InvalidOperationException, MetaException;
 
-  void dropWMTrigger(String resourcePlanName, String triggerName)
+  void dropWMTrigger(String resourcePlanName, String triggerName, String ns)
       throws NoSuchObjectException, InvalidOperationException, MetaException;
 
-  List<WMTrigger> getTriggersForResourcePlan(String resourcePlanName)
+  List<WMTrigger> getTriggersForResourcePlan(String resourcePlanName, String ns)
       throws NoSuchObjectException, MetaException;
 
   void createPool(WMPool pool) throws AlreadyExistsException, NoSuchObjectException,
@@ -1581,7 +1575,7 @@ public interface RawStore extends Configurable {
   void alterPool(WMNullablePool pool, String poolPath) throws AlreadyExistsException,
       NoSuchObjectException, InvalidOperationException, MetaException;
 
-  void dropWMPool(String resourcePlanName, String poolPath)
+  void dropWMPool(String resourcePlanName, String poolPath, String ns)
       throws NoSuchObjectException, InvalidOperationException, MetaException;
 
   void createOrUpdateWMMapping(WMMapping mapping, boolean update)
@@ -1591,11 +1585,11 @@ public interface RawStore extends Configurable {
   void dropWMMapping(WMMapping mapping)
       throws NoSuchObjectException, InvalidOperationException, MetaException;
 
-  void createWMTriggerToPoolMapping(String resourcePlanName, String triggerName, String poolPath)
+  void createWMTriggerToPoolMapping(String resourcePlanName, String triggerName, String poolPath, String ns)
       throws AlreadyExistsException, NoSuchObjectException, InvalidOperationException,
           MetaException;
 
-  void dropWMTriggerToPoolMapping(String resourcePlanName, String triggerName, String poolPath)
+  void dropWMTriggerToPoolMapping(String resourcePlanName, String triggerName, String poolPath, String ns)
       throws NoSuchObjectException, InvalidOperationException, MetaException;
 
   /**

http://git-wip-us.apache.org/repos/asf/hive/blob/5258c67e/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/cache/CachedStore.java
----------------------------------------------------------------------
diff --git a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/cache/CachedStore.java b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/cache/CachedStore.java
index 47ac68c..e4ef46f 100644
--- a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/cache/CachedStore.java
+++ b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/cache/CachedStore.java
@@ -1644,7 +1644,7 @@ public class CachedStore implements RawStore, Configurable {
     }
     return partitions;
   }
-  
+
   private String getPartNameMatcher(Table table, List<String> partSpecs) throws MetaException {
     List<FieldSchema> partCols = table.getPartitionKeys();
     int numPartKeys = partCols.size();
@@ -2407,39 +2407,39 @@ public class CachedStore implements RawStore, Configurable {
   }
 
   @Override
-  public WMFullResourcePlan getResourcePlan(String name)
+  public WMFullResourcePlan getResourcePlan(String name, String ns)
       throws NoSuchObjectException, MetaException {
-    return rawStore.getResourcePlan(name);
+    return rawStore.getResourcePlan(name, ns);
   }
 
   @Override
-  public List<WMResourcePlan> getAllResourcePlans() throws MetaException {
-    return rawStore.getAllResourcePlans();
+  public List<WMResourcePlan> getAllResourcePlans(String ns) throws MetaException {
+    return rawStore.getAllResourcePlans(ns);
   }
 
   @Override
-  public WMFullResourcePlan alterResourcePlan(String name, WMNullableResourcePlan resourcePlan,
+  public WMFullResourcePlan alterResourcePlan(String name, String ns, WMNullableResourcePlan resourcePlan,
     boolean canActivateDisabled, boolean canDeactivate, boolean isReplace)
       throws AlreadyExistsException, NoSuchObjectException, InvalidOperationException,
           MetaException {
     return rawStore.alterResourcePlan(
-      name, resourcePlan, canActivateDisabled, canDeactivate, isReplace);
+      name, ns, resourcePlan, canActivateDisabled, canDeactivate, isReplace);
   }
 
   @Override
-  public WMFullResourcePlan getActiveResourcePlan() throws MetaException {
-    return rawStore.getActiveResourcePlan();
+  public WMFullResourcePlan getActiveResourcePlan(String ns) throws MetaException {
+    return rawStore.getActiveResourcePlan(ns);
   }
 
   @Override
-  public WMValidateResourcePlanResponse validateResourcePlan(String name)
+  public WMValidateResourcePlanResponse validateResourcePlan(String name, String ns)
       throws NoSuchObjectException, InvalidObjectException, MetaException {
-    return rawStore.validateResourcePlan(name);
+    return rawStore.validateResourcePlan(name, ns);
   }
 
   @Override
-  public void dropResourcePlan(String name) throws NoSuchObjectException, MetaException {
-    rawStore.dropResourcePlan(name);
+  public void dropResourcePlan(String name, String ns) throws NoSuchObjectException, MetaException {
+    rawStore.dropResourcePlan(name, ns);
   }
 
   @Override
@@ -2456,15 +2456,15 @@ public class CachedStore implements RawStore, Configurable {
   }
 
   @Override
-  public void dropWMTrigger(String resourcePlanName, String triggerName)
+  public void dropWMTrigger(String resourcePlanName, String triggerName, String ns)
       throws NoSuchObjectException, InvalidOperationException, MetaException {
-    rawStore.dropWMTrigger(resourcePlanName, triggerName);
+    rawStore.dropWMTrigger(resourcePlanName, triggerName, ns);
   }
 
   @Override
-  public List<WMTrigger> getTriggersForResourcePlan(String resourcePlanName)
+  public List<WMTrigger> getTriggersForResourcePlan(String resourcePlanName, String ns)
       throws NoSuchObjectException, MetaException {
-    return rawStore.getTriggersForResourcePlan(resourcePlanName);
+    return rawStore.getTriggersForResourcePlan(resourcePlanName, ns);
   }
 
   @Override
@@ -2480,9 +2480,9 @@ public class CachedStore implements RawStore, Configurable {
   }
 
   @Override
-  public void dropWMPool(String resourcePlanName, String poolPath)
+  public void dropWMPool(String resourcePlanName, String poolPath, String ns)
       throws NoSuchObjectException, InvalidOperationException, MetaException {
-    rawStore.dropWMPool(resourcePlanName, poolPath);
+    rawStore.dropWMPool(resourcePlanName, poolPath, ns);
   }
 
   @Override
@@ -2500,15 +2500,15 @@ public class CachedStore implements RawStore, Configurable {
 
   @Override
   public void createWMTriggerToPoolMapping(String resourcePlanName, String triggerName,
-      String poolPath) throws AlreadyExistsException, NoSuchObjectException,
+      String poolPath, String ns) throws AlreadyExistsException, NoSuchObjectException,
       InvalidOperationException, MetaException {
-    rawStore.createWMTriggerToPoolMapping(resourcePlanName, triggerName, poolPath);
+    rawStore.createWMTriggerToPoolMapping(resourcePlanName, triggerName, poolPath, ns);
   }
 
   @Override
   public void dropWMTriggerToPoolMapping(String resourcePlanName, String triggerName,
-      String poolPath) throws NoSuchObjectException, InvalidOperationException, MetaException {
-    rawStore.dropWMTriggerToPoolMapping(resourcePlanName, triggerName, poolPath);
+      String poolPath, String ns) throws NoSuchObjectException, InvalidOperationException, MetaException {
+    rawStore.dropWMTriggerToPoolMapping(resourcePlanName, triggerName, poolPath, ns);
   }
 
   public long getCacheUpdateCount() {

http://git-wip-us.apache.org/repos/asf/hive/blob/5258c67e/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/model/MWMResourcePlan.java
----------------------------------------------------------------------
diff --git a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/model/MWMResourcePlan.java b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/model/MWMResourcePlan.java
index ac51f2d..648587e 100644
--- a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/model/MWMResourcePlan.java
+++ b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/model/MWMResourcePlan.java
@@ -25,6 +25,7 @@ import java.util.Set;
  */
 public class MWMResourcePlan {
   private String name;
+  private String ns;
   private Integer queryParallelism;
   private Status status;
   private Set<MWMPool> pools;
@@ -51,6 +52,14 @@ public class MWMResourcePlan {
     return name;
   }
 
+  public void setNs(String name) {
+    this.ns = name;
+  }
+
+  public String getNs() {
+    return ns;
+  }
+
   public void setName(String name) {
     this.name = name;
   }

http://git-wip-us.apache.org/repos/asf/hive/blob/5258c67e/standalone-metastore/metastore-server/src/main/resources/package.jdo
----------------------------------------------------------------------
diff --git a/standalone-metastore/metastore-server/src/main/resources/package.jdo b/standalone-metastore/metastore-server/src/main/resources/package.jdo
index fef6a42..01306e6 100644
--- a/standalone-metastore/metastore-server/src/main/resources/package.jdo
+++ b/standalone-metastore/metastore-server/src/main/resources/package.jdo
@@ -1230,6 +1230,9 @@
       <field name="name">
         <column name="NAME" length="128" jdbc-type="VARCHAR" allows-null="false"/>
       </field>
+      <field name="ns">
+        <column name="NS" length="128" jdbc-type="VARCHAR" allows-null="true"/>
+      </field>
       <field name="queryParallelism">
         <column name="QUERY_PARALLELISM" jdbc-type="integer" allows-null="true"/>
       </field>
@@ -1241,6 +1244,7 @@
       </field>
       <index name="UniqueResourcePlan" unique="true">
         <column name="NAME"/>
+        <column name="NS"/>
       </index>
 
       <field name="pools" mapped-by="resourcePlan">

http://git-wip-us.apache.org/repos/asf/hive/blob/5258c67e/standalone-metastore/metastore-server/src/main/sql/derby/hive-schema-4.0.0.derby.sql
----------------------------------------------------------------------
diff --git a/standalone-metastore/metastore-server/src/main/sql/derby/hive-schema-4.0.0.derby.sql b/standalone-metastore/metastore-server/src/main/sql/derby/hive-schema-4.0.0.derby.sql
index c889bbd..a3c4196 100644
--- a/standalone-metastore/metastore-server/src/main/sql/derby/hive-schema-4.0.0.derby.sql
+++ b/standalone-metastore/metastore-server/src/main/sql/derby/hive-schema-4.0.0.derby.sql
@@ -182,7 +182,7 @@ CREATE TABLE "APP"."KEY_CONSTRAINTS" ("CHILD_CD_ID" BIGINT, "CHILD_INTEGER_IDX"
 
 CREATE TABLE "APP"."METASTORE_DB_PROPERTIES" ("PROPERTY_KEY" VARCHAR(255) NOT NULL, "PROPERTY_VALUE" VARCHAR(1000) NOT NULL, "DESCRIPTION" VARCHAR(1000));
 
-CREATE TABLE "APP"."WM_RESOURCEPLAN" (RP_ID BIGINT NOT NULL, NAME VARCHAR(128) NOT NULL, QUERY_PARALLELISM INTEGER, STATUS VARCHAR(20) NOT NULL, DEFAULT_POOL_ID BIGINT);
+CREATE TABLE "APP"."WM_RESOURCEPLAN" (RP_ID BIGINT NOT NULL, NS VARCHAR(128), NAME VARCHAR(128) NOT NULL, QUERY_PARALLELISM INTEGER, STATUS VARCHAR(20) NOT NULL, DEFAULT_POOL_ID BIGINT);
 
 CREATE TABLE "APP"."WM_POOL" (POOL_ID BIGINT NOT NULL, RP_ID BIGINT NOT NULL, PATH VARCHAR(1024) NOT NULL, ALLOC_FRACTION DOUBLE, QUERY_PARALLELISM INTEGER, SCHEDULING_POLICY VARCHAR(1024));
 
@@ -264,7 +264,7 @@ CREATE INDEX "APP"."CONSTRAINTS_PARENT_TBL_ID_INDEX" ON "APP"."KEY_CONSTRAINTS"(
 
 CREATE INDEX "APP"."CONSTRAINTS_CONSTRAINT_TYPE_INDEX" ON "APP"."KEY_CONSTRAINTS"("CONSTRAINT_TYPE");
 
-CREATE UNIQUE INDEX "APP"."UNIQUE_WM_RESOURCEPLAN" ON "APP"."WM_RESOURCEPLAN" ("NAME");
+CREATE UNIQUE INDEX "APP"."UNIQUE_WM_RESOURCEPLAN" ON "APP"."WM_RESOURCEPLAN" ("NS", "NAME");
 
 CREATE UNIQUE INDEX "APP"."UNIQUE_WM_POOL" ON "APP"."WM_POOL" ("RP_ID", "PATH");
 

http://git-wip-us.apache.org/repos/asf/hive/blob/5258c67e/standalone-metastore/metastore-server/src/main/sql/derby/upgrade-3.2.0-to-4.0.0.derby.sql
----------------------------------------------------------------------
diff --git a/standalone-metastore/metastore-server/src/main/sql/derby/upgrade-3.2.0-to-4.0.0.derby.sql b/standalone-metastore/metastore-server/src/main/sql/derby/upgrade-3.2.0-to-4.0.0.derby.sql
index aca5227..bcaebd1 100644
--- a/standalone-metastore/metastore-server/src/main/sql/derby/upgrade-3.2.0-to-4.0.0.derby.sql
+++ b/standalone-metastore/metastore-server/src/main/sql/derby/upgrade-3.2.0-to-4.0.0.derby.sql
@@ -3,6 +3,13 @@
 ALTER TABLE "APP"."TBLS" ADD WRITE_ID bigint DEFAULT 0;
 ALTER TABLE "APP"."PARTITIONS" ADD WRITE_ID bigint DEFAULT 0;
 
+-- HIVE-20793
+ALTER TABLE "APP"."WM_RESOURCEPLAN" ADD NS VARCHAR(128);
+UPDATE "APP"."WM_RESOURCEPLAN" SET NS = 'default' WHERE NS IS NULL;
+DROP INDEX "APP"."UNIQUE_WM_RESOURCEPLAN";
+CREATE UNIQUE INDEX "APP"."UNIQUE_WM_RESOURCEPLAN" ON "APP"."WM_RESOURCEPLAN" ("NS", "NAME");
+
+
 -- This needs to be the last thing done.  Insert any changes above this line.
 UPDATE "APP".VERSION SET SCHEMA_VERSION='4.0.0', VERSION_COMMENT='Hive release version 4.0.0' where VER_ID=1;
 

http://git-wip-us.apache.org/repos/asf/hive/blob/5258c67e/standalone-metastore/metastore-server/src/main/sql/mssql/hive-schema-4.0.0.mssql.sql
----------------------------------------------------------------------
diff --git a/standalone-metastore/metastore-server/src/main/sql/mssql/hive-schema-4.0.0.mssql.sql b/standalone-metastore/metastore-server/src/main/sql/mssql/hive-schema-4.0.0.mssql.sql
index 91ba134..5ea1b44 100644
--- a/standalone-metastore/metastore-server/src/main/sql/mssql/hive-schema-4.0.0.mssql.sql
+++ b/standalone-metastore/metastore-server/src/main/sql/mssql/hive-schema-4.0.0.mssql.sql
@@ -642,6 +642,7 @@ CREATE TABLE WM_RESOURCEPLAN
 (
     RP_ID bigint NOT NULL,
     "NAME" nvarchar(128) NOT NULL,
+    NS nvarchar(128),
     QUERY_PARALLELISM int,
     STATUS nvarchar(20) NOT NULL,
     DEFAULT_POOL_ID bigint
@@ -963,7 +964,7 @@ CREATE INDEX TABLE_PARAMS_N49 ON TABLE_PARAMS (TBL_ID);
 
 -- Constraints for resource plan tables.
 
-CREATE UNIQUE INDEX UNIQUE_WM_RESOURCEPLAN ON WM_RESOURCEPLAN ("NAME");
+CREATE UNIQUE INDEX UNIQUE_WM_RESOURCEPLAN ON WM_RESOURCEPLAN ("NS", "NAME");
 
 CREATE UNIQUE INDEX UNIQUE_WM_POOL ON WM_POOL (RP_ID, PATH);
 

http://git-wip-us.apache.org/repos/asf/hive/blob/5258c67e/standalone-metastore/metastore-server/src/main/sql/mssql/upgrade-3.2.0-to-4.0.0.mssql.sql
----------------------------------------------------------------------
diff --git a/standalone-metastore/metastore-server/src/main/sql/mssql/upgrade-3.2.0-to-4.0.0.mssql.sql b/standalone-metastore/metastore-server/src/main/sql/mssql/upgrade-3.2.0-to-4.0.0.mssql.sql
index f0d861b..edde08d 100644
--- a/standalone-metastore/metastore-server/src/main/sql/mssql/upgrade-3.2.0-to-4.0.0.mssql.sql
+++ b/standalone-metastore/metastore-server/src/main/sql/mssql/upgrade-3.2.0-to-4.0.0.mssql.sql
@@ -4,6 +4,12 @@ SELECT 'Upgrading MetaStore schema from 3.2.0 to 4.0.0' AS MESSAGE;
 ALTER TABLE TBLS ADD WRITE_ID bigint  NOT NULL DEFAULT 0;
 ALTER TABLE PARTITIONS ADD WRITE_ID bigint  NOT NULL DEFAULT 0;
 
+-- HIVE-20793
+ALTER TABLE WM_RESOURCEPLAN ADD NS nvarchar(128);
+UPDATE WM_RESOURCEPLAN SET NS = 'default' WHERE NS IS NULL;
+DROP INDEX UNIQUE_WM_RESOURCEPLAN ON WM_RESOURCEPLAN;
+CREATE UNIQUE INDEX UNIQUE_WM_RESOURCEPLAN ON WM_RESOURCEPLAN ("NS", "NAME");
+
 -- These lines need to be last.  Insert any changes above.
 UPDATE VERSION SET SCHEMA_VERSION='4.0.0', VERSION_COMMENT='Hive release version 4.0.0' where VER_ID=1;
 SELECT 'Finished upgrading MetaStore schema from 3.2.0 to 4.0.0' AS MESSAGE;

http://git-wip-us.apache.org/repos/asf/hive/blob/5258c67e/standalone-metastore/metastore-server/src/main/sql/mysql/hive-schema-4.0.0.mysql.sql
----------------------------------------------------------------------
diff --git a/standalone-metastore/metastore-server/src/main/sql/mysql/hive-schema-4.0.0.mysql.sql b/standalone-metastore/metastore-server/src/main/sql/mysql/hive-schema-4.0.0.mysql.sql
index 3af2ebb..5555a59 100644
--- a/standalone-metastore/metastore-server/src/main/sql/mysql/hive-schema-4.0.0.mysql.sql
+++ b/standalone-metastore/metastore-server/src/main/sql/mysql/hive-schema-4.0.0.mysql.sql
@@ -917,11 +917,12 @@ CREATE TABLE IF NOT EXISTS `METASTORE_DB_PROPERTIES` (
 CREATE TABLE IF NOT EXISTS WM_RESOURCEPLAN (
     `RP_ID` bigint(20) NOT NULL,
     `NAME` varchar(128) NOT NULL,
+    `NS` varchar(128),
     `QUERY_PARALLELISM` int(11),
     `STATUS` varchar(20) NOT NULL,
     `DEFAULT_POOL_ID` bigint(20),
     PRIMARY KEY (`RP_ID`),
-    UNIQUE KEY `UNIQUE_WM_RESOURCEPLAN` (`NAME`)
+    UNIQUE KEY `UNIQUE_WM_RESOURCEPLAN` (`NAME`, `NS`)
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
 
 CREATE TABLE IF NOT EXISTS WM_POOL

http://git-wip-us.apache.org/repos/asf/hive/blob/5258c67e/standalone-metastore/metastore-server/src/main/sql/mysql/upgrade-3.2.0-to-4.0.0.mysql.sql
----------------------------------------------------------------------
diff --git a/standalone-metastore/metastore-server/src/main/sql/mysql/upgrade-3.2.0-to-4.0.0.mysql.sql b/standalone-metastore/metastore-server/src/main/sql/mysql/upgrade-3.2.0-to-4.0.0.mysql.sql
index ee0f691..701acb0 100644
--- a/standalone-metastore/metastore-server/src/main/sql/mysql/upgrade-3.2.0-to-4.0.0.mysql.sql
+++ b/standalone-metastore/metastore-server/src/main/sql/mysql/upgrade-3.2.0-to-4.0.0.mysql.sql
@@ -4,6 +4,13 @@ SELECT 'Upgrading MetaStore schema from 3.2.0 to 4.0.0' AS ' ';
 ALTER TABLE TBLS ADD WRITE_ID bigint DEFAULT 0;
 ALTER TABLE PARTITIONS ADD WRITE_ID bigint DEFAULT 0;
 
+
+-- HIVE-20793
+ALTER TABLE `WM_RESOURCEPLAN` ADD `NS` varchar(128);
+UPDATE `WM_RESOURCEPLAN` SET `NS` = 'default' WHERE `NS` IS NULL;
+ALTER TABLE `WM_RESOURCEPLAN` DROP KEY `UNIQUE_WM_RESOURCEPLAN`;
+ALTER TABLE `WM_RESOURCEPLAN` ADD UNIQUE KEY `UNIQUE_WM_RESOURCEPLAN` (`NAME`, `NS`);
+
 -- These lines need to be last.  Insert any changes above.
 UPDATE VERSION SET SCHEMA_VERSION='4.0.0', VERSION_COMMENT='Hive release version 4.0.0' where VER_ID=1;
 SELECT 'Finished upgrading MetaStore schema from 3.2.0 to 4.0.0' AS ' ';

http://git-wip-us.apache.org/repos/asf/hive/blob/5258c67e/standalone-metastore/metastore-server/src/main/sql/oracle/hive-schema-4.0.0.oracle.sql
----------------------------------------------------------------------
diff --git a/standalone-metastore/metastore-server/src/main/sql/oracle/hive-schema-4.0.0.oracle.sql b/standalone-metastore/metastore-server/src/main/sql/oracle/hive-schema-4.0.0.oracle.sql
index 33aa080..b1980c5 100644
--- a/standalone-metastore/metastore-server/src/main/sql/oracle/hive-schema-4.0.0.oracle.sql
+++ b/standalone-metastore/metastore-server/src/main/sql/oracle/hive-schema-4.0.0.oracle.sql
@@ -638,6 +638,7 @@ CREATE TABLE WM_RESOURCEPLAN
 (
     RP_ID NUMBER NOT NULL,
     "NAME" VARCHAR2(128) NOT NULL,
+    NS VARCHAR2(128),
     QUERY_PARALLELISM NUMBER(10),
     STATUS VARCHAR2(20) NOT NULL,
     DEFAULT_POOL_ID NUMBER
@@ -927,7 +928,7 @@ ALTER TABLE METASTORE_DB_PROPERTIES ADD CONSTRAINT PROPERTY_KEY_PK PRIMARY KEY (
 
 -- Constraints for resource plan tables.
 
-CREATE UNIQUE INDEX UNIQUE_WM_RESOURCEPLAN ON WM_RESOURCEPLAN ("NAME");
+CREATE UNIQUE INDEX UNIQUE_WM_RESOURCEPLAN ON WM_RESOURCEPLAN (NS, "NAME");
 
 CREATE UNIQUE INDEX UNIQUE_WM_POOL ON WM_POOL (RP_ID, PATH);
 

http://git-wip-us.apache.org/repos/asf/hive/blob/5258c67e/standalone-metastore/metastore-server/src/main/sql/oracle/upgrade-3.2.0-to-4.0.0.oracle.sql
----------------------------------------------------------------------
diff --git a/standalone-metastore/metastore-server/src/main/sql/oracle/upgrade-3.2.0-to-4.0.0.oracle.sql b/standalone-metastore/metastore-server/src/main/sql/oracle/upgrade-3.2.0-to-4.0.0.oracle.sql
index bbb4a39..b9f6331 100644
--- a/standalone-metastore/metastore-server/src/main/sql/oracle/upgrade-3.2.0-to-4.0.0.oracle.sql
+++ b/standalone-metastore/metastore-server/src/main/sql/oracle/upgrade-3.2.0-to-4.0.0.oracle.sql
@@ -3,6 +3,12 @@ SELECT 'Upgrading MetaStore schema from 3.2.0 to 4.0.0' AS Status from dual;
 ALTER TABLE TBLS ADD WRITE_ID number DEFAULT 0 NOT NULL;
 ALTER TABLE PARTITIONS ADD WRITE_ID number DEFAULT 0 NOT NULL;
 
+-- HIVE-20793
+ALTER TABLE WM_RESOURCEPLAN ADD NS VARCHAR2(128);
+UPDATE WM_RESOURCEPLAN SET NS = 'default' WHERE NS IS NULL;
+DROP INDEX UNIQUE_WM_RESOURCEPLAN;
+CREATE UNIQUE INDEX UNIQUE_WM_RESOURCEPLAN ON WM_RESOURCEPLAN (NS, "NAME");
+
 -- These lines need to be last.  Insert any changes above.
 UPDATE VERSION SET SCHEMA_VERSION='4.0.0', VERSION_COMMENT='Hive release version 4.0.0' where VER_ID=1;
 SELECT 'Finished upgrading MetaStore schema from 3.2.0 to 4.0.0' AS Status from dual;

http://git-wip-us.apache.org/repos/asf/hive/blob/5258c67e/standalone-metastore/metastore-server/src/main/sql/postgres/hive-schema-4.0.0.postgres.sql
----------------------------------------------------------------------
diff --git a/standalone-metastore/metastore-server/src/main/sql/postgres/hive-schema-4.0.0.postgres.sql b/standalone-metastore/metastore-server/src/main/sql/postgres/hive-schema-4.0.0.postgres.sql
index ea088d7..9040005 100644
--- a/standalone-metastore/metastore-server/src/main/sql/postgres/hive-schema-4.0.0.postgres.sql
+++ b/standalone-metastore/metastore-server/src/main/sql/postgres/hive-schema-4.0.0.postgres.sql
@@ -670,6 +670,7 @@ CREATE TABLE "METASTORE_DB_PROPERTIES"
 CREATE TABLE "WM_RESOURCEPLAN" (
     "RP_ID" bigint NOT NULL,
     "NAME" character varying(128) NOT NULL,
+    "NS" character varying(128),
     "QUERY_PARALLELISM" integer,
     "STATUS" character varying(20) NOT NULL,
     "DEFAULT_POOL_ID" bigint
@@ -1060,7 +1061,7 @@ ALTER TABLE ONLY "WM_RESOURCEPLAN"
     ADD CONSTRAINT "WM_RESOURCEPLAN_pkey" PRIMARY KEY ("RP_ID");
 
 ALTER TABLE ONLY "WM_RESOURCEPLAN"
-    ADD CONSTRAINT "UNIQUE_WM_RESOURCEPLAN" UNIQUE ("NAME");
+    ADD CONSTRAINT "UNIQUE_WM_RESOURCEPLAN" UNIQUE ("NS", "NAME");
 
 ALTER TABLE ONLY "WM_POOL"
     ADD CONSTRAINT "WM_POOL_pkey" PRIMARY KEY ("POOL_ID");

http://git-wip-us.apache.org/repos/asf/hive/blob/5258c67e/standalone-metastore/metastore-server/src/main/sql/postgres/upgrade-3.2.0-to-4.0.0.postgres.sql
----------------------------------------------------------------------
diff --git a/standalone-metastore/metastore-server/src/main/sql/postgres/upgrade-3.2.0-to-4.0.0.postgres.sql b/standalone-metastore/metastore-server/src/main/sql/postgres/upgrade-3.2.0-to-4.0.0.postgres.sql
index 2a2d70a..0c36069 100644
--- a/standalone-metastore/metastore-server/src/main/sql/postgres/upgrade-3.2.0-to-4.0.0.postgres.sql
+++ b/standalone-metastore/metastore-server/src/main/sql/postgres/upgrade-3.2.0-to-4.0.0.postgres.sql
@@ -4,6 +4,13 @@ SELECT 'Upgrading MetaStore schema from 3.2.0 to 4.0.0';
 ALTER TABLE "TBLS" ADD "WRITE_ID" bigint DEFAULT 0;
 ALTER TABLE "PARTITIONS" ADD "WRITE_ID" bigint DEFAULT 0;
 
+
+-- HIVE-20793
+ALTER TABLE "WM_RESOURCEPLAN" ADD "NS" character varying(128);
+UPDATE "WM_RESOURCEPLAN" SET "NS" = 'default' WHERE "NS" IS NULL;
+ALTER TABLE "WM_RESOURCEPLAN" DROP CONSTRAINT "UNIQUE_WM_RESOURCEPLAN";
+ALTER TABLE ONLY "WM_RESOURCEPLAN" ADD CONSTRAINT "UNIQUE_WM_RESOURCEPLAN" UNIQUE ("NS", "NAME");
+
 -- These lines need to be last.  Insert any changes above.
 UPDATE "VERSION" SET "SCHEMA_VERSION"='4.0.0', "VERSION_COMMENT"='Hive release version 4.0.0' where "VER_ID"=1;
 SELECT 'Finished upgrading MetaStore schema from 3.2.0 to 4.0.0';

http://git-wip-us.apache.org/repos/asf/hive/blob/5258c67e/standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/DummyRawStoreControlledCommit.java
----------------------------------------------------------------------
diff --git a/standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/DummyRawStoreControlledCommit.java b/standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/DummyRawStoreControlledCommit.java
index 9669798..c13e538 100644
--- a/standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/DummyRawStoreControlledCommit.java
+++ b/standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/DummyRawStoreControlledCommit.java
@@ -1060,39 +1060,39 @@ public class DummyRawStoreControlledCommit implements RawStore, Configurable {
   }
 
   @Override
-  public WMFullResourcePlan getResourcePlan(String name) throws NoSuchObjectException,
+  public WMFullResourcePlan getResourcePlan(String name, String ns) throws NoSuchObjectException,
       MetaException {
-    return objectStore.getResourcePlan(name);
+    return objectStore.getResourcePlan(name, ns);
   }
 
   @Override
-  public List<WMResourcePlan> getAllResourcePlans() throws MetaException {
-    return objectStore.getAllResourcePlans();
+  public List<WMResourcePlan> getAllResourcePlans(String ns) throws MetaException {
+    return objectStore.getAllResourcePlans(ns);
   }
 
   @Override
-  public WMFullResourcePlan alterResourcePlan(String name, WMNullableResourcePlan resourcePlan,
+  public WMFullResourcePlan alterResourcePlan(String name, String ns, WMNullableResourcePlan resourcePlan,
       boolean canActivateDisabled, boolean canDeactivate, boolean isReplace)
       throws AlreadyExistsException, NoSuchObjectException, InvalidOperationException,
           MetaException {
     return objectStore.alterResourcePlan(
-      name, resourcePlan, canActivateDisabled, canDeactivate, isReplace);
+      name, ns, resourcePlan, canActivateDisabled, canDeactivate, isReplace);
   }
 
   @Override
-  public WMFullResourcePlan getActiveResourcePlan() throws MetaException {
-    return objectStore.getActiveResourcePlan();
+  public WMFullResourcePlan getActiveResourcePlan(String ns) throws MetaException {
+    return objectStore.getActiveResourcePlan(ns);
   }
 
   @Override
-  public WMValidateResourcePlanResponse validateResourcePlan(String name)
+  public WMValidateResourcePlanResponse validateResourcePlan(String name, String ns)
       throws NoSuchObjectException, InvalidObjectException, MetaException {
-    return objectStore.validateResourcePlan(name);
+    return objectStore.validateResourcePlan(name, ns);
   }
 
   @Override
-  public void dropResourcePlan(String name) throws NoSuchObjectException, MetaException {
-    objectStore.dropResourcePlan(name);
+  public void dropResourcePlan(String name, String ns) throws NoSuchObjectException, MetaException {
+    objectStore.dropResourcePlan(name, ns);
   }
 
   @Override
@@ -1109,15 +1109,15 @@ public class DummyRawStoreControlledCommit implements RawStore, Configurable {
   }
 
   @Override
-  public void dropWMTrigger(String resourcePlanName, String triggerName)
+  public void dropWMTrigger(String resourcePlanName, String triggerName, String ns)
       throws NoSuchObjectException, InvalidOperationException, MetaException {
-    objectStore.dropWMTrigger(resourcePlanName, triggerName);
+    objectStore.dropWMTrigger(resourcePlanName, triggerName, ns);
   }
 
   @Override
-  public List<WMTrigger> getTriggersForResourcePlan(String resourcePlanName)
+  public List<WMTrigger> getTriggersForResourcePlan(String resourcePlanName, String ns)
       throws NoSuchObjectException, MetaException {
-    return objectStore.getTriggersForResourcePlan(resourcePlanName);
+    return objectStore.getTriggersForResourcePlan(resourcePlanName, ns);
   }
 
   @Override
@@ -1133,9 +1133,9 @@ public class DummyRawStoreControlledCommit implements RawStore, Configurable {
   }
 
   @Override
-  public void dropWMPool(String resourcePlanName, String poolPath)
+  public void dropWMPool(String resourcePlanName, String poolPath, String ns)
       throws NoSuchObjectException, InvalidOperationException, MetaException {
-    objectStore.dropWMPool(resourcePlanName, poolPath);
+    objectStore.dropWMPool(resourcePlanName, poolPath, ns);
   }
 
   @Override
@@ -1153,15 +1153,15 @@ public class DummyRawStoreControlledCommit implements RawStore, Configurable {
 
   @Override
   public void createWMTriggerToPoolMapping(String resourcePlanName, String triggerName,
-      String poolPath) throws AlreadyExistsException, NoSuchObjectException,
+      String poolPath, String ns) throws AlreadyExistsException, NoSuchObjectException,
       InvalidOperationException, MetaException {
-    objectStore.createWMTriggerToPoolMapping(resourcePlanName, triggerName, poolPath);
+    objectStore.createWMTriggerToPoolMapping(resourcePlanName, triggerName, poolPath, ns);
   }
 
   @Override
   public void dropWMTriggerToPoolMapping(String resourcePlanName, String triggerName,
-      String poolPath) throws NoSuchObjectException, InvalidOperationException, MetaException {
-    objectStore.dropWMTriggerToPoolMapping(resourcePlanName, triggerName, poolPath);
+      String poolPath, String ns) throws NoSuchObjectException, InvalidOperationException, MetaException {
+    objectStore.dropWMTriggerToPoolMapping(resourcePlanName, triggerName, poolPath, ns);
   }
 
 

http://git-wip-us.apache.org/repos/asf/hive/blob/5258c67e/standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/DummyRawStoreForJdoConnection.java
----------------------------------------------------------------------
diff --git a/standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/DummyRawStoreForJdoConnection.java b/standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/DummyRawStoreForJdoConnection.java
index 593d562..e943f17 100644
--- a/standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/DummyRawStoreForJdoConnection.java
+++ b/standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/DummyRawStoreForJdoConnection.java
@@ -1051,36 +1051,36 @@ public class DummyRawStoreForJdoConnection implements RawStore {
   }
 
   @Override
-  public WMFullResourcePlan getResourcePlan(String name) throws NoSuchObjectException {
+  public WMFullResourcePlan getResourcePlan(String name, String ns) throws NoSuchObjectException {
     return null;
   }
 
   @Override
-  public List<WMResourcePlan> getAllResourcePlans() throws MetaException {
+  public List<WMResourcePlan> getAllResourcePlans(String ns) throws MetaException {
     return null;
   }
 
   @Override
   public WMFullResourcePlan alterResourcePlan(
-      String name, WMNullableResourcePlan resourcePlan, boolean canActivateDisabled, boolean canDeactivate,
+      String name, String ns, WMNullableResourcePlan resourcePlan, boolean canActivateDisabled, boolean canDeactivate,
       boolean isReplace)
       throws NoSuchObjectException, InvalidOperationException, MetaException {
     return null;
   }
 
   @Override
-  public WMFullResourcePlan getActiveResourcePlan() throws MetaException {
+  public WMFullResourcePlan getActiveResourcePlan(String ns) throws MetaException {
     return null;
   }
 
   @Override
-  public WMValidateResourcePlanResponse validateResourcePlan(String name)
+  public WMValidateResourcePlanResponse validateResourcePlan(String name, String ns)
       throws NoSuchObjectException, InvalidObjectException, MetaException {
     return null;
   }
 
   @Override
-  public void dropResourcePlan(String name) throws NoSuchObjectException, MetaException {
+  public void dropResourcePlan(String name, String ns) throws NoSuchObjectException, MetaException {
   }
 
   @Override
@@ -1093,12 +1093,12 @@ public class DummyRawStoreForJdoConnection implements RawStore {
   }
 
   @Override
-  public void dropWMTrigger(String resourcePlanName, String triggerName)
+  public void dropWMTrigger(String resourcePlanName, String triggerName, String ns)
       throws NoSuchObjectException, MetaException {
   }
 
   @Override
-  public List<WMTrigger> getTriggersForResourcePlan(String resourcePlanName)
+  public List<WMTrigger> getTriggersForResourcePlan(String resourcePlanName, String ns)
       throws NoSuchObjectException, MetaException {
     return null;
   }
@@ -1114,7 +1114,7 @@ public class DummyRawStoreForJdoConnection implements RawStore {
   }
 
   @Override
-  public void dropWMPool(String resourcePlanName, String poolPath)
+  public void dropWMPool(String resourcePlanName, String poolPath, String ns)
       throws NoSuchObjectException, InvalidOperationException, MetaException {
   }
 
@@ -1131,13 +1131,13 @@ public class DummyRawStoreForJdoConnection implements RawStore {
 
   @Override
   public void createWMTriggerToPoolMapping(String resourcePlanName, String triggerName,
-      String poolPath) throws AlreadyExistsException, NoSuchObjectException,
+      String poolPath, String ns) throws AlreadyExistsException, NoSuchObjectException,
       InvalidOperationException, MetaException {
   }
 
   @Override
   public void dropWMTriggerToPoolMapping(String resourcePlanName, String triggerName,
-      String poolPath) throws NoSuchObjectException, InvalidOperationException, MetaException {
+      String poolPath, String ns) throws NoSuchObjectException, InvalidOperationException, MetaException {
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/hive/blob/5258c67e/standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClientPreCatalog.java
----------------------------------------------------------------------
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 4293579..9fe9a65 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
@@ -51,6 +51,7 @@ import java.util.concurrent.atomic.AtomicInteger;
 import javax.security.auth.login.LoginException;
 
 import com.google.common.base.Preconditions;
+
 import org.apache.hadoop.classification.InterfaceAudience;
 import org.apache.hadoop.classification.InterfaceStability;
 import org.apache.hadoop.conf.Configuration;
@@ -2833,34 +2834,39 @@ public class HiveMetaStoreClientPreCatalog implements IMetaStoreClient, AutoClos
   }
 
   @Override
-  public WMFullResourcePlan getResourcePlan(String resourcePlanName)
+  public WMFullResourcePlan getResourcePlan(String resourcePlanName, String ns)
       throws NoSuchObjectException, MetaException, TException {
     WMGetResourcePlanRequest request = new WMGetResourcePlanRequest();
     request.setResourcePlanName(resourcePlanName);
+    request.setNs(ns);
     return client.get_resource_plan(request).getResourcePlan();
   }
 
   @Override
-  public List<WMResourcePlan> getAllResourcePlans()
+  public List<WMResourcePlan> getAllResourcePlans(String ns)
       throws NoSuchObjectException, MetaException, TException {
     WMGetAllResourcePlanRequest request = new WMGetAllResourcePlanRequest();
+    request.setNs(ns);
     return client.get_all_resource_plans(request).getResourcePlans();
   }
 
   @Override
-  public void dropResourcePlan(String resourcePlanName)
+  public void dropResourcePlan(String resourcePlanName, String ns)
       throws NoSuchObjectException, MetaException, TException {
     WMDropResourcePlanRequest request = new WMDropResourcePlanRequest();
     request.setResourcePlanName(resourcePlanName);
+    request.setNs(ns);
     client.drop_resource_plan(request);
   }
 
   @Override
-  public WMFullResourcePlan alterResourcePlan(String resourcePlanName, WMNullableResourcePlan resourcePlan,
+  public WMFullResourcePlan alterResourcePlan(String resourcePlanName, String ns,
+      WMNullableResourcePlan resourcePlan,
       boolean canActivateDisabled, boolean isForceDeactivate, boolean isReplace)
       throws NoSuchObjectException, InvalidObjectException, MetaException, TException {
     WMAlterResourcePlanRequest request = new WMAlterResourcePlanRequest();
     request.setResourcePlanName(resourcePlanName);
+    request.setNs(ns);
     request.setResourcePlan(resourcePlan);
     request.setIsEnableAndActivate(canActivateDisabled);
     request.setIsForceDeactivate(isForceDeactivate);
@@ -2870,15 +2876,18 @@ public class HiveMetaStoreClientPreCatalog implements IMetaStoreClient, AutoClos
   }
 
   @Override
-  public WMFullResourcePlan getActiveResourcePlan() throws MetaException, TException {
-    return client.get_active_resource_plan(new WMGetActiveResourcePlanRequest()).getResourcePlan();
+  public WMFullResourcePlan getActiveResourcePlan(String ns) throws MetaException, TException {
+    WMGetActiveResourcePlanRequest request = new WMGetActiveResourcePlanRequest();
+    request.setNs(ns);
+    return client.get_active_resource_plan(request).getResourcePlan();
   }
 
   @Override
-  public WMValidateResourcePlanResponse validateResourcePlan(String resourcePlanName)
+  public WMValidateResourcePlanResponse validateResourcePlan(String resourcePlanName, String ns)
       throws NoSuchObjectException, InvalidObjectException, MetaException, TException {
     WMValidateResourcePlanRequest request = new WMValidateResourcePlanRequest();
     request.setResourcePlanName(resourcePlanName);
+    request.setNs(ns);
     return client.validate_resource_plan(request);
   }
 
@@ -2899,19 +2908,21 @@ public class HiveMetaStoreClientPreCatalog implements IMetaStoreClient, AutoClos
   }
 
   @Override
-  public void dropWMTrigger(String resourcePlanName, String triggerName)
+  public void dropWMTrigger(String resourcePlanName, String triggerName, String ns)
       throws NoSuchObjectException, MetaException, TException {
     WMDropTriggerRequest request = new WMDropTriggerRequest();
     request.setResourcePlanName(resourcePlanName);
     request.setTriggerName(triggerName);
+    request.setNs(ns);
     client.drop_wm_trigger(request);
   }
 
   @Override
-  public List<WMTrigger> getTriggersForResourcePlan(String resourcePlan)
+  public List<WMTrigger> getTriggersForResourcePlan(String resourcePlan, String ns)
       throws NoSuchObjectException, MetaException, TException {
     WMGetTriggersForResourePlanRequest request = new WMGetTriggersForResourePlanRequest();
     request.setResourcePlanName(resourcePlan);
+    request.setNs(ns);
     return client.get_triggers_for_resourceplan(request).getTriggers();
   }
 
@@ -2933,11 +2944,12 @@ public class HiveMetaStoreClientPreCatalog implements IMetaStoreClient, AutoClos
   }
 
   @Override
-  public void dropWMPool(String resourcePlanName, String poolPath)
+  public void dropWMPool(String resourcePlanName, String poolPath, String ns)
       throws NoSuchObjectException, MetaException, TException {
     WMDropPoolRequest request = new WMDropPoolRequest();
     request.setResourcePlanName(resourcePlanName);
     request.setPoolPath(poolPath);
+    request.setNs(ns);
     client.drop_wm_pool(request);
   }
 
@@ -2960,16 +2972,18 @@ public class HiveMetaStoreClientPreCatalog implements IMetaStoreClient, AutoClos
 
   @Override
   public void createOrDropTriggerToPoolMapping(String resourcePlanName, String triggerName,
-      String poolPath, boolean shouldDrop) throws AlreadyExistsException, NoSuchObjectException,
+      String poolPath, boolean shouldDrop, String ns) throws AlreadyExistsException, NoSuchObjectException,
       InvalidObjectException, MetaException, TException {
     WMCreateOrDropTriggerToPoolMappingRequest request = new WMCreateOrDropTriggerToPoolMappingRequest();
     request.setResourcePlanName(resourcePlanName);
     request.setTriggerName(triggerName);
     request.setPoolPath(poolPath);
     request.setDrop(shouldDrop);
+    request.setNs(ns);
     client.create_or_drop_wm_trigger_to_pool_mapping(request);
   }
 
+
   @Override
   public void createCatalog(Catalog catalog) throws AlreadyExistsException, InvalidObjectException,
       MetaException, TException {


Mime
View raw message