How to use the translators.bucket_script_translator function in translators

To help you get started, we’ve selected a few translators examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github taowen / es-monitor / executors / select_from_all_buckets_executor.py View on Github external
def build_sibling_pipeline_aggs(self):
        sibling_pipeline_aggs = {}
        for projection_name, projection in self.sql_select.projections.iteritems():
            if not isinstance(projection, stypes.Function):
                raise Exception('unexpected: %s' % repr(projection))
            params = projection.get_parameters()
            sql_func_name = projection.get_name().upper()
            if sql_func_name in FUNC_NAMES:
                inner_most = self.sql_select.inner_most
                projection = inner_most.projections.get(params[0].get_name())
                bucket_key = '>'.join(inner_most.group_by.keys())
                metric_name = '_count' if bucket_script_translator.is_count_star(projection) else projection.get_name()
                if not bucket_key:
                    raise Exception('select from all buckets must nested with group by')
                buckets_path = '%s.%s' % (bucket_key, metric_name)
                sibling_pipeline_aggs[projection_name] = {
                    '%s_bucket' % sql_func_name.lower(): {'buckets_path': buckets_path}
                }
            else:
                raise Exception('unexpected: %s' % repr(projection))
        return sibling_pipeline_aggs
github taowen / es-monitor / executors / select_from_per_bucket_executor.py View on Github external
def __init__(self, sql_select, inner_executor):
        self.sql_select = sql_select
        self.inner_executor = inner_executor
        self.parent_pipeline_aggs = {}
        if sql_select.having:
            bucket_selector_agg = bucket_script_translator.translate_script(
                    sql_select, sql_select.having,
                    include_sub_aggregation=True)
            self.parent_pipeline_aggs['having'] = {'bucket_selector': bucket_selector_agg}
        for projection_name, projection in sql_select.projections.iteritems():
            if isinstance(projection, stypes.Function):
                sql_function_name = projection.tokens[0].get_name().lower()
                params = list(projection.get_parameters())
                buckets_path = params[0].value
                if 'serial_diff' == sql_function_name:
                    self.parent_pipeline_aggs[projection_name] = {
                        sql_function_name: {'buckets_path': buckets_path, 'lag': eval(params[1].value)}}
                elif 'moving_avg' == sql_function_name:
                    if len(params) == 2:
                        moving_avg = eval(eval(params[1].value))
                    else:
                        moving_avg = {}
github taowen / es-monitor / executors / select_from_all_buckets_executor.py View on Github external
def __init__(self, sql_select, inner_executor):
        self.sql_select = sql_select
        self.inner_executor = inner_executor
        self.sibling_pipeline_aggs = self.build_sibling_pipeline_aggs()
        if sql_select.where:
            bucket_selector_agg = bucket_script_translator.translate_script(
                    sql_select, sql_select.where.tokens[1:],
                    include_sub_aggregation=True)
            self.parent_pipeline_aggs = {'having': {'bucket_selector': bucket_selector_agg}}
        else:
            self.parent_pipeline_aggs = {}
github taowen / es-monitor / executors / select_from_per_bucket_executor.py View on Github external
sql_function_name: {'buckets_path': buckets_path, 'lag': eval(params[1].value)}}
                elif 'moving_avg' == sql_function_name:
                    if len(params) == 2:
                        moving_avg = eval(eval(params[1].value))
                    else:
                        moving_avg = {}
                    moving_avg['buckets_path'] = buckets_path
                    self.parent_pipeline_aggs[projection_name] = {sql_function_name: moving_avg}
                else:
                    self.parent_pipeline_aggs[projection_name] = {
                        sql_function_name: {'buckets_path': buckets_path}}
            else:
                tokens = projection.tokens
                if isinstance(tokens[0], stypes.Parenthesis):
                    tokens = tokens[0].tokens[1:-1]
                bucket_script_agg = bucket_script_translator.translate_script(
                        sql_select, tokens,
                        include_sub_aggregation=True)
                self.parent_pipeline_aggs[projection_name] = {'bucket_script': bucket_script_agg}