@VisibleForTesting
  boolean needToFlush() {
    boolean needToFlushAccordingToQueueSize = queryHistoryQueue.size() >= batchSize;
    if (needToFlushAccordingToQueueSize) {
      LOG.info("Need to flush query history records as queue size ({}) >= batch size ({})",
          queryHistoryQueue.size(), batchSize);
      return true;
    }

    // whether ignore the consumed memory or not
    if (maxQueueSizeInMemoryBytes == 0) {
      return false;
    }

    long queueMemorySize =
        queryHistoryQueue.stream().mapToLong(Record::getEstimatedSizeInMemoryBytes).sum();
    boolean needToFlushAccordingToQueueMemorySize = queueMemorySize > maxQueueSizeInMemoryBytes;
    if (needToFlushAccordingToQueueMemorySize) {
      LOG.info("Need to flush query history records as queue size in memory ({} bytes) is greater than the limit " +
              "({} bytes)",
          queueMemorySize, maxQueueSizeInMemoryBytes);
    }
    return needToFlushAccordingToQueueMemorySize;
  }
Creates a Query History record from a given DriverContext and adds it to the queue.
This is done asynchronously to completely decouple from the threads that run the query to make this service work
silently in the background.
@param driverContext a DriverContext containing all the needed information for a record to be created
ql/src/java/org/apache/hadoop/hive/ql/queryhistory/QueryHistoryService.java