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

I have updated the query for issue #3132 to match version 10. #5909

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

keitoueno
Copy link

@keitoueno keitoueno commented Mar 15, 2023

What type of PR is this?

  • Refactor
  • Feature
  • Bug Fix
  • New Query Runner (Data Source)
  • New Alert Destination
  • Other

Description

I am writing a lot of queries in Python data sources.
Most of the time, I use Python's "execute_query" to directly specify the data source and query.

However, recently I have had too many queries, so I wanted to use one query like a module. Therefore, I found a solution in issue #3132 and made modifications to match redash version 10. Please review and approve it.

How is this tested?

  • Unit tests (pytest, jest)
  • E2E Tests (Cypress)
  • Manually
  • N/A

Query A needs to be created as follows. The datasource used is MySQL.

SELECT customer_id FROM customer WHERE customer_id = {{customer_id}}
Note: The query ID for this query is 2 in my local Redash environment.

Query B needs to be created as follows.

data = execute_by_query_id(2, {"customer_id": "1234567"})
result = {}
for rows1 in data['rows']:
    add_result_row(result, {
        'customer_id' : rows1['customer_id'],
    })

add_result_column(result, 'customer_id', '', 'string')

The result for Query B is the data obtained from Query A (query ID 2).

Related Tickets & Documents

Mobile & Desktop Screenshots/Recordings (if there are UI changes)

@keitoueno keitoueno changed the title created an improved version of #3132 I have updated the query for issue #3132 to match version 10. Mar 15, 2023
@justinclift
Copy link
Member

justinclift commented Jul 10, 2023

I'm not really understanding how this is different from the existing ability to run SQL on the result of a previous query.

https://redash.io/help/user-guide/querying/query-results-data-source

Is it something to do with the use of parameters?

query = models.Query.get_by_id(query_id)
except models.NoResultFound:
raise Exception("Query id %s does not exist." % query_id)
# try:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not good to leave commented out code around like this. 😉

@konnectr
Copy link
Collaborator

I understand the code was taken from here #3132

@keitoueno
Copy link
Author

I'm not really understanding how this is different from the existing ability to run SQL on the result of a previous query.

https://redash.io/help/user-guide/querying/query-results-data-source

Is it something to do with the use of parameters?

Thank you for your reply. Yes, that's correct. With this customization, you will be able to call a query created in Python with arguments from different resources. In the example, it shows using "customer_id," but in many cases, you might use it for date-based calls. In fact, what I'm using it for is creating queries called from resources like Athena or RDS in Python and wanting to call them from different resources.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants