public Exceptional<BinaryExpressionDefinition> GetBinaryExpression(DBContext myDBContext) { AExpressionDefinition right; var op = myDBContext.DBPluginManager.GetBinaryOperator(_OperatorSymbol); if (op == null) { return new Exceptional<BinaryExpressionDefinition>(new Error_OperatorDoesNotExist(_OperatorSymbol)); } if (op.Label == BinaryOperator.Subtraction) right = new ValueDefinition(new DBInt32(-1)); else right = new ValueDefinition(new DBInt32(1)); var binExpr = new BinaryExpressionDefinition("*", _Expression, right); binExpr.Validate(myDBContext); return new Exceptional<BinaryExpressionDefinition>(binExpr, binExpr.ValidateResult); }
public Exceptional<AOperationDefinition> SimpleOperation(ValueDefinition left, ValueDefinition right) { #region Data ValueDefinition resultObject = null; ADBBaseObject leftObject = left.Value; ADBBaseObject rightObject = right.Value; #endregion if (!GraphDBTypeMapper.ConvertToBestMatchingType(ref leftObject, ref rightObject).Value) { return new Exceptional<AOperationDefinition>(new Error_DataTypeDoesNotMatch(leftObject.ObjectName, rightObject.ObjectName)); } ADBBaseObject resultValue = leftObject.Div(leftObject, rightObject); resultObject = new ValueDefinition(resultValue.Type, resultValue.Value); return new Exceptional<AOperationDefinition>(resultObject); }
protected Exceptional<AOperationDefinition> SimpleOperation(ValueDefinition left, ValueDefinition right) { #region Data ValueDefinition resultObject = null; #endregion ADBBaseObject leftObj = left.Value; ADBBaseObject rightObj = right.Value; if (!GraphDBTypeMapper.ConvertToBestMatchingType(ref leftObj, ref rightObj).Value) return new Exceptional<AOperationDefinition>(new Error_DataTypeDoesNotMatch(leftObj.ObjectName, rightObj.ObjectName)); //return new Exceptional<IOperationValue>(new GraphError(ErrorCode.DataTypeDoesNotMatchValue, (leftObj.ObjectName + " != " + rightObj.ToString()))); var resultValue = Compare(leftObj, rightObj); resultObject = new ValueDefinition(BasicType.Boolean, (object)resultValue.Value); return new Exceptional<AOperationDefinition>(resultObject); }
protected Exceptional<AOperationDefinition> SimpleOperation(TupleDefinition left, TupleDefinition right) { #region Data ValueDefinition resultObject = null; Object resultValue = false; #endregion //foreach (ADBBaseObject leftObj in left.Values) foreach (var valLeft in left) { ADBBaseObject leftObj = (valLeft.Value as ValueDefinition).Value; //foreach (ADBBaseObject rightObj in right.Values) foreach(var valRight in right) { ADBBaseObject rightObj = (valRight.Value as ValueDefinition).Value; if (!GraphDBTypeMapper.ConvertToBestMatchingType(ref leftObj, ref rightObj).Value) { return new Exceptional<AOperationDefinition>(new Error_DataTypeDoesNotMatch(leftObj.Type.ToString(), rightObj.Type.ToString())); } var res = Compare(leftObj, rightObj); if (res.Failed()) return new Exceptional<AOperationDefinition>(res); if (res.Value) { resultValue = true; } else { resultValue = false; break; } } if (!(Boolean)resultValue) break; } resultObject = new ValueDefinition(BasicType.Boolean, (object)resultValue); return new Exceptional<AOperationDefinition>(resultObject); }
/// <summary> /// This method extracts an IOperationValue out of a DBObjectStream. /// </summary> /// <param name="myIDChainDefinition">The corresponding IDNode.</param> /// <param name="myExtraordinary">Sth extraordinary like an aggregate or function call.</param> /// <param name="dbContext">The TypeManager of the database.</param> /// <param name="myDBObjectStream">The DBObjectStream.</param> /// <returns>An IOperationValue.</returns> private Exceptional<AOperationDefinition> GetOperand(IDChainDefinition myIDChainDefinition, AExpressionDefinition myExtraordinary, DBContext dbContext, DBObjectStream myDBObjectStream, DBObjectCache dbObjectCache, SessionSettings mySessionToken) { var aCtype = GraphDBTypeMapper.ConvertGraph2CSharp(myIDChainDefinition.LastAttribute.GetDBType(dbContext.DBTypeManager).Name); IObject dbos = GetDbos(myIDChainDefinition, myDBObjectStream, dbContext, mySessionToken, dbObjectCache); if (dbos == null) { return null; } AOperationDefinition operand = null; if (myExtraordinary != null) { #region extraordinary if (myExtraordinary is AggregateDefinition) { System.Diagnostics.Debug.Assert(false); //var aggrNode = ((AggregateDefinition)myExtraordinary).ChainPartAggregateDefinition; //aggrNode.Validate(dbContext); ////result of aggregate //var pResult = aggrNode.Aggregate.Aggregate(dbos, myIDChainDefinition.LastAttribute, dbContext); //if (pResult.Failed()) // return new Exceptional<AOperationDefinition>(pResult); //aCtype = aggrNode.Aggregate.TypeOfResult; //operand = new ValueDefinition(aggrNode.Aggregate.TypeOfResult, pResult.Value); } else { if (myExtraordinary is IDChainDefinition) { var chainFunc = (myExtraordinary as IDChainDefinition).First(id => id is ChainPartFuncDefinition) as ChainPartFuncDefinition; chainFunc.Validate(dbContext); var func = chainFunc.Function; func.CallingAttribute = myIDChainDefinition.LastAttribute; func.CallingObject = dbos; //result of function var pResult = chainFunc.Execute(myIDChainDefinition.LastAttribute.GetDBType(dbContext.DBTypeManager), myDBObjectStream, myIDChainDefinition.Reference.Item1, dbContext); if (pResult.Failed()) return new Exceptional<AOperationDefinition>(pResult); //aCtype = funcCallNode.Function.TypeOfResult; //aCtype = ((FuncParameter)pResult.Value).TypeOfOperatorResult; operand = new ValueDefinition(((FuncParameter)pResult.Value).Value); aCtype = (operand as ValueDefinition).Value.Type; } else { return new Exceptional<AOperationDefinition>(new Error_NotImplemented(new System.Diagnostics.StackTrace(true))); } } #endregion } else { #region simple if (aCtype == BasicType.SetOfDBObjects) { operand = new TupleDefinition(aCtype, dbos, myIDChainDefinition.LastAttribute.GetDBType(dbContext.DBTypeManager)); } else { if (dbos is AListOfBaseEdgeType) { operand = new TupleDefinition(aCtype, dbos, myIDChainDefinition.LastAttribute.GetDBType(dbContext.DBTypeManager)); } else if (dbos is ADBBaseObject) { operand = new ValueDefinition(dbos as ADBBaseObject); } else { operand = new ValueDefinition(aCtype, dbos); } } #endregion } return new Exceptional<AOperationDefinition>(operand); }
private Exceptional<Boolean> MatchComplexData(TypesOfAssociativity associativity, DataContainer data, DBContext dbContext, DBObjectCache dbObjectCache, TypesOfBinaryExpression typeOfBinExpr, IEnumerable<Tuple<GraphDBType, AAttributeIndex>> leftIndices, IEnumerable<Tuple<GraphDBType, AAttributeIndex>> rightIndices, ref List<GraphDBError> errors, ref IExpressionGraph result, SessionSettings mySessionToken) { #region data Dictionary<DBObjectStream, AOperationDefinition> operandsLeft = null; Dictionary<DBObjectStream, AOperationDefinition> operandsRight = null; #endregion #region handle extraordinaries if (data.Extraordinaries.Item1 != null) { #region left extraordinary //there is something like a function or so operandsLeft = new Dictionary<DBObjectStream, AOperationDefinition>(); //we have to calculate the real operand. //TODO: try to use attribute idx instead of uuid idx foreach (var aLeftIDX in leftIndices) { AAttributeIndex currentLeftIdx = null; #region get UUID idx if (!(aLeftIDX.Item2.IsUUIDIndex)) { currentLeftIdx = aLeftIDX.Item1.GetUUIDIndex(dbContext); } else { currentLeftIdx = aLeftIDX.Item2; } #endregion var currentIndexRelatedType = dbContext.DBTypeManager.GetTypeByUUID(currentLeftIdx.IndexRelatedTypeUUID); foreach (var aObjectUUIDs_Left in currentLeftIdx.GetAllValues(currentIndexRelatedType, dbContext)) { foreach (var aObjectUUID_Left in aObjectUUIDs_Left) { var leftDBObject = dbObjectCache.LoadDBObjectStream(aLeftIDX.Item1, aObjectUUID_Left); if (leftDBObject.Failed()) { throw new NotImplementedException(); } if (IsValidDBObjectStreamForBinExpr(leftDBObject.Value, data.IDChainDefinitions.Item1.LastAttribute, dbContext.DBTypeManager)) { var oper = GetOperand(data.IDChainDefinitions.Item1, data.Extraordinaries.Item1, dbContext, leftDBObject.Value, dbObjectCache, mySessionToken); if (oper.Failed()) return new Exceptional<bool>(oper); if (oper != null) { operandsLeft.Add(leftDBObject.Value, oper.Value); } } } } } //from now on the binary expression is right complex, because there are atom values on the left typeOfBinExpr = TypesOfBinaryExpression.RightComplex; #endregion } if (data.Extraordinaries.Item2 != null) { #region right extraordinary //there is something like a function or so operandsRight = new Dictionary<DBObjectStream, AOperationDefinition>(); foreach (var aRightIDX in rightIndices) { AAttributeIndex currentRightIdx = null; #region get UUID idx //we have to calculate the real operand. //TODO: try to use attribute idx instead of uuid idx if (!(aRightIDX.Item2.IsUUIDIndex)) { currentRightIdx = aRightIDX.Item1.GetUUIDIndex(dbContext); } else { currentRightIdx = aRightIDX.Item2; } #endregion var currentIndexRelatedType = dbContext.DBTypeManager.GetTypeByUUID(currentRightIdx.IndexRelatedTypeUUID); foreach (var aObjectUUIDs_Right in currentRightIdx.GetAllValues(currentIndexRelatedType, dbContext)) { foreach (var aObjectUUID_Right in aObjectUUIDs_Right) { var rightDBObject = dbObjectCache.LoadDBObjectStream(aRightIDX.Item1, aObjectUUID_Right); if (rightDBObject.Failed()) { throw new NotImplementedException(); } if (IsValidDBObjectStreamForBinExpr(rightDBObject.Value, data.IDChainDefinitions.Item2.LastAttribute, dbContext.DBTypeManager)) { var oper = GetOperand(data.IDChainDefinitions.Item2, data.Extraordinaries.Item2, dbContext, rightDBObject.Value, dbObjectCache, mySessionToken); if (oper.Failed()) return new Exceptional<bool>(oper); if (oper != null) { operandsRight.Add(rightDBObject.Value, oper.Value); } } } } } if (typeOfBinExpr == TypesOfBinaryExpression.RightComplex) { typeOfBinExpr = TypesOfBinaryExpression.Atom; } #endregion } #endregion switch (typeOfBinExpr) { case TypesOfBinaryExpression.Atom: #region atom switch (associativity) { case TypesOfAssociativity.Unknown: case TypesOfAssociativity.Neutral: GetComplexAtom(dbContext, operandsLeft, operandsRight, data.IDChainDefinitions.Item1, dbObjectCache, ref result); GetComplexAtom(dbContext, operandsRight, operandsLeft, data.IDChainDefinitions.Item2, dbObjectCache, ref result); break; case TypesOfAssociativity.Left: GetComplexAtom(dbContext, operandsLeft, operandsRight, data.IDChainDefinitions.Item1, dbObjectCache, ref result); break; case TypesOfAssociativity.Right: GetComplexAtom(dbContext, operandsRight, operandsLeft, data.IDChainDefinitions.Item2, dbObjectCache, ref result); break; default: return new Exceptional<bool>(new Error_NotImplemented(new System.Diagnostics.StackTrace(true))); } #endregion break; case TypesOfBinaryExpression.LeftComplex: #region Left complex GetComplexMatch(leftIndices, operandsRight, dbObjectCache, data.IDChainDefinitions.Item1, data.IDChainDefinitions.Item2, dbContext, associativity, ref result, mySessionToken); #endregion break; case TypesOfBinaryExpression.RightComplex: #region Right complex GetComplexMatch(rightIndices, operandsLeft, dbObjectCache, data.IDChainDefinitions.Item2, data.IDChainDefinitions.Item1, dbContext, associativity, ref result, mySessionToken); #endregion break; case TypesOfBinaryExpression.Complex: #region Complex LevelKey leftLevelKey = CreateLevelKey(data.IDChainDefinitions.Item1, dbContext.DBTypeManager); LevelKey rightLevelKey = CreateLevelKey(data.IDChainDefinitions.Item2, dbContext.DBTypeManager); GraphDBType leftGraphDBType = data.IDChainDefinitions.Item1.LastType; GraphDBType rightGraphDBType = data.IDChainDefinitions.Item2.LastType; #region exception if (leftIndices.CountIsGreater(1) || rightIndices.CountIsGreater(1)) { return new Exceptional<bool>(new Error_NotImplemented(new System.Diagnostics.StackTrace(true))); } #endregion var leftIndexRelatedType = dbContext.DBTypeManager.GetTypeByUUID(leftIndices.First().Item2.IndexRelatedTypeUUID); var rightIndexRelatedType = dbContext.DBTypeManager.GetTypeByUUID(rightIndices.First().Item2.IndexRelatedTypeUUID); foreach (var ObjectUUIDs_left in leftIndices.First().Item2.GetAllValues(leftIndexRelatedType, dbContext)) { foreach (var aLeftUUID in ObjectUUIDs_left) { var leftDBObject = dbObjectCache.LoadDBObjectStream(leftIndices.First().Item1, aLeftUUID); if (leftDBObject.Failed()) { return new Exceptional<bool>(new Error_NotImplemented(new System.Diagnostics.StackTrace(true))); } if (IsValidDBObjectStreamForBinExpr(leftDBObject.Value, data.IDChainDefinitions.Item1.LastAttribute, dbContext.DBTypeManager)) { foreach (var ObjectUUIDs_right in rightIndices.First().Item2.GetAllValues(rightIndexRelatedType, dbContext)) { foreach (var aRightUUID in ObjectUUIDs_right) { var rightDBObject = dbObjectCache.LoadDBObjectStream(rightIndices.First().Item1, aRightUUID); if (rightDBObject.Failed()) { return new Exceptional<bool>(new Error_NotImplemented(new System.Diagnostics.StackTrace(true))); } if (IsValidDBObjectStreamForBinExpr(rightDBObject.Value, data.IDChainDefinitions.Item2.LastAttribute, dbContext.DBTypeManager)) { //everything is valid var leftType = GraphDBTypeMapper.ConvertGraph2CSharp(data.IDChainDefinitions.Item1.LastAttribute.GetDBType(dbContext.DBTypeManager).Name); var rightType = GraphDBTypeMapper.ConvertGraph2CSharp(data.IDChainDefinitions.Item2.LastAttribute.GetDBType(dbContext.DBTypeManager).Name); AOperationDefinition leftValue; AOperationDefinition rightValue; if (data.IDChainDefinitions.Item1.LastAttribute.KindOfType == KindsOfType.SetOfReferences || data.IDChainDefinitions.Item1.LastAttribute.KindOfType == KindsOfType.ListOfNoneReferences || data.IDChainDefinitions.Item1.LastAttribute.KindOfType == KindsOfType.SetOfNoneReferences) leftValue = new TupleDefinition(leftType, leftDBObject.Value.GetAttribute(data.IDChainDefinitions.Item1.LastAttribute.UUID), data.IDChainDefinitions.Item1.LastAttribute.GetDBType(dbContext.DBTypeManager)); else leftValue = new ValueDefinition(leftType, leftDBObject.Value.GetAttribute(data.IDChainDefinitions.Item1.LastAttribute.UUID, data.IDChainDefinitions.Item1.LastAttribute.GetRelatedType(dbContext.DBTypeManager), dbContext)); if (data.IDChainDefinitions.Item2.LastAttribute.KindOfType == KindsOfType.SetOfReferences || data.IDChainDefinitions.Item2.LastAttribute.KindOfType == KindsOfType.ListOfNoneReferences || data.IDChainDefinitions.Item2.LastAttribute.KindOfType == KindsOfType.SetOfNoneReferences) rightValue = new TupleDefinition(rightType, rightDBObject.Value.GetAttribute(data.IDChainDefinitions.Item2.LastAttribute.UUID), data.IDChainDefinitions.Item2.LastAttribute.GetDBType(dbContext.DBTypeManager)); else rightValue = new ValueDefinition(rightType, rightDBObject.Value.GetAttribute(data.IDChainDefinitions.Item2.LastAttribute.UUID, data.IDChainDefinitions.Item2.LastAttribute.GetRelatedType(dbContext.DBTypeManager), dbContext)); var tempSimpleOperationResult = this.SimpleOperation(leftValue, rightValue, typeOfBinExpr); if (tempSimpleOperationResult.Failed()) return new Exceptional<bool>(tempSimpleOperationResult); var tempOperatorResult = tempSimpleOperationResult.Value; if ((Boolean)(tempOperatorResult as ValueDefinition).Value.Value) { //found sth that is really true #region insert into graph switch (associativity) { case TypesOfAssociativity.Neutral: case TypesOfAssociativity.Left: IntegrateInGraph(leftDBObject.Value, result, leftLevelKey, dbContext, dbObjectCache); break; case TypesOfAssociativity.Right: IntegrateInGraph(rightDBObject.Value, result, rightLevelKey, dbContext, dbObjectCache); break; case TypesOfAssociativity.Unknown: if (Type == TypesOfOperators.AffectsLowerLevels) { result.AddNodesWithComplexRelation(leftDBObject, leftLevelKey, rightDBObject, rightLevelKey, dbObjectCache, 1); } else { result.AddNodesWithComplexRelation(leftDBObject, leftLevelKey, rightDBObject, rightLevelKey, dbObjectCache, 0); } break; default: return new Exceptional<bool>(new Error_NotImplemented(new System.Diagnostics.StackTrace(true))); } #endregion } } } } #region clean lower levels if (Type == TypesOfOperators.AffectsLowerLevels) { switch (associativity) { case TypesOfAssociativity.Neutral: case TypesOfAssociativity.Left: CleanLowerLevel(leftLevelKey, dbContext, dbObjectCache, result); break; case TypesOfAssociativity.Right: CleanLowerLevel(rightLevelKey, dbContext, dbObjectCache, result); break; case TypesOfAssociativity.Unknown: CleanLowerLevel(leftLevelKey, dbContext, dbObjectCache, result); CleanLowerLevel(rightLevelKey, dbContext, dbObjectCache, result); break; default: return new Exceptional<bool>(new Error_NotImplemented(new System.Diagnostics.StackTrace(true))); } } #endregion } } } #endregion break; default: return new Exceptional<bool>(new Error_NotImplemented(new System.Diagnostics.StackTrace(true))); } return new Exceptional<bool>(true); }
protected Exceptional<AOperationDefinition> SimpleOperation(ValueDefinition left, ValueDefinition right, TypesOfBinaryExpression myTypeOfBinaryExpression) { #region Data ValueDefinition resultObject = null; Object resultValue = false; #endregion resultValue = Compare(left.Value, right.Value); resultObject = new ValueDefinition(BasicType.Boolean, (object)resultValue); return new Exceptional<AOperationDefinition>(resultObject); }
protected Exceptional<AOperationDefinition> SimpleOperation(ValueDefinition left, TupleDefinition right, TypesOfBinaryExpression myTypeOfBinaryExpression) { #region Data ValueDefinition resultObject = null; Object resultValue = false; #endregion resultValue = right.Contains(new TupleElement(left)); resultObject = new ValueDefinition(BasicType.Boolean, (object)resultValue); return new Exceptional<AOperationDefinition>(resultObject); }
public SelectValueAssignment(ValueAssignmentTypes myValueAssignmentType, ValueDefinition myValueDefinition) { ValueAssignmentType = myValueAssignmentType; TermDefinition = myValueDefinition; }
public Exceptional<AOperationDefinition> SimpleOperation(ValueDefinition left, ValueDefinition right) { ADBBaseObject leftObject = left.Value; ADBBaseObject rightObject = right.Value; if (!GraphDBTypeMapper.ConvertToBestMatchingType(ref leftObject, ref rightObject).Value) { return new Exceptional<AOperationDefinition>(new Error_DataTypeDoesNotMatch(leftObject.Type.ToString(), rightObject.Type.ToString())); } if (leftObject.CompareTo(rightObject) < 0 && leftObject is DBUInt64 && DBInt64.IsValid(leftObject.Value)) { leftObject = new DBInt64(leftObject.Value); if (!GraphDBTypeMapper.ConvertToBestMatchingType(ref leftObject, ref rightObject).Value) { return new Exceptional<AOperationDefinition>(new Error_DataTypeDoesNotMatch(leftObject.Type.ToString(), rightObject.Type.ToString())); } } ADBBaseObject resultValue = leftObject.Sub(leftObject, rightObject); var resultObject = new ValueDefinition(resultValue.Type, resultValue.Value); return new Exceptional<AOperationDefinition>(resultObject); }
protected new Exceptional<AOperationDefinition> SimpleOperation(ValueDefinition left, ValueDefinition right) { #region Data ValueDefinition resultObject = null; #endregion var resultValue = Compare(left.Value, right.Value); if (resultValue.Failed()) return new Exceptional<AOperationDefinition>(resultValue); resultObject = new ValueDefinition(BasicType.Boolean, (object)resultValue); return new Exceptional<AOperationDefinition>(resultObject); }
protected new Exceptional<AOperationDefinition> SimpleOperation(TupleDefinition left, TupleDefinition right) { #region Data ValueDefinition resultObject = null; Object resultValue = false; #endregion foreach (var leftVal in left) { foreach (var rightVal in right) { var comp = Compare((leftVal.Value as ValueDefinition).Value, (rightVal.Value as ValueDefinition).Value); if (comp.Failed()) return new Exceptional<AOperationDefinition>(comp); if (!comp.Value) { resultValue = false; break; } else { resultValue = true; } } if ((Boolean)resultValue) break; } resultObject = new ValueDefinition(BasicType.Boolean, (object)resultValue); return new Exceptional<AOperationDefinition>(resultObject); }
private Exceptional<Boolean> EvaluateHaving(Vertex myDBObjectReadoutGroup, AExpressionDefinition complexValue, out String attributeName, out ValueDefinition simpleValue, DBContext dbContext) { //GraphDBType graphDBType = null; attributeName = null; simpleValue = null; if (complexValue is IDChainDefinition) { if (((IDChainDefinition)complexValue).LastAttribute == null) { if (((IDChainDefinition)complexValue).Last() is ChainPartFuncDefinition) { var func = (((IDChainDefinition)complexValue).Last() as ChainPartFuncDefinition); if (func.Parameters.Count != 1) return new Exceptional<Boolean>(new Error_NotImplemented(new System.Diagnostics.StackTrace(true))); attributeName = func.SourceParsedString; //graphDBType = func.Parameters.First().LastAttribute.GetDBType(dbContext.DBTypeManager); } else if (((IDChainDefinition)complexValue).IsUndefinedAttribute) { attributeName = ((IDChainDefinition)complexValue).UndefinedAttribute; //return new Exceptional<bool>(new Error_NotImplemented(new System.Diagnostics.StackTrace(true))); } else { //return new Exceptional<bool>(new Error_NotImplemented(new System.Diagnostics.StackTrace(true))); } } else { attributeName = ((IDChainDefinition)complexValue).LastAttribute.Name; //graphDBType = ((IDChainDefinition)complexValue).LastAttribute.GetDBType(dbContext.DBTypeManager); } } else { if (complexValue is AggregateDefinition) { var func = (complexValue as AggregateDefinition); if (func.ChainPartAggregateDefinition.Parameters.Count != 1) return new Exceptional<Boolean>(new Error_NotImplemented(new System.Diagnostics.StackTrace(true))); attributeName = func.ChainPartAggregateDefinition.SourceParsedString; //graphDBType = func.ContainingIDNodes.First().LastAttribute.GetDBType(dbContext.DBTypeManager); } else { return new Exceptional<bool>(new Error_NotImplemented(new System.Diagnostics.StackTrace(true))); } } if (myDBObjectReadoutGroup.IsAttribute(attributeName)) { ADBBaseObject objectValue = GraphDBTypeMapper.GetBaseObjectFromCSharpType(myDBObjectReadoutGroup.ObsoleteAttributes[attributeName]); simpleValue = new ValueDefinition(objectValue); return new Exceptional<bool>(true); } return new Exceptional<bool>(false); }
/// <summary> /// This will check all tupe value. If it contains only one value it will be converted to a ValueDefinition. If it contains a SelectDefinition it will be executed and the result added to the tuple. /// </summary> /// <param name="myTupleDefinition"></param> /// <param name="myOperator"></param> /// <param name="myDBContext"></param> /// <returns></returns> private Exceptional<AOperationDefinition> AssignCorrectTuple(TupleDefinition myTupleDefinition, ABinaryOperator myOperator, DBContext myDBContext) { var retVal = new TupleDefinition(myTupleDefinition.KindOfTuple); var validTuple = myOperator.GetValidTupleReloaded(myTupleDefinition, myDBContext); if (validTuple is TupleDefinition) { foreach (var tupleVal in (validTuple as TupleDefinition)) { if (tupleVal.Value is ValueDefinition) { retVal.AddElement(tupleVal); } else if (tupleVal.Value is SelectDefinition) { #region partial select var selectManager = new SelectManager(); var qresult = selectManager.ExecuteSelect(myDBContext, (tupleVal.Value as SelectDefinition)); if (qresult.Failed) { return new Exceptional<AOperationDefinition>(qresult.Errors); } TypeAttribute curAttr = ((tupleVal.Value as SelectDefinition).SelectedElements.First().Item1 as IDChainDefinition).LastAttribute; var dbTypeOfAttribute = curAttr.GetDBType(myDBContext.DBTypeManager); var aTypeOfOperatorResult = GraphDBTypeMapper.ConvertGraph2CSharp(dbTypeOfAttribute.Name); foreach (var _Vertex in qresult.Vertices) { if (!(_Vertex.IsAttribute(curAttr.Name))) continue; if (curAttr != null) { var val = new ValueDefinition(aTypeOfOperatorResult, _Vertex.ObsoleteAttributes[curAttr.Name]); retVal.AddElement(new TupleElement(aTypeOfOperatorResult, val)); } else { return new Exceptional<AOperationDefinition>(new Error_NotImplemented(new System.Diagnostics.StackTrace(true))); } } #endregion } else { return new Exceptional<AOperationDefinition>(new Error_NotImplemented(new System.Diagnostics.StackTrace(true))); } } } else { return new Exceptional<AOperationDefinition>(validTuple); } return new Exceptional<AOperationDefinition>(retVal); }
public Exceptional<AOperationDefinition> SimpleOperation(ValueDefinition left, TupleDefinition right) { right.Remove(left); return new Exceptional<AOperationDefinition>(right); }
/// <summary> /// Extracts data for a binary expression /// </summary> /// <param name="myComplexValue">The complex part of the binary expression.</param> /// <param name="mySimpleValue">The simple/atomic part of the expression.</param> /// <param name="errors">The list of errors.</param> /// <param name="typeOfBinExpr">The kind of the binary expression</param> /// <returns>A data tuple.</returns> private Exceptional<DataContainer> ExtractData(AExpressionDefinition myComplexValue, AExpressionDefinition mySimpleValue, ref TypesOfBinaryExpression typeOfBinExpr, DBObjectCache myDBObjectCache, SessionSettings mySessionToken, DBContext dbContext, Boolean aggregateAllowed) { #region data //the complex IDNode (sth. like U.Age or Count(U.Friends)) IDChainDefinition complexIDNode = null; //the value that is on the opposite of the complex IDNode AExpressionDefinition simpleValue = null; //a complex IDNode may result in a complexValue (i.e. Count(U.Friends) --> 3) AExpressionDefinition complexValue = null; //reference to former myComplexValue AExpressionDefinition extraordinaryValue = null; #endregion #region extraction if (myComplexValue is IDChainDefinition) { #region IDNode #region Data complexIDNode = (IDChainDefinition)myComplexValue; var validateResult = complexIDNode.Validate(dbContext, false); if (validateResult.Failed()) { return new Exceptional<DataContainer>(validateResult); } if (complexIDNode.Any(id => id is ChainPartFuncDefinition)) { if (complexIDNode.Edges.IsNullOrEmpty()) { #region parameterless function var fcn = (complexIDNode.First(id => id is ChainPartFuncDefinition) as ChainPartFuncDefinition); // somes functions (aggregates) like SUM are not valid for where expressions, though they are not resolved if (fcn.Function == null) return new Exceptional<DataContainer>(new Error_FunctionDoesNotExist(fcn.FuncName)); Exceptional<FuncParameter> pResult = fcn.Function.ExecFunc(dbContext); if (pResult.Failed()) { return new Exceptional<DataContainer>(pResult); } //simpleValue = new AtomValue(fcn.Function.TypeOfResult, ((FuncParameter)pResult.Value).Value); //the new simple value extraced from the function simpleValue = new ValueDefinition(((FuncParameter)pResult.Value).Value); typeOfBinExpr = TypesOfBinaryExpression.Unknown; //we do not know if we are left or right associated complexIDNode = null; //we resolved it... so it's null #endregion } else { //extraordinaryValue = (complexIDNode.First(id => id is ChainPartFuncDefinition) as ChainPartFuncDefinition); extraordinaryValue = complexIDNode; if (mySimpleValue is ValueDefinition) { simpleValue = mySimpleValue; } } } else { if(mySimpleValue is ValueDefinition) { try { if (complexIDNode.IsUndefinedAttribute) { throw new GraphDBException(new Error_AttributeIsNotDefined(complexIDNode.UndefinedAttribute)); } simpleValue = GetCorrectValueDefinition(complexIDNode.LastAttribute, complexIDNode.LastType, ((ValueDefinition)mySimpleValue), dbContext, mySessionToken); } catch (FormatException) { return new Exceptional<DataContainer>(new Error_DataTypeDoesNotMatch(complexIDNode.LastAttribute.GetDBType(dbContext.DBTypeManager).Name, ((ValueDefinition)mySimpleValue).Value.ObjectName)); } } else { if (mySimpleValue is TupleDefinition) { ((TupleDefinition)mySimpleValue).ConvertToAttributeType(complexIDNode.LastAttribute, dbContext); simpleValue = mySimpleValue; } //else if (mySimpleValue is TupleNode) //{ // var simpleValE = (mySimpleValue as TupleNode).GetAsTupleValue(dbContext, complexIDNode.LastAttribute); // if (!simpleValE.Success()) // { // return new Exceptional<DataContainer>(simpleValE); // } // simpleValue = simpleValE.Value; //} else { //return new Exceptional<DataContainer>(new Error_NotImplemented(new System.Diagnostics.StackTrace(true))); } } } #endregion #endregion } else if (myComplexValue is TupleDefinition) { #region TupleSetNode complexValue = ((TupleDefinition)myComplexValue); simpleValue = mySimpleValue; typeOfBinExpr = TypesOfBinaryExpression.Atom; #endregion } else if (myComplexValue is AggregateDefinition) { #region AggregateNode if (aggregateAllowed) { if (((AggregateDefinition)myComplexValue).ChainPartAggregateDefinition.Parameters.Count != 1) { return new Exceptional<DataContainer>(new Error_ArgumentException("An aggregate must have exactly one expression.")); } if (!(((AggregateDefinition)myComplexValue).ChainPartAggregateDefinition.Parameters[0] is IDChainDefinition)) { return new Exceptional<DataContainer>(new Error_ArgumentException("An aggregate must have exactly one IDNode.")); } #region Data complexIDNode = (((AggregateDefinition)myComplexValue).ChainPartAggregateDefinition.Parameters[0] as IDChainDefinition); if (complexIDNode == null) { return new Exceptional<DataContainer>(new Error_InvalidIDNode("Only single IDNodes are currently allowed in aggregates!")); } #endregion #region values simpleValue = mySimpleValue; extraordinaryValue = myComplexValue; #endregion } else { return new Exceptional<DataContainer>(new Error_AggregateNotAllowed(((AggregateDefinition)myComplexValue).ChainPartAggregateDefinition)); } #endregion } else { return new Exceptional<DataContainer>(new Error_NotImplementedExpressionNode(myComplexValue.GetType())); } #endregion return new Exceptional<DataContainer>(new DataContainer(new Tuple<IDChainDefinition, IDChainDefinition>(complexIDNode, null), new Tuple<AExpressionDefinition, AExpressionDefinition>(simpleValue, complexValue), new Tuple<AExpressionDefinition, AExpressionDefinition>(extraordinaryValue, null))); }
/// <summary> /// Extracts a AExpressionDefinition from the ParseTreeNode /// </summary> /// <param name="myParseTreeNode"></param> /// <returns></returns> protected AExpressionDefinition GetExpressionDefinition(ParseTreeNode myParseTreeNode) { AExpressionDefinition retVal = null; if (myParseTreeNode.Term is NonTerminal) { #region left is NonTerminal if (myParseTreeNode.AstNode is IDNode) { retVal = (myParseTreeNode.AstNode as IDNode).IDChainDefinition; } else if (myParseTreeNode.AstNode is TupleNode) { retVal = (myParseTreeNode.AstNode as TupleNode).TupleDefinition; } else if (myParseTreeNode.AstNode is BinaryExpressionNode) { retVal = (myParseTreeNode.AstNode as BinaryExpressionNode).BinaryExpressionDefinition; } else if (myParseTreeNode.AstNode is UnaryExpressionNode) { retVal = (myParseTreeNode.AstNode as UnaryExpressionNode).UnaryExpressionDefinition; } else if (myParseTreeNode.AstNode is AggregateNode) { retVal = (myParseTreeNode.AstNode as AggregateNode).AggregateDefinition; } #endregion } else { #region No NonTerminal retVal = new ValueDefinition(myParseTreeNode.Token.Value); #endregion } return retVal; }
private ValueDefinition GetCorrectValueDefinition(TypeAttribute typeAttribute, GraphDBType graphDBType, ValueDefinition myValueDefinition, DBContext dbContext, SessionSettings mySessionsInfos) { if (typeAttribute.IsBackwardEdge) { return GetCorrectValueDefinition(dbContext.DBTypeManager.GetTypeByUUID(typeAttribute.BackwardEdgeDefinition.TypeUUID).GetTypeAttributeByUUID(typeAttribute.BackwardEdgeDefinition.AttrUUID), graphDBType, myValueDefinition, dbContext, mySessionsInfos); } else { if (typeAttribute is ASpecialTypeAttribute && typeAttribute.UUID == SpecialTypeAttribute_UUID.AttributeUUID) { //var uuid = SpecialTypeAttribute_UUID.ConvertToUUID(atomValue.Value.Value.ToString(), graphDBType, mySessionsInfos, dbContext.DBTypeManager); //if (uuid.Failed()) //{ // throw new GraphDBException(uuid.Errors); //} //return new AtomValue(new DBReference(uuid.Value)); return new ValueDefinition(new DBReference(ObjectUUID.FromString(myValueDefinition.Value.Value.ToString()))); } else if (!typeAttribute.GetDBType(dbContext.DBTypeManager).IsUserDefined) { return new ValueDefinition(GraphDBTypeMapper.GetADBBaseObjectFromUUID(typeAttribute.DBTypeUUID, myValueDefinition.Value)); } else { throw new GraphDBException(new Error_InvalidAttributeValue(typeAttribute.Name, myValueDefinition.Value)); } } }
public ValueDefinition(ValueDefinition myValue) { Value = myValue.Value; IsDefined = myValue.IsDefined; }
/// <summary> /// Single IDNode selection attribute /// </summary> /// <param name="myReference"></param> /// <param name="myAlias"></param> /// <param name="myAStructureNode"></param> /// <param name="myGraphType"></param> public Exceptional AddElementToSelection(string myAlias, String myReference, IDChainDefinition myIDChainDefinition, Boolean myIsGroupedOrAggregated, SelectValueAssignment mySelectValueAssignment = null) { SelectionElement lastElem = null; var curLevel = new EdgeList(); EdgeList preLevel = null; if (myReference != null && _Selections.ContainsKey(myReference) && _Selections[myReference].Any(kv => kv.Value.Any(se => se.RelatedIDChainDefinition == myIDChainDefinition && se.Alias == myAlias))) { return new Exceptional(new Error_DuplicateAttributeSelection(myAlias)); } foreach (var nodeEdgeKey in myIDChainDefinition) { if (nodeEdgeKey is ChainPartTypeOrAttributeDefinition) { #region Usual attribute preLevel = null; var selElem = new SelectionElement(myAlias, curLevel, myIsGroupedOrAggregated, myIDChainDefinition); var typeOrAttr = (nodeEdgeKey as ChainPartTypeOrAttributeDefinition); if (true || typeOrAttr.DBType != null && typeOrAttr.TypeAttribute != null) { #region defined var edgeKey = typeOrAttr.EdgeKey; selElem.Element = typeOrAttr.TypeAttribute; //_DBContext.DBTypeManager.GetTypeAttributeByEdge(edgeKey); if (String.IsNullOrEmpty(selElem.Alias) || (nodeEdgeKey.Next != null && !(nodeEdgeKey.Next is ChainPartFuncDefinition))) { selElem.Alias = typeOrAttr.TypeAttribute.Name;//_DBContext.DBTypeManager.GetTypeAttributeByEdge(edgeKey).Name; } curLevel += edgeKey; preLevel = curLevel.GetPredecessorLevel(); #endregion } else { #region undefined attribute if (myIDChainDefinition.Level == 0) { preLevel = new EdgeList(myIDChainDefinition.LastType.UUID); } else { var element = _Selections[myReference].Last(); preLevel = curLevel.GetPredecessorLevel(); //preLevel = curLevel; } selElem.Alias = typeOrAttr.TypeOrAttributeName; selElem.Element = new UndefinedTypeAttribute(typeOrAttr.TypeOrAttributeName); #endregion } #region Add to _Selections if valid if (!_Selections.ContainsKey(myReference)) { _Selections.Add(myReference, new Dictionary<EdgeList, List<SelectionElement>>()); } if (!_Selections[myReference].ContainsKey(preLevel)) { _Selections[myReference].Add(preLevel, new List<SelectionElement>()); } /// /// Duplicate AttributeSelection is: "U.Name, U.Name" or "U.Name.TOUPPER(), U.Name" but not "U.Friends.TOP(1).Name, U.Friends.TOP(1).Age" if ((nodeEdgeKey.Next == null || (nodeEdgeKey.Next is ChainPartFuncDefinition && nodeEdgeKey.Next.Next == null)) // U.Name, U.Name U.Name.TOUPPER, U.Name && _Selections[myReference][preLevel].Exists(item => item.Alias == selElem.Alias && selElem.EdgeList.Level == item.EdgeList.Level && item.RelatedIDChainDefinition.Depth == selElem.RelatedIDChainDefinition.Depth && item.Element != null) && !myIsGroupedOrAggregated) { return new Exceptional(new Error_DuplicateAttributeSelection(selElem.Alias)); } // Do not add again if: // - it is a defined attribute and there is an asterisk selection at this level // - it is not the last part AND // - there is already an item of this part with the same alias and the same Depth if (nodeEdgeKey.Next == null || _Selections[myReference][preLevel].Count == 0 || _Selections[myReference][preLevel].Any(item => IsNewSelectionElement(item, selElem))) { _Selections[myReference][preLevel].Add(selElem); } #endregion lastElem = selElem; #endregion } else if (nodeEdgeKey is ChainPartFuncDefinition) { var chainPartFuncDefinition = (nodeEdgeKey as ChainPartFuncDefinition); #region Function if (myReference == null) { #region Type independent functions var selElem = new SelectionElement(myAlias, myIDChainDefinition); if (String.IsNullOrEmpty(selElem.Alias)) { selElem.Alias = chainPartFuncDefinition.SourceParsedString; } var funcElem = new SelectionElementFunction(selElem, chainPartFuncDefinition, chainPartFuncDefinition.Parameters); if (lastElem is SelectionElementFunction) { (lastElem as SelectionElementFunction).AddFollowingFunction(funcElem); lastElem = funcElem; } else { if (_SelectionElementsTypeIndependend.Any(se => se.Alias == funcElem.Alias)) { return new Exceptional(new Error_DuplicateAttributeSelection(funcElem.Alias)); } _SelectionElementsTypeIndependend.Add(funcElem); lastElem = funcElem; } #endregion } else { #region Type dependent function var funcElem = new SelectionElementFunction(lastElem, (nodeEdgeKey as ChainPartFuncDefinition), (nodeEdgeKey as ChainPartFuncDefinition).Parameters); funcElem.RelatedIDChainDefinition = myIDChainDefinition; if (!String.IsNullOrEmpty(myAlias) && nodeEdgeKey.Next == null) { funcElem.Alias = myAlias; } if (lastElem is SelectionElementFunction) { (lastElem as SelectionElementFunction).AddFollowingFunction(funcElem); lastElem = funcElem; } else if (_Selections[myReference][preLevel].Contains(lastElem)) { #region Add function to the last selection element (replace it) _Selections[myReference][preLevel].Remove(lastElem); //lastElem = new SelectionElementFunction(lastElem, (nodeEdgeKey as ChainPartFuncDefinition), (nodeEdgeKey as ChainPartFuncDefinition).Parameters); //lastElem.RelatedIDChainDefinition = myIDChainDefinition; //if (!String.IsNullOrEmpty(alias) && nodeEdgeKey.Next == null) //{ // lastElem.Alias = alias; //} lastElem = funcElem; if (!_Selections[myReference][preLevel].Contains(lastElem)) // In case this Element with func is already in the selection list do nothing. { _Selections[myReference][preLevel].Add(lastElem); } #endregion } else if (!_Selections[myReference][preLevel].Contains(funcElem)) { #region In this case we have a similar function but NOT THE SAME. Since we don't know what to do, return error. return new Exceptional(new Error_InvalidAttributeSelection(myIDChainDefinition.ContentString)); #endregion } #endregion } #endregion } } #region Set the SelectValueAssignment for the last element if (lastElem != null && mySelectValueAssignment != null) { #region Error handling System.Diagnostics.Debug.Assert(lastElem.Element != null); if (lastElem.Element.IsUserDefinedType(_DBContext.DBTypeManager)) { return new Exceptional(new Error_InvalidSelectValueAssignment(lastElem.Element.Name)); } if (!(mySelectValueAssignment.TermDefinition is ValueDefinition)) { return new Exceptional(new Error_NotImplemented(new System.Diagnostics.StackTrace(true))); } #endregion #region Validate datatype if the attribute is a defined attribute if (!(lastElem.Element is UndefinedTypeAttribute)) { if (!lastElem.Element.GetADBBaseObjectType(_DBContext.DBTypeManager).IsValidValue((mySelectValueAssignment.TermDefinition as ValueDefinition).Value.Value)) { return new Exceptional(new Error_SelectValueAssignmentDataTypeDoesNotMatch(lastElem.Element.GetADBBaseObjectType(_DBContext.DBTypeManager).ObjectName, (mySelectValueAssignment.TermDefinition as ValueDefinition).Value.ObjectName)); } var typedValue = new ValueDefinition(lastElem.Element.GetADBBaseObjectType(_DBContext.DBTypeManager).Clone((mySelectValueAssignment.TermDefinition as ValueDefinition).Value.Value)); mySelectValueAssignment.TermDefinition = typedValue; } #endregion lastElem.SelectValueAssignment = mySelectValueAssignment; } #endregion return Exceptional.OK; }
public Exceptional<AOperationDefinition> SimpleOperation(ValueDefinition left, TupleDefinition right) { right.AddElement(new TupleElement(left)); return new Exceptional<AOperationDefinition>(right); }