
package org.apache.calcite.sql.fun;

import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.rel.type.RelDataTypeFactory;
import org.apache.calcite.sql.SqlAggFunction;
import org.apache.calcite.sql.SqlFunctionCategory;
import org.apache.calcite.sql.SqlKind;
import org.apache.calcite.sql.type.OperandTypes;
import org.apache.calcite.sql.type.ReturnTypes;

import com.google.common.collect.ImmutableList;

import java.util.List;

/**
 * <code>HistogramAgg</code> is base operator which supports the Histogram
 * MIN/MAX aggregatoin functions. which returns the sum of the values which go
 * into it. It has precisely one argument of numeric type (<code>int</code>,
 * <code>long</code>, <code>float</code>, <code>double</code>) results are
 * retrived with (<code>HistogramMin</code>) and (<code>HistogramMax</code>)
 */
public class SqlHistogramAggFunction extends SqlAggFunction {
  //~ Instance fields --------------------------------------------------------

  private final RelDataType type;

  //~ Constructors -----------------------------------------------------------

  public SqlHistogramAggFunction(RelDataType type) {
    super(
        "$HISTOGRAM",
        null,
        SqlKind.OTHER_FUNCTION,
        ReturnTypes.HISTOGRAM,
        null,
        OperandTypes.NUMERIC_OR_STRING,
        SqlFunctionCategory.NUMERIC,
        false,
        false);
    this.type = type;
  }

  //~ Methods ----------------------------------------------------------------

  public List<RelDataType> getParameterTypes(RelDataTypeFactory typeFactory) {
    return ImmutableList.of(type);
  }

  public RelDataType getType() {
    return type;
  }

  public RelDataType getReturnType(RelDataTypeFactory typeFactory) {
    return type;
  }
}

// End SqlHistogramAggFunction.java
