function executeQuery(queryParams) {
    const client = createAthenaClient(queryParams);

    return new Promise(function(resolve, reject) {
        return startQuery(client, queryParams).then(queryExecutionId => {

            // Define the wait interval
            let retryInterval = queryParams.queryInterval;

            // If retry interval is not defined or less 0 set retry to 1000
            if ((!retryInterval) || (retryInterval < 1)) {
                retryInterval = 1000;
            }

            const checkQueryStatus = () => {
                queryResultsCompleted(client, queryExecutionId).then(queryResult => {
                    if (queryResult.queryState < 0) {
                        return reject(new Error(queryResult.queryStatus));
                    } else if (queryResult.queryState === 1) {
                        return getQueryResults(client, queryExecutionId).then(rst => {

                            if (rst && rst.ResultSet && rst.ResultSet.Rows) {
                                return resolve(rst.ResultSet.Rows);
                            }
                            return resolve([]);
                        });
                    }
                    // Loop again
                    return setTimeout(checkQueryStatus, retryInterval);
                }).catch(err => {
                    return reject(err);
                });
            };

            checkQueryStatus();

        }).catch(err => {
            return reject(err);
        });
    });
}
The following function will execute a query against athena.  It will first start
by starting the query request.  It will then start a timer to periodically
check to see if the query results have completed. If the Query Timeout has
Exceeded it will reject the query.  If the it receives data before the query
times out it will return the response.
@param {object} queryParams - Query Parameters
@param {string} queryParams.accessKey - AWS Access Key
@param {string} queryParams.secretAccessKey - AWS Secret Key
@param {string} queryParams.region - AWS Region
@param {string} queryParams.dbName - Database name to connect to
@param {string} queryParams.sqlStatement - SQL statement to execute
@param {string} queryParams.s3Outputlocation - Location will Athena will output resutls of query
@param {number} queryParams.queryInterval  - The timeout interval when the query should stop
@returns {Promise} resolve to AWS Query Response