def _range_composer(edge, domain, es_query, to_float, schema): # USE RANGES _min = coalesce(domain.min, MIN(domain.partitions.min)) _max = coalesce(domain.max, MAX(domain.partitions.max)) if edge.allowNulls: missing_filter = set_default( { "filter": NotOp("not", AndOp("and", [ edge.value.exists(), InequalityOp("gte", [edge.value, Literal(None, to_float(_min))]), InequalityOp("lt", [edge.value, Literal(None, to_float(_max))]) ]).partial_eval()).to_esfilter(schema) }, es_query ) else: missing_filter = None if isinstance(edge.value, Variable): calc = {"field": schema.leaves(edge.value.var)[0].es_column} else: calc = {"script": edge.value.to_painless(schema).script(schema)} return wrap({"aggs": { "_match": set_default( {"range": calc}, {"range": {"ranges": [{"from": to_float(p.min), "to": to_float(p.max)} for p in domain.partitions]}}, es_query ), "_missing": missing_filter }})
def append_query(self, query_path, es_query): edge = self.edge range = edge.range domain = edge.domain aggs = Aggs() for i, p in enumerate(domain.partitions): filter_ = AndOp("and", [ InequalityOp("lte", [range.min, Literal("literal", self.to_float(p.min))]), InequalityOp("gt", [range.max, Literal("literal", self.to_float(p.min))]) ]) aggs.add(FilterAggs("_match" + text_type(i), filter_, self).add(es_query)) return aggs
def append_query(self, es_query, start): self.start = start edge = self.edge range = edge.range domain = edge.domain aggs = {} for i, p in enumerate(domain.partitions): filter_ = AndOp("and", [ InequalityOp("lte", [range.min, Literal("literal", self.to_float(p.min))]), InequalityOp("gt", [range.max, Literal("literal", self.to_float(p.min))]) ]) aggs["_join_" + text_type(i)] = set_default( {"filter": filter_.to_esfilter(self.schema)}, es_query ) return wrap({"aggs": aggs})
def _range_composer(self, edge, domain, es_query, to_float, schema): # USE RANGES _min = coalesce(domain.min, MIN(domain.partitions.min)) _max = coalesce(domain.max, MAX(domain.partitions.max)) output = Aggs() if edge.allowNulls: output.add(FilterAggs( "_missing", NotOp("not", AndOp("and", [ edge.value.exists(), InequalityOp("gte", [edge.value, Literal(None, to_float(_min))]), InequalityOp("lt", [edge.value, Literal(None, to_float(_max))]) ]).partial_eval()), self ).add(es_query)) if isinstance(edge.value, Variable): calc = {"field": first(schema.leaves(edge.value.var)).es_column} else: calc = {"script": edge.value.to_es_script(schema).script(schema)} calc['ranges'] = [{"from": to_float(p.min), "to": to_float(p.max)} for p in domain.partitions] return output.add(RangeAggs("_match", calc, self).add(es_query))