public String mapSessionToPoolName(MappingInput input, boolean allowAnyPool, Set<String> pools) {
    if (allowAnyPool && input.wmPool != null) {
      return (pools == null || pools.contains(input.wmPool)) ? input.wmPool : null;
    }
    // For equal-priority rules, user rules come first because they are more specific; then apps,
    // then groups (this is arbitrary).
    Mapping mapping = userMappings.get(input.getUserName());
    boolean isExplicitMatch = false;
    if (mapping != null) {
      isExplicitMatch = isExplicitPoolMatch(input, mapping);
      if (isExplicitMatch) return mapping.fullPoolName;
    }
    // We don't check explicit pool match for apps; both are specified on the jdbc string
    // so it doesn't make sense to have both and make sure one matches the other.
    if (mapping == null && input.getAppName() != null) {
      mapping = appMappings.get(input.getAppName());
    }
    for (String group : input.getGroups()) {
      Mapping candidate = groupMappings.get(group);
      if (candidate == null) continue;
      isExplicitMatch = isExplicitPoolMatch(input, candidate);
      if (isExplicitMatch) return candidate.fullPoolName;
      if (mapping == null || candidate.priority < mapping.priority) {
        mapping = candidate;
      }
    }
    if (input.wmPool != null && !isExplicitMatch) return null;
    if (mapping != null) return mapping.fullPoolName;
    return defaultPoolPath;
  }
Contains all the information necessary to map a query to a pool.
ql/src/java/org/apache/hadoop/hive/ql/exec/tez/UserPoolMapping.java