es-monitor icon indicating copy to clipboard operation
es-monitor copied to clipboard

是否支持sum(a)/sum(b)

Open hexsum opened this issue 7 years ago • 1 comments

是否支持 seletc sum(a)/sum(b) 这种聚合后结果相除的sql表达式呢

我知道es的bucket_script应该可以写出来 但是不知道sql的方式是否可以 看中文文档例子里没有涉及

hexsum avatar May 28 '17 01:05 hexsum

https://github.com/taowen/es-monitor/blob/master/es_sql/tests/select_inside_branch/projection_test.py

    def test_bucket_script(self):
        executor = es_query.create_executor([
            "WITH all_estimate AS (SELECT err_count/total_count AS err_rate, COUNT(*) AS total_count "
            "FROM gs_plutus_debug GROUP BY req.district)",
            "WITH err AS (SELECT COUNT(*) AS err_count FROM all_estimate WHERE errno>0)"])
        self.assertEqual(
                {'aggs': {'req.district': {
                    'terms': {'field': 'req.district', 'size': 0},
                    'aggs': {'err': {'filter': {'range': {u'errno': {'gt': 0}}}, 'aggs': {}},
                             u'err_rate': {'bucket_script': {
                                 'buckets_path': {u'total_count': '_count',
                                                  u'err_count': 'err._count'},
                                 'script': {'lang': 'expression',
                                            'inline': u'err_count/total_count'}}}}}}, 'size': 0},
                executor.request)

taowen avatar Jun 01 '17 02:06 taowen