コード例 #1
0
        internal override List <RawRecord> CrossApply(RawRecord record)
        {
            List <RawRecord> results = new List <RawRecord>();

            foreach (int propertyIndex in this.propertiesIndex)
            {
                FieldObject propertyObject = record[propertyIndex];
                if (propertyObject == null)
                {
                    continue;
                }

                VertexPropertyField vp = propertyObject as VertexPropertyField;
                if (vp != null)
                {
                    foreach (VertexSinglePropertyField vsp in vp.Multiples.Values)
                    {
                        RawRecord r = new RawRecord();
                        r.Append(new StringField(vsp.PropertyValue, vsp.JsonDataType));
                        results.Add(r);
                    }
                    continue;
                }

                VertexSinglePropertyField singleVp = propertyObject as VertexSinglePropertyField;
                if (singleVp != null)
                {
                    RawRecord r = new RawRecord();
                    r.Append(new StringField(singleVp.PropertyValue, singleVp.JsonDataType));
                    results.Add(r);
                    continue;
                }

                EdgePropertyField edgePf = propertyObject as EdgePropertyField;
                if (edgePf != null)
                {
                    RawRecord r = new RawRecord();
                    r.Append(new StringField(edgePf.PropertyValue, edgePf.JsonDataType));
                    results.Add(r);
                    continue;
                }

                ValuePropertyField metaPf = propertyObject as ValuePropertyField;
                if (metaPf != null)
                {
                    RawRecord r = new RawRecord();
                    r.Append(new StringField(metaPf.PropertyValue, metaPf.JsonDataType));
                    results.Add(r);
                    continue;
                }

                Debug.Assert(false, "Should not get here.");
            }

            return(results);
        }
コード例 #2
0
        private void DropVertexPropertyMetaProperty(ValuePropertyField metaProperty)
        {
            Debug.Assert(metaProperty.Parent is VertexSinglePropertyField);
            VertexSinglePropertyField vertexSingleProperty = (VertexSinglePropertyField)metaProperty.Parent;

            VertexField vertexField  = vertexSingleProperty.VertexProperty.Vertex;
            JObject     vertexObject = this.connection.RetrieveDocumentById(vertexField.VertexId);

            Debug.Assert(vertexObject[vertexSingleProperty.PropertyName] != null);

            JToken propertyJToken = ((JArray)vertexObject[vertexSingleProperty.PropertyName])
                                    .First(singleProperty => (string)singleProperty["_propId"] == vertexSingleProperty.PropertyId);

            JObject metaPropertyJObject = (JObject)propertyJToken?["_meta"];

            metaPropertyJObject?.Property(metaProperty.PropertyName)?.Remove();

            // Update DocDB
            this.connection.ReplaceOrDeleteDocumentAsync(vertexField.VertexId, vertexObject, (string)vertexObject["_partition"]).Wait();

            // Update vertex field
            vertexSingleProperty.MetaProperties.Remove(metaProperty.PropertyName);
        }
コード例 #3
0
        internal override List <RawRecord> CrossApply(RawRecord record)
        {
            List <RawRecord> results = new List <RawRecord>();

            FieldObject inputTarget = record[this.inputTargetIndex];

            if (inputTarget is VertexField)
            {
                VertexField vertexField = (VertexField)inputTarget;
                foreach (VertexPropertyField property in vertexField.VertexProperties.Values)
                {
                    string propertyName = property.PropertyName;
                    Debug.Assert(!VertexField.IsVertexMetaProperty(propertyName));
                    Debug.Assert(propertyName == "_edge");
                    Debug.Assert(propertyName == "_reverse_edge");

                    switch (propertyName)
                    {
                    case "_rid":
                    case "_self":
                    case "_etag":
                    case "_attachments":
                    case "_ts":
                        continue;

                    default:
                        foreach (VertexSinglePropertyField singleVp in property.Multiples.Values)
                        {
                            RawRecord r = new RawRecord();
                            r.Append(new StringField(singleVp.PropertyValue, singleVp.JsonDataType));
                            results.Add(r);
                        }
                        break;
                    }
                }
            }
            else if (inputTarget is EdgeField)
            {
                EdgeField edgeField = (EdgeField)inputTarget;

                foreach (KeyValuePair <string, EdgePropertyField> propertyPair in edgeField.EdgeProperties)
                {
                    string            propertyName      = propertyPair.Key;
                    EdgePropertyField edgePropertyField = propertyPair.Value;

                    switch (propertyName)
                    {
                    // Reserved properties for meta-data
                    case "_edgeId":
                    case "_offset":
                    case "_srcV":
                    case "_sinkV":
                    case "_srcVLabel":
                    case "_sinkVLabel":
                        continue;

                    default:
                        RawRecord r = new RawRecord();
                        r.Append(new StringField(edgePropertyField.PropertyValue, edgePropertyField.JsonDataType));
                        results.Add(r);
                        break;
                    }
                }
            }
            else if (inputTarget is VertexSinglePropertyField)
            {
                VertexSinglePropertyField singleVp = inputTarget as VertexSinglePropertyField;
                foreach (KeyValuePair <string, ValuePropertyField> kvp in singleVp.MetaProperties)
                {
                    RawRecord          r = new RawRecord();
                    ValuePropertyField metaPropertyField = kvp.Value;
                    r.Append(new StringField(metaPropertyField.PropertyValue, metaPropertyField.JsonDataType));
                    results.Add(r);
                }
            }
            else
            {
                throw new GraphViewException("The input of values() cannot be a meta or edge property.");
            }
            return(results);
        }
コード例 #4
0
        internal override List <RawRecord> CrossApply(RawRecord record)
        {
            List <RawRecord> results = new List <RawRecord>();

            foreach (int propertyIndex in this.propertiesIndex)
            {
                FieldObject propertyObject = record[propertyIndex];
                if (propertyObject == null)
                {
                    continue;
                }

                VertexPropertyField vp = propertyObject as VertexPropertyField;
                if (vp != null)
                {
                    foreach (VertexSinglePropertyField vsp in vp.Multiples.Values)
                    {
                        RawRecord r = new RawRecord();
                        r.Append(new VertexSinglePropertyField(vsp));
                        foreach (string metapropertyName in this.populateMetaproperties)
                        {
                            r.Append(vsp[metapropertyName]);
                        }

                        results.Add(r);
                    }
                    continue;
                }

                VertexSinglePropertyField singleVp = propertyObject as VertexSinglePropertyField;
                if (singleVp != null)
                {
                    RawRecord r = new RawRecord();
                    r.Append(new VertexSinglePropertyField(singleVp));
                    foreach (string metapropertyName in this.populateMetaproperties)
                    {
                        r.Append(singleVp[metapropertyName]);
                    }
                    results.Add(r);
                    continue;
                }

                EdgePropertyField edgePf = propertyObject as EdgePropertyField;
                if (edgePf != null)
                {
                    if (this.populateMetaproperties.Count > 0)
                    {
                        throw new GraphViewException("An edge property cannot contain meta properties.");
                    }

                    RawRecord r = new RawRecord();
                    r.Append(new EdgePropertyField(edgePf));
                    results.Add(r);
                    continue;
                }

                ValuePropertyField metaPf = propertyObject as ValuePropertyField;
                if (metaPf != null)
                {
                    if (this.populateMetaproperties.Count > 0)
                    {
                        throw new GraphViewException("A meta property cannot contain meta properties.");
                    }

                    RawRecord r = new RawRecord();
                    r.Append(new ValuePropertyField(metaPf));
                    results.Add(r);
                    continue;
                }

                Debug.Assert(false, "Should not get here.");
            }

            return(results);
        }
コード例 #5
0
        public FieldObject Terminate()
        {
            if (this.subgraphState.graph != null)
            {
                return(this.subgraphState.graph);
            }


            if (this.subgraphState.vertexIds.Any())
            {
                // this API would modify the parameter, so deep copy it first.
                List <VertexField> vertices = this.subgraphState.command.Connection.CreateDatabasePortal()
                                              .GetVerticesByIds(new HashSet <string>(this.subgraphState.vertexIds), this.subgraphState.command, null, true);

                List <string> vertexGraphSON = new List <string>();

                foreach (VertexField vertexField in vertices)
                {
                    JObject vertex = new JObject
                    {
                        new JProperty("type", "vertex"),
                        new JProperty("id", vertexField.VertexMetaProperties[KW_DOC_ID].PropertyValue)
                    };

                    Debug.Assert(vertexField.VertexMetaProperties.ContainsKey(KW_VERTEX_LABEL));
                    if (vertexField.VertexMetaProperties[KW_VERTEX_LABEL] != null)
                    {
                        vertex.Add(new JProperty("label", vertexField.VertexMetaProperties[KW_VERTEX_LABEL].PropertyValue));
                    }

                    // Add in Edges
                    JObject inE = new JObject();
                    if (vertexField.RevAdjacencyList != null && vertexField.RevAdjacencyList.AllEdges.Any())
                    {
                        var groupByLabel = vertexField.RevAdjacencyList.AllEdges.GroupBy(e => e.Label);
                        foreach (var g in groupByLabel)
                        {
                            string edgelLabel = g.Key;
                            JArray group      = new JArray();

                            foreach (EdgeField edgeField in g)
                            {
                                string edgeId = edgeField.EdgeProperties[KW_EDGE_ID].ToValue;
                                if (!this.subgraphState.edgeIds.Contains(edgeId))
                                {
                                    continue;
                                }
                                JObject edge = new JObject
                                {
                                    new JProperty("id", edgeField.EdgeProperties[KW_EDGE_ID].ToValue),
                                    new JProperty("outV", edgeField.OutV)
                                };

                                // Add edge properties
                                JObject properties = new JObject();
                                foreach (string propertyName in edgeField.EdgeProperties.Keys)
                                {
                                    switch (propertyName)
                                    {
                                    case KW_EDGE_ID:
                                    case KW_EDGE_LABEL:
                                    case KW_EDGE_SRCV:
                                    case KW_EDGE_SINKV:
                                    case KW_EDGE_SRCV_LABEL:
                                    case KW_EDGE_SINKV_LABEL:
                                    case KW_EDGE_SRCV_PARTITION:
                                    case KW_EDGE_SINKV_PARTITION:
                                        continue;

                                    default:
                                        break;
                                    }

                                    properties.Add(new JProperty(propertyName,
                                                                 JsonDataTypeHelper.GetStringFieldData(edgeField.EdgeProperties[propertyName].PropertyValue,
                                                                                                       edgeField.EdgeProperties[propertyName].JsonDataType)));
                                }
                                edge.Add(new JProperty("properties", properties));
                                group.Add(edge);
                            }

                            if (group.Count != 0)
                            {
                                inE.Add(edgelLabel, group);
                            }
                        }
                    }
                    if (inE.Count != 0)
                    {
                        vertex.Add(new JProperty("inE", inE));
                    }



                    // Add out Edges
                    JObject outE = new JObject();
                    if (vertexField.AdjacencyList != null && vertexField.AdjacencyList.AllEdges.Any())
                    {
                        var groupByLabel = vertexField.AdjacencyList.AllEdges.GroupBy(e => e.Label);
                        foreach (var g in groupByLabel)
                        {
                            string edgelLabel = g.Key;
                            JArray group      = new JArray();

                            foreach (EdgeField edgeField in g)
                            {
                                string edgeId = edgeField.EdgeProperties[KW_EDGE_ID].ToValue;
                                if (!this.subgraphState.edgeIds.Contains(edgeId))
                                {
                                    continue;
                                }
                                JObject edge = new JObject
                                {
                                    new JProperty("id", edgeField.EdgeProperties[KW_EDGE_ID].ToValue),
                                    new JProperty("inV", edgeField.InV)
                                };

                                // Add edge properties
                                JObject properties = new JObject();
                                foreach (string propertyName in edgeField.EdgeProperties.Keys)
                                {
                                    switch (propertyName)
                                    {
                                    case KW_EDGE_ID:
                                    case KW_EDGE_LABEL:
                                    //case KW_EDGE_OFFSET:
                                    case KW_EDGE_SRCV:
                                    case KW_EDGE_SINKV:
                                    case KW_EDGE_SRCV_LABEL:
                                    case KW_EDGE_SINKV_LABEL:
                                    case KW_EDGE_SRCV_PARTITION:
                                    case KW_EDGE_SINKV_PARTITION:
                                        continue;

                                    default:
                                        break;
                                    }

                                    properties.Add(new JProperty(propertyName,
                                                                 JsonDataTypeHelper.GetStringFieldData(edgeField.EdgeProperties[propertyName].PropertyValue,
                                                                                                       edgeField.EdgeProperties[propertyName].JsonDataType)));
                                }
                                edge.Add(new JProperty("properties", properties));
                                group.Add(edge);
                            }

                            if (group.Count != 0)
                            {
                                outE.Add(edgelLabel, group);
                            }
                        }
                    }
                    if (outE.Count != 0)
                    {
                        vertex.Add(new JProperty("outE", outE));
                    }


                    // Add vertex properties
                    JObject vertexProperties = new JObject();
                    foreach (KeyValuePair <string, VertexPropertyField> kvp in vertexField.VertexProperties)
                    {
                        string propertyName = kvp.Key;

                        Debug.Assert(!VertexField.IsVertexMetaProperty(propertyName), "Bug!");
                        Debug.Assert(!(propertyName == KW_VERTEX_EDGE || propertyName == KW_VERTEX_REV_EDGE), "Bug!");

                        JArray propertyArray = new JArray();
                        foreach (VertexSinglePropertyField vsp in kvp.Value.Multiples.Values)
                        {
                            JObject property = new JObject
                            {
                                new JProperty("id", vsp.PropertyId),
                                new JProperty("value",
                                              JsonDataTypeHelper.GetStringFieldData(vsp.PropertyValue, vsp.JsonDataType))
                            };

                            if (vsp.MetaProperties.Count > 0)
                            {
                                JObject metaProperties = new JObject();

                                foreach (KeyValuePair <string, ValuePropertyField> metaKvp in vsp.MetaProperties)
                                {
                                    string             key   = metaKvp.Key;
                                    ValuePropertyField value = metaKvp.Value;

                                    metaProperties.Add(new JProperty(key, JsonDataTypeHelper.GetStringFieldData(value.PropertyValue, value.JsonDataType)));
                                }
                                property.Add(new JProperty("properties", metaProperties));
                            }

                            propertyArray.Add(property);
                        }
                        vertexProperties.Add(new JProperty(propertyName, propertyArray));
                    }

                    vertex.Add(new JProperty("properties", vertexProperties));

                    vertexGraphSON.Add(vertex.ToString(Formatting.None));
                }

                this.subgraphState.graph = new StringField("[" + string.Join(", ", vertexGraphSON) + "]");
            }
            else
            {
                this.subgraphState.graph = new StringField("[]");
            }

            return(this.subgraphState.graph);
        }
コード例 #6
0
ファイル: TVFOperator.cs プロジェクト: georgeycliu/k-core
        internal override List <RawRecord> CrossApply(RawRecord record)
        {
            MapField valueMap = new MapField();

            FieldObject inputTarget = record[this.inputTargetIndex];

            if (inputTarget is VertexField)
            {
                VertexField vertexField = (VertexField)inputTarget;

                if (this.propertyNameList.Any())
                {
                    foreach (string propertyName in this.propertyNameList)
                    {
                        FieldObject property = vertexField[propertyName];
                        if (property == null)
                        {
                            continue;
                        }

                        List <FieldObject>  values = new List <FieldObject>();
                        VertexPropertyField vp     = property as VertexPropertyField;
                        if (vp != null)
                        {
                            foreach (VertexSinglePropertyField vsp in vp.Multiples.Values)
                            {
                                values.Add(vsp);
                            }
                        }

                        valueMap.Add(new StringField(propertyName), new CollectionField(values));
                    }
                }
                else
                {
                    foreach (VertexPropertyField property in vertexField.VertexProperties.Values)
                    {
                        string propertyName = property.PropertyName;
                        Debug.Assert(!VertexField.IsVertexMetaProperty(propertyName));
                        Debug.Assert(!propertyName.Equals(KW_VERTEX_EDGE));
                        Debug.Assert(!propertyName.Equals(KW_VERTEX_REV_EDGE));

                        switch (propertyName)
                        {
                        case "_rid":
                        case "_self":
                        case "_etag":
                        case "_attachments":
                        case "_ts":
                            continue;

                        default:
                            List <FieldObject> values = new List <FieldObject>();
                            foreach (VertexSinglePropertyField singleVp in property.Multiples.Values)
                            {
                                values.Add(singleVp);
                            }
                            valueMap.Add(new StringField(propertyName), new CollectionField(values));
                            break;
                        }
                    }
                }
            }
            else if (inputTarget is EdgeField)
            {
                EdgeField edgeField = (EdgeField)inputTarget;

                if (this.propertyNameList.Any())
                {
                    foreach (string propertyName in this.propertyNameList)
                    {
                        FieldObject property = edgeField[propertyName];
                        if (property == null)
                        {
                            continue;
                        }

                        EdgePropertyField edgePf = property as EdgePropertyField;
                        if (edgePf != null)
                        {
                            valueMap.Add(new StringField(propertyName), edgePf);
                        }
                    }
                }
                else
                {
                    foreach (KeyValuePair <string, EdgePropertyField> propertyPair in edgeField.EdgeProperties)
                    {
                        string            propertyName      = propertyPair.Key;
                        EdgePropertyField edgePropertyField = propertyPair.Value;

                        switch (propertyName)
                        {
                        // Reserved properties for meta-data
                        case KW_EDGE_ID:
                        //case KW_EDGE_OFFSET:
                        case KW_EDGE_SRCV:
                        case KW_EDGE_SINKV:
                        case KW_EDGE_SRCV_LABEL:
                        case KW_EDGE_SINKV_LABEL:
                            continue;

                        default:
                            valueMap.Add(new StringField(propertyName), edgePropertyField);
                            break;
                        }
                    }
                }
            }
            else if (inputTarget is VertexSinglePropertyField)
            {
                VertexSinglePropertyField singleVp = inputTarget as VertexSinglePropertyField;

                if (this.propertyNameList.Any())
                {
                    foreach (string propertyName in this.propertyNameList)
                    {
                        FieldObject property = singleVp[propertyName];
                        if (property == null)
                        {
                            continue;
                        }

                        ValuePropertyField metaPf = property as ValuePropertyField;
                        if (metaPf != null)
                        {
                            valueMap.Add(new StringField(propertyName), metaPf);
                        }
                    }
                }
                else
                {
                    foreach (KeyValuePair <string, ValuePropertyField> kvp in singleVp.MetaProperties)
                    {
                        valueMap.Add(new StringField(kvp.Key), kvp.Value);
                    }
                }
            }
            else
            {
                throw new GraphViewException("The input of valueMap() cannot be a meta or edge property.");
            }

            RawRecord result = new RawRecord();

            result.Append(valueMap);
            return(new List <RawRecord> {
                result
            });
        }
コード例 #7
0
ファイル: TVFOperator.cs プロジェクト: georgeycliu/k-core
        internal override List <RawRecord> CrossApply(RawRecord record)
        {
            List <RawRecord> results = new List <RawRecord>();

            FieldObject inputTarget = record[this.inputTargetIndex];

            if (inputTarget is VertexField)
            {
                VertexField vertexField = (VertexField)inputTarget;
                foreach (VertexPropertyField property in vertexField.VertexProperties.Values)
                {
                    string propertyName = property.PropertyName;
                    Debug.Assert(!VertexField.IsVertexMetaProperty(propertyName));
                    Debug.Assert(!propertyName.Equals(KW_VERTEX_EDGE));
                    Debug.Assert(!propertyName.Equals(KW_VERTEX_REV_EDGE));

                    switch (propertyName)
                    {
                    case "_rid":
                    case "_self":
                    case "_etag":
                    case "_attachments":
                    case "_ts":
                        continue;

                    default:
                        foreach (VertexSinglePropertyField singleVp in property.Multiples.Values)
                        {
                            RawRecord r = new RawRecord();
                            r.Append(new VertexSinglePropertyField(singleVp));
                            foreach (string metaPropertyName in this.populateMetaProperties)
                            {
                                r.Append(singleVp[metaPropertyName]);
                            }
                            results.Add(r);
                        }
                        break;
                    }
                }
            }
            else if (inputTarget is EdgeField)
            {
                EdgeField edgeField = (EdgeField)inputTarget;
                foreach (KeyValuePair <string, EdgePropertyField> propertyPair in edgeField.EdgeProperties)
                {
                    string            propertyName      = propertyPair.Key;
                    EdgePropertyField edgePropertyField = propertyPair.Value;

                    switch (propertyName)
                    {
                    // Reserved properties for meta-data
                    case KW_EDGE_LABEL:
                    case KW_EDGE_ID:
                    //case KW_EDGE_OFFSET:
                    case KW_EDGE_SRCV:
                    case KW_EDGE_SINKV:
                    case KW_EDGE_SRCV_LABEL:
                    case KW_EDGE_SINKV_LABEL:
                        continue;

                    default:
                        RawRecord r = new RawRecord();
                        r.Append(new EdgePropertyField(edgePropertyField));
                        results.Add(r);
                        break;
                    }
                }

                if (this.populateMetaProperties.Count > 0 && results.Count > 0)
                {
                    throw new GraphViewException("An edge property cannot contain meta properties.");
                }
            }
            else if (inputTarget is VertexSinglePropertyField)
            {
                VertexSinglePropertyField singleVp = (VertexSinglePropertyField)inputTarget;
                foreach (KeyValuePair <string, ValuePropertyField> kvp in singleVp.MetaProperties)
                {
                    RawRecord          r = new RawRecord();
                    ValuePropertyField metaPropertyField = kvp.Value;
                    r.Append(new ValuePropertyField(metaPropertyField));
                    results.Add(r);
                }

                if (this.populateMetaProperties.Count > 0 && results.Count > 0)
                {
                    throw new GraphViewException("An edge property cannot contain meta properties.");
                }
            }
            else
            {
                throw new GraphViewException("The input of properties() cannot be a meta or edge property.");
            }
            return(results);
        }