コード例 #1
0
    'last': lambda x, y: y,
    'min': lambda x, y: x if x < y else y,
    'max': lambda x, y: x if x > y else y,
}

FullAggs = {
    'avg': (
        lambda v: (v, 1),
        lambda s_c, v: (s_c[0] + v, s_c[1] + 1),
        lambda x, y: (x[0] + y[0], x[1] + y[1]),
        lambda s_c: float(s_c[0]) / s_c[1],
    ),
    'count': (lambda v: 1 if v is not None else 0, lambda s, v: s +
              (1
               if v is not None else 0), lambda s1, s2: s1 + s2, lambda s: s),
    'adcount': (lambda v: HyperLogLog([v]), lambda s, v: s.add(v) or s,
                lambda s1, s2: s1.update(s2) or s1, lambda s: len(s)),
    'group_concat': (
        lambda v: [v],
        lambda s, v: s.append(v) or s,
        lambda s1, s2: s1.extend(s2) or s1,
        lambda s: ','.join(s),
    ),
    'top': (lambda v: HotCounter([v], 20), lambda s, v: s.add(v) or s,
            lambda s1, s2: s1.update(s2) or s1, lambda s: s.top(20)),
}

Aggs = dict(SimpleAggs)
Aggs.update(FullAggs)

Globals = {}
コード例 #2
0
ファイル: table.py プロジェクト: zxh1986123/dpark
FullAggs = {
    'avg': (
        lambda v: (v, 1),
        lambda s_c, v: (s_c[0] + v, s_c[1] + 1),
        lambda x, y: (x[0] + y[0], x[1] + y[1]),
        lambda s_c: float(s_c[0]) / s_c[1],
    ),
    'count': (
        lambda v: 1 if v is not None else 0,
        lambda s, v: s + (1 if v is not None else 0),
        lambda s1, s2: s1 + s2,
        lambda s: s
    ),
    'adcount': (
        lambda v: HyperLogLog([v]),
        lambda s, v: s.add(v) or s,
        lambda s1, s2: s1.update(s2) or s1,
        lambda s: len(s)
    ),
    'group_concat': (
        lambda v: [v],
        lambda s, v: s.append(v) or s,
        lambda s1, s2: s1.extend(s2) or s1,
        lambda s: ','.join(s),
    ),
    'top': (
        lambda v: HotCounter([v], 20),
        lambda s, v: s.add(v) or s,
        lambda s1, s2: s1.update(s2) or s1,
        lambda s: s.top(20)