Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
re:dash Python datasource join example
# get existing queries results
users = get_query_result(132) # this one has {id, name}
events_by_users = get_query_result(131) # this one has {user_id, events count}
# actual merging. can be replaced with helper function and/or some Pandas code
events_dict = {}
for row in events_by_users['rows']:
events_dict[row['user_id']] = row['count']
for row in users['rows']:
row['events_count'] = events_dict.get(row['id'], 0)
# set the result to show
result = users
add_result_column(result, 'events_count', '', 'integer')
@kausikram

This comment has been minimized.

Show comment Hide comment
@kausikram

kausikram Jul 5, 2016

Is this inside a class of some kind? I am getting an Error

Error running query: 'NoneType' object has no attribute 'annotate_query'

I am not sure what i did wrong :/

Is this inside a class of some kind? I am getting an Error

Error running query: 'NoneType' object has no attribute 'annotate_query'

I am not sure what i did wrong :/

@WesleyBatista

This comment has been minimized.

Show comment Hide comment
@WesleyBatista

WesleyBatista Jul 22, 2016

Hey @arikfr, do you have an example importing packages?
How I need to setup the data source?

Hey @arikfr, do you have an example importing packages?
How I need to setup the data source?

@manubhats

This comment has been minimized.

Show comment Hide comment
@manubhats

manubhats Oct 6, 2016

I have been trying to setup python data source but no luck.Can someone please tell how to setup a python data source? What to write in the query text area? where to store the python module(directory)?

Edit: I got this working! Just enable python data source,choose a name and add it to data sources(Assuming no modules imported).
Type this in the query field:
result = get_query_result(your_query_id)
new_result = whatever_changes_you_need_in_the_resultset
add_result_column(new_result, 'column_name', '', 'integer/string/etc')

manubhats commented Oct 6, 2016

I have been trying to setup python data source but no luck.Can someone please tell how to setup a python data source? What to write in the query text area? where to store the python module(directory)?

Edit: I got this working! Just enable python data source,choose a name and add it to data sources(Assuming no modules imported).
Type this in the query field:
result = get_query_result(your_query_id)
new_result = whatever_changes_you_need_in_the_resultset
add_result_column(new_result, 'column_name', '', 'integer/string/etc')

@existeundelta

This comment has been minimized.

Show comment Hide comment
@existeundelta

existeundelta Oct 7, 2016

would be possible to get data from pinkle files?

would be possible to get data from pinkle files?

@erans

This comment has been minimized.

Show comment Hide comment
@erans

erans Nov 20, 2016

@WesleyBatista you need to put the name of the package in the data source configuration (modules to load) and make sure its in a python path (global or specific) that the python code in redash can actually find.

Then you can use "import mymodule". You also need to specifically name the modules you would like to load if these are python built-in module like json and datetime as the purpose of this is to make sure non authorized modules are not loaded and used.

erans commented Nov 20, 2016

@WesleyBatista you need to put the name of the package in the data source configuration (modules to load) and make sure its in a python path (global or specific) that the python code in redash can actually find.

Then you can use "import mymodule". You also need to specifically name the modules you would like to load if these are python built-in module like json and datetime as the purpose of this is to make sure non authorized modules are not loaded and used.

@vmendiratta

This comment has been minimized.

Show comment Hide comment
@vmendiratta

vmendiratta Aug 25, 2017

@kausikram - were you able to get around the 'NoneType' object has no attribute 'annotate_query'?

I've hit the same issue and I'm not sure what to do.

@kausikram - were you able to get around the 'NoneType' object has no attribute 'annotate_query'?

I've hit the same issue and I'm not sure what to do.

@Niraj-Fonseka

This comment has been minimized.

Show comment Hide comment
@Niraj-Fonseka

Niraj-Fonseka Oct 12, 2017

Getting the same issue. Has anyone found any solution for this ?

Getting the same issue. Has anyone found any solution for this ?

@Niraj-Fonseka

This comment has been minimized.

Show comment Hide comment
@Niraj-Fonseka

Niraj-Fonseka Oct 13, 2017

@vmendiratta solved it by restarting the celery workers.
getredash/redash#1169

@vmendiratta solved it by restarting the celery workers.
getredash/redash#1169

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