public LongSerde getSerde(String name, Config config) { return new LongSerde(); } }
public LongSerde getSerde(String name, Config config) { return new LongSerde(); } }
@Test public void testLongTimeSeriesKey() { TimeSeriesKey<Long> storeKey = new TimeSeriesKey<>(30L, 1, 23); TimeSeriesKeySerde<Long> serde = new TimeSeriesKeySerde<>(new LongSerde()); byte[] serializedBytes = serde.toBytes(storeKey); TimeSeriesKey<Long> deserializedTimeSeriesKey = serde.fromBytes(serializedBytes); assertEquals(storeKey.getKey(), deserializedTimeSeriesKey.getKey()); assertEquals(storeKey.getSeqNum(), deserializedTimeSeriesKey.getSeqNum()); assertEquals(storeKey.getTimestamp(), deserializedTimeSeriesKey.getTimestamp()); assertEquals(storeKey, deserializedTimeSeriesKey); } }
void translate(final LogicalAggregate aggregate, final TranslatorContext context) { validateAggregateFunctions(aggregate); MessageStream<SamzaSqlRelMessage> inputStream = context.getMessageStream(aggregate.getInput().getId()); // At this point, the assumption is that only count function is supported. SupplierFunction<Long> initialValue = () -> (long) 0; FoldLeftFunction<SamzaSqlRelMessage, Long> foldCountFn = (m, c) -> c + 1; final ArrayList<String> aggFieldNames = getAggFieldNames(aggregate); MessageStream<SamzaSqlRelMessage> outputStream = inputStream .window(Windows.keyedTumblingWindow(m -> m, Duration.ofMillis(context.getExecutionContext().getSamzaSqlApplicationConfig().getWindowDurationMs()), initialValue, foldCountFn, new SamzaSqlRelMessageSerdeFactory.SamzaSqlRelMessageSerde(), new LongSerde()) .setAccumulationMode(AccumulationMode.DISCARDING), "tumblingWindow_" + windowId) .map(windowPane -> { List<String> fieldNames = windowPane.getKey().getKey().getSamzaSqlRelRecord().getFieldNames(); List<Object> fieldValues = windowPane.getKey().getKey().getSamzaSqlRelRecord().getFieldValues(); fieldNames.add(aggFieldNames.get(0)); fieldValues.add(windowPane.getMessage()); return new SamzaSqlRelMessage(fieldNames, fieldValues); }); context.registerMessageStream(aggregate.getId(), outputStream); }
void translate(final LogicalAggregate aggregate, final TranslatorContext context) { validateAggregateFunctions(aggregate); MessageStream<SamzaSqlRelMessage> inputStream = context.getMessageStream(aggregate.getInput().getId()); // At this point, the assumption is that only count function is supported. SupplierFunction<Long> initialValue = () -> (long) 0; FoldLeftFunction<SamzaSqlRelMessage, Long> foldCountFn = (m, c) -> c + 1; final ArrayList<String> aggFieldNames = getAggFieldNames(aggregate); MessageStream<SamzaSqlRelMessage> outputStream = inputStream .map(new TranslatorInputMetricsMapFunction(logicalOpId)) .window(Windows.keyedTumblingWindow(m -> m, Duration.ofMillis(context.getExecutionContext().getSamzaSqlApplicationConfig().getWindowDurationMs()), initialValue, foldCountFn, new SamzaSqlRelMessageSerdeFactory.SamzaSqlRelMessageSerde(), new LongSerde()) .setAccumulationMode( AccumulationMode.DISCARDING), changeLogStorePrefix + "_tumblingWindow_" + logicalOpId) .map(windowPane -> { List<String> fieldNames = windowPane.getKey().getKey().getSamzaSqlRelRecord().getFieldNames(); List<Object> fieldValues = windowPane.getKey().getKey().getSamzaSqlRelRecord().getFieldValues(); fieldNames.add(aggFieldNames.get(0)); fieldValues.add(windowPane.getMessage()); return new SamzaSqlRelMessage(fieldNames, fieldValues, new SamzaSqlRelMsgMetadata("", "", "")); }); context.registerMessageStream(aggregate.getId(), outputStream); outputStream.map(new TranslatorOutputMetricsMapFunction(logicalOpId)); }
GenericInputDescriptor<KV<String, PageViewEvent>> pageView = isd.getInputDescriptor("PageView", pvSerde); KVSerde<String, Long> pvcSerde = KVSerde.of(new StringSerde(), new LongSerde()); GenericSystemDescriptor osd = new GenericSystemDescriptor("kafka", "mockSystemFactoryClass"); GenericOutputDescriptor<KV<String, Long>> pageViewCount = osd.getOutputDescriptor("PageViewCount", pvcSerde); (m, c) -> c + 1L, new StringSerde(), new LongSerde()), "count-by-country") .map(pane -> new KV<>(pane.getKey().getKey(), pane.getMessage())) .sendTo(outputStream);