python3
This commit is contained in:
Родитель
290df11f29
Коммит
4a846689ee
|
@ -138,7 +138,7 @@ class Dimension(object):
|
|||
def edges2value(*values):
|
||||
if isinstance(fields, Mapping):
|
||||
output = Data()
|
||||
for e, v in zip(edges, values):
|
||||
for e, v in transpose(edges, values):
|
||||
output[e.name] = v
|
||||
return output
|
||||
else:
|
||||
|
|
|
@ -172,9 +172,9 @@ class _MVEL(object):
|
|||
if len(split_field(self.fromData.name)) == 1 and fields:
|
||||
if isinstance(fields, Mapping):
|
||||
# CONVERT UNORDERED FIELD DEFS
|
||||
jx_fields, es_fields = zip(*[(k, fields[k]) for k in sorted(fields.keys())])
|
||||
jx_fields, es_fields = transpose(*[(k, fields[k]) for k in sorted(fields.keys())])
|
||||
else:
|
||||
jx_fields, es_fields = zip(*[(i, e) for i, e in enumerate(fields)])
|
||||
jx_fields, es_fields = transpose(*[(i, e) for i, e in enumerate(fields)])
|
||||
|
||||
# NO LOOPS BECAUSE QUERY IS SHALLOW
|
||||
# DOMAIN IS FROM A DIMENSION, USE IT'S FIELD DEFS TO PULL
|
||||
|
|
|
@ -175,7 +175,7 @@ def es_setop(es, mvel, query):
|
|||
if not data_list:
|
||||
cube = Cube(select, [], {s.name: Matrix.wrap([]) for s in select})
|
||||
else:
|
||||
output = zip(*data_list)
|
||||
output = transpose(*data_list)
|
||||
cube = Cube(select, [], {s.name: Matrix(list=output[i]) for i, s in enumerate(select)})
|
||||
|
||||
return Data(
|
||||
|
@ -221,7 +221,7 @@ def es_deepop(es, mvel, query):
|
|||
data = es_post(es, FromES, query.limit)
|
||||
|
||||
rows = unpack_terms(data.facets.mvel, query.edges)
|
||||
terms = zip(*rows)
|
||||
terms = transpose(*rows)
|
||||
|
||||
# NUMBER ALL EDGES FOR JSON EXPRESSION INDEXING
|
||||
edges = query.edges
|
||||
|
|
|
@ -159,7 +159,7 @@ class SetDecoder(AggsDecoder):
|
|||
domain = self.domain
|
||||
|
||||
domain_key = domain.key
|
||||
include, text_include = zip(*(
|
||||
include, text_include = transpose(*(
|
||||
(
|
||||
float(v) if isinstance(v, (int, float)) else v,
|
||||
text_type(float(v)) if isinstance(v, (int, float)) else v
|
||||
|
@ -497,7 +497,7 @@ class ObjectDecoder(AggsDecoder):
|
|||
prefix = edge.value.var
|
||||
flatter = lambda k: relative_field(k, prefix)
|
||||
|
||||
self.put, self.fields = zip(*[
|
||||
self.put, self.fields = transpose(*[
|
||||
(flatter(untype_path(c.names["."])), c.es_column)
|
||||
for c in query.frum.schema.leaves(prefix)
|
||||
])
|
||||
|
|
|
@ -328,7 +328,7 @@ def format_cube(T, select, query=None):
|
|||
data={h: Matrix(list=[]) for i, h in enumerate(table.header)}
|
||||
)
|
||||
|
||||
cols = zip(*unwrap(table.data))
|
||||
cols = transpose(*unwrap(table.data))
|
||||
return Cube(
|
||||
select,
|
||||
edges=[{"name": "rownum", "domain": {"type": "rownum", "min": 0, "max": len(table.data), "interval": 1}}],
|
||||
|
|
|
@ -22,7 +22,7 @@ from jx_elasticsearch.es52.expressions import Variable, NotOp, InOp, Literal, An
|
|||
from jx_elasticsearch.es52.util import es_missing
|
||||
from jx_python import jx
|
||||
from mo_dots import wrap, set_default, coalesce, literal_field, Data, relative_field, unwraplist
|
||||
from mo_future import text_type
|
||||
from mo_future import text_type, transpose
|
||||
from mo_json.typed_encoder import untype_path
|
||||
from mo_logs import Log
|
||||
from mo_logs.strings import quote, expand_template
|
||||
|
@ -161,7 +161,7 @@ class SetDecoder(AggsDecoder):
|
|||
domain = self.domain
|
||||
|
||||
domain_key = domain.key
|
||||
include, text_include = zip(*(
|
||||
include, text_include = transpose(*(
|
||||
(
|
||||
float(v) if isinstance(v, (int, float)) else v,
|
||||
text_type(float(v)) if isinstance(v, (int, float)) else v
|
||||
|
@ -502,7 +502,7 @@ class ObjectDecoder(AggsDecoder):
|
|||
prefix = edge.value.var
|
||||
flatter = lambda k: relative_field(k, prefix)
|
||||
|
||||
self.put, self.fields = zip(*[
|
||||
self.put, self.fields = transpose(*[
|
||||
(flatter(untype_path(c.names["."])), c.es_column)
|
||||
for c in query.frum.schema.leaves(prefix)
|
||||
])
|
||||
|
@ -562,7 +562,7 @@ class ObjectDecoder(AggsDecoder):
|
|||
return None
|
||||
|
||||
output = Data()
|
||||
for k, v in zip(self.put, part):
|
||||
for k, v in transpose(self.put, part):
|
||||
output[k] = v.get('key')
|
||||
return output
|
||||
|
||||
|
|
|
@ -327,7 +327,7 @@ def format_cube(T, select, query=None):
|
|||
data={h: Matrix(list=[]) for i, h in enumerate(table.header)}
|
||||
)
|
||||
|
||||
cols = zip(*unwrap(table.data))
|
||||
cols = transpose(*unwrap(table.data))
|
||||
return Cube(
|
||||
select,
|
||||
edges=[{"name": "rownum", "domain": {"type": "rownum", "min": 0, "max": len(table.data), "interval": 1}}],
|
||||
|
|
|
@ -322,16 +322,16 @@ class Cube(Container):
|
|||
|
||||
if isinstance(self.select, list):
|
||||
selects = listwrap(self.select)
|
||||
index, v = zip(*self.data[selects[0].name].groupby(selector))
|
||||
index, v = transpose(*self.data[selects[0].name].groupby(selector))
|
||||
|
||||
coord = wrap([coord2term(c) for c in index])
|
||||
|
||||
values = [v]
|
||||
for s in selects[1::]:
|
||||
i, v = zip(*self.data[s.name].group_by(selector))
|
||||
i, v = transpose(*self.data[s.name].group_by(selector))
|
||||
values.append(v)
|
||||
|
||||
output = zip(coord, [Cube(self.select, remainder, {s.name: v[i] for i, s in enumerate(selects)}) for v in zip(*values)])
|
||||
output = transpose(coord, [Cube(self.select, remainder, {s.name: v[i] for i, s in enumerate(selects)}) for v in zip(*values)])
|
||||
elif not remainder:
|
||||
# v IS A VALUE, NO NEED TO WRAP IT IN A Cube
|
||||
output = (
|
||||
|
@ -377,7 +377,7 @@ class Cube(Container):
|
|||
|
||||
if isinstance(self.select, list):
|
||||
selects = listwrap(self.select)
|
||||
index, v = zip(*self.data[selects[0].name].groupby(selector))
|
||||
index, v = transpose(*self.data[selects[0].name].groupby(selector))
|
||||
|
||||
coord = wrap([coord2term(c) for c in index])
|
||||
|
||||
|
@ -386,7 +386,7 @@ class Cube(Container):
|
|||
i, v = zip(*self.data[s.name].group_by(selector))
|
||||
values.append(v)
|
||||
|
||||
output = zip(coord, [Cube(self.select, remainder, {s.name: v[i] for i, s in enumerate(selects)}) for v in zip(*values)])
|
||||
output = transpose(coord, [Cube(self.select, remainder, {s.name: v[i] for i, s in enumerate(selects)}) for v in zip(*values)])
|
||||
elif not remainder:
|
||||
# v IS A VALUE, NO NEED TO WRAP IT IN A Cube
|
||||
output = (
|
||||
|
|
|
@ -335,18 +335,18 @@ def _getitem(c, i):
|
|||
return (len(c), ), c
|
||||
elif isinstance(select, slice):
|
||||
sub = c[select]
|
||||
dims, cube = zip(*[_getitem(cc, i[1::]) for cc in sub])
|
||||
dims, cube = transpose(*[_getitem(cc, i[1::]) for cc in sub])
|
||||
return (len(cube),) + dims[0], cube
|
||||
else:
|
||||
return (), c[select]
|
||||
else:
|
||||
select = i[0]
|
||||
if select == None:
|
||||
dims, cube = zip(*[_getitem(cc, i[1::]) for cc in c])
|
||||
dims, cube = transpose(*[_getitem(cc, i[1::]) for cc in c])
|
||||
return (len(cube),)+dims[0], cube
|
||||
elif isinstance(select, slice):
|
||||
sub = c[select]
|
||||
dims, cube = zip(*[_getitem(cc, i[1::]) for cc in sub])
|
||||
dims, cube = transpose(*[_getitem(cc, i[1::]) for cc in sub])
|
||||
return (len(cube),)+dims[0], cube
|
||||
else:
|
||||
with suppress_exception:
|
||||
|
|
|
@ -187,7 +187,7 @@ def tab(value):
|
|||
:return:
|
||||
"""
|
||||
if isinstance(value, Mapping):
|
||||
h, d = zip(*wrap(value).leaves())
|
||||
h, d = transpose(*wrap(value).leaves())
|
||||
return (
|
||||
"\t".join(map(value2json, h)) +
|
||||
"\n" +
|
||||
|
|
|
@ -308,7 +308,7 @@ class MySQL(object):
|
|||
self.cursor.execute(sql)
|
||||
grid = [[utf8_to_unicode(c) for c in row] for row in self.cursor]
|
||||
# columns = [utf8_to_unicode(d[0]) for d in coalesce(self.cursor.description, [])]
|
||||
result = zip(*grid)
|
||||
result = transpose(*grid)
|
||||
|
||||
if not old_cursor: # CLEANUP AFTER NON-TRANSACTIONAL READS
|
||||
self.cursor.close()
|
||||
|
|
Загрузка…
Ссылка в новой задаче