예제 #1
0
        /// <summary>
        /// Create a simple aggregate query.
        /// </summary>
        /// <param name="app">The application that will host the query.</param>
        /// <param name="queryName">The name of the query.</param>
        /// <param name="queryDescription">The description of the query.</param>
        /// <param name="inputFile">The file to read input from.</param>
        /// <param name="outputPath">The path under which to put our output. This will go to a file of the form [app].[query].out</param>
        /// <param name="eventFrequency">How often the input adapter should produce events. Zero will produce them as fast as possible.</param>
        /// <returns>The new query.</returns>
        private static Query CreateAggregationQuery(Application app, string queryName, string queryDescription, string inputFile, string outputPath, TimeSpan eventFrequency)
        {
            // Create a configuration for our input adapter.
            var inputConfig = new ReplayablePointCsvInputAdapterConfig(inputFile, eventFrequency);

            // Declare the input stream.
            var inputStream = CepStream<XYPayload>.Create(
                queryName + ":input",
                typeof(ReplayablePointCsvInputAdapterFactory),
                inputConfig,
                EventShape.Point,
                null);

            // Do some simple aggregation.
            var q = from window in inputStream.HoppingWindow(TimeSpan.FromHours(1), TimeSpan.FromMinutes(1))
                    select new { AvgX = window.Avg(e => e.X), AvgY = window.Avg(e => e.Y) };

            // Create the query. This declares which output adapter to use, and also configures
            // the query for resiliency.
            Query rval = q.ToQuery(
                app,
                queryName,
                queryDescription,
                typeof(DedupingPointCsvOuputAdapterFactory),
                new DedupingPointCsvOutputAdapterConfig(Path.Combine(outputPath, GetOutputFileName(app.ShortName, queryName)), new string[] { "AvgX", "AvgY" }),
                EventShape.Point,
                StreamEventOrder.FullyOrdered,
                true); // <== *** This says that the query is resilient and enables it for checkpointing. ***

            return rval;
        }
예제 #2
0
        /// <summary>
        /// Create a simple aggregate query.
        /// </summary>
        /// <param name="app">The application that will host the query.</param>
        /// <param name="queryName">The name of the query.</param>
        /// <param name="queryDescription">The description of the query.</param>
        /// <param name="inputFile">The file to read input from.</param>
        /// <param name="outputPath">The path under which to put our output. This will go to a file of the form [app].[query].out</param>
        /// <param name="eventFrequency">How often the input adapter should produce events. Zero will produce them as fast as possible.</param>
        /// <returns>The new query.</returns>
        private static Query CreateAggregationQuery(Application app, string queryName, string queryDescription, string inputFile, string outputPath, TimeSpan eventFrequency)
        {
            // Create a configuration for our input adapter.
            var inputConfig = new ReplayablePointCsvInputAdapterConfig(inputFile, eventFrequency);

            // Declare the input stream.
            var inputStream = CepStream <XYPayload> .Create(
                queryName + ":input",
                typeof(ReplayablePointCsvInputAdapterFactory),
                inputConfig,
                EventShape.Point,
                null);

            // Do some simple aggregation.
            var q = from window in inputStream.HoppingWindow(TimeSpan.FromHours(1), TimeSpan.FromMinutes(1))
                    select new { AvgX = window.Avg(e => e.X), AvgY = window.Avg(e => e.Y) };

            // Create the query. This declares which output adapter to use, and also configures
            // the query for resiliency.
            Query rval = q.ToQuery(
                app,
                queryName,
                queryDescription,
                typeof(DedupingPointCsvOuputAdapterFactory),
                new DedupingPointCsvOutputAdapterConfig(Path.Combine(outputPath, GetOutputFileName(app.ShortName, queryName)), new string[] { "AvgX", "AvgY" }),
                EventShape.Point,
                StreamEventOrder.FullyOrdered,
                true); // <== *** This says that the query is resilient and enables it for checkpointing. ***

            return(rval);
        }
예제 #3
0
        /// <summary>
        /// Create a simple passthrough query.
        /// </summary>
        /// <param name="app">The application that will host the query.</param>
        /// <param name="queryName">The name of the query.</param>
        /// <param name="queryDescription">The description of the query.</param>
        /// <param name="inputFile">The file to read input from.</param>
        /// <param name="outputPath">The path under which to put our output. This will go to a file of the form [app].[query].out</param>
        /// <param name="eventFrequency">How often the input adapter should produce events. Zero will produce them as fast as possible.</param>
        /// <returns>The new query.</returns>
        private static Query CreatePassthroughQuery(Application app, string queryName, string queryDescription, string inputFile, string outputPath, TimeSpan eventFrequency)
        {
            // Create a configuration for our input adapter.
            var inputConfig = new ReplayablePointCsvInputAdapterConfig(inputFile, eventFrequency);

            // Declare the input stream.
            var inputStream = CepStream <XYPayload> .Create(
                queryName + ":input",
                typeof(ReplayablePointCsvInputAdapterFactory),
                inputConfig,
                EventShape.Point,
                null);

            // Just a passthrough template.
            var q = from e in inputStream select e;

            // Create the query. This declares which output adapter to use, and also configures
            // the query for resiliency.
            Query rval = q.ToQuery(
                app,
                queryName,
                queryDescription,
                typeof(DedupingPointCsvOuputAdapterFactory),
                new DedupingPointCsvOutputAdapterConfig(Path.Combine(outputPath, GetOutputFileName(app.ShortName, queryName))),
                EventShape.Point,
                StreamEventOrder.FullyOrdered,
                true); // <== *** This says that the query is resilient and enables it for checkpointing. ***

            return(rval);
        }
예제 #4
0
        /// <summary>
        /// Bucket things based on position and take counts.
        /// </summary>
        /// <param name="app">The application that will host the query.</param>
        /// <param name="queryName">The name of the query.</param>
        /// <param name="queryDescription">The description of the query.</param>
        /// <param name="inputFile">The file to read input from.</param>
        /// <param name="outputPath">The path under which to put our output. This will go to a file of the form [app].[query].out</param>
        /// <param name="eventFrequency">How often the input adapter should produce events. Zero will produce them as fast as possible.</param>
        /// <returns>The new query.</returns>
        private static Query CreateBucketQuery(Application app, string queryName, string queryDescription, string inputFile, string outputPath, TimeSpan eventFrequency)
        {
            // Create a configuration for our input adapter.
            var inputConfig = new ReplayablePointCsvInputAdapterConfig(inputFile, eventFrequency);

            // Declare the input stream.
            var inputStream = CepStream <XYPayload> .Create(
                queryName + ":input",
                typeof(ReplayablePointCsvInputAdapterFactory),
                inputConfig,
                EventShape.Point,
                null);

            // Do some aggregation by leading digit of x and y coordinate.
            var q = from e in inputStream
                    group e by new { XBucket = (int)(e.X * 10), YBucket = (int)(e.Y * 10) } into xygroups
            from window in xygroups.TumblingWindow(TimeSpan.FromDays(1))
            select new
            {
                XBucket = xygroups.Key.XBucket,
                YBucket = xygroups.Key.YBucket,
                Count   = window.Count(),
                AvgX    = window.Avg(e => e.X),
                AvgY    = window.Avg(e => e.Y)
            };

            // Create the query. This declares which output adapter to use, and also configures
            // the query for resiliency.
            Query rval = q.ToQuery(
                app,
                queryName,
                queryDescription,
                typeof(DedupingPointCsvOuputAdapterFactory),
                new DedupingPointCsvOutputAdapterConfig(Path.Combine(outputPath, GetOutputFileName(app.ShortName, queryName)), new string[] { "XBucket", "YBucket", "AvgX", "AvgY", "Count" }),
                EventShape.Point,
                StreamEventOrder.FullyOrdered,
                true); // <== *** This says that the query is resilient and enables it for checkpointing. ***

            return(rval);
        }
예제 #5
0
        /// <summary>
        /// Create a simple passthrough query.
        /// </summary>
        /// <param name="app">The application that will host the query.</param>
        /// <param name="queryName">The name of the query.</param>
        /// <param name="queryDescription">The description of the query.</param>
        /// <param name="inputFile">The file to read input from.</param>
        /// <param name="outputPath">The path under which to put our output. This will go to a file of the form [app].[query].out</param>
        /// <param name="eventFrequency">How often the input adapter should produce events. Zero will produce them as fast as possible.</param>
        /// <returns>The new query.</returns>
        private static Query CreatePassthroughQuery(Application app, string queryName, string queryDescription, string inputFile, string outputPath, TimeSpan eventFrequency)
        {
            // Create a configuration for our input adapter.
            var inputConfig = new ReplayablePointCsvInputAdapterConfig(inputFile, eventFrequency);

            // Declare the input stream.
            var inputStream = CepStream<XYPayload>.Create(
                queryName + ":input",
                typeof(ReplayablePointCsvInputAdapterFactory),
                inputConfig,
                EventShape.Point,
                null);

            // Just a passthrough template.
            var q = from e in inputStream select e;

            // Create the query. This declares which output adapter to use, and also configures
            // the query for resiliency.
            Query rval = q.ToQuery(
                app,
                queryName,
                queryDescription,
                typeof(DedupingPointCsvOuputAdapterFactory),
                new DedupingPointCsvOutputAdapterConfig(Path.Combine(outputPath, GetOutputFileName(app.ShortName, queryName))),
                EventShape.Point,
                StreamEventOrder.FullyOrdered,
                true); // <== *** This says that the query is resilient and enables it for checkpointing. ***

            return rval;
        }
예제 #6
0
        /// <summary>
        /// Bucket things based on position and take counts.
        /// </summary>
        /// <param name="app">The application that will host the query.</param>
        /// <param name="queryName">The name of the query.</param>
        /// <param name="queryDescription">The description of the query.</param>
        /// <param name="inputFile">The file to read input from.</param>
        /// <param name="outputPath">The path under which to put our output. This will go to a file of the form [app].[query].out</param>
        /// <param name="eventFrequency">How often the input adapter should produce events. Zero will produce them as fast as possible.</param>
        /// <returns>The new query.</returns>
        private static Query CreateBucketQuery(Application app, string queryName, string queryDescription, string inputFile, string outputPath, TimeSpan eventFrequency)
        {
            // Create a configuration for our input adapter.
            var inputConfig = new ReplayablePointCsvInputAdapterConfig(inputFile, eventFrequency);

            // Declare the input stream.
            var inputStream = CepStream<XYPayload>.Create(
                queryName + ":input",
                typeof(ReplayablePointCsvInputAdapterFactory),
                inputConfig,
                EventShape.Point,
                null);

            // Do some aggregation by leading digit of x and y coordinate.
            var q = from e in inputStream
                    group e by new { XBucket = (int)(e.X * 10), YBucket = (int)(e.Y * 10) } into xygroups
                    from window in xygroups.TumblingWindow(TimeSpan.FromDays(1))
                    select new
                    {
                        XBucket = xygroups.Key.XBucket,
                        YBucket = xygroups.Key.YBucket,
                        Count = window.Count(),
                        AvgX = window.Avg(e => e.X),
                        AvgY = window.Avg(e => e.Y)
                    };

            // Create the query. This declares which output adapter to use, and also configures
            // the query for resiliency.
            Query rval = q.ToQuery(
                app,
                queryName,
                queryDescription,
                typeof(DedupingPointCsvOuputAdapterFactory),
                new DedupingPointCsvOutputAdapterConfig(Path.Combine(outputPath, GetOutputFileName(app.ShortName, queryName)), new string[] { "XBucket", "YBucket", "AvgX", "AvgY", "Count" }),
                EventShape.Point,
                StreamEventOrder.FullyOrdered,
                true); // <== *** This says that the query is resilient and enables it for checkpointing. ***

            return rval;
        }