Exemplo n.º 1
0
  public void initAggregateValue(final AggregateValue aggregateValue) throws HBqlException {

    switch (this.getFunctionType()) {
      case COUNT:
        {
          aggregateValue.setValue(0L);
          break;
        }

      case MIN:
      case MAX:
        {
          break;
        }

      default:
        throw new InternalErrorException("Invalid aggregate function: " + this.getFunctionType());
    }
  }
Exemplo n.º 2
0
  public void applyResultToAggregateValue(final AggregateValue aggVal, final Result result)
      throws HBqlException, ResultMissingColumnException, NullColumnValueException {

    switch (this.getFunctionType()) {
      case COUNT:
        {
          final long currval = (Long) aggVal.getCurrentValue();
          aggVal.setValue(currval + 1);
          break;
        }

      case MIN:
        {
          final Number v1 = (Number) this.getExprArg(0).getValue(null, result);

          if (v1 instanceof Short) {
            final short val = v1.shortValue();
            aggVal.setValue(aggVal.isValueSet() ? Math.min(val, (Short) aggVal.getValue()) : val);
          } else if (v1 instanceof Integer) {
            final int val = v1.intValue();
            aggVal.setValue(aggVal.isValueSet() ? Math.min(val, (Integer) aggVal.getValue()) : val);
          } else if (v1 instanceof Long) {
            final long val = v1.longValue();
            aggVal.setValue(aggVal.isValueSet() ? Math.min(val, (Long) aggVal.getValue()) : val);
          } else if (v1 instanceof Float) {
            final float val = v1.floatValue();
            aggVal.setValue(aggVal.isValueSet() ? Math.min(val, (Float) aggVal.getValue()) : val);
          } else if (v1 instanceof Double) {
            final double val = v1.doubleValue();
            aggVal.setValue(aggVal.isValueSet() ? Math.min(val, (Double) aggVal.getValue()) : val);
          }
          break;
        }

      case MAX:
        {
          final Number v1 = (Number) this.getExprArg(0).getValue(null, result);

          if (v1 instanceof Short) {
            final short val = v1.shortValue();
            aggVal.setValue(aggVal.isValueSet() ? Math.max(val, (Short) aggVal.getValue()) : val);
          } else if (v1 instanceof Integer) {
            final int val = v1.intValue();
            aggVal.setValue(aggVal.isValueSet() ? Math.max(val, (Integer) aggVal.getValue()) : val);
          } else if (v1 instanceof Long) {
            final long val = v1.longValue();
            aggVal.setValue(aggVal.isValueSet() ? Math.max(val, (Long) aggVal.getValue()) : val);
          } else if (v1 instanceof Float) {
            final float val = v1.floatValue();
            aggVal.setValue(aggVal.isValueSet() ? Math.max(val, (Float) aggVal.getValue()) : val);
          } else if (v1 instanceof Double) {
            final double val = v1.doubleValue();
            aggVal.setValue(aggVal.isValueSet() ? Math.max(val, (Double) aggVal.getValue()) : val);
          }
          break;
        }

      default:
        throw new InternalErrorException("Invalid aggregate function: " + this.getFunctionType());
    }
  }