@Override public ValueLong asLong() { return orig.asLong(); }
@Override public ValueDouble asDouble() { return orig.asDouble(); }
@Override public Numeric doMerge(Numeric nextValue, Numeric value) { return value.diff(nextValue); } }
private Numeric doOp(PivotOp op, Numeric accum, Numeric cell) { if (accum == null || cell == null) { //System.out.println("accum = " + accum + " cell = " + cell); return accum != null ? accum : cell; } if (op != null) { switch (op) { case SUM: return accum.sum(cell); case MIN: return accum.min(cell); case MAX: return accum.max(cell); case AVG: if (accum.getClass() != PivotAvg.class) { accum = new PivotAvg(accum); } return accum.sum(cell); } } return accum; }
v1 = stack.pop(); while (!stack.isEmpty()) { v1 = v1.sum(stack.pop()); stack.push(v1.sum(v2)); v1 = stack.pop(); v2 = stack.pop(); stack.push(v2.diff(v1)); break; case OP_MULT: { if (v1 == vector) { v1 = stack.pop(); long mult = v1.asLong().getLong(); while (!stack.isEmpty()) { mult *= stack.pop().asLong().getLong(); long mult = v1.asLong().getLong() * v2.asLong().getLong(); stack.push(ValueFactory.create(mult)); if (v1 == vector) { v1 = stack.pop(); double mult = v1.asDouble().getDouble(); while (!stack.isEmpty()) { mult *= stack.pop().asDouble().getDouble(); double mult = v1.asDouble().getDouble() * v2.asDouble().getDouble(); stack.push(ValueFactory.create(mult));
case DELTA: Numeric newval = toType(row.getValue(colIn[i])); state[i] = newval.diff(oldvals[i]); oldvals[i] = newval; break; case MIN: state[i] = toType(state[i].min(toType(row.getValue(colIn[i])))); break; case MAX: state[i] = toType(state[i].max(toType(row.getValue(colIn[i])))); break; case SUM: state[i] = state[i].sum(toType(row.getValue(colIn[i]))); break; case AVG: state[i] = toType(state[i].sum(toType(row.getValue(colIn[i])))); break; row.setValue(colOut[i], state[i].avg(rows)); } else { row.setValue(colOut[i], state[i]);
@Override public Bundle rowOp(Bundle row) { if (binder == null) { binder = getSourceColumnBinder(row); rowFactory = row.createBundle(); } Numeric value = ValueUtil.asNumberOrParse(binder.getColumn(row, column)); long increment; if (frequency >= 0) { Numeric incNumeric = ValueUtil.asNumberOrParseLong(binder.getColumn(row, frequency), 10); increment = (incNumeric != null) ? incNumeric.asLong().asNative() : 1; } else { increment = 1; } if (mode == Mode.FLOAT) { float target = (float) value.asDouble().getDouble(); int position = Arrays.binarySearch(keys, target); if (position < 0) position = ~position - 1; counts[position] += increment; } else { int target = (int) value.asLong().getLong(); int position = Arrays.binarySearch(keys, target); if (position < 0) position = ~position - 1; counts[position] += increment; } return null; }
@Override public Numeric doMerge(Numeric nextValue, Numeric value) { return value.sum(nextValue); } }
@Override public PivotAvg min(Numeric val) { ops++; orig = orig.min(val); return this; }
@Override protected Numeric doMerge(Numeric nextValue, Numeric value) { return value.max(nextValue); } }
@Override public Numeric avg(int count) { return orig.avg(ops); }
@Override public ValueString asString() { return orig.asString(); }
@Override public Numeric sum(Numeric val) { return new DataReservoirValue(asNative().merge((DataReservoir) val.asNative()), targetEpoch, numObservations, doubleToLongBits, raw, percentile, sigma, minMeasurement, mode); }
@Override public ValueObject filterValue(ValueObject value) { if (value == null) { return value; } try { Boolean res = false; if (rh != null) { long val = ValueUtil.asNumberOrParseLong(value, 10).asLong().getLong(); res = evalExpression(iop, val, rh); } else if (rhd != null) { double val = ValueUtil.asNumberOrParseDouble(value).asDouble().getDouble(); res = evalExpressionD(iop, val, rhd); } if (res) { return value; } else { return null; } } catch (Exception ex) { return value; } }
@Override public PivotAvg sum(Numeric val) { ops++; orig = orig.sum(val); return this; }
@Override public Numeric doMerge(Numeric nextValue, Numeric value) { return value.min(nextValue); } }
@Override public PivotAvg max(Numeric val) { ops++; orig = orig.max(val); return this; }
@Override public Numeric doEmit(Numeric value, MergedRow mergedRow) { return value.avg(mergedRow.getMergedCount()); } }
@Override public Numeric min(Numeric val) { if (val.asLong().getLong() < toLong()) { return val; } else { return this; } }
/** * @param s1 * @param s2 * @return */ private int doubleCompare(ValueObject s1, ValueObject s2) { if (s1 == s2) { return 0; } if (s1 == null) { return 1; } if (s2 == null) { return -1; } return Double.compare(ValueUtil.asNumberOrParseDouble(s1).asDouble().getDouble(), ValueUtil.asNumberOrParseDouble(s2).asDouble().getDouble()); }