sql - Factorial in Google BigQuery -
i need compute factorial of variable in google bigquery - there function this? cannot find 1 in documentation here:
https://cloud.google.com/bigquery/query-reference#arithmeticoperators
my proposed solution @ point compute factorial numbers 1 through 100 , upload table , join table. if have better, please advise.
as context may reveal best solution, factorial used in context of computing poisson probability of random variable (number of events in window of time). see first equation here: https://en.wikipedia.org/wiki/poisson_distribution
try below. quick & dirty example
select number, factorial js( // input table (select number (select 4 number), (select 6 number), (select 12 number) ), // input columns number, // output schema "[{name: 'number', type: 'integer'}, {name: 'factorial', type: 'integer'}]", // function "function(r, emit){ function fact(num) { if(num<0) return 0; var fact=1; for(var i=num;i>1;i--) fact*=i; return fact; } var factorial = fact(r.number) emit({number: r.number, factorial: factorial}); }" )
Comments
Post a Comment