Search in sources :

Example 6 with GPOMutable

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

the class AggregatorMin 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 7 with GPOMutable

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

the class AggregatorMin 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];
                }
            }
        }
    }
}
Also used : GPOMutable(org.apache.apex.malhar.lib.appdata.gpo.GPOMutable)

Example 8 with GPOMutable

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

the class AbstractAppDataSnapshotServer method processData.

protected void processData(List<INPUT_EVENT> rows) {
    currentData.clear();
    for (INPUT_EVENT inputEvent : rows) {
        GPOMutable gpoRow = convert(inputEvent);
        currentData.add(gpoRow);
    }
}
Also used : GPOMutable(org.apache.apex.malhar.lib.appdata.gpo.GPOMutable)

Example 9 with GPOMutable

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

the class DimensionsEventTest method eventKeyEqualsHashCodeTest.

@Test
public void eventKeyEqualsHashCodeTest() {
    Map<String, Type> fieldToTypeA = Maps.newHashMap();
    fieldToTypeA.put("a", Type.LONG);
    fieldToTypeA.put("b", Type.STRING);
    FieldsDescriptor fdA = new FieldsDescriptor(fieldToTypeA);
    GPOMutable gpoA = new GPOMutable(fdA);
    gpoA.setField("a", 1L);
    gpoA.setField("b", "hello");
    EventKey eventKeyA = new EventKey(1, 1, 1, gpoA);
    Map<String, Type> fieldToTypeB = Maps.newHashMap();
    fieldToTypeB.put("a", Type.LONG);
    fieldToTypeB.put("b", Type.STRING);
    FieldsDescriptor fdB = new FieldsDescriptor(fieldToTypeB);
    GPOMutable gpoB = new GPOMutable(fdB);
    gpoB.setField("a", 1L);
    gpoB.setField("b", "hello");
    EventKey eventKeyB = new EventKey(1, 1, 1, gpoB);
    Assert.assertEquals("The two hashcodes should equal", eventKeyA.hashCode(), eventKeyB.hashCode());
    Assert.assertEquals("The two event keys should equal", eventKeyA, eventKeyB);
}
Also used : Type(org.apache.apex.malhar.lib.appdata.schemas.Type) GPOMutable(org.apache.apex.malhar.lib.appdata.gpo.GPOMutable) FieldsDescriptor(org.apache.apex.malhar.lib.appdata.schemas.FieldsDescriptor) EventKey(org.apache.apex.malhar.lib.dimensions.DimensionsEvent.EventKey) Test(org.junit.Test)

Example 10 with GPOMutable

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

the class DataResultSnapshotSerializerTest method simpleCountdownTest.

@Test
public void simpleCountdownTest() throws Exception {
    List<GPOMutable> dataValues = createValues();
    DataQuerySnapshot gQuery = new DataQuerySnapshot("1", new Fields(Sets.newHashSet("a", "b")));
    DataResultSnapshot result = new DataResultSnapshot(gQuery, dataValues, 2);
    DataResultSnapshotSerializer serializer = new DataResultSnapshotSerializer();
    String resultJSON = serializer.serialize(result, new ResultFormatter());
    JSONObject rjo = new JSONObject(resultJSON);
    long countdown = rjo.getLong(Result.FIELD_COUNTDOWN);
    Assert.assertEquals(2, countdown);
}
Also used : GPOMutable(org.apache.apex.malhar.lib.appdata.gpo.GPOMutable) DataResultSnapshotSerializer(org.apache.apex.malhar.lib.appdata.query.serde.DataResultSnapshotSerializer) JSONObject(org.codehaus.jettison.json.JSONObject) Test(org.junit.Test)

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