tableau / TabPy

Execute Python code on the fly and display results in Tableau visualizations:
https://tableau.github.io/TabPy/
MIT License
1.56k stars 598 forks source link

Deployed Function Receiving Separate Asynchronous Calls for each Row #463

Closed MasonLegere closed 3 years ago

MasonLegere commented 3 years ago

Environment information:

Describe the issue In the current implementation if a column with N rows is passed into a function (deployed or local script) the function will be called N (asynchronous) times, each passing in a value in the array. This makes it infeasible to preform calculations that hold state. I am sure that this is a design constraint of Tableau so I am ensure about the feasibility.

To Reproduce Here is an simple example where, based upon the last index of a time series we may like to perform a different action.

SCRIPT_REAL("
bar = []
last = _arg1[-1]

if last < 10: 
    factor = 2
else: 
    factor = 3
for foo in _arg1: 
    bar.append(foo*factor)
return bar",
SUM([dummy_arg])) # <- issue here
ethanj20 commented 3 years ago

Would this method allow you to compute rolling averages?

MasonLegere commented 3 years ago

I believe any solution to the issue would imply that we could compute rolling averages.

ethanj20 commented 3 years ago

https://github.com/tableau/TabPy/issues/464

does this provide any insight to what you are experiencing? Or do you have any solution to the problem discussed here?

nmannheimer commented 3 years ago

This is a factor of how the table calculation is being computed (the SCRIPT_REAL function). What is happening is you have some dimensions on the view that are partitioning the table calc, and the SCRIPT_X calcs will make a call to the external server for each partition. It's entirely possible to compute the calc so it sends all data in one call, what you need to do is on the calculation (when it's placed in the view) got to 'edit table calculation' then select Specific Dimensions and check the boxes next to each dimension. This will pass the data to Python in a single call as opposed to many smaller calls. Data are passed as lists with a length of as many marks as there are in the view or each partition.

For more details on table calculations check here: https://help.tableau.com/current/pro/desktop/en-us/calculations_tablecalculations.htm#specific-dimensions

For more details on how to use analytics extensions look here: https://www.youtube.com/watch?v=nRtOMTnBz_Y

https://www.youtube.com/watch?v=0BN_Y2CxdYY