def _normalize_select_no_context(select, schema=None): """ SAME NORMALIZE, BUT NO SOURCE OF COLUMNS """ if is_text(select): select = Data(value=select) else: select = to_data(select) output = select.copy() if not select.value: output.name = coalesce(select.name, select.aggregate) if output.name: output.value = jx_expression(".", schema=schema) elif len(select): Log.error(BAD_SELECT, select=select) else: return Null elif is_text(select.value): if select.value.endswith(".*"): name = select.value[:-2].lstrip(".") output.name = coalesce(select.name, name) output.value = LeavesOp(Variable(name), prefix=coalesce(select.prefix, name)) else: if select.value == ".": output.name = coalesce(select.name, select.aggregate, ".") output.value = jx_expression(select.value, schema=schema) elif select.value == "*": output.name = coalesce(select.name, select.aggregate, ".") output.value = LeavesOp(Variable(".")) else: output.name = coalesce(select.name, select.value.lstrip("."), select.aggregate) output.value = jx_expression(select.value, schema=schema) elif is_number(output.value): if not output.name: output.name = text(output.value) output.value = jx_expression(select.value, schema=schema) else: output.value = jx_expression(select.value, schema=schema) if not output.name: Log.error("expecting select to have a name: {{select}}", select=select) if output.name.endswith(".*"): Log.error("{{name|quote}} is invalid select", name=output.name) output.aggregate = coalesce(canonical_aggregates[select.aggregate].name, select.aggregate, "none") output.default = coalesce(select.default, canonical_aggregates[output.aggregate].default) return output
def define(cls, expr): term = expr.between if is_sequence(term): return cls.lang[BetweenOp( value=jx_expression(term[0]), prefix=jx_expression(term[1]), suffix=jx_expression(term[2]), default=jx_expression(expr.default), start=jx_expression(expr.start), )] elif is_data(term): var, vals = term.items()[0] if is_sequence(vals) and len(vals) == 2: return cls.lang[BetweenOp( value=Variable(var), prefix=Literal(vals[0]), suffix=Literal(vals[1]), default=jx_expression(expr.default), start=jx_expression(expr.start), )] else: Log.error( "`between` parameters are expected to be in {var: [prefix, suffix]} form" ) else: Log.error( "`between` parameters are expected to be in {var: [prefix, suffix]} form" )
def __data__(self): output = [{"name": f, "value": Variable(f)} for f in self.fields] if self.get_source: output = [default_select] for n, e in self.scripts.items(): output.append({"name": n, "value": e}) return output
def define(cls, expr): term = expr.get('prefix') if not term: return PrefixOp(NULL, NULL) elif is_data(term): expr, const = first(term.items()) return PrefixOp(Variable(expr), Literal(const)) else: return PrefixOp(*term)
def __new__(cls, terms): if is_many(terms): return object.__new__(cls) items = terms.items() if len(items) == 1: if is_many(items[0][1]): return cls.lang[InOp(items[0])] else: return cls.lang[EqOp(items[0])] else: acc = [] for lhs, rhs in items: if rhs.json.startswith("["): acc.append(cls.lang[InOp([Variable(lhs), rhs])]) else: acc.append(cls.lang[EqOp([Variable(lhs), rhs])]) return cls.lang[AndOp(acc)]
def define(cls, expr): term = expr.get("prefix") if not term: return PrefixOp(NULL, NULL) elif is_data(term): expr, const = first(term.items()) return PrefixOp(Variable(expr), Literal(const)) else: expr, const = term return PrefixOp(jx_expression(expr), jx_expression(const))
def define(cls, expr): terms = expr["concat"] if is_data(terms): k, v = first(terms.items()) terms = [Variable(k), Literal(v)] else: terms = [jx_expression(t) for t in terms] return ConcatOp( terms, **{ k: Literal(v) if is_text(v) and not is_variable_name(v) else jx_expression(v) for k, v in expr.items() if k in ["default", "separator"] })
def vars(self): output = set(Variable(f) for f in self.fields) for e in self.scripts.values(): output |= e.vars() return output
def _normalize_group(edge, dim_index, limit, schema=None): """ :param edge: Not normalized groupby :param dim_index: Dimensions are ordered; this is this groupby's index into that order :param schema: for context :return: a normalized groupby """ if is_text(edge): if edge.endswith(".*"): prefix = edge[:-2] if schema: output = list_to_data([ { # BECASUE THIS IS A GROUPBY, EARLY SPLIT INTO LEAVES WORKS JUST FINE "name": concat_field( prefix, literal_field( relative_field(untype_path(c.name), prefix))), "put": { "name": literal_field(untype_path(c.name)) }, "value": jx_expression(c.es_column, schema=schema), "allowNulls": True, "domain": { "type": "default" } } for c in schema.leaves(prefix) ]) return output else: return list_to_data([{ "name": untype_path(prefix), "put": { "name": literal_field(untype_path(prefix)) }, "value": LeavesOp(Variable(prefix)), "allowNulls": True, "dim": dim_index, "domain": { "type": "default" } }]) return list_to_data([{ "name": edge, "value": jx_expression(edge, schema=schema), "allowNulls": True, "dim": dim_index, "domain": Domain(type="default", limit=limit) }]) else: edge = to_data(edge) if (edge.domain and edge.domain.type != "default"): Log.error("groupby does not accept complicated domains") if not edge.name and not is_text(edge.value): Log.error("You must name compound edges: {{edge}}", edge=edge) return list_to_data([{ "name": coalesce(edge.name, edge.value), "value": jx_expression(edge.value, schema=schema), "allowNulls": True, "dim": dim_index, "domain": { "type": "default" } }])