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;
}
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;
}
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;
}
}
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;
}
}
}
}
}
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);
}
}
Aggregations