StreamInsight -- Convert a string csv PointEvent to multiple int PointEvent's

142 views Asked by At

I can do it in a UDSO :

public sealed class PromoIdsToEvents : CepPointStreamOperator<string, int>
{
    public override IEnumerable<int> ProcessEvent(PointEvent<string> inputEvent)
    {
        if (inputEvent.Payload.Length > 0)
        {
            string[] separator = new[] { "," };
            string[] idStrings = inputEvent.Payload.Split(separator, StringSplitOptions.RemoveEmptyEntries);

            foreach (var p in idStrings)
            {
                yield return int.Parse(p);
            }
        }
    }

    public override bool IsEmpty
    {
        get { return false; }
    }
}

Is it possible to do it all in a query? All this does is make an IEnumberable :

var multipleEventsAsInts = from c in csvEvents
                           let split = c.Split(',').Select(int.Parse)
                           select split;
2

There are 2 answers

0
TXPower275 On

You might be able to do this work in a subject, but I think the way you are doing it, through a UDSO is the proper way to work with a StreamInsight event in a procedural manner.

By creating that UDSO, you now have a reusable chunk of code. If you just did that work in the query logic, you wouldn't have the ability to re-use it as easily.

0
DevBiker On

TXPower is absolutely correct. Additionally, the UDSO will be more efficient than using a UDF (static method) in a query. However, your sample UDSO could be a bit better ... note that the return value from ProcessEvent is an IEnumerable. You don't need to yield return one at a time; create your enumerable (an array would be fine) and then simply return it.