use of org.apache.apex.malhar.lib.appdata.gpo.GPOMutable in project apex-malhar by apache.
the class AppDataSnapshotServerMap method convert.
@Override
public GPOMutable convert(Map<String, Object> inputEvent) {
FieldsDescriptor fd = schema.getValuesDescriptor();
GPOMutable values = new GPOMutable(fd);
List<String> fields = fd.getFieldList();
for (int index = 0; index < fields.size(); index++) {
String field = fields.get(index);
values.setFieldGeneric(field, inputEvent.get(getMapField(field)));
}
return values;
}
use of org.apache.apex.malhar.lib.appdata.gpo.GPOMutable in project apex-malhar by apache.
the class DimensionsEvent method copy.
/**
* This is a utility method which copies the given src event to the given
* destination event.
*
* @param aeDest
* The destination event.
* @param aeSrc
* The source event.
*/
public static void copy(DimensionsEvent aeDest, DimensionsEvent aeSrc) {
GPOMutable destAggs = aeDest.getAggregates();
GPOMutable srcAggs = aeSrc.getAggregates();
if (srcAggs.getFieldsBoolean() != null) {
System.arraycopy(srcAggs.getFieldsBoolean(), 0, destAggs.getFieldsBoolean(), 0, srcAggs.getFieldsBoolean().length);
}
if (srcAggs.getFieldsCharacter() != null) {
System.arraycopy(srcAggs.getFieldsCharacter(), 0, destAggs.getFieldsCharacter(), 0, srcAggs.getFieldsCharacter().length);
}
if (srcAggs.getFieldsString() != null) {
System.arraycopy(srcAggs.getFieldsString(), 0, destAggs.getFieldsString(), 0, srcAggs.getFieldsString().length);
}
if (srcAggs.getFieldsShort() != null) {
System.arraycopy(srcAggs.getFieldsShort(), 0, destAggs.getFieldsShort(), 0, srcAggs.getFieldsShort().length);
}
if (srcAggs.getFieldsInteger() != null) {
System.arraycopy(srcAggs.getFieldsInteger(), 0, destAggs.getFieldsInteger(), 0, srcAggs.getFieldsInteger().length);
}
if (srcAggs.getFieldsLong() != null) {
System.arraycopy(srcAggs.getFieldsLong(), 0, destAggs.getFieldsLong(), 0, srcAggs.getFieldsLong().length);
}
if (srcAggs.getFieldsFloat() != null) {
System.arraycopy(srcAggs.getFieldsFloat(), 0, destAggs.getFieldsFloat(), 0, srcAggs.getFieldsFloat().length);
}
if (srcAggs.getFieldsDouble() != null) {
System.arraycopy(srcAggs.getFieldsDouble(), 0, destAggs.getFieldsDouble(), 0, srcAggs.getFieldsDouble().length);
}
}
use of org.apache.apex.malhar.lib.appdata.gpo.GPOMutable in project apex-malhar by apache.
the class AbstractIncrementalAggregator method createEventKey.
/**
* Creates an {@link EventKey} from the given {@link InputEvent}.
*
* @param inputEvent The {@link InputEvent} to extract an {@link EventKey} from.
* @param context The conversion context required to extract the {@link EventKey} from
* the given {@link InputEvent}.
* @param aggregatorIndex The aggregatorIndex to assign to this {@link InputEvent}.
* @return The {@link EventKey} extracted from the given {@link InputEvent}.
*/
public static EventKey createEventKey(InputEvent inputEvent, DimensionsConversionContext context, int aggregatorIndex) {
GPOMutable keys = new GPOMutable(context.keyDescriptor);
GPOUtils.indirectCopy(keys, inputEvent.getKeys(), context.indexSubsetKeys);
if (context.outputTimebucketIndex >= 0) {
CustomTimeBucket timeBucket = context.dd.getCustomTimeBucket();
keys.getFieldsInteger()[context.outputTimebucketIndex] = context.customTimeBucketRegistry.getTimeBucketId(timeBucket);
keys.getFieldsLong()[context.outputTimestampIndex] = timeBucket.roundDown(inputEvent.getKeys().getFieldsLong()[context.inputTimestampIndex]);
}
EventKey eventKey = new EventKey(context.schemaID, context.dimensionsDescriptorID, context.aggregatorID, keys);
return eventKey;
}
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, Aggregate src) {
dest.getMetaData().applyObjectPayloadFix();
src.getMetaData().applyObjectPayloadFix();
@SuppressWarnings("unchecked") List<GPOMutable> destKeys = (List<GPOMutable>) dest.getMetaData().getFieldsObject()[KEYS_INDEX];
@SuppressWarnings("unchecked") List<GPOMutable> srcKeys = (List<GPOMutable>) src.getMetaData().getFieldsObject()[KEYS_INDEX];
@SuppressWarnings("unchecked") List<GPOMutable> destAggregates = (List<GPOMutable>) dest.getMetaData().getFieldsObject()[AGGREGATES_INDEX];
@SuppressWarnings("unchecked") List<GPOMutable> srcAggregates = (List<GPOMutable>) src.getMetaData().getFieldsObject()[AGGREGATES_INDEX];
List<GPOMutable> newKeys = Lists.newArrayList();
List<GPOMutable> newAggs = Lists.newArrayList();
for (int index = 0; index < srcKeys.size(); index++) {
GPOMutable currentSrcKey = srcKeys.get(index);
GPOMutable currentSrcAgg = srcAggregates.get(index);
if (!contains(destKeys, currentSrcKey)) {
newKeys.add(currentSrcKey);
newAggs.add(currentSrcAgg);
this.aggregateAggs(dest.getAggregates(), currentSrcAgg);
}
}
destKeys.addAll(newKeys);
destAggregates.addAll(newAggs);
}
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, Aggregate src) {
GPOMutable destAggs = dest.getAggregates();
GPOMutable srcAggs = src.getAggregates();
{
byte[] destByte = destAggs.getFieldsByte();
if (destByte != null) {
byte[] srcByte = srcAggs.getFieldsByte();
for (int index = 0; index < destByte.length; index++) {
if (destByte[index] < srcByte[index]) {
destByte[index] = srcByte[index];
}
}
}
}
{
short[] destShort = destAggs.getFieldsShort();
if (destShort != null) {
short[] srcShort = srcAggs.getFieldsShort();
for (int index = 0; index < destShort.length; index++) {
if (destShort[index] < srcShort[index]) {
destShort[index] = srcShort[index];
}
}
}
}
{
int[] destInteger = destAggs.getFieldsInteger();
if (destInteger != null) {
int[] srcInteger = srcAggs.getFieldsInteger();
for (int index = 0; index < destInteger.length; index++) {
if (destInteger[index] < srcInteger[index]) {
destInteger[index] = srcInteger[index];
}
}
}
}
{
long[] destLong = destAggs.getFieldsLong();
if (destLong != null) {
long[] srcLong = srcAggs.getFieldsLong();
for (int index = 0; index < destLong.length; index++) {
if (destLong[index] < srcLong[index]) {
destLong[index] = srcLong[index];
}
}
}
}
{
float[] destFloat = destAggs.getFieldsFloat();
if (destFloat != null) {
float[] srcFloat = srcAggs.getFieldsFloat();
for (int index = 0; index < destFloat.length; index++) {
if (destFloat[index] < srcFloat[index]) {
destFloat[index] = srcFloat[index];
}
}
}
}
{
double[] destDouble = destAggs.getFieldsDouble();
if (destDouble != null) {
double[] srcDouble = srcAggs.getFieldsDouble();
for (int index = 0; index < destDouble.length; index++) {
if (destDouble[index] < srcDouble[index]) {
destDouble[index] = srcDouble[index];
}
}
}
}
}
Aggregations