Ejemplo n.º 1
0
        public IKStream <K, VR> MapValues <VR>(IValueMapperWithKey <K, V, VR> mapper, string named = null)
        {
            if (mapper == null)
            {
                throw new ArgumentNullException($"Mapper function can't be null");
            }

            String name = new Named(named).OrElseGenerateWithPrefix(this.builder, MAPVALUES_NAME);

            ProcessorParameters <K, V> processorParameters    = new ProcessorParameters <K, V>(new KStreamMapValues <K, V, VR>(mapper), name);
            ProcessorGraphNode <K, V>  mapValuesProcessorNode = new ProcessorGraphNode <K, V>(name, processorParameters);

            mapValuesProcessorNode.ValueChangingOperation = true;

            builder.AddGraphNode(this.node, mapValuesProcessorNode);

            // value serde cannot be preserved
            return(new KStream <K, VR>(
                       name,
                       this.keySerdes,
                       null,
                       this.setSourceNodes,
                       mapValuesProcessorNode,
                       builder));
        }
Ejemplo n.º 2
0
        private IKTable <K, VR> DoMapValues <VR>(IValueMapperWithKey <K, V, VR> mapper, string named, Materialized <K, VR, IKeyValueStore <Bytes, byte[]> > materializedInternal)
        {
            ISerDes <K>  keySerde;
            ISerDes <VR> valueSerde;
            String       queryableStoreName;
            StoreBuilder <TimestampedKeyValueStore <K, VR> > storeBuilder;

            if (materializedInternal != null)
            {
                // we actually do not need to generate store names at all since if it is not specified, we will not
                // materialize the store; but we still need to burn one index BEFORE generating the processor to keep compatibility.
                if (materializedInternal.StoreName == null)
                {
                    builder.NewStoreName(MAPVALUES_NAME);
                }
                keySerde           = materializedInternal.KeySerdes != null ? materializedInternal.KeySerdes : this.keySerdes;
                valueSerde         = materializedInternal.ValueSerdes != null ? materializedInternal.ValueSerdes : null;
                queryableStoreName = materializedInternal.QueryableStoreName;
                // only materialize if materialized is specified and it has queryable name
                storeBuilder = queryableStoreName != null ? new TimestampedKeyValueStoreMaterializer <K, VR>(materializedInternal).Materialize() : null;
            }
            else
            {
                keySerde           = this.keySerdes;
                valueSerde         = null;
                queryableStoreName = null;
                storeBuilder       = null;
            }

            var name = new Named(named).OrElseGenerateWithPrefix(this.builder, MAPVALUES_NAME);

            var processorSupplier   = new KTableMapValues <K, V, VR>(this, mapper, queryableStoreName);
            var processorParameters = new TableProcessorParameters <K, V>(processorSupplier, name);

            var tableNode = new TableProcessorNode <K, V, K, VR>(
                name,
                processorParameters,
                storeBuilder
                );

            builder.AddGraphNode(this.node, tableNode);

            // don't inherit parent value serde, since this operation may change the value type, more specifically:
            // we preserve the key following the order of 1) materialized, 2) parent, 3) null
            // we preserve the value following the order of 1) materialized, 2) null
            return(new KTable <K, V, VR>(
                       name,
                       keySerde,
                       valueSerde,
                       this.setSourceNodes,
                       queryableStoreName,
                       processorSupplier,
                       tableNode,
                       builder
                       ));
        }
Ejemplo n.º 3
0
        public void ShouldNotAllowNullMapValuesAction()
        {
            var builder = new StreamBuilder();
            var table   = builder.Table <string, string>("ktable-topic");
            Func <string, string>         mapper1 = null;
            Func <string, string, string> mapper3 = null;
            IValueMapper <string, string> mapper2 = null;
            IValueMapperWithKey <string, string, string> mapper4 = null;

            Assert.Throws <ArgumentNullException>(() => table.MapValues(mapper1));
            Assert.Throws <ArgumentNullException>(() => table.MapValues(mapper2));
            Assert.Throws <ArgumentNullException>(() => table.MapValues(mapper3));
            Assert.Throws <ArgumentNullException>(() => table.MapValues(mapper4));
        }
        public void ShouldNotAllowNullFlatmapAction()
        {
            var builder = new StreamBuilder();
            var stream  = builder.Stream <string, string>("topic");

            Func <string, string>         mapper1 = null;
            IValueMapper <string, string> mapper2 = null;
            IValueMapperWithKey <string, string, string> mapper3 = null;
            Func <string, string, string> mapper4 = null;

            Assert.Throws <ArgumentNullException>(() => stream.MapValues(mapper1));
            Assert.Throws <ArgumentNullException>(() => stream.MapValues(mapper2));
            Assert.Throws <ArgumentNullException>(() => stream.MapValues(mapper3));
            Assert.Throws <ArgumentNullException>(() => stream.MapValues(mapper4));
        }
Ejemplo n.º 5
0
        public IKStream <K, VR> FlatMapValues <VR>(IValueMapperWithKey <K, V, IEnumerable <VR> > mapper, string named = null)
        {
            var name = new Named(named).OrElseGenerateWithPrefix(this.builder, FLATMAPVALUES_NAME);

            ProcessorParameters <K, V> processorParameters = new ProcessorParameters <K, V>(new KStreamFlatMapValues <K, V, VR>(mapper), name);
            ProcessorGraphNode <K, V>  flatMapValuesNode   = new ProcessorGraphNode <K, V>(name, processorParameters);

            flatMapValuesNode.ValueChangingOperation = true;

            builder.AddGraphNode(this.node, flatMapValuesNode);

            // value serde cannot be preserved
            return(new KStream <K, VR>(
                       name,
                       this.keySerdes,
                       null,
                       this.setSourceNodes,
                       flatMapValuesNode,
                       builder));
        }
 public KStreamMapValues(IValueMapperWithKey <K, V, V1> mapper)
 {
     this.mapper = mapper;
 }
 public KStreamFlatMapValuesProcessor(IValueMapperWithKey <K, V, IEnumerable <VR> > mapper)
 {
     this.mapper = mapper;
 }
 public KTableMapValuesProcessor(IValueMapperWithKey <K, V, VR> mapper, bool sendOldValues, string queryableStoreName)
     : base(queryableStoreName, sendOldValues)
 {
     this.mapper = mapper;
 }
 public KStreamFlatMapValues(IValueMapperWithKey <K, V, IEnumerable <VR> > mapper)
 {
     Mapper = mapper;
 }
Ejemplo n.º 10
0
 public KTableMapValues(IKTableGetter <K, V> parent, IValueMapperWithKey <K, V, VR> mapper, string queryableName)
 {
     this.parentTable   = parent;
     this.mapper        = mapper;
     this.queryableName = queryableName;
 }
Ejemplo n.º 11
0
 public KTableMapValuesValueGetter(IValueMapperWithKey <K, V, VR> mapper, IKTableValueGetter <K, V> getter)
 {
     this.ktablegetter = getter;
     this.mapper       = mapper;
 }
Ejemplo n.º 12
0
 public IKTable <K, VR> MapValues <VR>(IValueMapperWithKey <K, V, VR> mapperWithKey, Materialized <K, VR, IKeyValueStore <Bytes, byte[]> > materialized, string named)
 => DoMapValues(mapperWithKey, named, materialized);
Ejemplo n.º 13
0
 public IKTable <K, VR> MapValues <VR>(IValueMapperWithKey <K, V, VR> mapperWithKey, string named = null)
 => this.MapValues(mapperWithKey, null, named);