Chilkat Online Tools

GetQueryExecution unicodeCpp Example

Athena

#include <CkRestW.h>
#include <CkAuthAwsW.h>
#include <CkJsonObjectW.h>
#include <CkStringBuilderW.h>

void ChilkatSample(void)
    {
    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    CkRestW rest;
    bool success;

    CkAuthAwsW authAws;
    authAws.put_AccessKey(L"AWS_ACCESS_KEY");
    authAws.put_SecretKey(L"AWS_SECRET_KEY");

    // Don't forget to change the region to your particular region. (Also make the same change in the call to Connect below.)
    authAws.put_Region(L"us-west-2");
    authAws.put_ServiceName(L"athena");
    // SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    rest.SetAuthAws(authAws);

    // URL: https://athena.us-west-2.amazonaws.com/
    // Use the same region as specified above.
    success = rest.Connect(L"athena.us-west-2.amazonaws.com",443,true,true);
    if (success != true) {
        wprintf(L"ConnectFailReason: %d\n",rest.get_ConnectFailReason());
        wprintf(L"%s\n",rest.lastErrorText());
        return;
    }

    // The following code creates the JSON request body.
    // The JSON created by this code is shown below.

    // Use this online tool to generate code from sample JSON:
    // Generate Code to Create JSON

    CkJsonObjectW json;
    json.UpdateString(L"QueryExecutionId",L"string");

    // The JSON request body created by the above code:

    // {
    //   "QueryExecutionId": "string"
    // }

    rest.AddHeader(L"Content-Type",L"application/x-amz-json-1.1");
    rest.AddHeader(L"X-Amz-Target",L"AmazonAthena.GetQueryExecution");

    CkStringBuilderW sbRequestBody;
    json.EmitSb(sbRequestBody);
    CkStringBuilderW sbResponseBody;
    success = rest.FullRequestSb(L"POST",L"/",sbRequestBody,sbResponseBody);
    if (success != true) {
        wprintf(L"%s\n",rest.lastErrorText());
        return;
    }

    int respStatusCode = rest.get_ResponseStatusCode();
    wprintf(L"response status code = %d\n",respStatusCode);
    if (respStatusCode != 200) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",rest.responseHeader());
        wprintf(L"Response Body:\n");
        wprintf(L"%s\n",sbResponseBody.getAsString());
        return;
    }

    CkJsonObjectW jResp;
    jResp.LoadSb(sbResponseBody);

    // The following code parses the JSON response.
    // A sample JSON response is shown below the sample code.

    // Use this online tool to generate parsing code from sample JSON:
    // Generate Parsing Code from JSON

    // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.
    // See this example explaining how this memory should be used: const char * functions.

    const wchar_t *EffectiveEngineVersion = jResp.stringOf(L"QueryExecution.EngineVersion.EffectiveEngineVersion");
    const wchar_t *SelectedEngineVersion = jResp.stringOf(L"QueryExecution.EngineVersion.SelectedEngineVersion");
    const wchar_t *Query = jResp.stringOf(L"QueryExecution.Query");
    const wchar_t *Catalog = jResp.stringOf(L"QueryExecution.QueryExecutionContext.Catalog");
    const wchar_t *Database = jResp.stringOf(L"QueryExecution.QueryExecutionContext.Database");
    const wchar_t *QueryExecutionId = jResp.stringOf(L"QueryExecution.QueryExecutionId");
    const wchar_t *S3AclOption = jResp.stringOf(L"QueryExecution.ResultConfiguration.AclConfiguration.S3AclOption");
    const wchar_t *EncryptionOption = jResp.stringOf(L"QueryExecution.ResultConfiguration.EncryptionConfiguration.EncryptionOption");
    const wchar_t *KmsKey = jResp.stringOf(L"QueryExecution.ResultConfiguration.EncryptionConfiguration.KmsKey");
    const wchar_t *ExpectedBucketOwner = jResp.stringOf(L"QueryExecution.ResultConfiguration.ExpectedBucketOwner");
    const wchar_t *OutputLocation = jResp.stringOf(L"QueryExecution.ResultConfiguration.OutputLocation");
    const wchar_t *StatementType = jResp.stringOf(L"QueryExecution.StatementType");
    const wchar_t *DataManifestLocation = jResp.stringOf(L"QueryExecution.Statistics.DataManifestLocation");
    int DataScannedInBytes = jResp.IntOf(L"QueryExecution.Statistics.DataScannedInBytes");
    int EngineExecutionTimeInMillis = jResp.IntOf(L"QueryExecution.Statistics.EngineExecutionTimeInMillis");
    int QueryPlanningTimeInMillis = jResp.IntOf(L"QueryExecution.Statistics.QueryPlanningTimeInMillis");
    int QueryQueueTimeInMillis = jResp.IntOf(L"QueryExecution.Statistics.QueryQueueTimeInMillis");
    int ServiceProcessingTimeInMillis = jResp.IntOf(L"QueryExecution.Statistics.ServiceProcessingTimeInMillis");
    int TotalExecutionTimeInMillis = jResp.IntOf(L"QueryExecution.Statistics.TotalExecutionTimeInMillis");
    int ErrorCategory = jResp.IntOf(L"QueryExecution.Status.AthenaError.ErrorCategory");
    const wchar_t *ErrorMessage = jResp.stringOf(L"QueryExecution.Status.AthenaError.ErrorMessage");
    int ErrorType = jResp.IntOf(L"QueryExecution.Status.AthenaError.ErrorType");
    int Retryable = jResp.IntOf(L"QueryExecution.Status.AthenaError.Retryable");
    int CompletionDateTime = jResp.IntOf(L"QueryExecution.Status.CompletionDateTime");
    const wchar_t *State = jResp.stringOf(L"QueryExecution.Status.State");
    const wchar_t *StateChangeReason = jResp.stringOf(L"QueryExecution.Status.StateChangeReason");
    int SubmissionDateTime = jResp.IntOf(L"QueryExecution.Status.SubmissionDateTime");
    const wchar_t *WorkGroup = jResp.stringOf(L"QueryExecution.WorkGroup");

    // A sample JSON response body parsed by the above code:

    // {
    //   "QueryExecution": {
    //     "EngineVersion": {
    //       "EffectiveEngineVersion": "string",
    //       "SelectedEngineVersion": "string"
    //     },
    //     "Query": "string",
    //     "QueryExecutionContext": {
    //       "Catalog": "string",
    //       "Database": "string"
    //     },
    //     "QueryExecutionId": "string",
    //     "ResultConfiguration": {
    //       "AclConfiguration": {
    //         "S3AclOption": "string"
    //       },
    //       "EncryptionConfiguration": {
    //         "EncryptionOption": "string",
    //         "KmsKey": "string"
    //       },
    //       "ExpectedBucketOwner": "string",
    //       "OutputLocation": "string"
    //     },
    //     "StatementType": "string",
    //     "Statistics": {
    //       "DataManifestLocation": "string",
    //       "DataScannedInBytes": number,
    //       "EngineExecutionTimeInMillis": number,
    //       "QueryPlanningTimeInMillis": number,
    //       "QueryQueueTimeInMillis": number,
    //       "ServiceProcessingTimeInMillis": number,
    //       "TotalExecutionTimeInMillis": number
    //     },
    //     "Status": {
    //       "AthenaError": {
    //         "ErrorCategory": number,
    //         "ErrorMessage": "string",
    //         "ErrorType": number,
    //         "Retryable": boolean
    //       },
    //       "CompletionDateTime": number,
    //       "State": "string",
    //       "StateChangeReason": "string",
    //       "SubmissionDateTime": number
    //     },
    //     "WorkGroup": "string"
    //   }
    // }
    }