コード例 #1
0
        public static void Example()
        {
            // Create an Amazon Athena client
            var athenaConfig = new AmazonAthenaConfig
            {
                RegionEndpoint = RegionEndpoint.USEast1,
                Timeout        = TimeSpan.FromMilliseconds(ExampleConstants.CLIENT_EXECUTION_TIMEOUT)
            };
            var athenaClient = new AmazonAthenaClient(config: athenaConfig);

            String sampleQueryExecutionId = submitAthenaQuery(athenaClient);

            // Submit the stop query Request
            var stopQueryExecutionRequest = new StopQueryExecutionRequest()
            {
                QueryExecutionId = sampleQueryExecutionId
            };

            var stopQueryExecutionResponse = athenaClient.StopQueryExecution(stopQueryExecutionRequest);

            // Ensure that the query was stopped
            var getQueryExecutionRequest = new GetQueryExecutionRequest()
            {
                QueryExecutionId = sampleQueryExecutionId
            };


            var getQueryExecutionResponse = athenaClient.GetQueryExecution(getQueryExecutionRequest);

            if (getQueryExecutionResponse.QueryExecution.Status.State == QueryExecutionState.CANCELLED)
            {
                Console.WriteLine("Query has been cancelled");
            }
        }
コード例 #2
0
        /**
         * Wait for an Athena query to complete, fail or to be cancelled. This is done by polling Athena over an
         * interval of time. If a query fails or is cancelled, then it will throw an exception.
         */
        private static void waitForQueryToComplete(AmazonAthenaClient athenaClient, String queryExecutionId)
        {
            var getQueryExecutionRequest = new GetQueryExecutionRequest()
            {
                QueryExecutionId = queryExecutionId
            };

            GetQueryExecutionResponse getQueryExecutionResponse = null;
            bool isQueryStillRunning = true;

            while (isQueryStillRunning)
            {
                getQueryExecutionResponse = athenaClient.GetQueryExecution(getQueryExecutionRequest);
                var queryState = getQueryExecutionResponse.QueryExecution.Status.State;
                if (queryState == QueryExecutionState.FAILED)
                {
                    throw new Exception("Query Failed to run with Error Message: " + getQueryExecutionResponse.QueryExecution.Status.StateChangeReason);
                }
                else if (queryState == QueryExecutionState.CANCELLED)
                {
                    throw new Exception("Query was cancelled.");
                }
                else if (queryState == QueryExecutionState.SUCCEEDED)
                {
                    isQueryStillRunning = false;
                }
                else
                {
                    // Sleep an amount of time before retrying again.
                    Thread.Sleep(TimeSpan.FromMilliseconds(ExampleConstants.SLEEP_AMOUNT_IN_MS));
                }
                Console.WriteLine("Current Status is: " + queryState);
            }
        }