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