2 Risposte
- Più recenti
- Maggior numero di voti
- Maggior numero di commenti
2
There is no option to add header in TEXTFILE using UNLOAD option in Athena. Please check https://docs.aws.amazon.com/athena/latest/ug/unload.html
If your goal is to use csv files, every Athena query execution stores the results as a csv file in the S3 location that you have set up. You can check that under "Settings" > "Query location" The query results are available based on query execution ID and you can download these files with the first column as column names.
If you are doing this programmatically, I can provide an example using Python boto3
con risposta un anno fa
1
If you use the location variable, that should have your query result location. It is named query ID.csv - so, you could also construct the file name using that logic as another option.
import boto3,time
client = boto3.client('athena')
config_dict = {'query':'','bucket':''}
## This function executes the query and returns the query execution ID
response_query_execution_id = client.start_query_execution(
QueryString = config_dict['query'],
QueryExecutionContext = {
'Database' : "default"
},
ResultConfiguration = {
'OutputLocation': 's3://' + config_dict['bucket'] + '/queryoutput/' +
}
)
response_get_query_details = client.get_query_execution(
QueryExecutionId = response_query_execution_id['QueryExecutionId']
)
status = 'RUNNING'
iterations = 360 # 30 mins
while (iterations > 0):
iterations = iterations - 1
response_get_query_details = client.get_query_execution(
QueryExecutionId = response_query_execution_id['QueryExecutionId']
)
status = response_get_query_details['QueryExecution']['Status']['State']
if (status == 'FAILED') or (status == 'CANCELLED') :
failure_reason = response_get_query_details['QueryExecution']['Status']['StateChangeReason']
print(failure_reason)
elif status == 'SUCCEEDED':
location = response_get_query_details['QueryExecution']['ResultConfiguration']['OutputLocation']
else:
time.sleep(10)
con risposta un anno fa
Contenuto pertinente
- AWS UFFICIALEAggiornata 3 anni fa
- AWS UFFICIALEAggiornata 2 anni fa
- AWS UFFICIALEAggiornata 2 anni fa
- AWS UFFICIALEAggiornata 2 anni fa
Awesome! Would love to see your programatic solution with Python boto3. Thanks!