code: public static String generateStagingCTASStatement(HiveDatasetFinder.DbAndTable outputDbAndTable,
        String sourceQuery, StorageFormat storageFormat, String outputTableLocation) {
      Preconditions.checkArgument(!Strings.isNullOrEmpty(outputDbAndTable.getDb()) &&
          !Strings.isNullOrEmpty(outputDbAndTable.getTable()), "Invalid output db and table " + outputDbAndTable);
  
      return String.format("CREATE TEMPORARY TABLE `%s`.`%s` STORED AS %s LOCATION '%s' AS %s", outputDbAndTable.getDb(),
          outputDbAndTable.getTable(), storageFormat.getHiveName(), outputTableLocation, sourceQuery);
    }
docs: Generates a CTAS statement to dump the results of a query into a new table.
  @param outputDbAndTable output db and table where contents should be written.
  @param sourceQuery query to materialize.
  @param storageFormat format of output table.
  @param outputTableLocation location where files of output table should be written.