@Override public ValueLong asLong() { return orig.asLong(); }
@Override public Numeric min(Numeric val) { if (val.asLong().getLong() < toLong()) { return val; } else { return this; } }
private long getBitValue(ValueObject value) { long ret = ValueUtil.asNumberOrParseLong(value, radix).asLong().getLong(); if (filterMask != 0 && (ret & filterMask) == filterMask) { return 0; } if (matchMask != 0 && (ret & matchMask) != matchMask) { return ret; } return ret; }
@Override public Numeric max(Numeric val) { if (val.asLong().getLong() > toLong()) { return val; } else { return this; } }
@Override public ValueObject filterValue(ValueObject value) { if (value == null) { return value; } try { Numeric num; if (!inDouble) { num = ValueUtil.asNumberOrParseLong(value, in); } else { num = ValueUtil.asNumberOrParseDouble(value); } if (outAsLong) { return num.asLong(); } else { return ValueFactory.create(Long.toString(num.asLong().getLong(), out)); } } catch (Exception ex) { log.warn("", ex); return value; } }
/** * @param s1 * @param s2 * @return */ private int longCompare(ValueObject s1, ValueObject s2) { if (s1 == s2) { return 0; } if (s1 == null) { return 1; } if (s2 == null) { return -1; } return Long.compare(ValueUtil.asNumberOrParseLong(s1, 10).asLong().getLong(), ValueUtil.asNumberOrParseLong(s2, 10).asLong().getLong()); }
@Override public ValueObject filterValue(ValueObject value) { Numeric lv = ValueUtil.asNumberOrParse(value); if (lv != null) { long v = lv.asLong().getLong(); if (abs) { v = Math.abs(v); } return ValueFactory.create(v % mod); } return value; } }
/** * @param s1 * @param s2 * @return */ private static int longCompare(ValueObject s1, ValueObject s2) { if (s1 == s2) { return 0; } if (s1 == null) { return 1; } if (s2 == null) { return -1; } return Long.compare(ValueUtil.asNumberOrParseLong(s1, 10).asLong().getLong(), ValueUtil.asNumberOrParseLong(s2, 10).asLong().getLong()); }
@Override public Numeric sum(Numeric val) { try { if (val.getClass() == LCValue.class) { return new LCValue(heldObject.merge(((LCValue) val).heldObject)); } } catch (Exception e) { throw new RuntimeException(e); } return asLong().sum(val.asLong()); }
@Override public Numeric diff(Numeric val) { return sum(val).asLong().diff(asLong()); }
@Override public Numeric sum(Numeric val) { if (TDigestValue.class == val.getClass()) { return new TDigestValue(TDigest.merge(heldObject.compression(), Arrays.asList(this.heldObject, ((TDigestValue) val).heldObject)), op, quantile); } return asLong().sum(val.asLong()); }
@Override public Numeric prod(Numeric val) { return sum(val).asLong().prod(asLong()); }
@Override public Numeric divide(Numeric val) { return sum(val).asLong().divide(asLong()); }
private void update(ValueObject value) { histogram.update(ValueUtil.asNumberOrParseLong(value, 10).asLong().getLong()); }
@Override public boolean updateChildData(DataTreeNodeUpdater state, DataTreeNode tn, Config conf) { Bundle p = state.getBundle(); if (keyAccess == null) { keyAccess = p.getFormat().getField(conf.key); } long packetTime = ValueUtil.asNumberOrParseLong(p.getValue(keyAccess), 10).asLong().getLong(); first = Math.min(first, packetTime); last = Math.max(last, packetTime); return true; }
public long toUnix(ValueObject val) { if (radix > 0) { Numeric num = ValueUtil.asNumberOrParseLong(val, radix); return num != null ? num.asLong().getLong() : JitterClock.globalTime(); } else { try { return formatter.parseDateTime(ValueUtil.asNativeString(val)).getMillis(); } catch (IllegalArgumentException e) { log.warn("unable to parse date time for val starting with : " + LessStrings.printable(LessStrings.trunc(ValueUtil.asNativeString(val), 256))); return -1; } } }
@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 Bundle rowOp(Bundle row) { if (binder == null) { binder = getSourceColumnBinder(row); rowFactory = row.createBundle(); } histo.update(0, ValueUtil.asNumberOrParse(binder.getColumn(row, column)).asLong().getLong()); return null; }
@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; } }
@Test public void testMerge() { TDigest t1 = new TDigest(100); TDigest t2 = new TDigest(100); t1.add(2); t1.add(4); t1.add(6); t1.add(8); t1.add(10); t2.add(1); t2.add(3); t2.add(5); t2.add(7); t2.add(9); DataTDigest.TDigestValue v1 = new DataTDigest.TDigestValue(t1, DataTDigest.TDigestValue.OP.QUANTILE, 0.90); DataTDigest.TDigestValue v2 = new DataTDigest.TDigestValue(t2, DataTDigest.TDigestValue.OP.QUANTILE, 0.90); assertEquals(8, v1.sum(v2).asLong().getLong()); assertEquals(8, v2.sum(v1).asLong().getLong()); }