src/LogicalPlanner/Logical/DataSourceOperator.cs
/// <summary>
/// This function bind the data source to a given graph definitions
/// </summary>
/// <param name="graphDefinition"></param>
This function bind the data source to a given graph definitions
This function bind the data source to a given graph definitions
public void Bind(IGraphSchemaProvider graphDefinition)
        {
            var properties = new List<ValueField>();
            string entityUniqueName;
            string sourceEntityName = null;
            string sinkEntityName = null;
            ValueField nodeIdField = null;
            ValueField edgeSrcIdField = null;
            ValueField edgeSinkIdField = null;
            if (Entity is NodeEntity)
            {
                var nodeDef = graphDefinition.GetNodeDefinition(Entity.EntityName);
                if (nodeDef == null)
                {
                    throw new TranspilerBindingException($"Failed to bind entity with alias '{Entity.Alias}' of type '{Entity.EntityName}' to graph definition.");
                }
                entityUniqueName = nodeDef.Id;
                nodeIdField = new ValueField(nodeDef.NodeIdProperty.PropertyName, nodeDef.NodeIdProperty.DataType);
                properties.AddRange(nodeDef.Properties.Select(p => new ValueField(p.PropertyName, p.DataType)));
                properties.Add(nodeIdField);
            }
            else
            {
                var edgeEnt = Entity as RelationshipEntity;
                EdgeSchema edgeDef = null;
                switch (edgeEnt.RelationshipDirection)
                {
                    case RelationshipEntity.Direction.Forward:
                        edgeDef = graphDefinition.GetEdgeDefinition(edgeEnt.EntityName, edgeEnt.LeftEntityName, edgeEnt.RightEntityName);
                        break;
                    case RelationshipEntity.Direction.Backward:
                        edgeDef = graphDefinition.GetEdgeDefinition(edgeEnt.EntityName, edgeEnt.RightEntityName, edgeEnt.LeftEntityName);
                        break;
                    default:
                        Debug.Assert(edgeEnt.RelationshipDirection == RelationshipEntity.Direction.Both);
                        edgeDef = graphDefinition.GetEdgeDefinition(edgeEnt.EntityName, edgeEnt.LeftEntityName, edgeEnt.RightEntityName);
                        if (edgeDef == null)
                        {
                            edgeDef = graphDefinition.GetEdgeDefinition(edgeEnt.EntityName, edgeEnt.RightEntityName, edgeEnt.LeftEntityName);
                        }
                        break;
                }
                if (edgeDef == null)
                {
                    throw new TranspilerBindingException($"Failed to bind entity with alias '{Entity.Alias}' of type '{Entity.EntityName}' to graph definition.");
                }
                entityUniqueName = edgeDef.Id;
                sourceEntityName = edgeDef.SourceNodeId;
                sinkEntityName = edgeDef.SinkNodeId;
                edgeSrcIdField = new ValueField(edgeDef.SourceIdProperty.PropertyName, edgeDef.SourceIdProperty.DataType);
                edgeSinkIdField = new ValueField(edgeDef.SinkIdProperty.PropertyName, edgeDef.SinkIdProperty.DataType);
                properties.AddRange(edgeDef.Properties.Select(p => new ValueField(p.PropertyName, p.DataType)));
                properties.Add(edgeSrcIdField);
                properties.Add(edgeSinkIdField);
            }
            Debug.Assert(OutputSchema.Count == 1
                && OutputSchema.First() is EntityField
                && (OutputSchema.First() as EntityField).EntityName == Entity.EntityName);
            var field = OutputSchema.First() as EntityField;
            field.BoundEntityName = entityUniqueName;
            field.BoundSourceEntityName = sourceEntityName;
            field.BoundSinkEntityName = sinkEntityName;
            field.EncapsulatedFields = properties;
            field.NodeJoinField = nodeIdField;
            field.RelSourceJoinField = edgeSrcIdField;
            field.RelSinkJoinField = edgeSinkIdField;
        }
public void Bind ( IGraphSchemaProvider graphDefinition ) { var properties = new List < ValueField > ( ) ; string entityUniqueName ; string sourceEntityName = null ; string sinkEntityName = null ; ValueField nodeIdField = null ; ValueField edgeSrcIdField = null ; ValueField edgeSinkIdField = null ; if ( Entity is NodeEntity ) { var nodeDef = graphDefinition . GetNodeDefinition ( Entity . EntityName ) ; if ( nodeDef == null ) { throw new TranspilerBindingException ( $" Failed to bind entity with alias ' { Entity . Alias } ' of type ' { Entity . EntityName } ' to graph definition. " ) ; } entityUniqueName = nodeDef . Id ; nodeIdField = new ValueField ( nodeDef . NodeIdProperty . PropertyName , nodeDef . NodeIdProperty . DataType ) ; properties . AddRange ( nodeDef . Properties . Select ( p => new ValueField ( p . PropertyName , p . DataType ) ) ) ; properties . Add ( nodeIdField ) ; } else { var edgeEnt = Entity as RelationshipEntity ; EdgeSchema edgeDef = null ; switch ( edgeEnt . RelationshipDirection ) { case RelationshipEntity . Direction . Forward : edgeDef = graphDefinition . GetEdgeDefinition ( edgeEnt . EntityName , edgeEnt . LeftEntityName , edgeEnt . RightEntityName ) ; break ; case RelationshipEntity . Direction . Backward : edgeDef = graphDefinition . GetEdgeDefinition ( edgeEnt . EntityName , edgeEnt . RightEntityName , edgeEnt . LeftEntityName ) ; break ; default : Debug . Assert ( edgeEnt . RelationshipDirection == RelationshipEntity . Direction . Both ) ; edgeDef = graphDefinition . GetEdgeDefinition ( edgeEnt . EntityName , edgeEnt . LeftEntityName , edgeEnt . RightEntityName ) ; if ( edgeDef == null ) { edgeDef = graphDefinition . GetEdgeDefinition ( edgeEnt . EntityName , edgeEnt . RightEntityName , edgeEnt . LeftEntityName ) ; } break ; } if ( edgeDef == null ) { throw new TranspilerBindingException ( $" Failed to bind entity with alias ' { Entity . Alias } ' of type ' { Entity . EntityName } ' to graph definition. " ) ; } entityUniqueName = edgeDef . Id ; sourceEntityName = edgeDef . SourceNodeId ; sinkEntityName = edgeDef . SinkNodeId ; edgeSrcIdField = new ValueField ( edgeDef . SourceIdProperty . PropertyName , edgeDef . SourceIdProperty . DataType ) ; edgeSinkIdField = new ValueField ( edgeDef . SinkIdProperty . PropertyName , edgeDef . SinkIdProperty . DataType ) ; properties . AddRange ( edgeDef . Properties . Select ( p => new ValueField ( p . PropertyName , p . DataType ) ) ) ; properties . Add ( edgeSrcIdField ) ; properties . Add ( edgeSinkIdField ) ; } Debug . Assert ( OutputSchema . Count == 1 && OutputSchema . First ( ) is EntityField && ( OutputSchema . First ( ) as EntityField ) . EntityName == Entity . EntityName ) ; var field = OutputSchema . First ( ) as EntityField ; field . BoundEntityName = entityUniqueName ; field . BoundSourceEntityName = sourceEntityName ; field . BoundSinkEntityName = sinkEntityName ; field . EncapsulatedFields = properties ; field . NodeJoinField = nodeIdField ; field . RelSourceJoinField = edgeSrcIdField ; field . RelSinkJoinField = edgeSinkIdField ; }
This function bind the data source to a given graph definitions
This function bind the data source to a given graph definitions
// During binding, we read graph definition of the entity // and populate the EntityField object in the output // with the list of fields that the node/edge definition can expose // either direction // TODO: we don't handle 'both' direction yet
graphDefinition
IGraphSchemaProvider
None