private static IExpression GenerateLiteral(AExpressionDefinition aExpressionDefinition, Type myTypeOfLiteral) { if (aExpressionDefinition is ValueDefinition) { if (myTypeOfLiteral.IsSubclassOf(typeof(AUserdefinedDataType))) { try { var userdefInstance = (AUserdefinedDataType)Activator.CreateInstance(myTypeOfLiteral, new object[] { (((ValueDefinition)aExpressionDefinition).Value.ConvertToIComparable(typeof(String))) }); return(new SingleLiteralExpression((IComparable)userdefInstance.Value)); } catch (Exception e) { throw new UnknownException(e); } } else { return(new SingleLiteralExpression(((ValueDefinition)aExpressionDefinition).Value.ConvertToIComparable(myTypeOfLiteral))); } } else { throw new NotImplementedQLException("TODO"); } }
private bool CheckIDNode(AExpressionDefinition myPotentialIDNode, Dictionary <string, string> attributes) { if (myPotentialIDNode is IDChainDefinition) { var chainDefinition = (myPotentialIDNode as IDChainDefinition); if (chainDefinition.Level == 0) { if (attributes.ContainsKey(chainDefinition.LastAttribute.Name)) { return(true); } else { return(false); } } else { throw new NotImplementedException(); } } else { return(false); } }
public void Init(ParsingContext context, ParseTreeNode parseNode) { _ParseTreeNode = parseNode.ChildNodes[0]; ExpressionDefinition = GetExpressionDefinition(_ParseTreeNode); if (HasChildNodes(parseNode.ChildNodes[1])) { Parameters = ((ParametersNode)parseNode.ChildNodes[1].AstNode).ParameterValues; } }
private static IExpression GenerateLiteral(AExpressionDefinition aExpressionDefinition, Type myTypeOfLiteral) { if (aExpressionDefinition is ValueDefinition) { return(new SingleLiteralExpression(((ValueDefinition)aExpressionDefinition).Value.ConvertToIComparable(myTypeOfLiteral))); } else { throw new NotImplementedQLException("TODO"); } }
/// <summary> /// Handles the Binary Expression node /// </summary> /// <param name="context"></param> /// <param name="parseNode"></param> /// <param name="typeManager"></param> public void GetContent(CompilerContext context, ParseTreeNode parseNode) { #region set type of binary expression _OperatorSymbol = parseNode.ChildNodes[1].Term.Name; _left = GetExpressionDefinition(parseNode.ChildNodes[0]); _right = GetExpressionDefinition(parseNode.ChildNodes[2]); #endregion BinaryExpressionDefinition = new BinaryExpressionDefinition(_OperatorSymbol, _left, _right); OriginalString += _left.ToString() + " "; OriginalString += _OperatorSymbol + " "; OriginalString += _right.ToString(); }
public void Init(ParsingContext context, ParseTreeNode parseNode) { if (HasChildNodes(parseNode)) { if (parseNode.ChildNodes[1].AstNode == null) { throw new NotImplementedQLException(""); } _OperatorSymbol = parseNode.ChildNodes[0].Token.Text; Expression = GetExpressionDefinition(parseNode.ChildNodes[1]); } System.Diagnostics.Debug.Assert(Expression != null); UnaryExpressionDefinition = new UnaryExpressionDefinition(_OperatorSymbol, Expression); }
/// <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 FuncParameter ValidateAndAddParameter(ParameterValue myParameter, AExpressionDefinition myValue, IAttributeDefinition myTypeAttribute) { if (!(myValue is ValueDefinition)) { throw new InvalidVertexAttributeValueException(myParameter.Name, myValue); } var val = (myValue as ValueDefinition).Value; try { Convert.ChangeType(val, myParameter.Value as Type); } catch (Exception e) { throw new FunctionParameterTypeMismatchException(myParameter.Value as Type, val.GetType(), e); } return(new FuncParameter(val, myTypeAttribute)); }
public void Init(ParsingContext context, ParseTreeNode parseNode) { #region set type of binary expression _OperatorSymbol = parseNode.ChildNodes[1].FirstChild.Token.ValueString; _left = GetExpressionDefinition(parseNode.ChildNodes[0]); _right = GetExpressionDefinition(parseNode.ChildNodes[2]); if (parseNode.ChildNodes.Count > 3) { _expressionIndex = ((AstNode)parseNode.ChildNodes[4].AstNode).AsString; } #endregion BinaryExpressionDefinition = new BinaryExpressionDefinition(_OperatorSymbol, _left, _right, _expressionIndex); OriginalString += _left.ToString() + " "; OriginalString += _OperatorSymbol + " "; OriginalString += _right.ToString(); }
public BinaryExpressionDefinition(String myOperatorSymbol, AExpressionDefinition myLeft, AExpressionDefinition myRight) { _OperatorSymbol = myOperatorSymbol; _Left = myLeft; _Right = myRight; }
private void GetContent(CompilerContext context, ParseTreeNode parseNode) { ExpressionDefinition = GetExpressionDefinition(parseNode.ChildNodes[0]); }
public abstract Exceptional<IExpressionGraph> TypeOperation(AExpressionDefinition myLeftValueObject, AExpressionDefinition myRightValueObject, DBContext dbContext, TypesOfBinaryExpression typeOfBinExpr, TypesOfAssociativity associativity, IExpressionGraph result, Boolean aggregateAllowed = true);
/// <summary> /// Finds matching result corresponding to a binary expression. /// </summary> /// <param name="myLeftValueObject">The left value of a binary expression.</param> /// <param name="myRightValueObject">The right value of a binary expression.</param> /// <param name="currentTypeDefinitione"></param> /// <param name="dbContext">The TypeManager of the database.</param> /// <param name="typeOfBinExpr">The type of the binary expression.</param> /// <param name="associativity">The associativity of the binary expression.</param> /// <param name="referenceList"></param> /// <param name="queryCache">The per query DBObject/BackwardEdge cache.</param> /// <returns></returns> public override Exceptional<IExpressionGraph> TypeOperation(AExpressionDefinition myLeftValueObject, AExpressionDefinition myRightValueObject, DBContext dbContext, TypesOfBinaryExpression typeOfBinExpr, TypesOfAssociativity associativity, IExpressionGraph resultGr, Boolean aggregateAllowed = true) { #region Data //list of errors List<GraphDBError> errors = new List<GraphDBError>(); //DataContainer for all data that is used by a binary expression/comparer Exceptional<DataContainer> data; //the index of the left attribute IEnumerable<Tuple<GraphDBType, AAttributeIndex>> leftIndex = null; //the index of the right attribute IEnumerable<Tuple<GraphDBType, AAttributeIndex>> rightIndex = null; #endregion #region extract data //data extraction with an eye on the type of the binary expression switch (typeOfBinExpr) { case TypesOfBinaryExpression.Atom: //sth like 3 = 4 #region Get Atom data //no further data has to be generated //data = new DataContainer(null, new Tuple<Object, Object>(myLeftValueObject, myRightValueObject), null); data = new Exceptional<DataContainer>(); #endregion break; case TypesOfBinaryExpression.LeftComplex: //sth like U.Age = 21 #region Get LeftComplex data data = ExtractData(myLeftValueObject, myRightValueObject, ref typeOfBinExpr, dbContext.DBObjectCache, dbContext.SessionSettings, dbContext, aggregateAllowed); if (!data.Success()) { return new Exceptional<IExpressionGraph>(data); } #endregion break; case TypesOfBinaryExpression.RightComplex: //sth like 21 = U.Age #region Get RightComplex data data = ExtractData(myRightValueObject, myLeftValueObject, ref typeOfBinExpr, dbContext.DBObjectCache, dbContext.SessionSettings, dbContext, aggregateAllowed); if (!data.Success()) { return new Exceptional<IExpressionGraph>(data); } #endregion break; case TypesOfBinaryExpression.Complex: //sth like U.Age = F.Alter #region Get Complex data var leftData = ExtractData(myLeftValueObject, myRightValueObject, ref typeOfBinExpr, dbContext.DBObjectCache, dbContext.SessionSettings, dbContext, aggregateAllowed); if (!leftData.Success()) { return new Exceptional<IExpressionGraph>(leftData); } var rightData = ExtractData(myRightValueObject, myLeftValueObject, ref typeOfBinExpr, dbContext.DBObjectCache, dbContext.SessionSettings, dbContext, aggregateAllowed); if (!rightData.Success()) { return new Exceptional<IExpressionGraph>(rightData); } if (typeOfBinExpr == TypesOfBinaryExpression.Unknown) { typeOfBinExpr = SetTypeOfBinaryExpression(leftData, rightData); switch (typeOfBinExpr) { case TypesOfBinaryExpression.Atom: data = new Exceptional<DataContainer>(new DataContainer(new Tuple<IDChainDefinition, IDChainDefinition>(null, null), new Tuple<AExpressionDefinition, AExpressionDefinition>(leftData.Value.Operands.Item1, leftData.Value.Operands.Item1), new Tuple<AExpressionDefinition, AExpressionDefinition>(null, null))); break; case TypesOfBinaryExpression.LeftComplex: data = new Exceptional<DataContainer>(new DataContainer(new Tuple<IDChainDefinition, IDChainDefinition>(leftData.Value.IDChainDefinitions.Item1, null), new Tuple<AExpressionDefinition, AExpressionDefinition>(rightData.Value.Operands.Item1, null), new Tuple<AExpressionDefinition, AExpressionDefinition>(null, null))); break; case TypesOfBinaryExpression.RightComplex: data = new Exceptional<DataContainer>(new DataContainer(new Tuple<IDChainDefinition, IDChainDefinition>(rightData.Value.IDChainDefinitions.Item1, null), new Tuple<AExpressionDefinition, AExpressionDefinition>(leftData.Value.Operands.Item1, null), new Tuple<AExpressionDefinition, AExpressionDefinition>(null, null))); break; case TypesOfBinaryExpression.Complex: case TypesOfBinaryExpression.Unknown: default: throw new GraphDBException(new Error_NotImplemented(new System.Diagnostics.StackTrace(true))); } } else { data = new Exceptional<DataContainer>(JoinData(leftData.Value, rightData.Value)); } #endregion break; default: throw new ArgumentException(); } #region handle errors if (data.Failed()) { return new Exceptional<IExpressionGraph>(data); } #endregion #endregion #region get indexes switch (typeOfBinExpr) { case TypesOfBinaryExpression.LeftComplex: leftIndex = GetIndex(data.Value.IDChainDefinitions.Item1.LastAttribute, dbContext, data.Value.IDChainDefinitions.Item1.LastType, data.Value.Extraordinaries.Item1); break; case TypesOfBinaryExpression.RightComplex: //data.IdNodes.TupelElement1 is correct, because of correct handling in extract data (data.IdNodes.TupelElement2 should be null here) rightIndex = GetIndex(data.Value.IDChainDefinitions.Item1.LastAttribute, dbContext, data.Value.IDChainDefinitions.Item1.LastType, data.Value.Extraordinaries.Item1); break; case TypesOfBinaryExpression.Complex: //both indexe have to be catched leftIndex = GetIndex(data.Value.IDChainDefinitions.Item1.LastAttribute, dbContext, data.Value.IDChainDefinitions.Item1.LastType, data.Value.Extraordinaries.Item1); rightIndex = GetIndex(data.Value.IDChainDefinitions.Item2.LastAttribute, dbContext, data.Value.IDChainDefinitions.Item2.LastType, data.Value.Extraordinaries.Item1); break; } #endregion //time to compare some things Exceptional<Boolean> matchDataResult = null; if (IsValidIndexOperation(data.Value, dbContext, typeOfBinExpr)) { #region match data switch (typeOfBinExpr) { case TypesOfBinaryExpression.Atom: #region Atom //do nothing 3 = 3 (or 2 != 3) doesnt bother U #endregion break; case TypesOfBinaryExpression.LeftComplex: #region LeftComplex matchDataResult = MatchData(data.Value, dbContext, dbContext.DBObjectCache, typeOfBinExpr, leftIndex, resultGr, dbContext.SessionSettings); #endregion break; case TypesOfBinaryExpression.RightComplex: #region RightComplex matchDataResult = MatchData(data.Value, dbContext, dbContext.DBObjectCache, typeOfBinExpr, rightIndex, resultGr, dbContext.SessionSettings); #endregion break; case TypesOfBinaryExpression.Complex: #region Complex matchDataResult = MatchComplexData(associativity, data.Value, dbContext, dbContext.DBObjectCache, typeOfBinExpr, leftIndex, rightIndex, ref errors, ref resultGr, dbContext.SessionSettings); #endregion break; } #endregion } else { return new Exceptional<IExpressionGraph>(new Error_InvalidBinaryExpression(this, data.Value.IDChainDefinitions, data.Value.Operands, typeOfBinExpr)); } if (matchDataResult != null && matchDataResult.Failed()) return new Exceptional<IExpressionGraph>(matchDataResult); else return new Exceptional<IExpressionGraph>(resultGr); }
public void Init(ParsingContext context, ParseTreeNode parseNode) { ExpressionDefinition = GetExpressionDefinition(parseNode.ChildNodes[0]); }
private bool CheckIDNode(AExpressionDefinition myPotentialIDNode, Dictionary<string, string> attributes) { if (myPotentialIDNode is IDChainDefinition) { var chainDefinition = (myPotentialIDNode as IDChainDefinition); if (chainDefinition.Level == 0) { if (attributes.ContainsKey(chainDefinition.LastAttribute.Name)) { return true; } else { return false; } } else { throw new NotImplementedException(); } } else { return false; } }
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); }
private Exceptional ValidateBinaryExpressionInternal(AExpressionDefinition aUniqueExpr, GraphDBType validationType, DBContext dbContext) { if (aUniqueExpr is BinaryExpressionDefinition) { return (aUniqueExpr as BinaryExpressionDefinition).Validate(dbContext, validationType); //return ValidateBinaryExpression((BinaryExpressionDefinition)aUniqueExpr, validationType, dbContext); } else { var _potIdNode = aUniqueExpr as IDChainDefinition; if (_potIdNode != null) { //var validationResult = _potIdNode.ValidateMe(validationType, typeManager); var validationResult = _potIdNode.Validate(dbContext, false, validationType); return validationResult; } else { return Exceptional.OK; } } }
/// <summary> /// This method checks if a binary expression is combinable. /// </summary> /// <param name="_left">Left part of the binary expression.</param> /// <param name="_right">Right part of the binary expression.</param> /// <returns></returns> private bool IsCombinableAble(AExpressionDefinition _left, AExpressionDefinition _right) { if (TypeOfBinaryExpression == TypesOfBinaryExpression.Complex) { return false; } if ((Operator.Label == BinaryOperator.Addition) || (Operator.Label == BinaryOperator.Subtraction) || (Operator.Label == BinaryOperator.Multiplication) || (Operator.Label == BinaryOperator.Division)) { if (TypeOfBinaryExpression == TypesOfBinaryExpression.LeftComplex) { #region left complex if (_left is BinaryExpressionDefinition) { #region data var leftNode = (BinaryExpressionDefinition)_left; #endregion if (leftNode.TypeOfBinaryExpression != TypesOfBinaryExpression.Complex) { return true; } else { return false; } } else { return false; } #endregion } else { #region right complex if (_right is BinaryExpressionDefinition) { #region data var rightNode = (BinaryExpressionDefinition)_right; #endregion if (rightNode.TypeOfBinaryExpression != TypesOfBinaryExpression.Complex) { return true; } else { return false; } } else { return false; } #endregion } } else { return false; } }
internal void ChangeType(AExpressionDefinition aExpressionDefinition) { if (aExpressionDefinition is IDChainDefinition) { ChangeType((aExpressionDefinition as IDChainDefinition).LastAttribute.DBTypeUUID); } }
public UnaryExpressionDefinition(string myOperatorSymbol, AExpressionDefinition myExpression) { _OperatorSymbol = myOperatorSymbol; _Expression = myExpression; }
/// <summary> /// This method combines simple binary expressions like (U.Age + 1) + 1 --> U.Age + 2 /// </summary> /// <param name="_left">Left part of the binary expression.</param> /// <param name="_right">Right part of the binary expression.</param> private void SimpleCombination(ref AExpressionDefinition _left, ref AExpressionDefinition _right) { if (TypeOfBinaryExpression == TypesOfBinaryExpression.LeftComplex) { #region left is complex #region data var leftNode = _left as BinaryExpressionDefinition; Boolean isValidOperation = false; #endregion foreach (String aSymbol in leftNode.Operator.Symbol) { if (Operator.ContraryOperationSymbol.Equals(aSymbol) || Operator.Symbol.Contains(aSymbol)) { isValidOperation = true; break; } } if (isValidOperation) { #region get values ValueDefinition simpleValue = null; AExpressionDefinition _leftComplex = null; if (leftNode.TypeOfBinaryExpression == TypesOfBinaryExpression.LeftComplex) { simpleValue = leftNode._Right as ValueDefinition; simpleValue.ChangeType(leftNode._Left); _leftComplex = leftNode._Left; } else { simpleValue = leftNode._Left as ValueDefinition; simpleValue.ChangeType(leftNode._Right); _leftComplex = leftNode._Right; } #endregion #region get the new left value _left = _leftComplex; #endregion #region get new right value for current node var _rightTempResult = Operator.SimpleOperation(simpleValue, ((ValueDefinition)_right), TypeOfBinaryExpression).Value; _right = _rightTempResult; #endregion } #endregion } else { #region right is complex #region data var rightNode = (BinaryExpressionDefinition)_right; Boolean isValidOperation = false; #endregion foreach (String aSymbol in rightNode.Operator.Symbol) { if (Operator.ContraryOperationSymbol.Equals(aSymbol) || Operator.Symbol.Contains(aSymbol)) { isValidOperation = true; break; } } if (isValidOperation) { #region get values ValueDefinition _rightAtom = null; AExpressionDefinition _rightComplex = null; if (rightNode.TypeOfBinaryExpression == TypesOfBinaryExpression.LeftComplex) { _rightAtom = ((ValueDefinition)rightNode.Right); _rightComplex = rightNode.Left; } else { _rightAtom = ((ValueDefinition)rightNode.Left); _rightComplex = rightNode.Right; } #endregion #region get the new right value _right = _rightComplex; #endregion #region get new left value for current node var _leftTempResult = Operator.SimpleOperation(((ValueDefinition)_left), _rightAtom, TypeOfBinaryExpression).Value; _left = _leftTempResult; #endregion } #endregion } }
/// <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); }
/// <summary> /// /// </summary> /// <param name="_left"></param> /// <param name="_right"></param> /// <param name="typeManager"></param> private void SimpleExpressionTweak(ref AExpressionDefinition _left, ref AExpressionDefinition _right, DBContext typeManager) { if (TypeOfBinaryExpression == TypesOfBinaryExpression.LeftComplex) { #region left is complex #region data var leftNode = (BinaryExpressionDefinition)_left; #endregion #region get contrary operator for complex part ABinaryOperator contraryOperator = typeManager.DBPluginManager.GetBinaryOperator(leftNode.Operator.ContraryOperationSymbol); #endregion #region get values ValueDefinition simpleValue = null; AExpressionDefinition _leftComplex = null; if (leftNode.TypeOfBinaryExpression == TypesOfBinaryExpression.LeftComplex) { simpleValue = (leftNode._Right as ValueDefinition); simpleValue.ChangeType(leftNode._Left); _leftComplex = leftNode._Left; } else { simpleValue = (leftNode._Left as ValueDefinition); simpleValue.ChangeType(leftNode._Right); _leftComplex = leftNode._Right; } #endregion #region get new right value for current node var _rightTempResult = contraryOperator.SimpleOperation((AOperationDefinition)_right, simpleValue, TypeOfBinaryExpression); _right = _rightTempResult.Value; #endregion #region get the new left value _left = _leftComplex; #endregion #region update operator in case of an inequality if (Operator.Label == BinaryOperator.Inequal) { if (leftNode.Operator.Label == BinaryOperator.Division) { if (Convert.ToDouble(simpleValue).CompareTo(0) < 0) { Operator = typeManager.DBPluginManager.GetBinaryOperator(Operator.ContraryOperationSymbol); } } } #endregion #endregion } else { #region right is complex #region data var rightNode = (BinaryExpressionDefinition)_right; #endregion #region get contrary operator for complex part ABinaryOperator contraryOperator = typeManager.DBPluginManager.GetBinaryOperator(rightNode.Operator.ContraryOperationSymbol); #endregion #region get values AOperationDefinition _rightAtom = null; AExpressionDefinition _rightComplex = null; if (rightNode.TypeOfBinaryExpression == TypesOfBinaryExpression.LeftComplex) { _rightAtom = (AOperationDefinition)rightNode._Right; _rightComplex = rightNode._Left; } else { _rightAtom = (AOperationDefinition)rightNode._Left; _rightComplex = rightNode._Right; } #endregion #region get new left value for current node var _leftTempResult = contraryOperator.SimpleOperation(((AOperationDefinition)_left), _rightAtom, TypeOfBinaryExpression).Value; _left = _leftTempResult; #endregion #region get the new right value _right = _rightComplex; #endregion #region update operator in case of an inequality if ((Operator.Label == BinaryOperator.Inequal) || (Operator.Label == BinaryOperator.GreaterEquals) || (Operator.Label == BinaryOperator.GreaterThan) || (Operator.Label == BinaryOperator.LessEquals) || (Operator.Label == BinaryOperator.LessThan)) { if (rightNode.Operator.Label == BinaryOperator.Division) { if (Convert.ToDouble(_rightAtom).CompareTo(0) < 0) { Operator = typeManager.DBPluginManager.GetBinaryOperator(Operator.ContraryOperationSymbol); } } } #endregion #endregion } }
/// <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> /// /// </summary> /// <param name="expression"></param> /// <returns></returns> private Exceptional<AExpressionDefinition> TryGetBinexpression(AExpressionDefinition expression, DBContext myDBContext) { if (expression is BinaryExpressionDefinition) { var validateResult = (expression as BinaryExpressionDefinition).Validate(myDBContext); return new Exceptional<AExpressionDefinition>((expression as BinaryExpressionDefinition), validateResult); } else { //for negative values like -U.Age if (expression is UnaryExpressionDefinition) { var binExpr = (expression as UnaryExpressionDefinition).GetBinaryExpression(myDBContext); return new Exceptional<AExpressionDefinition>(binExpr.Value, binExpr); } else { if (expression is TupleDefinition) { return TryGetBinexpression(((TupleDefinition)expression).First().Value, myDBContext); } } } return new Exceptional<AExpressionDefinition>(new Error_NotImplemented(new System.Diagnostics.StackTrace(true))); }
/// <summary> /// Finds matching result corresponding to a binary expression. /// </summary> /// <param name="myLeftValueObject">The left value of a binary expression.</param> /// <param name="myRightValueObject">The right value of a binary expression.</param> /// <param name="myPluginManager"></param> /// <param name="myGraphDB"></param> /// <param name="mySecurityToken"></param> /// <param name="myTransactionToken"></param> /// <param name="typeOfBinExpr">Type of the binary expression.</param> /// <param name="resultGr"></param> /// <param name="mytypesOfOpertators"></param> /// <param name="myOperator">The binary operator.</param> /// <param name="myExpressionIndex">The name of the index which should be used for the expression.</param> /// <param name="aggregateAllowed"></param> /// <returns>An expression graph.</returns> public static IExpressionGraph TypeOperation(AExpressionDefinition myLeftValueObject, AExpressionDefinition myRightValueObject, GQLPluginManager myPluginManager, IGraphDB myGraphDB, SecurityToken mySecurityToken, Int64 myTransactionToken, TypesOfBinaryExpression typeOfBinExpr, IExpressionGraph resultGr, TypesOfOperators mytypesOfOpertators, BinaryOperator myOperator, String myExpressionIndex, Boolean aggregateAllowed = true) { #region Data //DataContainer for all data that is used by a binary expression/comparer DataContainer data; #endregion #region extract data //data extraction with an eye on the type of the binary expression switch (typeOfBinExpr) { case TypesOfBinaryExpression.Atom: //sth like 3 = 4 #region Get Atom data //no further data has to be generated //data = new DataContainer(null, new Tuple<Object, Object>(myLeftValueObject, myRightValueObject), null); data = new DataContainer(); #endregion break; case TypesOfBinaryExpression.LeftComplex: //sth like U.Age = 21 #region Get LeftComplex data data = ExtractData(myLeftValueObject, myRightValueObject, ref typeOfBinExpr, myPluginManager, myGraphDB, mySecurityToken, myTransactionToken, aggregateAllowed); #endregion break; case TypesOfBinaryExpression.RightComplex: //sth like 21 = U.Age #region Get RightComplex data data = ExtractData(myRightValueObject, myLeftValueObject, ref typeOfBinExpr, myPluginManager, myGraphDB, mySecurityToken, myTransactionToken, aggregateAllowed); #endregion break; case TypesOfBinaryExpression.Complex: //sth like U.Age = F.Alter #region Get Complex data var leftData = ExtractData(myLeftValueObject, myRightValueObject, ref typeOfBinExpr, myPluginManager, myGraphDB, mySecurityToken, myTransactionToken, aggregateAllowed); var rightData = ExtractData(myRightValueObject, myLeftValueObject, ref typeOfBinExpr, myPluginManager, myGraphDB, mySecurityToken, myTransactionToken, aggregateAllowed); if (typeOfBinExpr == TypesOfBinaryExpression.Unknown) { typeOfBinExpr = SetTypeOfBinaryExpression(leftData, rightData); switch (typeOfBinExpr) { case TypesOfBinaryExpression.Atom: data = new DataContainer(new Tuple <IDChainDefinition, IDChainDefinition>(null, null), new Tuple <AExpressionDefinition, AExpressionDefinition>(leftData.Operands.Item1, leftData.Operands.Item1), new Tuple <AExpressionDefinition, AExpressionDefinition>(null, null)); break; case TypesOfBinaryExpression.LeftComplex: data = new DataContainer(new Tuple <IDChainDefinition, IDChainDefinition>(leftData.IDChainDefinitions.Item1, null), new Tuple <AExpressionDefinition, AExpressionDefinition>(rightData.Operands.Item1, null), new Tuple <AExpressionDefinition, AExpressionDefinition>(null, null)); break; case TypesOfBinaryExpression.RightComplex: data = new DataContainer(new Tuple <IDChainDefinition, IDChainDefinition>(rightData.IDChainDefinitions.Item1, null), new Tuple <AExpressionDefinition, AExpressionDefinition>(leftData.Operands.Item1, null), new Tuple <AExpressionDefinition, AExpressionDefinition>(null, null)); break; case TypesOfBinaryExpression.Complex: case TypesOfBinaryExpression.Unknown: default: throw new NotImplementedQLException(""); } } else { data = JoinData(leftData, rightData); } #endregion break; default: throw new ArgumentException(); } #endregion #region match data switch (typeOfBinExpr) { case TypesOfBinaryExpression.Atom: #region Atom //do nothing 3 = 3 (or 2 != 3) doesnt bother U #endregion break; case TypesOfBinaryExpression.LeftComplex: #region LeftComplex MatchData(data, resultGr, myGraphDB, mySecurityToken, myTransactionToken, mytypesOfOpertators, myOperator, myExpressionIndex); #endregion break; case TypesOfBinaryExpression.RightComplex: #region RightComplex MatchData(data, resultGr, myGraphDB, mySecurityToken, myTransactionToken, mytypesOfOpertators, myOperator, myExpressionIndex); #endregion break; case TypesOfBinaryExpression.Complex: #region Complex throw new NotImplementedQLException(""); #endregion } #endregion return(resultGr); }
/// <summary> /// /// </summary> /// <param name="myAExpressionDefinition"></param> /// <returns></returns> private Exceptional<AOperationDefinition> TryGetOperationValue(AExpressionDefinition myAExpressionDefinition) { #region data var expression = myAExpressionDefinition as BinaryExpressionDefinition; #endregion if (expression == null) { return null; } if (expression.TypeOfBinaryExpression == TypesOfBinaryExpression.Atom) { if (expression.ResultValue.Failed()) { return expression.ResultValue; } } if (expression.ResultValue != null) { return expression.ResultValue; } return null; }
/// <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 static DataContainer ExtractData(AExpressionDefinition myComplexValue, AExpressionDefinition mySimpleValue, ref TypesOfBinaryExpression typeOfBinExpr, GQLPluginManager myPluginManager, IGraphDB myGraphDB, SecurityToken mySecurityToken, Int64 myTransactionToken, 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; complexIDNode.Validate(myPluginManager, myGraphDB, mySecurityToken, myTransactionToken, false); if (complexIDNode.Any(id => id is ChainPartFuncDefinition)) { if (complexIDNode.Edges == null || complexIDNode.Edges.Count == 0) { #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) { throw new FunctionDoesNotExistException(fcn.FuncName); } FuncParameter pResult = fcn.Function.ExecFunc(null, null, null, myGraphDB, mySecurityToken, myTransactionToken); //simpleValue = new AtomValue(fcn.Function.TypeOfResult, ((FuncParameter)pResult.Value).Value); //the new simple value extraced from the function simpleValue = new ValueDefinition(((FuncParameter)pResult).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 VertexAttributeIsNotDefinedException(complexIDNode.UndefinedAttribute); } simpleValue = GetCorrectValueDefinition(complexIDNode.LastAttribute, complexIDNode.LastType, ((ValueDefinition)mySimpleValue)); } catch (FormatException) { throw new DataTypeDoesNotMatchException(((IPropertyDefinition)complexIDNode.LastAttribute).BaseType.Name, ((ValueDefinition)mySimpleValue).Value.GetType().Name); } } else { if (mySimpleValue is TupleDefinition) { ((TupleDefinition)mySimpleValue).ConvertToAttributeType(myPluginManager, complexIDNode.LastAttribute, myGraphDB, mySecurityToken, myTransactionToken); simpleValue = mySimpleValue; } } } #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) { throw new GQLAggregateArgumentException("An aggregate must have exactly one expression."); } if (!(((AggregateDefinition)myComplexValue).ChainPartAggregateDefinition.Parameters[0] is IDChainDefinition)) { throw new GQLAggregateArgumentException("An aggregate must have exactly one IDNode."); } #region Data complexIDNode = (((AggregateDefinition)myComplexValue).ChainPartAggregateDefinition.Parameters[0] as IDChainDefinition); if (complexIDNode == null) { throw new InvalidIDNodeException("Only single IDNodes are currently allowed in aggregates!"); } #endregion #region values simpleValue = mySimpleValue; extraordinaryValue = myComplexValue; #endregion } else { throw new AggregateNotAllowedException(((AggregateDefinition)myComplexValue).ChainPartAggregateDefinition.Aggregate.PluginShortName); } #endregion } else { throw new NotImplementedQLException(""); } #endregion return(new DataContainer(new Tuple <IDChainDefinition, IDChainDefinition>(complexIDNode, null), new Tuple <AExpressionDefinition, AExpressionDefinition>(simpleValue, complexValue), new Tuple <AExpressionDefinition, AExpressionDefinition>(extraordinaryValue, null))); }
/// <summary> /// Validates the expression (Set the TypeOfBinaryExpression, do some simplifications and validates all IDChains /// </summary> /// <param name="myDBContext"></param> /// <param name="types">This is optional, usually you wont pass any types</param> /// <returns></returns> public Exceptional Validate(DBContext myDBContext, params GraphDBType[] types) { if (IsValidated) { return ValidateResult; } ValidateResult = new Exceptional(); Operator = myDBContext.DBPluginManager.GetBinaryOperator(_OperatorSymbol); #region Left - Valid TypesOfBinaryExpression are RightComplex (left is atom) or LeftComplex (left is complex) if (_Left is ValueDefinition) { TypeOfBinaryExpression = TypesOfBinaryExpression.RightComplex; } else if (_Left is IDChainDefinition) { ValidateResult.PushIExceptional((_Left as IDChainDefinition).Validate(myDBContext, true, types)); TypeOfBinaryExpression = TypesOfBinaryExpression.LeftComplex; } else if (_Left is TupleDefinition) { #region TupleDefinition if (IsEncapsulatedBinaryExpression(_Left as TupleDefinition)) { var exceptionalResult = TryGetBinexpression((_Left as TupleDefinition).First().Value, myDBContext); if (exceptionalResult.Failed()) { return ValidateResult.PushIExceptional(exceptionalResult); } _Left = exceptionalResult.Value; TypeOfBinaryExpression = TypesOfBinaryExpression.LeftComplex; } else { var correctTuple = AssignCorrectTuple((_Left as TupleDefinition), Operator, myDBContext); if (correctTuple.Failed()) { return new Exceptional(correctTuple); } _Left = correctTuple.Value; TypeOfBinaryExpression = TypesOfBinaryExpression.RightComplex; } #endregion } else if (_Left is AggregateDefinition) { TypeOfBinaryExpression = TypesOfBinaryExpression.LeftComplex; } else if (_Left is UnaryExpressionDefinition) { TypeOfBinaryExpression = TypesOfBinaryExpression.LeftComplex; var binExprResult = (_Left as UnaryExpressionDefinition).GetBinaryExpression(myDBContext); ValidateResult.PushIExceptional(binExprResult); _Left = binExprResult.Value; } else { #region try binexpr var exceptionalResult = TryGetBinexpression(_Left, myDBContext); if (exceptionalResult.Failed()) { return ValidateResult.PushIExceptional(exceptionalResult); } _Left = exceptionalResult.Value; TypeOfBinaryExpression = TypesOfBinaryExpression.LeftComplex; #endregion } #endregion if (ValidateResult.Failed()) { return ValidateResult; } #region Right if (_Right is ValueDefinition) { if (TypeOfBinaryExpression == TypesOfBinaryExpression.RightComplex) { TypeOfBinaryExpression = TypesOfBinaryExpression.Atom; } } else if (_Right is IDChainDefinition) { ValidateResult.PushIExceptional((_Right as IDChainDefinition).Validate(myDBContext, false, types)); if (TypeOfBinaryExpression == TypesOfBinaryExpression.LeftComplex) { TypeOfBinaryExpression = TypesOfBinaryExpression.Complex; } } else if (_Right is UnaryExpressionDefinition) { if (TypeOfBinaryExpression == TypesOfBinaryExpression.LeftComplex) { TypeOfBinaryExpression = TypesOfBinaryExpression.Complex; } var binExprResult = (_Right as UnaryExpressionDefinition).GetBinaryExpression(myDBContext); ValidateResult.PushIExceptional(binExprResult); _Right = binExprResult.Value; } else if (_Right is TupleDefinition) { #region TupleDefinition if (IsEncapsulatedBinaryExpression(_Right as TupleDefinition)) { var exceptionalResult = TryGetBinexpression((_Right as TupleDefinition).First().Value, myDBContext); if (exceptionalResult.Failed()) { return ValidateResult.PushIExceptional(exceptionalResult); } _Right = exceptionalResult.Value; if (TypeOfBinaryExpression == TypesOfBinaryExpression.LeftComplex) { TypeOfBinaryExpression = TypesOfBinaryExpression.Complex; } } else { var correctTuple = AssignCorrectTuple((_Right as TupleDefinition), Operator, myDBContext); if (correctTuple.Failed()) { return new Exceptional(correctTuple); } _Right = correctTuple.Value; if (TypeOfBinaryExpression == TypesOfBinaryExpression.RightComplex) { TypeOfBinaryExpression = TypesOfBinaryExpression.Atom; } } #endregion } else if (_Right is AggregateDefinition) { if (TypeOfBinaryExpression == TypesOfBinaryExpression.LeftComplex) { TypeOfBinaryExpression = TypesOfBinaryExpression.Complex; } } else { #region try binexpr var exceptionalResult = TryGetBinexpression(_Right, myDBContext); if (exceptionalResult.Failed()) { return ValidateResult.PushIExceptional(exceptionalResult); } _Right = exceptionalResult.Value; if (TypeOfBinaryExpression == TypesOfBinaryExpression.LeftComplex) { TypeOfBinaryExpression = TypesOfBinaryExpression.Complex; } #endregion } #endregion if (ValidateResult.Failed()) { return ValidateResult; } #region try to get values from complex expr Exceptional<AOperationDefinition> leftTemp; Exceptional<AOperationDefinition> rightTemp; switch (TypeOfBinaryExpression) { case TypesOfBinaryExpression.Atom: break; case TypesOfBinaryExpression.LeftComplex: #region leftComplex leftTemp = TryGetOperationValue(_Left); if (leftTemp != null) { if (leftTemp.Failed()) { return ValidateResult.PushIExceptional(leftTemp); } TypeOfBinaryExpression = TypesOfBinaryExpression.Atom; _Left = leftTemp.Value; } #endregion break; case TypesOfBinaryExpression.RightComplex: #region rightComplex rightTemp = TryGetOperationValue(_Right); if (rightTemp != null) { if (rightTemp.Failed()) { return ValidateResult.PushIExceptional(rightTemp); } TypeOfBinaryExpression = TypesOfBinaryExpression.Atom; _Right = rightTemp.Value; } #endregion break; case TypesOfBinaryExpression.Complex: #region complex leftTemp = TryGetOperationValue(_Left); rightTemp = TryGetOperationValue(_Right); #region Check for errors if (leftTemp != null && leftTemp.Failed()) { return ValidateResult.PushIExceptional(leftTemp); } if (rightTemp != null && rightTemp.Failed()) { return ValidateResult.PushIExceptional(rightTemp); } #endregion if ((leftTemp != null) && (rightTemp != null)) { TypeOfBinaryExpression = TypesOfBinaryExpression.Atom; _Left = leftTemp.Value; _Right = rightTemp.Value; } else { if (leftTemp != null) { TypeOfBinaryExpression = TypesOfBinaryExpression.RightComplex; _Left = leftTemp.Value; } else if (rightTemp != null) { TypeOfBinaryExpression = TypesOfBinaryExpression.LeftComplex; _Right = rightTemp.Value; } } #endregion break; } #endregion #region process values if (TypeOfBinaryExpression == TypesOfBinaryExpression.Atom) { #region atomic values if ((_Left is AOperationDefinition) && (_Right is AOperationDefinition)) { var opResult = Operator.SimpleOperation(((AOperationDefinition)_Left), ((AOperationDefinition)_Right), TypeOfBinaryExpression); if (opResult.Failed()) { return ValidateResult.PushIExceptional(opResult); } ResultValue = new Exceptional<AOperationDefinition>(opResult.Value); } #endregion } else { #region some kind of complex values if (IsCombinableAble(_Left, _Right)) { #region summarize expressions //sth like (U.Age + 1) + 1 --> U.Age + 2 SimpleCombination(ref _Left, ref _Right); #endregion } else { #region tweak expressions while (IsTweakAble(_Left, _Right)) { SimpleExpressionTweak(ref _Left, ref _Right, myDBContext); } #endregion } #endregion } #endregion return ValidateResult; }
public override Exceptional<IExpressionGraph> TypeOperation(AExpressionDefinition myLeftValueObject, AExpressionDefinition myRightValueObject, DBContext dbContext, TypesOfBinaryExpression typeOfBinExpr, TypesOfAssociativity associativity, IExpressionGraph result, Boolean aggregateAllowed = true) { return new Exceptional<IExpressionGraph>(new Error_NotImplemented(new System.Diagnostics.StackTrace(true))); }
public override Exceptional<IExpressionGraph> TypeOperation(AExpressionDefinition myLeftValueObject, AExpressionDefinition myRightValueObject, DBContext dbContext, TypesOfBinaryExpression typeOfBinExpr, TypesOfAssociativity associativity, ExpressionGraph.IExpressionGraph result, bool aggregateAllowed = true) { throw new NotImplementedException(); }