Ejemplo n.º 1
0
def agg_Avg(a, group, bindings):

    c = 0
    s = 0
    dt = None
    for x in group:
        try:
            e = _eval(a.vars, x)
            n = numeric(e)
            if dt == None:
                dt = e.datatype
            else:
                dt = type_promotion(dt, e.datatype)

            if type(s) == float and type(n) == Decimal:
                s += float(n)
            elif type(n) == float and type(s) == Decimal:
                s = float(s) + n
            else:
                s += n
            c += 1
        except:
            return  # error in aggregate => no binding

    if c == 0:
        bindings[a.res] = Literal(0)
    if dt == XSD.float or dt == XSD.double:
        bindings[a.res] = Literal(s / c)
    else:
        bindings[a.res] = Literal(Decimal(s) / Decimal(c))
Ejemplo n.º 2
0
def agg_Avg(a, group, bindings):

    c = 0
    s = 0
    dt = None
    for x in group:
        try:
            e = _eval(a.vars, x)
            n = numeric(e)
            if dt == None:
                dt = e.datatype
            else:
                dt = type_promotion(dt, e.datatype)

            if type(s) == float and type(n) == Decimal:
                s += float(n)
            elif type(n) == float and type(s) == Decimal:
                s = float(s) + n
            else:
                s += n
            c += 1
        except:
            return  # error in aggregate => no binding

    if c == 0:
        bindings[a.res] = Literal(0)
    if dt == XSD.float or dt == XSD.double:
        bindings[a.res] = Literal(s / c)
    else:
        bindings[a.res] = Literal(Decimal(s) / Decimal(c))
Ejemplo n.º 3
0
def agg_Sum(a, group, bindings):
    c = 0

    for x in group:
        try:
            c += numeric(_eval(a.vars, x))
        except:
            pass  # simply dont count

    bindings[a.res] = Literal(c)
Ejemplo n.º 4
0
def agg_Max(a, group, bindings):
    m = None

    for x in group:
        try:
            v = numeric(_eval(a.vars, x))
            if m is None:
                m = v
            else:
                m = num_max(v, m)
        except:
            return  # error in aggregate => no binding

    if m is not None:
        bindings[a.res] = Literal(m)
Ejemplo n.º 5
0
def agg_Avg(a, group, bindings):

    c = 0
    s = 0
    for x in group:
        try:
            s += numeric(_eval(a.vars, x))
            c += 1
        except:
            pass  # simply dont count

    if c == 0:
        bindings[a.res] = Literal(0)
    else:
        bindings[a.res] = Literal(Decimal(s) / Decimal(c))
Ejemplo n.º 6
0
def agg_Max(a, group, bindings):
    m = None

    for x in group:
        try:
            v = numeric(_eval(a.vars, x))
            if m is None:
                m = v
            else:
                m = max(v, m)
        except:
            pass  # simply dont count

    if m is not None:
        bindings[a.res] = Literal(m)
Ejemplo n.º 7
0
def agg_Max(a, group, bindings):
    m = None

    for x in group:
        try:
            v = numeric(_eval(a.vars, x))
            if m is None:
                m = v
            else:
                m = num_max(v, m)
        except:
            return  # error in aggregate => no binding

    if m is not None:
        bindings[a.res] = Literal(m)
Ejemplo n.º 8
0
def agg_Sum(a, group, bindings):
    c = 0

    dt = None
    for x in group:
        try:
            e = _eval(a.vars, x)
            n = numeric(e)
            if dt == None:
                dt = e.datatype
            else:
                dt = type_promotion(dt, e.datatype)

            if type(c) == float and type(n) == Decimal:
                c += float(n)
            elif type(n) == float and type(c) == Decimal:
                c = float(c) + n
            else:
                c += n
        except:
            pass  # simply dont count

    bindings[a.res] = Literal(c, datatype=dt)
Ejemplo n.º 9
0
def agg_Sum(a, group, bindings):
    c = 0

    dt = None
    for x in group:
        try:
            e = _eval(a.vars, x)
            n = numeric(e)
            if dt == None:
                dt = e.datatype
            else:
                dt = type_promotion(dt, e.datatype)

            if type(c) == float and type(n) == Decimal:
                c += float(n)
            elif type(n) == float and type(c) == Decimal:
                c = float(c) + n
            else:
                c += n
        except:
            pass  # simply dont count

    bindings[a.res] = Literal(c, datatype=dt)