Github user kaspersorensen commented on a diff in the pull request:
https://github.com/apache/metamodel/pull/34#discussion_r36036345
--- Diff: core/src/main/java/org/apache/metamodel/query/FunctionType.java
---
@@ -18,105 +18,22 @@
*/
package org.apache.metamodel.query;
-import org.apache.metamodel.schema.Column;
-import org.apache.metamodel.schema.ColumnType;
import org.apache.metamodel.util.AggregateBuilder;
/**
- * Represents an aggregate function to use in a SelectItem.
- *
+ * Represents a generic function to use in a SelectItem.
+ *
* @see SelectItem
- */
-public enum FunctionType {
-
- COUNT {
- @Override
- public AggregateBuilder<Long> build() {
- return new CountAggregateBuilder();
- }
- },
- AVG {
- @Override
- public AggregateBuilder<Double> build() {
- return new AverageAggregateBuilder();
- }
- },
- SUM {
- @Override
- public AggregateBuilder<Double> build() {
- return new SumAggregateBuilder();
- }
- },
- MAX {
- @Override
- public AggregateBuilder<Object> build() {
- return new MaxAggregateBuilder();
- }
- },
- MIN {
- @Override
- public AggregateBuilder<Object> build() {
- return new MinAggregateBuilder();
- }
- };
-
- public ColumnType getExpectedColumnType(ColumnType type) {
- switch (this) {
- case COUNT:
- return ColumnType.BIGINT;
- case AVG:
- case SUM:
- return ColumnType.DOUBLE;
- case MAX:
- case MIN:
- return type;
- default:
- return type;
- }
- }
-
- public SelectItem createSelectItem(Column column) {
- return new SelectItem(this, column);
- }
-
- public SelectItem createSelectItem(String expression, String alias) {
- return new SelectItem(this, expression, alias);
- }
-
- public Object evaluate(Iterable<?> values) {
- AggregateBuilder<?> builder = build();
- for (Object object : values) {
- builder.add(object);
- }
- return builder.getAggregate();
- }
+*/
+public interface FunctionType extends Function {
- /**
- * Executes the function
- *
- * @param values
- * the values to be evaluated. If a value is null it won't
be
- * evaluated
- * @return the result of the function execution. The return type class
is
- * dependent on the FunctionType and the values provided. COUNT
- * yields a Long, AVG and SUM yields Double values and MAX and
MIN
- * yields the type of the provided values.
- */
- public Object evaluate(Object... values) {
- AggregateBuilder<?> builder = build();
- for (Object object : values) {
- builder.add(object);
- }
- return builder.getAggregate();
- }
+ public static final AggregateFunction COUNT = new
CountAggregateFunction();
+ public static final AggregateFunction AVG = new
AverageAggregateFunction();
+ public static final AggregateFunction SUM = new SumAggregateFunction();
+ public static final AggregateFunction MAX = new MaxAggregateFunction();
+ public static final AggregateFunction MIN = new MinAggregateFunction();
- public abstract AggregateBuilder<?> build();
+ public AggregateBuilder<?> build();
--- End diff --
I think this method is implementation oriented and should maybe then be
kept out of the interface. Or else the evaluate method should - they kinda
serve the same purpose.
And they are both aggregation function oriented so none of them should be
here but if anywhere in the AggregateFunction interface.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---