Пример #1
0
  /**
   * Scales the given string array.
   *
   * @param values
   * @param length The resulting length
   * @return
   */
  private String[] getScaledValues(String[] values, int length) {

    // Init
    AggregateFunction<String> function =
        AggregateFunction.forType(DataType.STRING).createSetFunction();
    double factor = (double) length / (double) values.length;
    String[] result = new String[length];

    // Aggregate
    int previous = 0;
    List<String> toAggregate = new ArrayList<String>();
    for (int i = 0; i < values.length; i++) {

      checkInterrupt();

      int index = (int) Math.round((double) i * factor);
      index = index < length ? index : length - 1;

      if (index != previous) {
        result[previous] = function.aggregate(toAggregate.toArray(new String[toAggregate.size()]));
        toAggregate.clear();
        previous = index;
      }
      toAggregate.add(values[i]);
    }

    result[length - 1] = function.aggregate(toAggregate.toArray(new String[toAggregate.size()]));
    return result;
  }
Пример #2
0
  @Override
  public void visit(AggregateFunction obj) {
    if (!obj.getParameters().isEmpty()) {
      visitNodes(obj.getParameters());
    }

    if (obj.getName().equals(AggregateFunction.COUNT)) {
      HashMap<String, String> options = new HashMap<String, String>();
      options.put(CountStarIterator.ALIAS, this.currentAlias);
      options.put(CountStarIterator.ENCODING, this.ef.getEncoding());
      IteratorSetting it =
          new IteratorSetting(this.iteratorPriority++, CountStarIterator.class, options);

      // expression expects a column
      Column c = new Column();
      c.setName(this.currentAlias);
      c.setDatatype(
          SystemMetadata.getInstance()
              .getSystemStore()
              .getDatatypes()
              .get("integer")); // $NON-NLS-1$
      c.setProperty(AccumuloMetadataProcessor.CF, this.currentAlias);

      this.scanIterators.add(it);
      this.onGoingExpression.push(c);
    } else if (obj.getName().equals(AggregateFunction.AVG)) {
    } else if (obj.getName().equals(AggregateFunction.SUM)) {
    } else if (obj.getName().equals(AggregateFunction.MIN)) {
    } else if (obj.getName().equals(AggregateFunction.MAX)) {
    } else {
    }
  }
 /**
  * Creates a new instance. Snapping is disabled. Repetition is disabled. Bound is determined
  * dynamically.
  *
  * @param type
  */
 protected HierarchyBuilderIntervalBased(DataType<T> type) {
   super(Type.INTERVAL_BASED, type);
   if (!(type instanceof DataTypeWithRatioScale)) {
     throw new IllegalArgumentException("Data type must have a ratio scale");
   }
   this.lowerRange = new Range<T>(null, null, null);
   this.upperRange = new Range<T>(null, null, null);
   this.function = AggregateFunction.forType(type).createIntervalFunction();
 }
 @Override
 public String toString() {
   DataType<T> type = (DataType<T>) builder.getDataType();
   return "Interval[min="
       + type.format(min)
       + ", max="
       + type.format(max)
       + ", function="
       + function.toString()
       + "]";
 }
 /**
  * Creates a new instance. Min is inclusive, max is exclusive
  *
  * @param builder
  * @param type
  * @param min
  * @param max
  * @param function
  */
 private Interval(
     HierarchyBuilderGroupingBased<T> builder,
     DataType<T> type,
     T min,
     T max,
     AggregateFunction<T> function) {
   super(function.aggregate(new String[] {type.format(min), type.format(max)}));
   this.builder = builder;
   this.min = min;
   this.max = max;
   this.function = function;
   this.lower = false;
 }
 /**
  * Adds an interval. Min is inclusive, max is exclusive. Interval is labeled with the given string
  *
  * @param min
  * @param max
  * @param label
  * @return
  */
 public HierarchyBuilderIntervalBased<T> addInterval(T min, T max, String label) {
   if (label == null) {
     throw new IllegalArgumentException("Label must not be null");
   }
   checkInterval(getDataType(), min, max);
   this.intervals.add(
       new Interval<T>(
           this,
           getDataType(),
           min,
           max,
           AggregateFunction.forType(getDataType()).createConstantFunction(label)));
   this.setPrepared(false);
   return this;
 }