public JavaObject get_custom_object() { if (getSetField() == _Fields.CUSTOM_OBJECT) { return (JavaObject)getFieldValue(); } else { throw new java.lang.RuntimeException("Cannot get field 'custom_object' because union is currently set to " + getFieldDesc(getSetField()).name); } }
private static Map<String, Object> groupingToJSONableMap(Grouping grouping) { Map<String, Object> groupingMap = new HashMap<>(); groupingMap.put("type", grouping.getSetField().toString()); if (grouping.is_set_fields()) { groupingMap.put("fields", grouping.get_fields()); } return groupingMap; }
public static Grouping custom_serialized(java.nio.ByteBuffer value) { Grouping x = new Grouping(); x.set_custom_serialized(value); return x; }
public static Grouping custom_object(JavaObject value) { Grouping x = new Grouping(); x.set_custom_object(value); return x; }
public static Grouping shuffle(NullStruct value) { Grouping x = new Grouping(); x.set_shuffle(value); return x; }
public Builder withGroupingType(Grouping grouping) { GroupingType group = GroupingType.SHUFFLE; Grouping._Fields thriftType = grouping.getSetField(); if (grouping.get_fields().isEmpty()) { group = GroupingType.GLOBAL; } else { case CUSTOM_SERIALIZED: byte[] data = grouping.get_custom_serialized(); try (ByteArrayInputStream bis = new ByteArrayInputStream(data); ObjectInputStream ois = new ObjectInputStream(bis);) {
public boolean equals(Grouping other) { return other != null && getSetField() == other.getSetField() && getFieldValue().equals(other.getFieldValue()); }
@Test public void testGlobalAggregate() throws Exception { Stream<String> stream = streamBuilder.newStream(newSpout(Utils.DEFAULT_STREAM_ID), new ValueMapper<>(0), 2); stream.aggregate(new Count<>()); StormTopology topology = streamBuilder.build(); assertEquals(2, topology.get_bolts_size()); Bolt bolt1 = topology.get_bolts().get("bolt1"); Bolt bolt2 = topology.get_bolts().get("bolt2"); String spoutId = topology.get_spouts().keySet().iterator().next(); Map<GlobalStreamId, Grouping> expected1 = new HashMap<>(); expected1.put(new GlobalStreamId(spoutId, "default"), Grouping.shuffle(new NullStruct())); Map<GlobalStreamId, Grouping> expected2 = new HashMap<>(); expected2.put(new GlobalStreamId("bolt1", "s1"), Grouping.fields(Collections.emptyList())); expected2.put(new GlobalStreamId("bolt1", "s1__punctuation"), Grouping.all(new NullStruct())); assertEquals(expected1, bolt1.get_common().get_inputs()); assertEquals(expected2, bolt2.get_common().get_inputs()); }
if (grouping.is_set_shuffle()) { } else if (grouping.is_set_fields()) { final List<String> fields = grouping.get_fields(); if (fields.size() > 0) { FlinkOutputFieldsDeclarer prodDeclarer = this.declarers.get(producerId); inputStream = inputStream.keyBy(prodDeclarer .getGroupingFieldIndexes(inputStreamId, grouping.get_fields())); } else { inputStream = inputStream.global(); } else if (grouping.is_set_all()) { inputStream = inputStream.broadcast(); } else if (!grouping.is_set_local_or_shuffle()) { throw new UnsupportedOperationException( "Flink only supports (local-or-)shuffle, fields, all, and global grouping");
public static Grouping prepareShuffleGrouping() { return Grouping.shuffle(new NullStruct()); }
public static Grouping prepareFieldsGrouping(List<String> fields) { return Grouping.fields(fields); }
public static Grouping prepareAllGrouping() { return Grouping.all(new NullStruct()); }
public static Grouping fields(java.util.List<java.lang.String> value) { Grouping x = new Grouping(); x.set_fields(value); return x; }
public static Grouping direct(NullStruct value) { Grouping x = new Grouping(); x.set_direct(value); return x; }
private static boolean isIdentityPartition(PartitionNode n) { Grouping g = n.thriftGrouping; if (g.is_set_custom_serialized()) { CustomStreamGrouping csg = (CustomStreamGrouping) Utils.javaDeserialize(g.get_custom_serialized(), Serializable.class); return csg instanceof IdentityGrouping; } return false; }
public static Grouping local_or_shuffle(NullStruct value) { Grouping x = new Grouping(); x.set_local_or_shuffle(value); return x; }
@Test public void testGroupBy() throws Exception { PairStream<String, String> stream = streamBuilder.newStream(newSpout(Utils.DEFAULT_STREAM_ID), new PairValueMapper<>(0, 1), 2); stream.window(TumblingWindows.of(BaseWindowedBolt.Count.of(10))).aggregateByKey(new Count<>()); StormTopology topology = streamBuilder.build(); assertEquals(2, topology.get_bolts_size()); Bolt bolt1 = topology.get_bolts().get("bolt1"); Bolt bolt2 = topology.get_bolts().get("bolt2"); assertEquals(Grouping.shuffle(new NullStruct()), bolt1.get_common().get_inputs().values().iterator().next()); assertEquals(Grouping.fields(Collections.singletonList("key")), bolt2.get_common().get_inputs().values().iterator().next()); }