public bool IsSatisfyHaving(IVertexView myDBObjectReadoutGroup) { if (TypeOfBinaryExpression == TypesOfBinaryExpression.LeftComplex) { String attributeName = null; ValueDefinition leftValue = null; if (!EvaluateHaving(myDBObjectReadoutGroup, _Left, out attributeName, out leftValue)) { return(false); } throw new NotImplementedQLException("TODO"); //var resultValue = Operator.SimpleOperation(leftValue, ((ValueDefinition)_Right), TypeOfBinaryExpression); //return (Boolean)((resultValue as ValueDefinition).Value); } else if (TypeOfBinaryExpression == TypesOfBinaryExpression.RightComplex) { String attributeName = null; ValueDefinition rightValue = null; if (!EvaluateHaving(myDBObjectReadoutGroup, _Right, out attributeName, out rightValue)) { return(false); } throw new NotImplementedQLException("TODO"); //var resultValue = Operator.SimpleOperation(((ValueDefinition)_Left), rightValue, TypeOfBinaryExpression); //return (Boolean)((resultValue as ValueDefinition).Value); } throw new NotImplementedQLException(""); }
internal void ConvertToAttributeType(GQLPluginManager myPluginManager, IAttributeDefinition typeAttribute, IGraphDB myGraphDB, SecurityToken mySecurityToken, Int64 myTransactionToken) { var newTuple = new List <TupleElement>(); for (int i = 0; i < TupleElements.Count; i++) { var tupleElement = TupleElements[i].Value; if (tupleElement is SelectDefinition) { #region partial select var selectManager = new SelectManager(myGraphDB, myPluginManager); var selectDefinition = (tupleElement as SelectDefinition); IQueryResult qresult = selectManager.ExecuteSelect(mySecurityToken, myTransactionToken, selectDefinition, String.Empty); if (qresult.Error != null) { throw qresult.Error; } IAttributeDefinition curAttr = ((tupleElement as SelectDefinition).SelectedElements.First().Item1 as IDChainDefinition).LastAttribute; foreach (var _Vertex in qresult.Vertices) { if (!(_Vertex.HasProperty(curAttr.Name))) { continue; } if (curAttr != null) { var val = new ValueDefinition(_Vertex.GetProperty <Object>(curAttr.Name)); newTuple.Add(new TupleElement(val)); } else { throw new NotImplementedQLException(""); } } #endregion } else if (TupleElements[i].Value is ValueDefinition) { newTuple.Add(new TupleElement(new ValueDefinition((TupleElements[i].Value as ValueDefinition).Value))); } else { throw new InvalidTupleException(TupleElements[i].Value.GetType().Name); } } TupleElements = newTuple; }
public BinaryExpressionDefinition GetBinaryExpression(GQLPluginManager myPluginManager, IGraphDB myGraphDB, SecurityToken mySecurityToken, TransactionToken myTransactionToken) { AExpressionDefinition right; var op = GetOperatorBySymbol(_OperatorSymbol); if (op == null) { throw new OperatorDoesNotExistException(_OperatorSymbol); } right = new ValueDefinition(1); var binExpr = new BinaryExpressionDefinition("*", _Expression, right); binExpr.Validate(myPluginManager, myGraphDB, mySecurityToken, myTransactionToken); return binExpr; }
public BinaryExpressionDefinition GetBinaryExpression(GQLPluginManager myPluginManager, IGraphDB myGraphDB, SecurityToken mySecurityToken, Int64 myTransactionToken) { AExpressionDefinition right; var op = GetOperatorBySymbol(_OperatorSymbol); if (op == null) { throw new OperatorDoesNotExistException(_OperatorSymbol); } right = new ValueDefinition(1); var binExpr = new BinaryExpressionDefinition("*", _Expression, right); binExpr.Validate(myPluginManager, myGraphDB, mySecurityToken, myTransactionToken); return(binExpr); }
private Boolean EvaluateHaving(IVertexView myDBObjectReadoutGroup, AExpressionDefinition complexValue, out String attributeName, out ValueDefinition simpleValue) { //VertexType 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) { throw new NotImplementedQLException(""); } 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) { throw new NotImplementedQLException(""); } attributeName = func.ChainPartAggregateDefinition.SourceParsedString; //graphDBType = func.ContainingIDNodes.First().LastAttribute.GetDBType(dbContext.DBTypeManager); } else { throw new NotImplementedQLException(""); } } if (myDBObjectReadoutGroup.HasProperty(attributeName)) { simpleValue = new ValueDefinition(myDBObjectReadoutGroup.GetProperty <Object>(attributeName)); return(true); } return(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> private AOperationDefinition AssignCorrectTuple(GQLPluginManager myPluginManager, TupleDefinition myTupleDefinition, BinaryOperator myOperator, IGraphDB myGraphDB, SecurityToken mySecurityToken, Int64 myTransactionToken) { var retVal = new TupleDefinition(myTupleDefinition.KindOfTuple); var validTuple = ABinaryOperator.GetValidTupleReloaded(myTupleDefinition, myGraphDB, mySecurityToken, myTransactionToken); 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(myGraphDB, myPluginManager); var qresult = selectManager.ExecuteSelect(mySecurityToken, myTransactionToken, (tupleVal.Value as SelectDefinition), String.Empty); if (qresult.Error != null) { throw qresult.Error; } IAttributeDefinition curAttr = ((tupleVal.Value as SelectDefinition).SelectedElements.First().Item1 as IDChainDefinition).LastAttribute; foreach (var _Vertex in qresult.Vertices) { if (!(_Vertex.HasProperty(curAttr.Name))) { continue; } if (curAttr != null) { var val = new ValueDefinition(_Vertex.GetProperty <Object>(curAttr.Name)); retVal.AddElement(new TupleElement(val)); } else { throw new NotImplementedQLException(""); } } #endregion } else { throw new NotImplementedQLException(""); } } } else { return(validTuple); } return(retVal); }
private static ValueDefinition GetCorrectValueDefinition(IAttributeDefinition typeAttribute, IVertexType graphDBType, ValueDefinition myValueDefinition) { if (typeAttribute.Kind == AttributeType.IncomingEdge) { return GetCorrectValueDefinition(((IIncomingEdgeDefinition)typeAttribute).RelatedEdgeDefinition, graphDBType, myValueDefinition); } else { if (typeAttribute.Kind == AttributeType.Property) { return myValueDefinition; } else { throw new InvalidVertexAttributeValueException(typeAttribute.Name, myValueDefinition.Value); } } }
/// <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)); }
private Boolean EvaluateHaving(IVertexView myDBObjectReadoutGroup, AExpressionDefinition complexValue, out String attributeName, out ValueDefinition simpleValue) { //VertexType 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) { throw new NotImplementedQLException(""); } 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) throw new NotImplementedQLException(""); attributeName = func.ChainPartAggregateDefinition.SourceParsedString; //graphDBType = func.ContainingIDNodes.First().LastAttribute.GetDBType(dbContext.DBTypeManager); } else { throw new NotImplementedQLException(""); } } if (myDBObjectReadoutGroup.HasProperty(attributeName)) { simpleValue = new ValueDefinition(myDBObjectReadoutGroup.GetProperty<Object>(attributeName)); return true; } return 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> private AOperationDefinition AssignCorrectTuple(GQLPluginManager myPluginManager, TupleDefinition myTupleDefinition, BinaryOperator myOperator, IGraphDB myGraphDB, SecurityToken mySecurityToken, Int64 myTransactionToken) { var retVal = new TupleDefinition(myTupleDefinition.KindOfTuple); var validTuple = ABinaryOperator.GetValidTupleReloaded(myTupleDefinition, myGraphDB, mySecurityToken, myTransactionToken); 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(myGraphDB, myPluginManager); var qresult = selectManager.ExecuteSelect(mySecurityToken, myTransactionToken, (tupleVal.Value as SelectDefinition), String.Empty); if (qresult.Error != null) { throw qresult.Error; } IAttributeDefinition curAttr = ((tupleVal.Value as SelectDefinition).SelectedElements.First().Item1 as IDChainDefinition).LastAttribute; foreach (var _Vertex in qresult.Vertices) { if (!(_Vertex.HasProperty(curAttr.Name))) continue; if (curAttr != null) { var val = new ValueDefinition(_Vertex.GetProperty<Object>(curAttr.Name)); retVal.AddElement(new TupleElement(val)); } else { throw new NotImplementedQLException(""); } } #endregion } else { throw new NotImplementedQLException(""); } } } else { return validTuple; } return retVal; }
public SelectValueAssignment(ValueAssignmentTypes myValueAssignmentType, ValueDefinition myValueDefinition) { ValueAssignmentType = myValueAssignmentType; TermDefinition = myValueDefinition; }
public void Remove(ValueDefinition myValueDefinition) { TupleElements.Remove(new TupleElement(myValueDefinition)); }
/// <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; }
public SelectValueAssignment(ValueAssignmentTypes myValueAssignmentType, ValueDefinition myValueDefinition) { ValueAssignmentType = myValueAssignmentType; TermDefinition = myValueDefinition; }
public void Init(ParsingContext context, ParseTreeNode parseNode) { //TupleDefinition = new TupleDefinition(GetKindOfTuple(context, parseNode)); TupleDefinition = new TupleDefinition(); ParseTreeNodeList childNodes; if (parseNode.ChildNodes[0].AstNode == null && parseNode.ChildNodes[0].ChildNodes.Count > 0) // this is a not resolved node and has childNodes { childNodes = parseNode.ChildNodes[0].ChildNodes; } else // single expression tuple - SetRefNode seems MarkTransient the tuple { childNodes = parseNode.ChildNodes; } #region get tuple elements foreach (ParseTreeNode aExpressionNode in childNodes) { #region Data Type typeOfExpression = null; TupleElement aElement = null; #endregion #region Check the AstNode type and set the typeOfExpression. In case of a tuple just add them. if (aExpressionNode.Term != null) { if ((aExpressionNode.Term.Name == SonesGQLConstants.BracketLeft) || (aExpressionNode.Term.Name == SonesGQLConstants.BracketRight)) { continue; } } if (aExpressionNode.AstNode is ExpressionOfAListNode) { typeOfExpression = ((ExpressionOfAListNode)aExpressionNode.AstNode).GetType(); } else if (aExpressionNode.AstNode is ExpressionNode) { typeOfExpression = ((ExpressionNode)aExpressionNode.AstNode).GetType(); } else if (aExpressionNode.AstNode is BinaryExpressionNode) { typeOfExpression = aExpressionNode.Term.GetType(); } else if (aExpressionNode.AstNode is UnaryExpressionNode) { typeOfExpression = aExpressionNode.Term.GetType(); } else if (aExpressionNode.AstNode is TupleNode) { TupleDefinition = ((TupleNode)aExpressionNode.AstNode).TupleDefinition; continue; } else if (aExpressionNode.AstNode is PartialSelectStmtNode) { typeOfExpression = aExpressionNode.Term.GetType(); } else if (aExpressionNode.AstNode is IDNode) { throw new NotImplementedQLException(""); } else { var val = new ValueDefinition(aExpressionNode.Token.Value); TupleDefinition.AddElement(new TupleElement(val)); continue; } #endregion if (aExpressionNode.AstNode is ExpressionNode) { aElement = new TupleElement(((ExpressionNode)aExpressionNode.AstNode).ExpressionDefinition); } else if (aExpressionNode.AstNode is ExpressionOfAListNode) { aElement = new TupleElement((((ExpressionOfAListNode)aExpressionNode.AstNode).ExpressionDefinition)); if (((ExpressionOfAListNode)aExpressionNode.AstNode).Parameters != null) { aElement.Parameters = ((ExpressionOfAListNode)aExpressionNode.AstNode).Parameters; } } else if (aExpressionNode.AstNode is BinaryExpressionNode) { aElement = new TupleElement((aExpressionNode.AstNode as BinaryExpressionNode).BinaryExpressionDefinition); } else if (aExpressionNode.AstNode is UnaryExpressionNode) { aElement = new TupleElement((aExpressionNode.AstNode as UnaryExpressionNode).UnaryExpressionDefinition); } else if (aExpressionNode.AstNode is PartialSelectStmtNode) { #region partial select aElement = new TupleElement(((PartialSelectStmtNode)aExpressionNode.AstNode).SelectDefinition); #endregion } else if (aExpressionNode.AstNode is ExpressionNode) { aElement = new TupleElement(((ExpressionNode)aExpressionNode.AstNode).ExpressionDefinition); } else if (aExpressionNode.AstNode is ExpressionOfAListNode) { aElement = new TupleElement(((ExpressionOfAListNode)aExpressionNode.AstNode).ExpressionDefinition); if (((ExpressionOfAListNode)aExpressionNode.AstNode).Parameters != null) { aElement.Parameters = ((ExpressionOfAListNode)aExpressionNode.AstNode).Parameters; } } else { throw new NotImplementedQLException(""); } TupleDefinition.AddElement(aElement); } #endregion }