@Override public Object compute(Map<String, Object> values) { Iterator<PostAggregator> fieldsIter = fields.iterator(); Double retVal = NullHandling.defaultDoubleValue(); if (fieldsIter.hasNext()) { Number nextVal = (Number) fieldsIter.next().compute(values); if (nextVal == null) { // As per SQL standard if any of the value is null, arithmetic operators will return null. return null; } retVal = nextVal.doubleValue(); while (fieldsIter.hasNext()) { nextVal = (Number) fieldsIter.next().compute(values); if (nextVal == null) { // As per SQL standard if any of the value is null, arithmetic operators will return null. return null; } retVal = op.compute(retVal, (nextVal).doubleValue()); } } return retVal; }
@JsonCreator public ArithmeticPostAggregator( @JsonProperty("name") String name, @JsonProperty("fn") String fnName, @JsonProperty("fields") List<PostAggregator> fields, @JsonProperty("ordering") String ordering ) { Preconditions.checkArgument(fnName != null, "fn cannot not be null"); Preconditions.checkArgument(fields != null && fields.size() > 1, "Illegal number of fields[%s], must be > 1"); this.name = name; this.fnName = fnName; this.fields = fields; this.op = Ops.lookup(fnName); if (op == null) { throw new IAE("Unknown operation[%s], known operations[%s]", fnName, Ops.getFns()); } this.ordering = ordering; this.comparator = ordering == null ? DEFAULT_COMPARATOR : Ordering.valueOf(ordering); }
@Override public int hashCode() { int result = name != null ? name.hashCode() : 0; result = 31 * result + fnName.hashCode(); result = 31 * result + fields.hashCode(); result = 31 * result + op.hashCode(); result = 31 * result + comparator.hashCode(); result = 31 * result + (ordering != null ? ordering.hashCode() : 0); return result; } }
@Override public Object compute(Map<String, Object> values) { Iterator<PostAggregator> fieldsIter = fields.iterator(); Double retVal = NullHandling.defaultDoubleValue(); if (fieldsIter.hasNext()) { Number nextVal = (Number) fieldsIter.next().compute(values); if (nextVal == null) { // As per SQL standard if any of the value is null, arithmetic operators will return null. return null; } retVal = nextVal.doubleValue(); while (fieldsIter.hasNext()) { nextVal = (Number) fieldsIter.next().compute(values); if (nextVal == null) { // As per SQL standard if any of the value is null, arithmetic operators will return null. return null; } retVal = op.compute(retVal, (nextVal).doubleValue()); } } return retVal; }
@JsonCreator public ArithmeticPostAggregator( @JsonProperty("name") String name, @JsonProperty("fn") String fnName, @JsonProperty("fields") List<PostAggregator> fields, @JsonProperty("ordering") String ordering ) { Preconditions.checkArgument(fnName != null, "fn cannot not be null"); Preconditions.checkArgument(fields != null && fields.size() > 1, "Illegal number of fields[%s], must be > 1"); this.name = name; this.fnName = fnName; this.fields = fields; this.op = Ops.lookup(fnName); if (op == null) { throw new IAE("Unknown operation[%s], known operations[%s]", fnName, Ops.getFns()); } this.ordering = ordering; this.comparator = ordering == null ? DEFAULT_COMPARATOR : Ordering.valueOf(ordering); }
@Override public int hashCode() { int result = name != null ? name.hashCode() : 0; result = 31 * result + fnName.hashCode(); result = 31 * result + fields.hashCode(); result = 31 * result + op.hashCode(); result = 31 * result + comparator.hashCode(); result = 31 * result + (ordering != null ? ordering.hashCode() : 0); return result; } }