Skip to content

Instantly share code, notes, and snippets.

@arikfr
Created May 21, 2015 15:19
Show Gist options
  • Save arikfr/be7c2888520c44cf4f0f to your computer and use it in GitHub Desktop.
Save arikfr/be7c2888520c44cf4f0f to your computer and use it in GitHub Desktop.
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')
@erans
Copy link

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
Copy link

@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
Copy link

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

@Niraj-Fonseka
Copy link

@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