KoteiIto / node-athena

a nodejs simple aws athena client
MIT License
105 stars 73 forks source link

Support of CTAS query #41

Closed jubry closed 5 years ago

jubry commented 5 years ago

Hello,

First of all, big thanks for your great work on that lib, we are using it and it works like a charm.

AWS has released an update a few weeks back for what they call CTAS queries:

https://docs.aws.amazon.com/athena/latest/ug/ctas.html

It offers great features, however, we hit a glitch using node-athena on that kind of query.

The "outputLocation" received in the response is not pointing to the csv result or the metadata file. Instead, the response is s3://[bucket_name]/[path]/[query_id] without the file extension.

When running this kind of queries with node-athena, we hit an error as the s3 key does not exists.

1) The key: s3://[bucket_name]/[path]/[query_id] doesn't exists. 2) Only the .metadata file is generated.

We have been able to patch the lib so it can handle this kind of query.

We have a compiled working version available at:

https://github.com/jubry/node-athena

I'm not a coder, so i'm not pretending my patch is how we should handle things.

I just changed a few lines of code in one file (client.js):

1) Adding a new property in the client config:

export interface AthenaClientConfig extends AthenaRequestConfig {
  pollingInterval?: number
  queryTimeout?: number
  concurrentExecMax?: number
  execRightCheckInterval?: number
  noResultExpected?: boolean
}

NB: noResultExpected?: boolean added

2) Adding a condition for not trying to access the CSV file in that case:

      if (!config.noResultExpected) {
        const resultsStream = this.request.getResultsStream(
          queryExecution.ResultConfiguration.OutputLocation,
        )
        resultsStream.pipe(csvTransform)
      }

NB: if (!config.noResultExpected) { added

By doing that, we are able to keep using your library.

Would it be possible for you to implement such functionality in a proper way ?

It would be greatly appreciated.

Find here an sql statement to reproduce the problem:

CREATE TABLE database.table WITH 
( format = 'PARQUET', 
external_location = 's3://mybucket_name/') 
AS SELECT 1 as myfield

Let me know if you have any question about it.

Thanks in advance,

And again, congratulation for your great work.

Regards,

:)

KoteiIto commented 5 years ago

We support CTAS from v2.4.0. Please set skipFetchResult to true to create client.