Search in sources :

Example 16 with GPOMutable

use of org.apache.apex.malhar.lib.appdata.gpo.GPOMutable in project apex-malhar by apache.

the class AbstractIncrementalAggregator method createAggregate.

/**
 * Creates an {@link Aggregate} from the given {@link InputEvent}.
 *
 * @param inputEvent      The {@link InputEvent} to unpack into an {@link Aggregate}.
 * @param context         The conversion context required to transform the {@link InputEvent} into
 *                        the correct {@link Aggregate}.
 * @param aggregatorIndex The aggregatorIndex assigned to this {@link Aggregate}.
 * @return The converted {@link Aggregate}.
 */
public static Aggregate createAggregate(InputEvent inputEvent, DimensionsConversionContext context, int aggregatorIndex) {
    GPOMutable aggregates = new GPOMutable(context.aggregateDescriptor);
    EventKey eventKey = createEventKey(inputEvent, context, aggregatorIndex);
    Aggregate aggregate = new Aggregate(eventKey, aggregates);
    aggregate.setAggregatorIndex(aggregatorIndex);
    return aggregate;
}
Also used : GPOMutable(org.apache.apex.malhar.lib.appdata.gpo.GPOMutable) EventKey(org.apache.apex.malhar.lib.dimensions.DimensionsEvent.EventKey) Aggregate(org.apache.apex.malhar.lib.dimensions.DimensionsEvent.Aggregate)

Example 17 with GPOMutable

use of org.apache.apex.malhar.lib.appdata.gpo.GPOMutable in project apex-malhar by apache.

the class AggregatorCumSum method getGroup.

@Override
public Aggregate getGroup(InputEvent src, int aggregatorIndex) {
    src.used = true;
    Aggregate agg = createAggregate(src, context, aggregatorIndex);
    GPOUtils.indirectCopy(agg.getAggregates(), src.getAggregates(), context.indexSubsetAggregates);
    GPOMutable metaData = new GPOMutable(getMetaDataDescriptor());
    GPOMutable fullKey = new GPOMutable(src.getKeys());
    if (context.inputTimestampIndex >= 0) {
        fullKey.getFieldsLong()[context.inputTimestampIndex] = -1L;
    }
    List<GPOMutable> keys = Lists.newArrayList(fullKey);
    GPOMutable value = new GPOMutable(agg.getAggregates());
    List<GPOMutable> values = Lists.newArrayList(value);
    metaData.getFieldsObject()[KEY_FD_INDEX] = fullKey.getFieldDescriptor();
    metaData.getFieldsObject()[AGGREGATE_FD_INDEX] = value.getFieldDescriptor();
    metaData.getFieldsObject()[KEYS_INDEX] = keys;
    metaData.getFieldsObject()[AGGREGATES_INDEX] = values;
    agg.setMetaData(metaData);
    return agg;
}
Also used : GPOMutable(org.apache.apex.malhar.lib.appdata.gpo.GPOMutable) SerdeListGPOMutable(org.apache.apex.malhar.lib.appdata.gpo.SerdeListGPOMutable) Aggregate(org.apache.apex.malhar.lib.dimensions.DimensionsEvent.Aggregate)

Example 18 with GPOMutable

use of org.apache.apex.malhar.lib.appdata.gpo.GPOMutable in project apex-malhar by apache.

the class AggregatorCumSum method aggregate.

@Override
public void aggregate(Aggregate dest, InputEvent src) {
    @SuppressWarnings("unchecked") List<GPOMutable> destKeys = (List<GPOMutable>) dest.getMetaData().getFieldsObject()[KEYS_INDEX];
    @SuppressWarnings("unchecked") List<GPOMutable> destAggregates = (List<GPOMutable>) dest.getMetaData().getFieldsObject()[AGGREGATES_INDEX];
    long timestamp = 0L;
    if (context.inputTimestampIndex >= 0) {
        timestamp = src.getKeys().getFieldsLong()[context.inputTimestampIndex];
        src.getKeys().getFieldsLong()[context.inputTimestampIndex] = -1L;
    }
    if (!contains(destKeys, src.getKeys())) {
        destKeys.add(new GPOMutable(src.getKeys()));
        GPOMutable aggregates = new GPOMutable(context.aggregateDescriptor);
        GPOUtils.indirectCopy(aggregates, src.getAggregates(), context.indexSubsetAggregates);
        destAggregates.add(aggregates);
        this.aggregateAggs(dest.getAggregates(), aggregates);
    }
    if (context.inputTimestampIndex >= 0) {
        src.getKeys().getFieldsLong()[context.inputTimestampIndex] = timestamp;
    }
}
Also used : GPOMutable(org.apache.apex.malhar.lib.appdata.gpo.GPOMutable) SerdeListGPOMutable(org.apache.apex.malhar.lib.appdata.gpo.SerdeListGPOMutable) List(java.util.List)

Example 19 with GPOMutable

use of org.apache.apex.malhar.lib.appdata.gpo.GPOMutable in project apex-malhar by apache.

the class AggregatorMax method aggregate.

@Override
public void aggregate(Aggregate dest, InputEvent src) {
    GPOMutable destAggs = dest.getAggregates();
    GPOMutable srcAggs = src.getAggregates();
    {
        byte[] destByte = destAggs.getFieldsByte();
        if (destByte != null) {
            byte[] srcByte = srcAggs.getFieldsByte();
            int[] srcIndices = context.indexSubsetAggregates.fieldsByteIndexSubset;
            for (int index = 0; index < destByte.length; index++) {
                byte tempVal = srcByte[srcIndices[index]];
                if (destByte[index] < tempVal) {
                    destByte[index] = tempVal;
                }
            }
        }
    }
    {
        short[] destShort = destAggs.getFieldsShort();
        if (destShort != null) {
            short[] srcShort = srcAggs.getFieldsShort();
            int[] srcIndices = context.indexSubsetAggregates.fieldsShortIndexSubset;
            for (int index = 0; index < destShort.length; index++) {
                short tempVal = srcShort[srcIndices[index]];
                if (destShort[index] < tempVal) {
                    destShort[index] = tempVal;
                }
            }
        }
    }
    {
        int[] destInteger = destAggs.getFieldsInteger();
        if (destInteger != null) {
            int[] srcInteger = srcAggs.getFieldsInteger();
            int[] srcIndices = context.indexSubsetAggregates.fieldsIntegerIndexSubset;
            for (int index = 0; index < destInteger.length; index++) {
                int tempVal = srcInteger[srcIndices[index]];
                if (destInteger[index] < tempVal) {
                    destInteger[index] = tempVal;
                }
            }
        }
    }
    {
        long[] destLong = destAggs.getFieldsLong();
        if (destLong != null) {
            long[] srcLong = srcAggs.getFieldsLong();
            int[] srcIndices = context.indexSubsetAggregates.fieldsLongIndexSubset;
            for (int index = 0; index < destLong.length; index++) {
                long tempVal = srcLong[srcIndices[index]];
                if (destLong[index] < tempVal) {
                    destLong[index] = tempVal;
                }
            }
        }
    }
    {
        float[] destFloat = destAggs.getFieldsFloat();
        if (destFloat != null) {
            float[] srcFloat = srcAggs.getFieldsFloat();
            int[] srcIndices = context.indexSubsetAggregates.fieldsFloatIndexSubset;
            for (int index = 0; index < destFloat.length; index++) {
                float tempVal = srcFloat[srcIndices[index]];
                if (destFloat[index] < tempVal) {
                    destFloat[index] = tempVal;
                }
            }
        }
    }
    {
        double[] destDouble = destAggs.getFieldsDouble();
        if (destDouble != null) {
            double[] srcDouble = srcAggs.getFieldsDouble();
            int[] srcIndices = context.indexSubsetAggregates.fieldsDoubleIndexSubset;
            for (int index = 0; index < destDouble.length; index++) {
                double tempVal = srcDouble[srcIndices[index]];
                if (destDouble[index] < tempVal) {
                    destDouble[index] = tempVal;
                }
            }
        }
    }
}
Also used : GPOMutable(org.apache.apex.malhar.lib.appdata.gpo.GPOMutable)

Example 20 with GPOMutable

use of org.apache.apex.malhar.lib.appdata.gpo.GPOMutable in project apex-malhar by apache.

the class JDBCDimensionalOutputOperator method setStatementParameters.

/**
 * Sets the parameters on the {@link java.sql.PreparedStatement} based on the
 * values in the given {@link Aggregate}.
 *
 * @param aggregate
 *          The {@link Aggregate} whose values will be set on the
 *          corresponding {@link java.sql.PreparedStatement}.
 */
private void setStatementParameters(Aggregate aggregate) {
    EventKey eventKey = aggregate.getEventKey();
    int ddID = eventKey.getDimensionDescriptorID();
    int aggID = eventKey.getAggregatorID();
    LOG.info("Setting statement params {} {}", ddID, aggID);
    FieldsDescriptor keyFD = schema.getDimensionsDescriptorIDToKeyDescriptor().get(ddID);
    FieldsDescriptor aggFD = schema.getDimensionsDescriptorIDToAggregatorIDToOutputAggregatorDescriptor().get(ddID).get(aggID);
    GPOMutable key = eventKey.getKey();
    key.setFieldDescriptor(keyFD);
    GPOMutable value = aggregate.getAggregates();
    value.setFieldDescriptor(aggFD);
    int qCounter = 1;
    PreparedStatement ps = ddIDToAggIDToStatement.get(ddID).get(aggID);
    try {
        qCounter = setParams(ps, key, qCounter, true);
        setParams(ps, value, qCounter, false);
        ps.addBatch();
    } catch (SQLException ex) {
        throw new RuntimeException(ex);
    }
}
Also used : GPOMutable(org.apache.apex.malhar.lib.appdata.gpo.GPOMutable) SQLException(java.sql.SQLException) EventKey(org.apache.apex.malhar.lib.dimensions.DimensionsEvent.EventKey) FieldsDescriptor(org.apache.apex.malhar.lib.appdata.schemas.FieldsDescriptor) PreparedStatement(java.sql.PreparedStatement)

Aggregations

GPOMutable (org.apache.apex.malhar.lib.appdata.gpo.GPOMutable)25 EventKey (org.apache.apex.malhar.lib.dimensions.DimensionsEvent.EventKey)6 FieldsDescriptor (org.apache.apex.malhar.lib.appdata.schemas.FieldsDescriptor)4 Aggregate (org.apache.apex.malhar.lib.dimensions.DimensionsEvent.Aggregate)4 SerdeListGPOMutable (org.apache.apex.malhar.lib.appdata.gpo.SerdeListGPOMutable)3 JSONObject (org.codehaus.jettison.json.JSONObject)3 Test (org.junit.Test)3 List (java.util.List)2 DataResultSnapshotSerializer (org.apache.apex.malhar.lib.appdata.query.serde.DataResultSnapshotSerializer)2 Type (org.apache.apex.malhar.lib.appdata.schemas.Type)2 JSONArray (org.codehaus.jettison.json.JSONArray)2 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1 CustomTimeBucket (org.apache.apex.malhar.lib.appdata.schemas.CustomTimeBucket)1 DataResultSnapshot (org.apache.apex.malhar.lib.appdata.schemas.DataResultSnapshot)1 Fields (org.apache.apex.malhar.lib.appdata.schemas.Fields)1