src/LogicalPlanner/Logical/LogicalOperator.cs
/// <summary>
/// Used by logic planner to update the list of ReferencedFields
/// </summary>
Used by logic planner to update the list of ReferencedFields
Used by logic planner to update the list of ReferencedFields
internal virtual void PropagateReferencedPropertiesForEntityFields()
        {
            var referredFieldsInDownstreamOps = OutOperators.SelectMany(op => op.InputSchema)
                .Where(f => f is EntityField)
                .Cast<EntityField>()
                .GroupBy(f => f.FieldAlias)
                .ToDictionary(kv => kv.Key, kv => kv.SelectMany(fn => fn.ReferencedFieldAliases).Distinct().ToList());
            foreach (var field in OutputSchema.Where(f => f is EntityField).Cast<EntityField>())
            {
                Debug.Assert(referredFieldsInDownstreamOps.ContainsKey(field.FieldAlias));
                field.AddReferenceFieldNames(referredFieldsInDownstreamOps[field.FieldAlias]);
            }
            if ((InputSchema?.Count ?? 0) > 0)
            {
                var aliasMap = new Dictionary<String, String>();
                if (this is ProjectionOperator)
                {
                    var aliasMap1 = (this as ProjectionOperator).ProjectionMap
                        .Where(u => OutputSchema.Where(n => n is EntityField).Any(k => k.FieldAlias == u.Key));
                    aliasMap = aliasMap1?.ToDictionary(n => n.Value.GetChildrenQueryExpressionType<QueryExpressionProperty>().First().VariableName, n => n.Key);
                }
                else
                {
                    aliasMap = OutputSchema.Where(n => n is EntityField).ToDictionary(n => n.FieldAlias, n=> n.FieldAlias);
                }
                foreach (var field in InputSchema.Where(f => f is EntityField).Cast<EntityField>())
                {
                    var mappedAlias = (aliasMap.ContainsKey(field.FieldAlias) ?aliasMap[field.FieldAlias]:null);
                    if (mappedAlias != null && referredFieldsInDownstreamOps.ContainsKey(mappedAlias))
                    {
                        field.AddReferenceFieldNames(referredFieldsInDownstreamOps[mappedAlias]);
                    }
                }
                var referredFieldsForUpstream = InputSchema
                    .Where(f => f is EntityField).Cast<EntityField>()
                    .ToDictionary(kv => kv.FieldAlias, kv => kv);
                AppendReferencedProperties(referredFieldsForUpstream);
            }
        }
internal virtual void PropagateReferencedPropertiesForEntityFields ( ) { var referredFieldsInDownstreamOps = OutOperators . SelectMany ( op => op . InputSchema ) . Where ( f => f is EntityField ) . Cast < EntityField > ( ) . GroupBy ( f => f . FieldAlias ) . ToDictionary ( kv => kv . Key , kv => kv . SelectMany ( fn => fn . ReferencedFieldAliases ) . Distinct ( ) . ToList ( ) ) ; foreach ( var field in OutputSchema . Where ( f => f is EntityField ) . Cast < EntityField > ( ) ) { Debug . Assert ( referredFieldsInDownstreamOps . ContainsKey ( field . FieldAlias ) ) ; field . AddReferenceFieldNames ( referredFieldsInDownstreamOps [ field . FieldAlias ] ) ; } if ( ( InputSchema ? . Count ?? 0 ) > 0 ) { var aliasMap = new Dictionary < String , String > ( ) ; if ( this is ProjectionOperator ) { var aliasMap1 = ( this as ProjectionOperator ) . ProjectionMap . Where ( u => OutputSchema . Where ( n => n is EntityField ) . Any ( k => k . FieldAlias == u . Key ) ) ; aliasMap = aliasMap1 ? . ToDictionary ( n => n . Value . GetChildrenQueryExpressionType < QueryExpressionProperty > ( ) . First ( ) . VariableName , n => n . Key ) ; } else { aliasMap = OutputSchema . Where ( n => n is EntityField ) . ToDictionary ( n => n . FieldAlias , n => n . FieldAlias ) ; } foreach ( var field in InputSchema . Where ( f => f is EntityField ) . Cast < EntityField > ( ) ) { var mappedAlias = ( aliasMap . ContainsKey ( field . FieldAlias ) ? aliasMap [ field . FieldAlias ] : null ) ; if ( mappedAlias != null && referredFieldsInDownstreamOps . ContainsKey ( mappedAlias ) ) { field . AddReferenceFieldNames ( referredFieldsInDownstreamOps [ mappedAlias ] ) ; } } var referredFieldsForUpstream = InputSchema . Where ( f => f is EntityField ) . Cast < EntityField > ( ) . ToDictionary ( kv => kv . FieldAlias , kv => kv ) ; AppendReferencedProperties ( referredFieldsForUpstream ) ; } }
Used by logic planner to update the list of ReferencedFields
Used by logic planner to update the list of ReferencedFields
// lift the referenced fields from the next layer of operators back to this one's output entity fields // lift the referenced fields in the entity fields from output to input schema of this operator, if // applicable // handle entity name renamed cases by creating a map from field alias before projection to after  // projection // create a dummy alias map ( A -> A, B -> B; not alias name modified) for non-projection operator // Some operators has additional fields may get referenced even they are not in output schema // Such as in WHERE or ORDER BY // Child logical operator class implement this and does the appending