public override RawRecord Next() { if (inputOp.State()) { RawRecord r = inputOp.Next(); if (r == null) { Close(); return(null); } FieldObject groupByKey = groupByKeyFieldIndex >= 0 ? new StringField(r[groupByKeyFieldIndex].ToValue) : groupByKeyFunction.Evaluate(r); GroupState.Accumulate(new Object[] { groupByKey, r }); if (!inputOp.State()) { Close(); } return(r); } return(null); }
internal override List <RawRecord> CrossApply(RawRecord record) { List <RawRecord> results = new List <RawRecord>(); FieldObject unfoldTarget = _unfoldTarget.Evaluate(record); if (unfoldTarget.GetType() == typeof(CollectionField)) { CollectionField cf = unfoldTarget as CollectionField; foreach (FieldObject fo in cf.Collection) { if (fo == null) { continue; } RawRecord newRecord = new RawRecord(); // Extract only needed columns from Compose1Field if (fo.GetType() == typeof(Compose1Field)) { Compose1Field compose1Field = fo as Compose1Field; foreach (string unfoldColumn in _unfoldColumns) { newRecord.Append(compose1Field.Map[new StringField(unfoldColumn)]); } } else { newRecord.Append(fo); } results.Add(newRecord); } } else if (unfoldTarget.GetType() == typeof(MapField)) { MapField mf = unfoldTarget as MapField; foreach (var pair in mf.Map) { RawRecord newRecord = new RawRecord(); string key = pair.Key.ToString(); string value = pair.Value.ToString(); newRecord.Append(new StringField(key + "=" + value)); results.Add(newRecord); } } else { RawRecord newRecord = new RawRecord(); newRecord.Append(unfoldTarget); results.Add(newRecord); } return(results); }
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)); } }
public void AddOptionTraversal(ScalarFunction value, Container container, GraphViewExecutionOperator optionTraversalOp) { if (value == null) { this.optionNoneTraversalOp = optionTraversalOp; this.optionNoneContainer = container; return; } this.traversalList.Add(new Tuple <FieldObject, Container, GraphViewExecutionOperator>( value.Evaluate(null), container, optionTraversalOp)); }
public override RawRecord Next() { RawRecord inputRec; while (this.inputOp.State() && (inputRec = this.inputOp.Next()) != null) { List <FieldObject> path = new List <FieldObject>(); int activeByFuncIndex = 0; foreach (Tuple <ScalarFunction, bool> tuple in pathStepList) { ScalarFunction accessPathStepFunc = tuple.Item1; bool needsUnfold = tuple.Item2; FieldObject step = accessPathStepFunc.Evaluate(inputRec); if (step == null) { continue; } if (needsUnfold) { CollectionField subPath = step as CollectionField; Debug.Assert(subPath != null, "(subPath as CollectionField) != null"); foreach (FieldObject subPathStep in subPath.Collection) { path.Add(GetStepProjectionResult(subPathStep, ref activeByFuncIndex)); } } else { path.Add(GetStepProjectionResult(step, ref activeByFuncIndex)); } } RawRecord r = new RawRecord(inputRec); r.Append(new CollectionField(path)); return(r); } Close(); return(null); }
internal override List <RawRecord> CrossApply(RawRecord record) { List <RawRecord> results = new List <RawRecord>(); FieldObject unfoldTarget = getUnfoldTargetFunc.Evaluate(record); if (unfoldTarget is CollectionField) { CollectionField cf = unfoldTarget as CollectionField; foreach (FieldObject singleObj in cf.Collection) { if (singleObj == null) { continue; } RawRecord newRecord = new RawRecord(); // Extract only needed columns from Compose1Field if (singleObj is Compose1Field) { Compose1Field compose1Field = singleObj as Compose1Field; foreach (string unfoldColumn in unfoldCompose1Columns) { newRecord.Append(compose1Field.CompositeFieldObject[unfoldColumn]); } } else { foreach (string columnName in this.unfoldCompose1Columns) { if (columnName.Equals(GremlinKeyword.TableDefaultColumnName)) { newRecord.Append(singleObj); } else { newRecord.Append((FieldObject)null); } } } results.Add(newRecord); } } else if (unfoldTarget is MapField) { MapField mf = unfoldTarget as MapField; foreach (KeyValuePair <FieldObject, FieldObject> pair in mf) { RawRecord newRecord = new RawRecord(); string key = pair.Key.ToString(); string value = pair.Value.ToString(); foreach (string columnName in this.unfoldCompose1Columns) { if (columnName.Equals(GremlinKeyword.TableDefaultColumnName)) { newRecord.Append(new StringField(key + "=" + value)); } else { newRecord.Append((FieldObject)null); } } results.Add(newRecord); } } else { RawRecord newRecord = new RawRecord(); foreach (string columnName in this.unfoldCompose1Columns) { if (columnName.Equals(GremlinKeyword.TableDefaultColumnName)) { newRecord.Append(unfoldTarget); } else { newRecord.Append((FieldObject)null); } } results.Add(newRecord); } return(results); }
internal override RawRecord DataModify(RawRecord record) { VertexField srcVertexField = _srcFunction.Evaluate(record) as VertexField; VertexField sinkVertexField = _sinkFunction.Evaluate(record) as VertexField; if (srcVertexField == null || sinkVertexField == null) { return(null); } string srcId = srcVertexField["id"].ToValue; string sinkId = sinkVertexField["id"].ToValue; //string srcJsonDocument = srcVertexField.JsonDocument; //string sinkJsonDocument = sinkVertexField.JsonDocument; JObject srcVertexObject = this.Connection.RetrieveDocumentById(srcId); JObject sinkVertexObject; if (srcId.Equals(sinkId)) { // MUST not use JObject.DeepClone() here! sinkVertexObject = srcVertexObject; } else { sinkVertexObject = this.Connection.RetrieveDocumentById(sinkId); } //VertexField srcVertexField = (srcFieldObject as VertexField) // ?? Connection.VertexCache.GetVertexField(srcId, srcVertexObject); //VertexField sinkVertexField = (sinkFieldObject as VertexField) // ?? Connection.VertexCache.GetVertexField(sinkId, sinkVertexObject); // // Interact with DocDB and add the edge // - For a small-degree vertex (now filled into one document), insert the edge in-place // - If the upload succeeds, done! // - If the upload fails with size-limit-exceeded(SLE), put either incoming or outgoing edges into a seperate document // - For a large-degree vertex (already spilled) // - Update either incoming or outgoing edges in the seperate edge-document // - If the upload fails with SLE, create a new document to store the edge, and update the vertex document // JObject outEdgeObject, inEdgeObject; string outEdgeDocID, inEdgeDocID; EdgeDocumentHelper.InsertEdgeAndUpload(this.Connection, srcId, sinkId, srcVertexField, sinkVertexField, this._edgeJsonObject, srcVertexObject, sinkVertexObject, out outEdgeObject, out outEdgeDocID, out inEdgeObject, out inEdgeDocID); // // Update vertex's adjacency list and reverse adjacency list (in vertex field) // EdgeField outEdgeField = EdgeField.ConstructForwardEdgeField(srcId, srcVertexField["label"]?.ToValue, outEdgeDocID, outEdgeObject); EdgeField inEdgeField = EdgeField.ConstructBackwardEdgeField(sinkId, sinkVertexField["label"]?.ToValue, inEdgeDocID, inEdgeObject); srcVertexField.AdjacencyList.AddEdgeField(srcId, outEdgeField.Offset, outEdgeField); sinkVertexField.RevAdjacencyList.AddEdgeField(srcId, inEdgeField.Offset, inEdgeField); // Construct the newly added edge's RawRecord RawRecord result = new RawRecord(); // source, sink, other, offset, * result.Append(new StringField(srcId)); result.Append(new StringField(sinkId)); result.Append(new StringField(_otherVTag == 0 ? srcId : sinkId)); result.Append(new StringField(outEdgeObject["_offset"].ToString())); result.Append(outEdgeField); for (int i = GraphViewReservedProperties.ReservedEdgeProperties.Count; i < _edgeProperties.Count; i++) { FieldObject fieldValue = outEdgeField[_edgeProperties[i]]; result.Append(fieldValue); } return(result); }
public override FieldObject Evaluate(RawRecord record) { List <FieldObject> path = new List <FieldObject>(); foreach (Tuple <ScalarFunction, bool, HashSet <string> > tuple in pathStepList) { ScalarFunction accessPathStepFunc = tuple.Item1; bool needsUnfold = tuple.Item2; HashSet <string> stepLabels = tuple.Item3; if (accessPathStepFunc == null) { PathStepField pathStepField = new PathStepField(null); foreach (string label in stepLabels) { pathStepField.AddLabel(label); } path.Add(pathStepField); continue; } FieldObject step = accessPathStepFunc.Evaluate(record); if (step == null) { PathStepField lastPathStep; if (path.Any()) { lastPathStep = (PathStepField)path[path.Count - 1]; } else { lastPathStep = new PathStepField(null); path.Add(lastPathStep); } foreach (string label in stepLabels) { lastPathStep.AddLabel(label); } continue; } if (needsUnfold) { PathField subPath = step as PathField; Debug.Assert(subPath != null, "(subPath as PathField) != null"); foreach (PathStepField subPathStep in subPath.Path.Cast <PathStepField>()) { if (subPathStep.StepFieldObject == null) { if (path.Any()) { PathStepField lastPathStep = (PathStepField)path[path.Count - 1]; foreach (string label in subPathStep.Labels) { lastPathStep.AddLabel(label); } } else { path.Add(subPathStep); } continue; } PathStepField pathStepField = new PathStepField(subPathStep.StepFieldObject); foreach (string label in subPathStep.Labels) { pathStepField.AddLabel(label); } path.Add(pathStepField); } PathStepField lastSubPathStep = (PathStepField)path.Last(); foreach (string label in stepLabels) { lastSubPathStep.AddLabel(label); } } else { PathStepField pathStepField = new PathStepField(step); foreach (string label in stepLabels) { pathStepField.AddLabel(label); } path.Add(pathStepField); } } return(new PathField(path)); }
public override FieldObject Evaluate(RawRecord record) { string value1 = f1.Evaluate(record)?.ToValue; string value2 = f2.Evaluate(record)?.ToValue; JsonDataType targetType = DataType(); switch (targetType) { case JsonDataType.Boolean: bool bool_value1, bool_value2; if (bool.TryParse(value1, out bool_value1) && bool.TryParse(value2, out bool_value2)) { switch (binaryType) { case BinaryExpressionType.BitwiseAnd: return(new StringField((bool_value1 ^ bool_value2).ToString(), JsonDataType.Boolean)); case BinaryExpressionType.BitwiseOr: return(new StringField((bool_value1 | bool_value2).ToString(), JsonDataType.Boolean)); case BinaryExpressionType.BitwiseXor: return(new StringField((bool_value1 ^ bool_value2).ToString(), JsonDataType.Boolean)); default: throw new QueryCompilationException("Operator " + binaryType.ToString() + " cannot be applied to operands of type \"boolean\"."); } } else { throw new QueryCompilationException(string.Format("Cannot cast \"{0}\" or \"{1}\" to values of type \"boolean\"", value1, value2)); } case JsonDataType.Bytes: switch (binaryType) { case BinaryExpressionType.Add: return(new StringField(value1 + value2.Substring(2), JsonDataType.Bytes)); default: throw new QueryCompilationException("Operator " + binaryType.ToString() + " cannot be applied to operands of type \"bytes\"."); } case JsonDataType.Int: int int_value1, int_value2; if (int.TryParse(value1, out int_value1) && int.TryParse(value2, out int_value2)) { switch (binaryType) { case BinaryExpressionType.Add: return(new StringField((int_value1 + int_value2).ToString(), JsonDataType.Int)); case BinaryExpressionType.BitwiseAnd: return(new StringField((int_value1 & int_value2).ToString(), JsonDataType.Int)); case BinaryExpressionType.BitwiseOr: return(new StringField((int_value1 | int_value2).ToString(), JsonDataType.Int)); case BinaryExpressionType.BitwiseXor: return(new StringField((int_value1 ^ int_value2).ToString(), JsonDataType.Int)); case BinaryExpressionType.Divide: return(new StringField((int_value1 / int_value2).ToString(), JsonDataType.Int)); case BinaryExpressionType.Modulo: return(new StringField((int_value1 % int_value2).ToString(), JsonDataType.Int)); case BinaryExpressionType.Multiply: return(new StringField((int_value1 * int_value2).ToString(), JsonDataType.Int)); case BinaryExpressionType.Subtract: return(new StringField((int_value1 - int_value2).ToString(), JsonDataType.Int)); default: return(new StringField("")); } } else { throw new QueryCompilationException(string.Format("Cannot cast \"{0}\" or \"{1}\" to values of type \"int\"", value1, value2)); } case JsonDataType.Long: long long_value1, long_value2; if (long.TryParse(value1, out long_value1) && long.TryParse(value2, out long_value2)) { switch (binaryType) { case BinaryExpressionType.Add: return(new StringField((long_value1 + long_value2).ToString(), JsonDataType.Long)); case BinaryExpressionType.BitwiseAnd: return(new StringField((long_value1 & long_value2).ToString(), JsonDataType.Long)); case BinaryExpressionType.BitwiseOr: return(new StringField((long_value1 | long_value2).ToString(), JsonDataType.Long)); case BinaryExpressionType.BitwiseXor: return(new StringField((long_value1 ^ long_value2).ToString(), JsonDataType.Long)); case BinaryExpressionType.Divide: return(new StringField((long_value1 / long_value2).ToString(), JsonDataType.Long)); case BinaryExpressionType.Modulo: return(new StringField((long_value1 % long_value2).ToString(), JsonDataType.Long)); case BinaryExpressionType.Multiply: return(new StringField((long_value1 * long_value2).ToString(), JsonDataType.Long)); case BinaryExpressionType.Subtract: return(new StringField((long_value1 - long_value2).ToString(), JsonDataType.Long)); default: return(new StringField("")); } } else { throw new QueryCompilationException(string.Format("Cannot cast \"{0}\" or \"{1}\" to values of type \"long\"", value1, value2)); } case JsonDataType.Double: double double_value1, double_value2; if (double.TryParse(value1, out double_value1) && double.TryParse(value2, out double_value2)) { switch (binaryType) { case BinaryExpressionType.Add: return(new StringField((double_value1 + double_value2).ToString(), JsonDataType.Double)); case BinaryExpressionType.Divide: return(new StringField((double_value1 / double_value2).ToString(), JsonDataType.Double)); case BinaryExpressionType.Modulo: return(new StringField((double_value1 % double_value2).ToString(), JsonDataType.Double)); case BinaryExpressionType.Multiply: return(new StringField((double_value1 * double_value2).ToString(), JsonDataType.Double)); case BinaryExpressionType.Subtract: return(new StringField((double_value1 - double_value2).ToString(), JsonDataType.Double)); default: throw new QueryCompilationException("Operator " + binaryType.ToString() + " cannot be applied to operands of type 'double'."); } } else { throw new QueryCompilationException(string.Format("Cannot cast \"{0}\" or \"{1}\" to values of type \"double\"", value1, value2)); } case JsonDataType.Float: float float_value1, float_value2; if (float.TryParse(value1, out float_value1) && float.TryParse(value2, out float_value2)) { switch (binaryType) { case BinaryExpressionType.Add: return(new StringField((float_value1 + float_value2).ToString(), JsonDataType.Float)); case BinaryExpressionType.Divide: return(new StringField((float_value1 / float_value2).ToString(), JsonDataType.Float)); case BinaryExpressionType.Modulo: return(new StringField((float_value1 % float_value2).ToString(), JsonDataType.Float)); case BinaryExpressionType.Multiply: return(new StringField((float_value1 * float_value2).ToString(), JsonDataType.Float)); case BinaryExpressionType.Subtract: return(new StringField((float_value1 - float_value2).ToString(), JsonDataType.Float)); default: throw new QueryCompilationException("Operator " + binaryType.ToString() + " cannot be applied to operands of type 'float'."); } } else { throw new QueryCompilationException(string.Format("Cannot cast \"{0}\" or \"{1}\" to values of type \"float\"", value1, value2)); } case JsonDataType.String: switch (binaryType) { case BinaryExpressionType.Add: return(new StringField(value1 + value2)); default: throw new QueryCompilationException("Operator " + binaryType.ToString() + " cannot be applied to operands of type \"string\"."); } case JsonDataType.Date: throw new NotImplementedException(); case JsonDataType.Null: return(null); default: throw new QueryCompilationException("Unsupported data type."); } }
public override RawRecord Next() { if (!this.State()) { return(null); } RawRecord r = null; while (this.inputOp.State() && (r = this.inputOp.Next()) != null) { FieldObject groupByKey = groupByKeyFunction.Evaluate(r); if (groupByKey == null) { throw new GraphViewException("The provided property name or traversal does not map to a value for some elements."); } if (!this.groupedStates.ContainsKey(groupByKey)) { this.groupedStates.Add(groupByKey, new List <RawRecord>()); } this.groupedStates[groupByKey].Add(r); } MapField result = new MapField(this.groupedStates.Count); if (this.isProjectingACollection) { foreach (FieldObject key in this.groupedStates.Keys) { List <FieldObject> projectFields = new List <FieldObject>(); foreach (RawRecord rawRecord in this.groupedStates[key]) { this.groupedSourceOp.ResetState(); this.aggregateOp.ResetState(); this.tempSourceOp.ConstantSource = rawRecord; this.groupedSourceOp.Next(); RawRecord aggregateTraversalRecord = this.aggregateOp.Next(); FieldObject projectResult = aggregateTraversalRecord?.RetriveData(0); if (projectResult == null) { throw new GraphViewException("The property does not exist for some of the elements having been grouped."); } projectFields.Add(projectResult); } result[key] = new CollectionField(projectFields); } } else { foreach (KeyValuePair <FieldObject, List <RawRecord> > pair in this.groupedStates) { FieldObject key = pair.Key; List <RawRecord> aggregatedRecords = pair.Value; this.groupedSourceOp.ResetState(); this.aggregateOp.ResetState(); foreach (RawRecord record in aggregatedRecords) { this.tempSourceOp.ConstantSource = record; this.groupedSourceOp.Next(); } RawRecord aggregateTraversalRecord = this.aggregateOp.Next(); FieldObject aggregateResult = aggregateTraversalRecord?.RetriveData(0); if (aggregateResult == null) { this.Close(); return(null); } result[key] = aggregateResult; } } RawRecord resultRecord = new RawRecord(); for (int i = 0; i < this.carryOnCount; i++) { resultRecord.Append((FieldObject)null); } resultRecord.Append(result); this.Close(); return(resultRecord); }
public override RawRecord Next() { if (!State()) { return(null); } RawRecord r = null; while (inputOp.State() && (r = inputOp.Next()) != null) { FieldObject groupByKey = groupByKeyFieldIndex >= 0 ? new StringField(r[groupByKeyFieldIndex].ToValue) : groupByKeyFunction.Evaluate(r); if (!groupedStates.ContainsKey(groupByKey)) { groupedStates.Add(groupByKey, new List <RawRecord>()); } groupedStates[groupByKey].Add(r); } Dictionary <FieldObject, FieldObject> resultCollection = new Dictionary <FieldObject, FieldObject>(groupedStates.Count); if (elementPropertyProjectionIndex >= 0) { foreach (FieldObject key in groupedStates.Keys) { List <FieldObject> projectFields = new List <FieldObject>(); foreach (var rawRecord in groupedStates[key]) { FieldObject fo = rawRecord[elementPropertyProjectionIndex]; if (fo is PropertyField) { PropertyField pf = fo as PropertyField; projectFields.Add(new StringField(pf.PropertyValue, pf.JsonDataType)); } else { projectFields.Add(fo); } } resultCollection[key] = new CollectionField(projectFields); } } else { foreach (KeyValuePair <FieldObject, List <RawRecord> > pair in groupedStates) { FieldObject key = pair.Key; List <RawRecord> aggregatedRecords = pair.Value; groupedSourceOp.ResetState(); aggregateOp.ResetState(); foreach (RawRecord record in aggregatedRecords) { tempSourceOp.ConstantSource = record; groupedSourceOp.Next(); } RawRecord aggregateTraversalRecord = aggregateOp.Next(); FieldObject aggregateResult = aggregateTraversalRecord?.RetriveData(0); if (aggregateResult == null) { Close(); return(null); } resultCollection[key] = aggregateResult; } } RawRecord resultRecord = new RawRecord(); for (int i = 0; i < carryOnCount; i++) { resultRecord.Append((FieldObject)null); } resultRecord.Append(new MapField(resultCollection)); Close(); return(resultRecord); }
public override RawRecord Next() { if (!this.State()) { return(null); } RawRecord r = null; while (this.inputOp.State() && (r = this.inputOp.Next()) != null) { FieldObject groupByKey = groupByKeyFunction.Evaluate(r); if (groupByKey == null) { throw new GraphViewException("The provided property name or traversal does not map to a value for some elements."); } if (!this.groupedStates.ContainsKey(groupByKey)) { this.groupedStates.Add(groupByKey, new List <RawRecord>()); } this.groupedStates[groupByKey].Add(r); } MapField result = new MapField(this.groupedStates.Count); if (this.isProjectingACollection) { foreach (FieldObject key in groupedStates.Keys) { List <FieldObject> projectFields = new List <FieldObject>(); this.container.ResetTableCache(groupedStates[key]); this.aggregateOp.ResetState(); for (int i = 0; i < groupedStates[key].Count; i++) { RawRecord aggregateTraversalRecord = this.aggregateOp.Next(); FieldObject projectResult = aggregateTraversalRecord?.RetriveData(0); if (projectResult == null) { throw new GraphViewException("The property does not exist for some of the elements having been grouped."); } projectFields.Add(projectResult); } Dictionary <string, FieldObject> compositeFieldObjects = new Dictionary <string, FieldObject>(); compositeFieldObjects.Add(DocumentDBKeywords.KW_TABLE_DEFAULT_COLUMN_NAME, new CollectionField(projectFields)); result[key] = new CompositeField(compositeFieldObjects, DocumentDBKeywords.KW_TABLE_DEFAULT_COLUMN_NAME); } } else { foreach (KeyValuePair <FieldObject, List <RawRecord> > pair in this.groupedStates) { FieldObject key = pair.Key; this.aggregateOp.ResetState(); this.container.ResetTableCache(pair.Value); RawRecord aggregateTraversalRecord = null; FieldObject aggregateResult = null; while (this.aggregateOp.State() && (aggregateTraversalRecord = this.aggregateOp.Next()) != null) { aggregateResult = aggregateTraversalRecord.RetriveData(0) ?? aggregateResult; } if (aggregateResult == null) { continue; } result[key] = aggregateResult; } } RawRecord resultRecord = new RawRecord(); for (int i = 0; i < this.carryOnCount; i++) { resultRecord.Append((FieldObject)null); } resultRecord.Append(result); this.Close(); return(resultRecord); }
public override bool Evaluate(RawRecord record) { //string value1 = firstScalarFunction.Evaluate(record); //string value2 = secondScalarFunction.Evaluate(record); string value1 = firstScalarFunction.Evaluate(record)?.ToValue; string value2 = secondScalarFunction.Evaluate(record)?.ToValue; JsonDataType type1 = firstScalarFunction.DataType(); JsonDataType type2 = secondScalarFunction.DataType(); JsonDataType targetType = type1 > type2 ? type1 : type2; if (value1 == null || value2 == null) { return(false); } switch (targetType) { case JsonDataType.Boolean: bool bool_value1, bool_value2; if (bool.TryParse(value1, out bool_value1) && bool.TryParse(value2, out bool_value2)) { switch (comparisonType) { case BooleanComparisonType.Equals: return(bool_value1 == bool_value2); case BooleanComparisonType.NotEqualToBrackets: case BooleanComparisonType.NotEqualToExclamation: return(bool_value1 != bool_value2); default: throw new QueryCompilationException("Operator " + comparisonType.ToString() + " cannot be applied to operands of type \"boolean\"."); } } else { throw new QueryCompilationException(string.Format("Cannot cast \"{0}\" or \"{1}\" to values of type \"boolean\"", value1, value2)); } case JsonDataType.Bytes: switch (comparisonType) { case BooleanComparisonType.Equals: return(value1 == value2); case BooleanComparisonType.NotEqualToBrackets: case BooleanComparisonType.NotEqualToExclamation: return(value1 != value2); default: throw new NotImplementedException(); } case JsonDataType.Int: int int_value1, int_value2; if (int.TryParse(value1, out int_value1) && int.TryParse(value2, out int_value2)) { switch (comparisonType) { case BooleanComparisonType.Equals: return(int_value1 == int_value2); case BooleanComparisonType.GreaterThan: return(int_value1 > int_value2); case BooleanComparisonType.GreaterThanOrEqualTo: return(int_value1 >= int_value2); case BooleanComparisonType.LessThan: return(int_value1 < int_value2); case BooleanComparisonType.LessThanOrEqualTo: return(int_value1 <= int_value2); case BooleanComparisonType.NotEqualToBrackets: case BooleanComparisonType.NotEqualToExclamation: return(int_value1 != int_value2); case BooleanComparisonType.NotGreaterThan: return(!(int_value1 > int_value2)); case BooleanComparisonType.NotLessThan: return(!(int_value1 < int_value2)); default: throw new QueryCompilationException("Operator " + comparisonType.ToString() + " cannot be applied to operands of type \"int\"."); } } else { throw new QueryCompilationException(string.Format("Cannot cast \"{0}\" or \"{1}\" to values of type \"int\"", value1, value2)); } case JsonDataType.Long: long long_value1, long_value2; if (long.TryParse(value1, out long_value1) && long.TryParse(value2, out long_value2)) { switch (comparisonType) { case BooleanComparisonType.Equals: return(long_value1 == long_value2); case BooleanComparisonType.GreaterThan: return(long_value1 > long_value2); case BooleanComparisonType.GreaterThanOrEqualTo: return(long_value1 >= long_value2); case BooleanComparisonType.LessThan: return(long_value1 < long_value2); case BooleanComparisonType.LessThanOrEqualTo: return(long_value1 <= long_value2); case BooleanComparisonType.NotEqualToBrackets: case BooleanComparisonType.NotEqualToExclamation: return(long_value1 != long_value2); case BooleanComparisonType.NotGreaterThan: return(!(long_value1 > long_value2)); case BooleanComparisonType.NotLessThan: return(!(long_value1 < long_value2)); default: throw new QueryCompilationException("Operator " + comparisonType.ToString() + " cannot be applied to operands of type \"long\"."); } } else { throw new QueryCompilationException(string.Format("Cannot cast \"{0}\" or \"{1}\" to values of type \"long\"", value1, value2)); } case JsonDataType.Double: double double_value1, double_value2; if (double.TryParse(value1, out double_value1) && double.TryParse(value2, out double_value2)) { switch (comparisonType) { case BooleanComparisonType.Equals: return(double_value1 == double_value2); case BooleanComparisonType.GreaterThan: return(double_value1 > double_value2); case BooleanComparisonType.GreaterThanOrEqualTo: return(double_value1 >= double_value2); case BooleanComparisonType.LessThan: return(double_value1 < double_value2); case BooleanComparisonType.LessThanOrEqualTo: return(double_value1 <= double_value2); case BooleanComparisonType.NotEqualToBrackets: case BooleanComparisonType.NotEqualToExclamation: return(double_value1 != double_value2); case BooleanComparisonType.NotGreaterThan: return(!(double_value1 > double_value2)); case BooleanComparisonType.NotLessThan: return(!(double_value1 < double_value2)); default: throw new QueryCompilationException("Operator " + comparisonType.ToString() + " cannot be applied to operands of type \"double\"."); } } else { throw new QueryCompilationException(string.Format("Cannot cast \"{0}\" or \"{1}\" to values of type \"double\"", value1, value2)); } case JsonDataType.Float: float float_value1, float_value2; if (float.TryParse(value1, out float_value1) && float.TryParse(value2, out float_value2)) { switch (comparisonType) { case BooleanComparisonType.Equals: return(float_value1 == float_value2); case BooleanComparisonType.GreaterThan: return(float_value1 > float_value2); case BooleanComparisonType.GreaterThanOrEqualTo: return(float_value1 >= float_value2); case BooleanComparisonType.LessThan: return(float_value1 < float_value2); case BooleanComparisonType.LessThanOrEqualTo: return(float_value1 <= float_value2); case BooleanComparisonType.NotEqualToBrackets: case BooleanComparisonType.NotEqualToExclamation: return(float_value1 != float_value2); case BooleanComparisonType.NotGreaterThan: return(!(float_value1 > float_value2)); case BooleanComparisonType.NotLessThan: return(!(float_value1 < float_value2)); default: throw new QueryCompilationException("Operator " + comparisonType.ToString() + " cannot be applied to operands of type \"float\"."); } } else { throw new QueryCompilationException(string.Format("Cannot cast \"{0}\" or \"{1}\" to values of type \"float\"", value1, value2)); } case JsonDataType.String: switch (comparisonType) { case BooleanComparisonType.Equals: return(value1 == value2); case BooleanComparisonType.GreaterThan: case BooleanComparisonType.GreaterThanOrEqualTo: return(value1.CompareTo(value2) > 0); case BooleanComparisonType.LessThan: case BooleanComparisonType.LessThanOrEqualTo: return(value1.CompareTo(value2) > 0); case BooleanComparisonType.NotEqualToBrackets: case BooleanComparisonType.NotEqualToExclamation: return(value1 != value2); case BooleanComparisonType.NotGreaterThan: return(value1.CompareTo(value2) <= 0); case BooleanComparisonType.NotLessThan: return(value1.CompareTo(value2) >= 0); default: throw new QueryCompilationException("Operator " + comparisonType.ToString() + " cannot be applied to operands of type \"string\"."); } case JsonDataType.Date: throw new NotImplementedException(); case JsonDataType.Null: return(false); default: throw new QueryCompilationException("Unsupported data type."); } }
public override RawRecord Next() { RawRecord inputRec; while (this.inputOp.State() && (inputRec = this.inputOp.Next()) != null) { List <FieldObject> path = new List <FieldObject>(); int activeByFuncIndex = 0; foreach (Tuple <ScalarFunction, bool, HashSet <string> > tuple in pathStepList) { ScalarFunction accessPathStepFunc = tuple.Item1; bool needsUnfold = tuple.Item2; HashSet <string> stepLabels = tuple.Item3; if (accessPathStepFunc == null) { PathStepField pathStepField = new PathStepField(null); foreach (string label in stepLabels) { pathStepField.AddLabel(label); } path.Add(pathStepField); continue; } FieldObject step = accessPathStepFunc.Evaluate(inputRec); if (step == null) { PathStepField lastPathStep; if (path.Any()) { lastPathStep = (PathStepField)path[path.Count - 1]; } else { lastPathStep = new PathStepField(null); path.Add(lastPathStep); } foreach (string label in stepLabels) { lastPathStep.AddLabel(label); } continue; } if (needsUnfold) { PathField subPath = step as PathField; Debug.Assert(subPath != null, "(subPath as PathField) != null"); foreach (PathStepField subPathStep in subPath.Path.Cast <PathStepField>()) { if (subPathStep.StepFieldObject == null) { if (path.Any()) { PathStepField lastPathStep = (PathStepField)path[path.Count - 1]; foreach (string label in subPathStep.Labels) { lastPathStep.AddLabel(label); } } else { path.Add(subPathStep); } continue; } FieldObject pathStep = GetStepProjectionResult(subPathStep.StepFieldObject, ref activeByFuncIndex); PathStepField pathStepField = new PathStepField(pathStep); foreach (string label in subPathStep.Labels) { pathStepField.AddLabel(label); } path.Add(pathStepField); } PathStepField lastSubPathStep = (PathStepField)path.Last(); foreach (string label in stepLabels) { lastSubPathStep.AddLabel(label); } } else { FieldObject pathStep = GetStepProjectionResult(step, ref activeByFuncIndex); Compose1Field compose1PathStep = pathStep as Compose1Field; Debug.Assert(compose1PathStep != null, "compose1PathStep != null"); // // g.V().optional(__.count().V()).path() // if (compose1PathStep[compose1PathStep.DefaultProjectionKey] == null) { continue; } PathStepField pathStepField = new PathStepField(pathStep); foreach (string label in stepLabels) { pathStepField.AddLabel(label); } path.Add(pathStepField); } } RawRecord r = new RawRecord(inputRec); r.Append(new PathField(path)); return(r); } this.Close(); return(null); }
internal override List <RawRecord> CrossApply(RawRecord record) { List <RawRecord> results = new List <RawRecord>(); FieldObject unfoldTarget = getUnfoldTargetFunc.Evaluate(record); if (unfoldTarget is PathField) { PathField path = (PathField)unfoldTarget; foreach (PathStepField pathStep in path.Path.Cast <PathStepField>()) { if (pathStep == null) { continue; } RawRecord flatRecord = new RawRecord(); Compose1Field compose1StepField = pathStep.StepFieldObject as Compose1Field; Debug.Assert(compose1StepField != null, "compose1StepField != null"); // // Extract only needed columns from Compose1Field // foreach (string unfoldColumn in populateColumns) { flatRecord.Append(compose1StepField[unfoldColumn]); } results.Add(flatRecord); } } else if (unfoldTarget is CollectionField) { CollectionField inputCollection = (CollectionField)unfoldTarget; foreach (FieldObject singleObj in inputCollection.Collection) { if (singleObj == null) { continue; } RawRecord flatRecord = new RawRecord(); Compose1Field compose1ObjField = singleObj as Compose1Field; Debug.Assert(compose1ObjField != null, "compose1ObjField != null"); // // Extract only needed columns from Compose1Field // foreach (string unfoldColumn in populateColumns) { flatRecord.Append(compose1ObjField[unfoldColumn]); } results.Add(flatRecord); } } else if (unfoldTarget is MapField) { MapField inputMap = (MapField)unfoldTarget; foreach (EntryField entry in inputMap) { RawRecord entryRecord = new RawRecord(); foreach (string columnName in this.populateColumns) { entryRecord.Append(columnName.Equals(GraphViewKeywords.KW_TABLE_DEFAULT_COLUMN_NAME) ? entry : (FieldObject)null); } results.Add(entryRecord); } } else { RawRecord flatRecord = unfoldTarget.FlatToRawRecord(this.populateColumns); results.Add(flatRecord); } return(results); }