我创建了一个Jython查询,该查询从redshift表中返回信息:
cursor = context.cursor()
cursor.execute('WITH t1 as (SELECT date, partner AS partner,
revenue AS revenue, avg(revenue)OVER (partition BY
partner ORDER BY date ROWS BETWEEN 7 preceding AND 1 PRECEDING) as
"7-day avg"FROM (SELECT date, partner, sum(revenue) as
revenue FROM data.base GROUP BY date,
partner))SELECT * FROM t1 WHERE date = CURRENT_DATE - 1 ORDER BY
revenue DESC')
然后:
for item in cursor.fetchall():
print item
返回:
(datetime.date(2018, 9, 4), u'Disney', 458.171787, 487.70715842857)
(datetime.date(2018, 9, 4), u'Amazon', 142.33, 741.864285714284)
(datetime.date(2018, 9, 4), u'Google', 82.26, 83.510000000002)
我遇到麻烦的地方是将其变成易于阅读的表格,可以通过SES通过电子邮件发送出去。理想情况下,最终版本应类似于:
| Date | Partner | Revenue | Avg |
|------------|---------|---------|--------|
| 2018-09-04 | Disney | 458.17 | 487.71 |
| 2018-09-04 | Amazon | 142.33 | 741.86 |
| 2018-09-04 | Google | 82.26 | 83.51 |
另一个限制因素是我没有安装软件包的权限,因此我只能使用基本的Jython或Python。
答案 0 :(得分:0)
这是我如何获得所需格式的方法:
//global
auto mymutex = std::mutex{};
std::future<std::vector<double>> EMX_Counter::getEmxEfficiency() {
return std::async([=]() {
std::vector<double> temp;
std::for_each(std::execution::par, WiresList.begin(), WiresList.end(), [&](auto& PolyObject) {
//your code...
auto lock = std::lock_guard<std::mutex>{ mymutex };
temp.push_back( result );
});
return temp;
});
}