private TableQuery SplitQueryExpression(StorageQueryOperand query) { string result = null; List <List <StorageComparisonExpression> > conditionGroups = ExtractConditionGroups(query); var contitions = conditionGroups.Select(BuildQueryExpression); foreach (var qry in contitions) { if (result == null) { result = qry.FilterString; } else { result = TableQuery.CombineFilters(result, TableOperators.Or, qry.FilterString); } } return(new TableQuery { FilterString = result, SelectColumns = new[] { "Content" }, TakeCount = Take }); }
private StorageQueryOperand Normalize(StorageQueryOperand toNormalize) { if (toNormalize is StorageLogicalExpression logical) { var left = Normalize(logical.LeftOperand); var right = Normalize(logical.RightOperand); if (logical.Operator == QueryLogicalOperator.Or) { return(new StorageLogicalExpression(left, right, QueryLogicalOperator.Or)); } if (logical.Operator == QueryLogicalOperator.And) { if (left is StorageLogicalExpression leftResult && leftResult.Operator == QueryLogicalOperator.Or) { var leftOperand = Normalize(new StorageLogicalExpression(right, leftResult.LeftOperand, QueryLogicalOperator.And)); var rightOperand = Normalize(new StorageLogicalExpression(right, leftResult.RightOperand, QueryLogicalOperator.And)); return(new StorageLogicalExpression(leftOperand, rightOperand, QueryLogicalOperator.Or)); } if (right is StorageLogicalExpression rightResult && rightResult.Operator == QueryLogicalOperator.Or) { var leftOperand = Normalize(new StorageLogicalExpression(left, rightResult.LeftOperand, QueryLogicalOperator.And)); var rightOperand = Normalize(new StorageLogicalExpression(left, rightResult.RightOperand, QueryLogicalOperator.And)); return(new StorageLogicalExpression(leftOperand, rightOperand, QueryLogicalOperator.Or)); } return(new StorageLogicalExpression(left, right, QueryLogicalOperator.And)); } } return(toNormalize); }
private List <StorageComparisonExpression> ProcessAndOperandTree(StorageQueryOperand logical) { List <StorageComparisonExpression> result = new List <StorageComparisonExpression>(); if (logical is StorageComparisonExpression condition) { result.Add(condition); } else { if (((StorageLogicalExpression)logical).Operator == QueryLogicalOperator.Or) { throw new StorageArgumentOutOfRangeException(nameof(logical), "Expression not normalized"); } result.AddRange(ProcessLogicalAndOperand((StorageLogicalExpression)logical)); } return(result); }
private void ProcessOrOperandTree(StorageQueryOperand logical, List <List <StorageComparisonExpression> > conditionList) { List <StorageComparisonExpression> result = new List <StorageComparisonExpression>(); if (logical is StorageComparisonExpression condition) { result.Add(condition); } else { if (((StorageLogicalExpression)logical).Operator == QueryLogicalOperator.And) { conditionList.Add(ProcessLogicalAndOperand((StorageLogicalExpression)logical)); } else { ProcessLogicalOrOperand((StorageLogicalExpression)logical, conditionList); } } }
private List <List <StorageComparisonExpression> > ExtractConditionGroups(StorageQueryOperand normalizedQuery) { var result = new List <List <StorageComparisonExpression> >(); if (normalizedQuery is StorageLogicalExpression logical) { if (logical.Operator == QueryLogicalOperator.And) { result.Add(ProcessLogicalAndOperand(logical)); } else { ProcessLogicalOrOperand(logical, result); } } else { result.Add(new List <StorageComparisonExpression> { (StorageComparisonExpression)normalizedQuery }); } return(result); }
protected StorageBinaryExpression(StorageQueryOperand left, StorageQueryOperand right) { LeftOperand = left; RightOperand = right; }