Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

would like to see Add GetNamedQuery By QueryName #753

Open
1 of 2 tasks
Diwamoto opened this issue May 13, 2024 · 3 comments
Open
1 of 2 tasks

would like to see Add GetNamedQuery By QueryName #753

Diwamoto opened this issue May 13, 2024 · 3 comments
Assignees
Labels
athena feature-request New feature or request service-api This issue pertains to the AWS API

Comments

@Diwamoto
Copy link

Describe the feature

hello.
It is an automatic translation and may result in strange English. Sorry.

I would like to be able to search an Athena NamedQuery by the Name of the Query.
The current implementation of GetNamedQuery() is only from the auto-generated query_id, and it is difficult to keep track of this id from the program.

ref: https://awscli.amazonaws.com/v2/documentation/api/latest/reference/athena/get-named-query.html

aws athena get-named-query --named-query-id <auto-generated-id>

Also, ListNamedQueries() must be implemented to retrieve this ID programmatically, but the response from this API is only a list of IDs, and we do not know which ID is the desired query.

ref: https://awscli.amazonaws.com/v2/documentation/api/latest/reference/athena/list-named-queries.html

aws athena list-named-queries
--> 
{
    "NamedQueryIds": [
        "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111",
        "a1b2c3d4-5678-90ab-cdef-EXAMPLE22222",
        "a1b2c3d4-5678-90ab-cdef-EXAMPLE33333"
    ]
}

(For example, if the name of the query as well as the ID is recorded here, you can use the query option of the AWS CLI to filter the results.)

Use Case

Looking at the implementation of getting NamedQuery in AWS Athena Console from Chrome Dev tools, it executes all ListNamedQueries and then GetNamedQuery one by one, which becomes more inefficient as the number of NamedQueries increases.

Proposed Solution

I would like to see GetNamedQueryByName added or name added to the ListNamedQueries response.

aws athena get-named-query --named-query-name <query_name>
aws athena list-named-queries
--> 
{
    "NamedQueries": [
        {
            "Id": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111",
            "Name": "named_query_example_1"
        },
        {
            "Id": "a1b2c3d4-5678-90ab-cdef-EXAMPLE22222",
            "Name": "named_query_example_2"
        },
        {
            "Id": "a1b2c3d4-5678-90ab-cdef-EXAMPLE33333",
            "Name": "named_query_example_3"
        }
    ]
}

Changing the response of ListNamedQueries would lose backward compatibility, so if anything we should add GetNamedQueryByName or another solution.

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CLI version used

aws-cli/2.15.36 Python/3.11.9 Darwin/23.4.0 source/arm64 prompt/off

Environment details (OS name and version, etc.)

Mac OS Sonoma 14.4.1

@tim-finnigan
Copy link

Thanks for the feature request. The Athena team maintains the underlying GetNamedQuery and ListNamedQueries APIs, so we would have to forward feature requests involving the API behavior to them.


Changing the response of ListNamedQueries would lose backward compatibility, so if anything we should add GetNamedQueryByName or another solution.

As you suggested above, creating a new API may be the best solution due to the need to maintain backwards compatibility.

To make sure that we correctly understand the ask here, can you verify that the following accomplishes what you're trying to do using Boto3:

import boto3

client = boto3.client('athena')
response = client.list_named_queries()

query_ids = response['NamedQueryIds']

named_queries = [client.get_named_query(NamedQueryId=id)['NamedQuery'] for id in query_ids]

filtered_queries = [q for q in named_queries if q['Name'] == '<query name>']

for query in filtered_queries:
    print(query)

Or using a bash script:

#!/bin/bash

# Set the query name to filter for
query_name="<query name>"

# List named queries
named_query_ids=$(aws athena list-named-queries --query "NamedQueryIds" --output text)

# Loop through the named query IDs
for query_id in $named_query_ids
do
    # Get the named query details
    named_query=$(aws athena get-named-query --named-query-id "$query_id")

    # Extract the query name
    query_name_from_response=$(echo "$named_query" | jq -r '.NamedQuery.Name')

    # Check if the query name matches the filter
    if [ "$query_name_from_response" == "$query_name" ]; then
        echo "$named_query"
    fi
done

I think those workarounds meet your use case, but we can still forward the feature request to the Athena team for review.

@tim-finnigan tim-finnigan added service-api This issue pertains to the AWS API athena response-requested This issue requires a response to continue and removed investigating needs-triage labels May 13, 2024
@Diwamoto
Copy link
Author

Yes, it can be accomplished with both the boto3 and shell scripts listed. (The AWS Athena console implementation was the same.)

That is where I would like to write this if possible (I will show an example with boto3)

import boto3

already_known_query_name = 'the query'

client = boto3.client('athena')
response = client.get_named_queries(name=already_known_query_name)

print(response[0]) # the query data

@github-actions github-actions bot removed the response-requested This issue requires a response to continue label May 14, 2024
@tim-finnigan
Copy link

tim-finnigan commented May 22, 2024

Thanks for confirming, I'll transfer this to our cross-SDK repository (since service APIs like this are used across AWS SDKs) and I'll reach out to the Athena team for feedback on this feature request. (ref: P131190888)

@tim-finnigan tim-finnigan transferred this issue from aws/aws-cli May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
athena feature-request New feature or request service-api This issue pertains to the AWS API
Projects
None yet
Development

No branches or pull requests

2 participants