public override FieldObject Evaluate(RawRecord record) { FieldObject checkObject = record[_checkFieldIndex]; CollectionField arrayObject = record[_arrayFieldIndex] as CollectionField; if (arrayObject == null) { throw new GraphViewException("The second paramter of the WithInArray function must be located to a collection field"); } if (checkObject == null) { return(new StringField("false", JsonDataType.Boolean)); } foreach (FieldObject fieldObject in arrayObject.Collection) { if (fieldObject is Compose1Field) { Compose1Field compose1Field = fieldObject as Compose1Field; if (checkObject.Equals(compose1Field.Map[compose1Field.DefaultProjectionKey])) { return(new StringField("true", JsonDataType.Boolean)); } } else if (checkObject.Equals(fieldObject)) { return(new StringField("true", JsonDataType.Boolean)); } } return(new StringField("false", JsonDataType.Boolean)); }
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 FieldObject Evaluate(RawRecord record) { FieldObject checkObject = record[this.checkFieldIndex]; if (checkObject == null) { return(new StringField("false", JsonDataType.Boolean)); } CollectionField arrayObject = record[this.arrayFieldIndex] as CollectionField; if (arrayObject != null) { foreach (FieldObject fieldObject in arrayObject.Collection) { if (fieldObject is Compose1Field) { Compose1Field compose1Field = fieldObject as Compose1Field; if (checkObject.Equals(compose1Field.CompositeFieldObject[compose1Field.DefaultProjectionKey])) { return(new StringField("true", JsonDataType.Boolean)); } } else if (checkObject.Equals(fieldObject)) { return(new StringField("true", JsonDataType.Boolean)); } } return(new StringField("false", JsonDataType.Boolean)); } return(checkObject.Equals(record[this.arrayFieldIndex]) ? new StringField("true", JsonDataType.Boolean) : new StringField("false", JsonDataType.Boolean)); }
private static void ConstructTree(TreeField root, int index, PathField pathField) { if (index >= pathField.Path.Count) { return; } PathStepField pathStepField = pathField.Path[index++] as PathStepField; Debug.Assert(pathStepField != null, "pathStepField != null"); Compose1Field compose1PathStep = pathStepField.StepFieldObject as Compose1Field; Debug.Assert(compose1PathStep != null, "compose1PathStep != null"); FieldObject nodeObject = compose1PathStep[compose1PathStep.DefaultProjectionKey]; TreeField child; if (!root.Children.TryGetValue(nodeObject, out child)) { child = new TreeField(nodeObject); root.Children[nodeObject] = child; } ConstructTree(child, index, pathField); }
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); }
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); }