Search in sources :

Example 11 with GPOMutable

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

the class DataResultSnapshotSerializerTest method simpleResultSerializerTest.

@Test
public void simpleResultSerializerTest() throws Exception {
    List<GPOMutable> dataValues = createValues();
    DataQuerySnapshot gQuery = new DataQuerySnapshot("1", new Fields(Sets.newHashSet("a", "b")));
    DataResultSnapshot result = new DataResultSnapshot(gQuery, dataValues);
    DataResultSnapshotSerializer serializer = new DataResultSnapshotSerializer();
    final String expectedJSONResult = "{\"id\":\"1\",\"type\":\"dataResult\",\"data\":[{\"b\":\"hello\",\"a\":\"1\"}," + "{\"b\":\"world\",\"a\":\"2\"}]}";
    String resultJSON = serializer.serialize(result, new ResultFormatter());
    JSONObject jo = new JSONObject(expectedJSONResult);
    JSONArray data = jo.getJSONArray("data");
    JSONObject jo1 = data.getJSONObject(0);
    JSONObject jo2 = data.getJSONObject(1);
    JSONObject rjo = new JSONObject(resultJSON);
    JSONArray rdata = rjo.getJSONArray("data");
    JSONObject rjo1 = rdata.getJSONObject(0);
    JSONObject rjo2 = rdata.getJSONObject(1);
    Assert.assertFalse(rjo.has(Result.FIELD_COUNTDOWN));
    Assert.assertEquals("The json doesn't match.", jo1.get("a"), rjo1.get("a"));
    Assert.assertEquals("The json doesn't match.", jo1.get("b"), rjo1.get("b"));
    Assert.assertEquals("The json doesn't match.", jo2.get("a"), rjo2.get("a"));
    Assert.assertEquals("The json doesn't match.", jo2.get("b"), rjo2.get("b"));
    Assert.assertEquals("The type doesn't match.", DataResultSnapshot.TYPE, jo.get(DataResultSnapshot.FIELD_TYPE));
}
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) JSONArray(org.codehaus.jettison.json.JSONArray) Test(org.junit.Test)

Example 12 with GPOMutable

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

the class DataResultSnapshotSerializerTest method createValues.

private List<GPOMutable> createValues() {
    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");
    FieldsDescriptor fdB = new FieldsDescriptor(fieldToTypeA);
    GPOMutable gpoB = new GPOMutable(fdB);
    gpoB.setField("a", 2L);
    gpoB.setField("b", "world");
    List<GPOMutable> values = Lists.newArrayList();
    values.add(gpoA);
    values.add(gpoB);
    return values;
}
Also used : GPOMutable(org.apache.apex.malhar.lib.appdata.gpo.GPOMutable)

Example 13 with GPOMutable

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

the class AggregatorSum method getGroup.

@Override
public Aggregate getGroup(InputEvent src, int aggregatorIndex) {
    src.used = true;
    Aggregate aggregate = createAggregate(src, context, aggregatorIndex);
    GPOMutable value = aggregate.getAggregates();
    GPOUtils.zeroFillNumeric(value);
    return aggregate;
}
Also used : GPOMutable(org.apache.apex.malhar.lib.appdata.gpo.GPOMutable) Aggregate(org.apache.apex.malhar.lib.dimensions.DimensionsEvent.Aggregate)

Example 14 with GPOMutable

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

the class AggregatorSum method aggregate.

@Override
public void aggregate(Aggregate dest, InputEvent src) {
    GPOMutable destAggs = dest.getAggregates();
    GPOMutable srcAggs = src.getAggregates();
    aggregateInput(destAggs, srcAggs);
}
Also used : GPOMutable(org.apache.apex.malhar.lib.appdata.gpo.GPOMutable)

Example 15 with GPOMutable

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

the class AggregatorSum method aggregate.

@Override
public void aggregate(Aggregate dest, Aggregate src) {
    GPOMutable destAggs = dest.getAggregates();
    GPOMutable srcAggs = src.getAggregates();
    aggregateAggs(destAggs, srcAggs);
}
Also used : GPOMutable(org.apache.apex.malhar.lib.appdata.gpo.GPOMutable)

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