Exemple #1
0
        public FusedObservable(
            IObservable <TInput> observable,
            Expression <Func <TInput, long> > startEdgeExtractor,
            Expression <Func <TInput, long> > endEdgeExtractor,
            Expression <Func <TInput, TKey> > keyExtractor,
            Expression <Func <TInput, TPayload> > payloadExtractor,
            FuseModule fuseModule,
            Expression <Func <long, long, TResult, TKey, TOutput> > resultConstructor,
            QueryContainer container,
            string ingressIdentifier,
            string egressIdentifier)
        {
            this.observable         = observable;
            this.inputParameter     = startEdgeExtractor.Parameters[0];
            this.startEdgeExtractor = startEdgeExtractor;
            this.endEdgeExtractor   = Expression.Lambda <Func <TInput, long> >(
                endEdgeExtractor.ReplaceParametersInBody(this.inputParameter), this.inputParameter);
            this.keyExtractor = Expression.Lambda <Func <TInput, TKey> >(
                keyExtractor.ReplaceParametersInBody(this.inputParameter), this.inputParameter);
            this.payloadExtractor = Expression.Lambda <Func <TInput, TPayload> >(
                payloadExtractor.ReplaceParametersInBody(this.inputParameter), this.inputParameter);
            this.fuseModule        = fuseModule;
            this.resultConstructor = resultConstructor;

            this.container         = container;
            this.ingressIdentifier = ingressIdentifier;
            this.egressIdentifier  = egressIdentifier;
            if (this.container != null)
            {
                this.container.RegisterEgressSite(egressIdentifier);
            }
        }
 internal static Tuple <Type, string> GenerateFused <TSource, TResult>(
     Expression <Func <TSource, long> > startEdgeExpression,
     Expression <Func <TSource, long> > endEdgeExpression,
     string latencyOption,
     string diagnosticOption,
     FuseModule fuseModule)
 => Generate <Empty, TSource, TResult>("Interval", string.Empty, null, startEdgeExpression, endEdgeExpression,
                                       latencyOption, diagnosticOption, fuseModule);
 internal static Tuple <Type, string> GenerateFused <TSource, TResult>(
     string latencyOption,
     string diagnosticOption,
     FuseModule fuseModule)
 {
     return(Generate <Empty, TSource, TResult>("StreamEvent", string.Empty, null, null, null,
                                               latencyOption, diagnosticOption, fuseModule));
 }
 internal static Tuple <Type, string> Generate <TKey, TSource>(
     string latencyOption,
     string diagnosticOption,
     FuseModule fuseModule)
 {
     return(Generate <TKey, TSource, TSource>("StreamEvent", "Partitioned", null, null, null,
                                              latencyOption, diagnosticOption, fuseModule));
 }
 internal static Tuple <Type, string> GenerateFused <TKey, TSource, TResult>(
     Expression <Func <TSource, TKey> > partitionExpression,
     Expression <Func <TSource, long> > startEdgeExpression,
     Expression <Func <TSource, long> > endEdgeExpression,
     string latencyOption,
     string diagnosticOption,
     FuseModule fuseModule)
 => Generate <TKey, TSource, TResult>("Interval", "Partitioned", partitionExpression, startEdgeExpression, endEdgeExpression,
                                      latencyOption, diagnosticOption, fuseModule);
Exemple #6
0
 private FuseModule(FuseModule that)
 {
     this.expressions        = new List <ExpressionProfile>(that.expressions.Select(o => o.Clone()));
     this.durationAdjustment = that.durationAdjustment;
 }
 internal static Tuple <Type, string> Generate <TSource>(
     string latencyOption,
     string diagnosticOption,
     FuseModule fuseModule)
 => Generate <Empty, TSource, TSource>("StreamEvent", string.Empty, null, null, null,
                                       latencyOption, diagnosticOption, fuseModule);
        private static Tuple <Type, string> Generate <TKey, TSource, TResult>(
            string ingressType,
            string partitionString,
            Expression <Func <TSource, TKey> > partitionExpression,
            Expression <Func <TSource, long> > startEdgeExpression,
            Expression <Func <TSource, long> > endEdgeExpression,
            string latencyOption,
            string diagnosticOption,
            FuseModule fuseModule)
        {
            var template = new TemporalIngressTemplate(
                $"GeneratedTemporalIngress_{TemporalIngressSequenceNumber++}",
                typeof(TKey), typeof(TSource), fuseModule?.OutputType ?? typeof(TResult));

            var tm  = new TypeMapper(template.keyType, template.payloadType, template.resultType);
            var gps = tm.GenericTypeVariables(template.keyType, template.payloadType);

            template.genericParameters = gps.BracketedCommaSeparatedString();
            template.payloadOrResult   = tm.CSharpNameFor(template.resultRepresentation.RepresentationFor);

            var batchGeneratedFrom_TKey_TPayload = string.IsNullOrEmpty(partitionString)
                ? Transformer.GetBatchClassName(template.keyType, template.resultType)
                : Transformer.GetBatchClassName(typeof(PartitionKey <TKey>), template.resultType);
            var keyAndPayloadGenericParameters = tm.GenericTypeVariables(template.keyType, template.resultType).BracketedCommaSeparatedString();

            template.GeneratedBatchName = batchGeneratedFrom_TKey_TPayload + keyAndPayloadGenericParameters;

            template.keyOrNothing        = string.IsNullOrEmpty(partitionString) ? string.Empty : template.TKey + ", ";
            template.diagnosticOption    = diagnosticOption;
            template.needsStreamEvent    = ingressType == "StreamEvent";
            template.genericArguments    = (string.IsNullOrEmpty(partitionString) ? string.Empty : template.TKey + ", ") + template.TPayload;
            template.adjustedGenericArgs = (string.IsNullOrEmpty(partitionString) ? string.Empty : template.TKey + ", ") + (!fuseModule.IsEmpty && Config.AllowFloatingReorderPolicy ? template.TResult : template.TPayload);
            template.emptyOrPartition    = string.IsNullOrEmpty(partitionString) ? "Microsoft.StreamProcessing.Empty.Default" : "new PartitionKey<" + template.TKey + ">(value.PartitionKey)";
            template.partitionString     = partitionString;
            template.baseStructure       = partitionString + "StreamEvent<" + template.genericArguments + ">";
            template.inheritBase         = (ingressType != "StreamEvent") ? template.TPayload : template.baseStructure;
            template.ingressType         = ingressType;
            template.latencyOption       = latencyOption;

            template.partitionFunction = x => partitionExpression == null ?
                                         string.Empty : partitionExpression.Body.ExpressionToCSharpStringWithParameterSubstitution(
                new Dictionary <ParameterExpression, string>
            {
                { partitionExpression.Parameters.Single(), x }
            });
            template.startEdgeFunction = x => startEdgeExpression == null ?
                                         string.Empty : startEdgeExpression.Body.ExpressionToCSharpStringWithParameterSubstitution(
                new Dictionary <ParameterExpression, string>
            {
                { startEdgeExpression.Parameters.Single(), x }
            });
            template.endEdgeFunction = x => endEdgeExpression == null ?
                                       "StreamEvent.InfinitySyncTime" :
                                       endEdgeExpression.Body.ExpressionToCSharpStringWithParameterSubstitution(
                new Dictionary <ParameterExpression, string>
            {
                { endEdgeExpression.Parameters.Single(), x }
            });

            template.fusionOption = fuseModule.IsEmpty ? "Simple" :
                                    (Config.AllowFloatingReorderPolicy ? "Disordered" : "Fused");
            template.resultMightBeNull = template.resultType.CanContainNull();

            Expression[] expressions = null;
            if (!fuseModule.IsEmpty)
            {
                template.valueString = fuseModule.Coalesce <TSource, TResult, TKey>("value.SyncTime", "value.OtherTime", "value.Payload", template.emptyOrPartition, out template.leadingText, out template.trailingText);
                template.generatedEndTimeVariable = "generatedEndTimeVariable";
                if (Config.AllowFloatingReorderPolicy)
                {
                    template.valueString = "value.Payload";
                    template.generatedEndTimeVariable = "value.OtherTime";
                }

                expressions = fuseModule.GetCodeGenExpressions();
            }

            return(template.Generate <TKey, TSource, TResult>(new Type[] { typeof(IStreamable <,>) }, expressions));
        }