private Set<String> getAllUniqueViewsAndTables(List<Pair<String, String>> tables) {
    Set<String> fullTableNames = new HashSet<>();
    Queue<Pair<String, String>> queue = new LinkedList<>(tables);
    LOG.debug("Getting all tables.");
    while (queue.peek() != null) {
      String tableOrView = getTableName(queue.remove());
      LOG.debug("Getting table " + tableOrView);
      Set<String> underlyingTables = underlyingTableHints.getIfPresent(tableOrView);
      if (underlyingTables != null) {
        // don't process the same table twice.
        if (fullTableNames.contains(tableOrView)) {
          continue;
        }
        // it's a view.
        LOG.debug("View in cache, adding its tables to queue.");
        for (String viewTable : underlyingTables) {
          LOG.debug("View table is " + viewTable);
          String[] dbTableArray = viewTable.split("\\.");
          Preconditions.checkNotNull(dbTableArray[0]);
          Preconditions.checkNotNull(dbTableArray[1]);
          queue.offer(new ImmutablePair<String, String>(dbTableArray[0], dbTableArray[1]));
        }
      }
      // We'll fetch validWriteIdList information whether it's a view or a table.
      fullTableNames.add(tableOrView);
    }
    return fullTableNames;
  }
Return all the unique views and tables given a list of tables. We iterate
through all the tables passed in. If it is a table in the list, we add the
table to our unique list. If it is a view, we add what we think are the
tables and views used by the view and iterate through those.

In order to generate a unique list, we need to add the dbname (from the SessionState)
if the db was not provided in the query from the user.
ql/src/java/org/apache/hadoop/hive/ql/parse/CacheTableHelper.java