/// <summary>
    /// Fetches a match table from a PQL statement and writes it to a file.
    /// </summary>
    /// <param name="pqlService">The PQL service.</param>
    /// <param name="selectStatement">The select statement.</param>
    /// <param name="fileName">Name of the file.</param>
    private static void fetchMatchTables(PublisherQueryLanguageService pqlService,
        StatementBuilder statementBuilder, string fileName) {

      int resultSetSize = 0;
      List<Row> allRows = new List<Row>();
      ResultSet resultSet;

      do {
        resultSet = pqlService.select(statementBuilder.ToStatement());
        allRows.AddRange(resultSet.rows);
        Console.WriteLine(PqlUtilities.ResultSetToString(resultSet));

        statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
        resultSetSize = resultSet.rows == null ? 0 : resultSet.rows.Length;
      } while (resultSetSize > 0);

      resultSet.rows = allRows.ToArray();
      List<String[]> rows = PqlUtilities.ResultSetToStringArrayList(resultSet);

      // Write the contents to a csv file.
      CsvFile file = new CsvFile();
      file.Headers.AddRange(rows[0]);
      file.Records.AddRange(rows.GetRange(1, rows.Count - 1).ToArray());
      file.Write(fileName);
    }
        /// <summary>
        /// Fetches a match table from a PQL statement and writes it to a file.
        /// </summary>
        /// <param name="pqlService">The PQL service.</param>
        /// <param name="selectStatement">The select statement.</param>
        /// <param name="fileName">Name of the file.</param>
        private static void fetchMatchTables(PublisherQueryLanguageService pqlService,
        string selectStatement, string fileName)
        {
            int pageSize = 500;
              Statement statement = new StatementBuilder(selectStatement).ToStatement();

              int offset = 0;
              int resultSetSize = 0;
              List<Row> allRows = new List<Row>();
              ResultSet resultSet;

              do {
            statement.query = selectStatement + " limit " + pageSize + " OFFSET " + offset;

            resultSet = pqlService.select(statement);
            allRows.AddRange(resultSet.rows);
            Console.WriteLine(PqlUtilities.ResultSetToString(resultSet));

            offset += pageSize;
            resultSetSize = resultSet.rows == null ? 0 : resultSet.rows.Length;
              } while (resultSetSize == pageSize);

              resultSet.rows = allRows.ToArray();
              List<String[]> rows = PqlUtilities.ResultSetToStringArrayList(resultSet);

              // Write the contents to a csv file.
              CsvFile file = new CsvFile();
              file.Headers.AddRange(rows[0]);
              file.Records.AddRange(rows.GetRange(1, rows.Count - 1).ToArray());
              file.Write(fileName);
        }