private void DropVertexSingleProperty(VertexSinglePropertyField vp)
        {
            // Update DocDB
            VertexField vertexField  = vp.VertexProperty.Vertex;
            JObject     vertexObject = this.connection.RetrieveDocumentById(vertexField.VertexId);

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

            JArray vertexProperty = (JArray)vertexObject[vp.PropertyName];

            vertexProperty
            .First(singleProperty => (string)singleProperty["_propId"] == vp.PropertyId)
            .Remove();
            if (vertexObject.Count == 0)
            {
                vertexProperty.Remove();
            }

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

            // Update vertex field
            VertexPropertyField vertexPropertyField = vertexField.VertexProperties[vp.PropertyName];
            bool found = vertexPropertyField.Multiples.Remove(vp.PropertyId);

            Debug.Assert(found);
            if (!vertexPropertyField.Multiples.Any())
            {
                vertexField.VertexProperties.Remove(vp.PropertyName);
            }
        }
        private void UpdatePropertiesOfVertex(VertexField vertex)
        {
            JObject vertexDocument = this.Connection.RetrieveDocumentById(vertex.VertexId);

            foreach (WPropertyExpression property in this.updateProperties)
            {
                Debug.Assert(property.Value != null);

                VertexPropertyField vertexProperty;
                string name = property.Key.Value;

                // Construct single property
                JObject meta = new JObject();
                foreach (KeyValuePair <WValueExpression, WValueExpression> pair in property.MetaProperties)
                {
                    meta[pair.Key.Value] = pair.Value.ToJValue();
                }
                JObject singleProperty = new JObject {
                    ["_value"]  = property.Value.ToJValue(),
                    ["_propId"] = GraphViewConnection.GenerateDocumentId(),
                    ["_meta"]   = meta,
                };

                // Set / Append to multiProperty
                JArray multiProperty;
                if (vertexDocument[name] == null)
                {
                    multiProperty        = new JArray();
                    vertexDocument[name] = multiProperty;
                }
                else
                {
                    multiProperty = (JArray)vertexDocument[name];
                }

                if (property.Cardinality == GremlinKeyword.PropertyCardinality.single)
                {
                    multiProperty.Clear();
                }
                multiProperty.Add(singleProperty);

                // Update vertex field
                bool existed = vertex.VertexProperties.TryGetValue(name, out vertexProperty);
                if (!existed)
                {
                    vertexProperty = new VertexPropertyField(vertexDocument.Property(name), vertex);
                    vertex.VertexProperties.Add(name, vertexProperty);
                }
                else
                {
                    vertexProperty.Replace(vertexDocument.Property(name));
                }
            }

            // Upload to DocDB
            this.Connection.ReplaceOrDeleteDocumentAsync(vertex.VertexId, vertexDocument, (string)vertexDocument["_partition"]).Wait();
        }
예제 #3
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);
        }
        private void DropVertexProperty(VertexPropertyField vp)
        {
            // Update DocDB
            VertexField vertexField  = vp.Vertex;
            JObject     vertexObject = this.connection.RetrieveDocumentById(vertexField.VertexId);

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

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

            // Update vertex field
            vertexField.VertexProperties.Remove(vp.PropertyName);
        }
예제 #5
0
        public override bool Evaluate(RawRecord record)
        {
            FieldObject lhs = this.lhsFunction.Evaluate(record);

            if (lhs == null)
            {
                return(false);
            }

            if (lhs is VertexPropertyField)
            {
                VertexPropertyField vp = (VertexPropertyField)lhs;
                foreach (VertexSinglePropertyField vsp in vp.Multiples.Values)
                {
                    JsonDataType lhsDataType = vsp.JsonDataType;
                    if (this.notDefined)
                    {
                        if (NotIn(vsp.ToValue, lhsDataType, record, this.values))
                        {
                            return(true);
                        }
                    }
                    else
                    {
                        if (In(vsp.ToValue, lhsDataType, record, this.values))
                        {
                            return(true);
                        }
                    }
                }

                return(false);
            }
            else
            {
                string       lhsValue    = lhs.ToValue;
                JsonDataType lhsDataType = this.lhsFunction.DataType();
                return(this.notDefined
                    ? NotIn(lhsValue, lhsDataType, record, this.values)
                    : In(lhsValue, lhsDataType, record, this.values));
            }
        }
예제 #6
0
        public override bool Evaluate(RawRecord record)
        {
            FieldObject lhs = firstScalarFunction.Evaluate(record);
            FieldObject rhs = secondScalarFunction.Evaluate(record);

            if (lhs == null || rhs == null)
            {
                return(false);
            }

            if (lhs is VertexPropertyField)
            {
                VertexPropertyField vp = (VertexPropertyField)lhs;
                foreach (VertexSinglePropertyField vsp in vp.Multiples.Values)
                {
                    JsonDataType type1 = vsp.JsonDataType;
                    JsonDataType type2 = secondScalarFunction.DataType();

                    JsonDataType targetType = type1 > type2 ? type1 : type2;

                    if (Compare(vsp.ToValue, rhs.ToValue, targetType, this.comparisonType))
                    {
                        return(true);
                    }
                }
                return(false);
            }
            else
            {
                JsonDataType type1 = firstScalarFunction.DataType();
                JsonDataType type2 = secondScalarFunction.DataType();

                JsonDataType targetType = type1 > type2 ? type1 : type2;

                string value1 = firstScalarFunction.Evaluate(record)?.ToValue;
                string value2 = secondScalarFunction.Evaluate(record)?.ToValue;

                return(Compare(value1, value2, targetType, this.comparisonType));
            }
        }
예제 #7
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);
        }
예제 #8
0
        internal override List <RawRecord> CrossApply(RawRecord record)
        {
            var results = new List <RawRecord>();

            // Extract all properties if allPropertyIndex >= 0
            if (allPropertyIndex >= 0 && record[allPropertyIndex] != null)
            {
                VertexField vertexField = record[allPropertyIndex] as VertexField;
                if (vertexField != null)
                {
                    foreach (var propertyPair in vertexField.VertexProperties)
                    {
                        string propertyName = propertyPair.Key;
                        VertexPropertyField propertyField = propertyPair.Value;

                        switch (propertyName)
                        {
                        // Reversed properties for meta-data
                        case "_edge":
                        case "_partition":
                        case "_reverse_edge":
                        case "_nextEdgeOffset":

                        case "_rid":
                        case "_self":
                        case "_etag":
                        case "_attachments":
                        case "_ts":
                            continue;

                        default:
                            RawRecord r = new RawRecord();
                            r.Append(propertyField);
                            results.Add(r);
                            break;
                        }
                    }
                }
                else
                {
                    EdgeField edgeField = record[allPropertyIndex] as EdgeField;
                    if (edgeField == null)
                    {
                        throw new GraphViewException(
                                  string.Format("The FieldObject record[{0}] should be a VertexField or EdgeField but now it is {1}.",
                                                allPropertyIndex, record[allPropertyIndex].ToString()));
                    }

                    foreach (var propertyPair in edgeField.EdgeProperties)
                    {
                        string            propertyName  = propertyPair.Key;
                        EdgePropertyField propertyField = propertyPair.Value;

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

                        default:
                            RawRecord r = new RawRecord();
                            r.Append(propertyField);
                            results.Add(r);
                            break;
                        }
                    }
                }
            }
            else
            {
                // TODO: Now translation code needn't to generate the key name for the operator
                foreach (var pair in propertyList)
                {
                    //string propertyName = pair.Item1;
                    int propertyValueIndex = pair.Item2;
                    var propertyValue      = record[propertyValueIndex];
                    if (propertyValue == null)
                    {
                        continue;
                    }

                    var result = new RawRecord();
                    result.Append(propertyValue);
                    results.Add(result);
                }
            }

            return(results);
        }
예제 #9
0
        internal override List <RawRecord> CrossApply(RawRecord record)
        {
            var results = new List <RawRecord>();

            // Extract all values if allValuesIndex >= 0
            if (allValuesIndex >= 0 && record[allValuesIndex] != null)
            {
                VertexField vertexField = record[allValuesIndex] as VertexField;
                if (vertexField != null)
                {
                    foreach (var propertyPair in vertexField.VertexProperties)
                    {
                        string propertyName = propertyPair.Key;
                        VertexPropertyField propertyField = propertyPair.Value;

                        switch (propertyName)
                        {
                        // Reversed properties for meta-data
                        case "_edge":
                        case "_partition":
                        case "_reverse_edge":
                        case "_nextEdgeOffset":

                        case "_rid":
                        case "_self":
                        case "_etag":
                        case "_attachments":
                        case "_ts":
                            continue;

                        default:
                            RawRecord r = new RawRecord();
                            r.Append(new StringField(propertyField.ToValue, propertyField.JsonDataType));
                            results.Add(r);
                            break;
                        }
                    }
                }
                else
                {
                    EdgeField edgeField = record[allValuesIndex] as EdgeField;
                    if (edgeField == null)
                    {
                        throw new GraphViewException(
                                  string.Format("The FieldObject record[{0}] should be a VertexField or EdgeField but now it is {1}.",
                                                allValuesIndex, record[allValuesIndex].ToString()));
                    }

                    foreach (var propertyPair in edgeField.EdgeProperties)
                    {
                        string            propertyName  = propertyPair.Key;
                        EdgePropertyField propertyField = propertyPair.Value;

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

                        default:
                            RawRecord r = new RawRecord();
                            r.Append(new StringField(propertyField.ToValue, propertyField.JsonDataType));
                            results.Add(r);
                            break;
                        }
                    }
                }
            }
            else
            {
                foreach (var propIdx in ValuesIdxList)
                {
                    PropertyField propertyValue = record[propIdx] as PropertyField;
                    if (propertyValue == null)
                    {
                        continue;
                    }

                    var result = new RawRecord();
                    result.Append(new StringField(propertyValue.ToValue, propertyValue.JsonDataType));
                    results.Add(result);
                }
            }

            return(results);
        }
예제 #10
0
        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
            });
        }