@SafeVarargs private static List<Map<String, String>> makeMetadata(Pair<Concept, String>... entries) { List<Map<String, String>> metadataList = new ArrayList<>(); for (Pair<Concept, String> entry : entries) { Map<String, String> metadata = new HashMap<>(); metadata.put(RESULT_METADATA_METRICS_CONCEPT_KEY, entry.getKey().getName()); metadata.put(RESULT_METADATA_METRICS_NAME_KEY, entry.getValue()); metadataList.add(metadata); } return metadataList; }
/** * Utility function to apply a method for a given {@link Concept} name if provided in the given {@link Map} of names. * * @param concept The concept to check in the map if present. * @param names A non-null map of concept names to their key names. * @param action The action to apply if the concept was provided in the map. */ public static void consumeRegisteredConcept(Concept concept, Map<String, String> names, Consumer<String> action) { // Only consume the concept if we have a key for it: i.e. it was registered String key = names.get(concept.getName()); if (key != null) { action.accept(key); } } }
/** * Utility function to add a concept with a configured name to a map representing metadata if both the name and * and a value for the name produced by a given {@link Supplier} are not null. * * @param meta The non-null {@link Map} representing the metadata. * @param names The non-null {@link Map} of configured {@link Concept} names to key names to use. * @param concept The concept to add * @param supplier A {@link Supplier} that can produce a value to add to the metadata for the concept. If the * supplier produces null, it is not added. */ public static void addIfNonNull(Map<String, Object> meta, Map<String, String> names, Concept concept, Supplier<Object> supplier) { Object data = null; String key = names.get(concept.getName()); if (key != null) { data = supplier.get(); } if (data != null) { meta.put(key, data); } }
@Test public void testMultipleMeta() { config = configWithRawMaxAndEmptyMeta(); enableMetadataInConfig(config, Concept.QUERY_METADATA.getName(), "meta"); enableMetadataInConfig(config, Concept.QUERY_ID.getName(), "id"); enableMetadataInConfig(config, Concept.QUERY_BODY.getName(), "query"); enableMetadataInConfig(config, Concept.QUERY_RECEIVE_TIME.getName(), "created"); enableMetadataInConfig(config, Concept.QUERY_FINISH_TIME.getName(), "finished"); setup(new JoinBolt(config));
@Test public void testUnknownConceptMetadata() { config = configWithRawMaxAndEmptyMeta(); enableMetadataInConfig(config, Concept.QUERY_METADATA.getName(), "meta"); enableMetadataInConfig(config, Concept.QUERY_ID.getName(), "id"); enableMetadataInConfig(config, "foo", "bar"); setup(new JoinBolt(config)); Tuple query = TupleUtils.makeIDTuple(TupleClassifier.Type.QUERY_TUPLE, "42", "{}", EMPTY); bolt.execute(query); List<BulletRecord> sent = sendRawRecordTuplesTo(bolt, "42"); Meta meta = new Meta(); meta.add("meta", singletonMap("id", "42")); Tuple expected = TupleUtils.makeTuple(TupleClassifier.Type.RESULT_TUPLE, "42", Clip.of(sent).add(meta).asJSON(), COMPLETED); Assert.assertTrue(wasResultEmittedTo(TopologyConstants.RESULT_STREAM, expected)); Tuple metadata = TupleUtils.makeTuple(TupleClassifier.Type.FEEDBACK_TUPLE, "42", new Metadata(Metadata.Signal.COMPLETE, null)); Assert.assertTrue(wasMetadataEmittedTo(TopologyConstants.FEEDBACK_STREAM, metadata)); Assert.assertEquals(collector.getAllEmittedTo(TopologyConstants.RESULT_STREAM).count(), 1); Assert.assertEquals(collector.getAllEmittedTo(TopologyConstants.FEEDBACK_STREAM).count(), 1); }
@Test public void testQueryIdentifierMetadata() { config = configWithRawMaxAndEmptyMeta(); enableMetadataInConfig(config, Concept.QUERY_METADATA.getName(), "meta"); enableMetadataInConfig(config, Concept.QUERY_ID.getName(), "id"); setup(new JoinBolt(config)); Tuple query = TupleUtils.makeIDTuple(TupleClassifier.Type.QUERY_TUPLE, "42", "{}", EMPTY); bolt.execute(query); List<BulletRecord> sent = sendRawRecordTuplesTo(bolt, "42"); Meta meta = new Meta(); meta.add("meta", singletonMap("id", "42")); Tuple expected = TupleUtils.makeTuple(TupleClassifier.Type.RESULT_TUPLE, "42", Clip.of(sent).add(meta).asJSON(), COMPLETED); Assert.assertTrue(wasResultEmittedTo(TopologyConstants.RESULT_STREAM, expected)); Tuple metadata = TupleUtils.makeTuple(TupleClassifier.Type.FEEDBACK_TUPLE, "42", new Metadata(Metadata.Signal.COMPLETE, null)); Assert.assertTrue(wasMetadataEmittedTo(TopologyConstants.FEEDBACK_STREAM, metadata)); Assert.assertEquals(collector.getAllEmittedTo(TopologyConstants.RESULT_STREAM).count(), 1); Assert.assertEquals(collector.getAllEmittedTo(TopologyConstants.FEEDBACK_STREAM).count(), 1); }
private String getMetaKey() { return shouldMeta ? metadataKeys.getOrDefault(Meta.Concept.SKETCH_METADATA.getName(), null) : null; } }
private String getMetaKey() { return metadataKeys.getOrDefault(Meta.Concept.WINDOW_METADATA.getName(), null); } }
private String getMetaKey() { return metaKeys.getOrDefault(Meta.Concept.QUERY_METADATA.getName(), null); }