Parse S3Select output AWS SDK C++

262 views Asked by At

I have the following code snippet.

#include <aws/core/Aws.h>
#include <aws/core/utils/logging/LogLevel.h>
#include <aws/s3/S3Client.h>
#include <aws/s3/S3Errors.h>
#include <aws/s3/model/SelectObjectContentRequest.h>
#include <aws/s3/model/InputSerialization.h>
#include <aws/s3/model/ExpressionType.h>
#include <aws/s3/model/ParquetInput.h>
#include <iostream>
using namespace Aws;

int main()
{
    //The Aws::SDKOptions struct contains SDK configuration options.
    //An instance of Aws::SDKOptions is passed to the Aws::InitAPI and
    //Aws::ShutdownAPI methods.  The same instance should be sent to both methods.
    SDKOptions options;
    options.loggingOptions.logLevel = Utils::Logging::LogLevel::Trace;
    Aws::InitAPI(options);

    Aws::Client::ClientConfiguration cfg;

    Aws::String region = "eu-west-1";
    cfg.region = region;


    S3::S3Client client(cfg,
            Aws::Client::AWSAuthV4Signer::PayloadSigningPolicy::Never,
            false);


    S3::Model::SelectObjectContentRequest request;
    request.SetBucket("my-bucket");
    request.SetKey("parquet_file.parquet");
    request.SetExpressionType(S3::Model::ExpressionType::SQL);
    request.SetExpression("SELECT * FROM s3object s LIMIT 5");

    S3::Model::InputSerialization inputSerialization;
    S3::Model::ParquetInput parquetInput;
    inputSerialization.SetParquet(parquetInput);
    request.SetInputSerialization(inputSerialization);

    S3::Model::OutputSerialization outputSerialization;
    S3::Model::CSVOutput csvOutput;
    outputSerialization.SetCSV(csvOutput);
    request.SetOutputSerialization(outputSerialization);

    auto s3_select_outcome =
        client.SelectObjectContent(request);
    if (s3_select_outcome.IsSuccess()) {
        std::cout << "Success" << std::endl;
    }
    else {
        std::cout << "Failed with error: " << s3_select_outcome.GetError() << std::endl;
    }

    //Before the application terminates, the SDK must be shut down.
    ShutdownAPI(options);
    return 0;
}

However as seen here, the result is of type Model::SelectObjectContentOutcome. By following the documentation here this consists of a Aws::NoResult and although there is a GetResult method, there is no actual way to get or parse the results. The program returns Success meaning that the request actually should return something. Does anybody have any idea how to do this? Thanks!

0

There are 0 answers