All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.codetaco.funnel.aggregation.Aggregate Maven / Gradle / Ivy

There is a newer version: 3.0.5
Show newest version
package com.codetaco.funnel.aggregation;

import com.codetaco.algebrain.Equ;
import com.codetaco.argument.annotation.Arg;
import com.codetaco.funnel.Funnel;
import com.codetaco.funnel.orderby.KeyPart;
import com.codetaco.funnel.parameters.FunnelContext;

/**
 * 

* Abstract Aggregate class. *

* * @author Chris DeGreef [email protected] */ abstract public class Aggregate { /** *

* aggregate. *

* * @param context a {@link com.codetaco.funnel.parameters.FunnelContext} * object. * @param originalRecordSize a int. * @param originalRecordNumber a long. * @throws java.lang.Exception if any. */ public static void aggregate(final FunnelContext context, final int originalRecordSize, final long originalRecordNumber) throws Exception { if (context.isAggregating()) { loadColumnsIntoAggregateEquations(context, originalRecordSize, originalRecordNumber); for (final Aggregate agg : context.getAggregates()) { agg.update(context); } } } private static void loadColumnsIntoAggregateEquations(final FunnelContext context, final int originalRecordSize, final long originalRecordNumber) throws Exception { for (final Aggregate agg : context.getAggregates()) { if (agg.equation != null) { for (final KeyPart col : context.columnHelper.getColumns()) agg.equation.getSupport().assignVariable(col.columnName, col.getContents()); agg.equation.getSupport().assignVariable(Funnel.SYS_RECORDNUMBER, new Long(originalRecordNumber)); agg.equation.getSupport().assignVariable(Funnel.SYS_RECORDSIZE, new Long(originalRecordSize)); } } } /** *

* loadValues. *

* * @param context a {@link com.codetaco.funnel.parameters.FunnelContext} * object. * @param referencesToAllOutputFormatEquations an array of * {@link com.codetaco.algebrain.Equ} objects. * @throws java.lang.Exception if any. */ public static void loadValues(final FunnelContext context, final Equ[] referencesToAllOutputFormatEquations) throws Exception { if (context.isAggregating()) for (final Aggregate agg : context.getAggregates()) { for (final Equ equ : referencesToAllOutputFormatEquations) { equ.getSupport().assignVariable(agg.name, agg.getValueForEquations()); } } } /** *

* newAvg. *

* * @return a {@link com.codetaco.funnel.aggregation.Aggregate} object. */ static public Aggregate newAvg() { return new AggregateAvg(); } /** *

* newCount. *

* * @return a {@link com.codetaco.funnel.aggregation.Aggregate} object. */ static public Aggregate newCount() { return new AggregateCount(); } /** *

* newMax. *

* * @return a {@link com.codetaco.funnel.aggregation.Aggregate} object. */ static public Aggregate newMax() { return new AggregateMax(); } /** *

* newMin. *

* * @return a {@link com.codetaco.funnel.aggregation.Aggregate} object. */ static public Aggregate newMin() { return new AggregateMin(); } /** *

* newSum. *

* * @return a {@link com.codetaco.funnel.aggregation.Aggregate} object. */ static public Aggregate newSum() { return new AggregateSum(); } /** *

* reset. *

* * @param context a {@link com.codetaco.funnel.parameters.FunnelContext} * object. */ public static void reset(final FunnelContext context) { if (context.isAggregating()) for (final Aggregate agg : context.getAggregates()) { agg.reset(); } } @Arg(positional = true, allowCamelCaps = true, help = "A previously defined column name.") public String columnName; @Arg(shortName = 'n', required = true, help = "A name for this aggregate so that it can be referenced.") public String name; @Arg(shortName = 'e', allowMetaphone = true, help = "Used instead of a column name.") public Equ equation; AggType aggType; abstract Object getValueForEquations(); abstract void reset(); /** *

* supportsDate. *

* * @return a boolean. */ public boolean supportsDate() { return true; } /** *

* supportsNumber. *

* * @return a boolean. */ public boolean supportsNumber() { return true; } abstract void update(FunnelContext context) throws Exception; }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy