/// <summary> /// Constructs Group by result processor. /// The suffix HS stands for Half Streamed solution, whereas the S stands for Full Streamed solution. /// The additional suffices B and L stand for the type of result storages. B is for buckets and L is for Lists. /// </summary> public static ResultProcessor Factory(QueryExpressionInfo expressionInfo, IGroupByExecutionHelper executionHelper, int columnCount, int[] usedVars, bool isStreamed) { if (executionHelper.IsSetSingleGroupGroupBy) { if (!isStreamed) { return(new SingleGroupGroupByHalfStreamed(expressionInfo, executionHelper, columnCount, usedVars)); } else { return(new SingleGroupGroupByStreamed(expressionInfo, executionHelper, columnCount, usedVars)); } } else { if (executionHelper.GrouperAlias == GrouperAlias.GlobalS) { return(new GlobalGroupByStreamed(expressionInfo, executionHelper, columnCount, usedVars)); } else if (executionHelper.GrouperAlias == GrouperAlias.TwoStepHSB) { return(new TwoStepHalfStreamedBucket(expressionInfo, executionHelper, columnCount, usedVars)); } else if (executionHelper.GrouperAlias == GrouperAlias.TwoStepHSL) { return(new TwoStepHalfStreamedListBucket(expressionInfo, executionHelper, columnCount, usedVars)); } else { throw new ArgumentException("Group by result processor, trying to create an unknown grouper."); } } }
protected GroupByResultProcessor(QueryExpressionInfo expressionInfo, IGroupByExecutionHelper executionHelper, int columnCount, int[] usedVars) { this.aggregates = expressionInfo.Aggregates.ToArray(); this.hashes = expressionInfo.GroupByhashExprs.ToArray(); this.executionHelper = executionHelper; this.ColumnCount = columnCount; this.usedVars = usedVars; }
public SingleGroupGroupByStreamed(QueryExpressionInfo expressionInfo, IGroupByExecutionHelper executionHelper, int columnCount, int[] usedVars) : base(expressionInfo, executionHelper, columnCount, usedVars) { this.finalResults = AggregateBucketResult.CreateBucketResults(this.aggregates); Aggregate.ExtractNonAstAggsAndResults(this.aggregates, this.finalResults, out nonAsterixAggregates, out nonAsterixResults); if (this.finalResults.Length != this.nonAsterixResults.Length) { this.containsAst = true; } }
/// <summary> /// Creates a group by object for a single group group by (not defined group by clause but only aggregations in select). /// Assumes that the executionHelper.IsSetSingleGroupGroupBy is set to true. /// </summary> /// <param name="executionHelper"> A group by execution helper. </param> /// <param name="exprInfo"> A query expression information. </param> public GroupByObject(IGroupByExecutionHelper executionHelper, QueryExpressionInfo exprInfo) { if (executionHelper == null || exprInfo == null) { throw new ArgumentNullException($"{this.GetType()}, passing null arguments to the constructor."); } this.aggregates = exprInfo.Aggregates; this.helper = executionHelper; }
/// <summary> /// Parses Group by parse tree, the information is stored in the expression info class. /// The reason this method is separated from constructor is because it cannot guess whether the /// clause is a normal group by or a single group group by, thus the group by must always be parsed /// as the first clause after the Match clause. /// </summary> public static void ParseGroupBy(Graph graph, VariableMap variableMap, IGroupByExecutionHelper executionHelper, GroupByNode groupByNode, QueryExpressionInfo exprInfo) { if (executionHelper == null || groupByNode == null || variableMap == null || graph == null || exprInfo == null) { throw new ArgumentNullException($"Group by results processor, passing null arguments to the constructor."); } var groupbyVisitor = new GroupByVisitor(graph.labels, variableMap, exprInfo); groupbyVisitor.Visit(groupByNode); executionHelper.IsSetGroupBy = true; }
protected Grouper(Aggregate[] aggs, ExpressionHolder[] hashes, IGroupByExecutionHelper helper, bool bucketStorage) { if (helper == null || aggs == null) { throw new ArgumentNullException($"{this.GetType()}, passing null arguments to the constructor."); } this.ThreadCount = helper.ThreadCount; this.aggregates = aggs; this.InParallel = helper.InParallel; this.hashes = hashes; this.BucketStorage = bucketStorage; }
public SingleGroupGroupByHalfStreamed(QueryExpressionInfo expressionInfo, IGroupByExecutionHelper helper, int columnCount, int[] usedVars) : base(expressionInfo, helper, columnCount, usedVars) { this.matcherNonAsterixResults = new AggregateBucketResult[this.executionHelper.ThreadCount][]; this.finalResults = AggregateBucketResult.CreateBucketResults(this.aggregates); Aggregate.ExtractNonAstAggsAndResults(this.aggregates, this.finalResults, out nonAsterixAggregates, out finalNonAsterixResults); if (this.finalResults.Length != this.finalNonAsterixResults.Length) { this.containsAst = true; } this.numberOfMatchedElements = new int[this.executionHelper.ThreadCount]; for (int i = 0; i < this.matcherNonAsterixResults.Length; i++) { this.matcherNonAsterixResults[i] = AggregateBucketResult.CreateBucketResults(this.nonAsterixAggregates); } }
/// <summary> /// Creates a group by object for multigroup group by (defined group by clause). /// </summary> /// <param name="graph"> A property graph. </param> /// <param name="variableMap"> A variable map. </param> /// <param name="executionHelper"> A group by execution helper. </param> /// <param name="groupByNode"> A parsed tree of group by expression. </param> /// <param name="exprInfo"> A query expression information. </param> public GroupByObject(Graph graph, VariableMap variableMap, IGroupByExecutionHelper executionHelper, GroupByNode groupByNode, QueryExpressionInfo exprInfo) { if (executionHelper == null || groupByNode == null || variableMap == null || graph == null || exprInfo == null) { throw new ArgumentNullException($"{this.GetType()}, passing null arguments to the constructor."); } this.helper = executionHelper; var groupbyVisitor = new GroupByVisitor(graph.labels, variableMap, exprInfo); groupbyVisitor.Visit(groupByNode); this.hashes = groupbyVisitor.GetResult().ToArray(); this.aggregates = exprInfo.Aggregates; this.helper.IsSetGroupBy = true; }
public GlobalGroupByStreamed(QueryExpressionInfo expressionInfo, IGroupByExecutionHelper executionHelper, int columnCount, int[] usedVars) : base(expressionInfo, executionHelper, columnCount, usedVars) { this.matcherBucketFactories = new BucketsKeyValueFactory[this.executionHelper.ThreadCount]; for (int i = 0; i < this.executionHelper.ThreadCount; i++) { this.matcherBucketFactories[i] = new BucketsKeyValueFactory(this.aggregates, this.hashes); } var comparer = new RowEqualityComparerAggregateBucketResult(this.hashes.Length, this.hashes); if (this.executionHelper.InParallel) { this.parGroups = new ConcurrentDictionary <AggregateBucketResult[], AggregateBucketResult[]>(comparer); } else { this.stGroups = new Dictionary <AggregateBucketResult[], AggregateBucketResult[]>(comparer); } }
public TwoStepHalfStreamedBucket(QueryExpressionInfo expressionInfo, IGroupByExecutionHelper executionHelper, int columnCount, int[] usedVars) : base(expressionInfo, executionHelper, columnCount, usedVars) { this.groupJobs = new GroupJob[this.executionHelper.ThreadCount]; // Create an initial job, comparers and hashers this.CreateHashersAndComparers(out ExpressionComparer[] comparers, out ExpressionHasher[] hashers); var firstComp = RowEqualityComparerGroupKey.Factory(null, comparers, true); var firstHasher = new RowHasher(hashers); firstHasher.SetCache(firstComp.comparers); this.groupJobs[0] = new GroupJob(firstComp, firstHasher, new TableResults(this.ColumnCount, this.executionHelper.FixedArraySize, this.usedVars)); for (int i = 1; i < this.executionHelper.ThreadCount; i++) { CloneHasherAndComparer(firstComp, firstHasher, out RowEqualityComparerGroupKey newComp, out RowHasher newHasher); groupJobs[i] = new GroupJob(newComp, newHasher, new TableResults(this.ColumnCount, this.executionHelper.FixedArraySize, this.usedVars)); } this.globalGroups = new ConcurrentDictionary <GroupDictKeyFull, AggregateBucketResult[]>(RowEqualityComparerGroupDickKeyFull.Factory(comparers, false)); }
public LocalGroupByLocalTwoWayMergeBucket(Aggregate[] aggs, ExpressionHolder[] hashes, IGroupByExecutionHelper helper, bool useBucketStorage) : base(aggs, hashes, helper, useBucketStorage) { }
public GroupByWithLists(Aggregate[] aggs, ExpressionHolder[] hashes, IGroupByExecutionHelper helper) : base(aggs, hashes, helper, false) { }
public TwoStepGroupBy(Aggregate[] aggs, ExpressionHolder[] hashes, IGroupByExecutionHelper helper, bool useBucketStorage) : base(aggs, hashes, helper, useBucketStorage) { }
public SingleGroupGroupBy(Aggregate[] aggs, ExpressionHolder[] hashes, IGroupByExecutionHelper helper) : base(aggs, hashes, helper, false) { }
/// <summary> /// A factory method. /// Creates an appropriate group by solution based on the provided alias. /// </summary> public static Grouper Factory(GrouperAlias grouperAlias, Aggregate[] aggs, ExpressionHolder[] hashes, IGroupByExecutionHelper helper) { if (grouperAlias == GrouperAlias.RefB) { return(new GroupByWithBuckets(aggs, hashes, helper)); } else if (grouperAlias == GrouperAlias.RefL) { return(new GroupByWithLists(aggs, hashes, helper)); } else if (grouperAlias == GrouperAlias.GlobalB) { return(new GlobalGroupByBucket(aggs, hashes, helper, true)); } else if (grouperAlias == GrouperAlias.GlobalL) { return(new GlobalGroupByArray(aggs, hashes, helper, false)); } else if (grouperAlias == GrouperAlias.LocalB) { return(new LocalGroupByLocalTwoWayMergeBucket(aggs, hashes, helper, true)); } else if (grouperAlias == GrouperAlias.LocalL) { return(new LocalGroupByLocalTwoWayMergeList(aggs, hashes, helper, false)); } else if (grouperAlias == GrouperAlias.TwoStepB) { return(new TwoStepGroupByBucket(aggs, hashes, helper, true)); } else if (grouperAlias == GrouperAlias.TwoStepL) { return(new TwoStepGroupByListBucket(aggs, hashes, helper, false)); } else { throw new ArgumentException("Grouper, trying to create an unknown grouper."); } }
public GroupByWithBuckets(Aggregate[] aggs, ExpressionHolder[] hashes, IGroupByExecutionHelper helper) : base(aggs, hashes, helper, true) { }
/// <summary> /// A factory method. /// Creates an appropriate group by solution based on the alias inside the provided helper. /// </summary> public static Grouper Factory(Aggregate[] aggs, ExpressionHolder[] hashes, IGroupByExecutionHelper helper) { return(Factory(helper.GrouperAlias, aggs, hashes, helper)); }