public ResultSetSpec( SelectClauseStreamSelectorEnum selectClauseStreamSelector, IList<OrderByItem> orderByList, SelectClauseSpecCompiled selectClauseSpec, InsertIntoDesc insertIntoDesc, GroupByClauseExpressions groupByClauseExpressions, ExprNode whereClause, ExprNode havingClause, OutputLimitSpec optionalOutputLimitSpec, RowLimitSpec rowLimitSpec, string contextName, ForClauseSpec forClauseSpec, IntoTableSpec intoTableSpec, StreamSpecCompiled[] streamSpecs, Attribute[] annotations) { this.SelectClauseStreamSelector = selectClauseStreamSelector; this.OrderByList = orderByList; this.SelectClauseSpec = selectClauseSpec; this.InsertIntoDesc = insertIntoDesc; this.GroupByClauseExpressions = groupByClauseExpressions; this.WhereClause = whereClause; this.HavingClause = havingClause; this.OptionalOutputLimitSpec = optionalOutputLimitSpec; this.RowLimitSpec = rowLimitSpec; this.ContextName = contextName; this.ForClauseSpec = forClauseSpec; this.IntoTableSpec = intoTableSpec; this.StreamSpecs = streamSpecs; this.Annotations = annotations; }
/// <summary> /// Returns processor for order-by clauses. /// </summary> /// <param name="selectionList">is a list of select expressions</param> /// <param name="groupByNodes">is a list of group-by expressions</param> /// <param name="orderByList">is a list of order-by expressions</param> /// <param name="rowLimitSpec">specification for row limit, or null if no row limit is defined</param> /// <param name="variableService">for retrieving variable state for use with row limiting</param> /// <param name="isSortUsingCollator">for string value sorting using compare or Collator</param> /// <param name="optionalContextName">Name of the optional context.</param> /// <returns>ordering processor instance</returns> /// <throws><seealso cref="ExprValidationException" /> when validation of expressions fails</throws> public static OrderByProcessorFactory GetProcessor( IList <SelectClauseExprCompiledSpec> selectionList, ExprNode[] groupByNodes, IList <OrderByItem> orderByList, RowLimitSpec rowLimitSpec, VariableService variableService, bool isSortUsingCollator, String optionalContextName) { // Get the order by expression nodes IList <ExprNode> orderByNodes = orderByList.Select(element => element.ExprNode).ToList(); // No order-by clause if (orderByList.IsEmpty()) { Log.Debug(".getProcessor Using no _orderByProcessor"); if (rowLimitSpec != null) { var rowLimitProcessorFactory = new RowLimitProcessorFactory(rowLimitSpec, variableService, optionalContextName); return(new OrderByProcessorRowLimitOnlyFactory(rowLimitProcessorFactory)); } return(null); } // Determine aggregate functions used in select, if any IList <ExprAggregateNode> selectAggNodes = new List <ExprAggregateNode>(); foreach (var element in selectionList) { ExprAggregateNodeUtil.GetAggregatesBottomUp(element.SelectExpression, selectAggNodes); } // Get all the aggregate functions occuring in the order-by clause IList <ExprAggregateNode> orderAggNodes = new List <ExprAggregateNode>(); foreach (var orderByNode in orderByNodes) { ExprAggregateNodeUtil.GetAggregatesBottomUp(orderByNode, orderAggNodes); } ValidateOrderByAggregates(selectAggNodes, orderAggNodes); // Tell the order-by processor whether to compute group-by // keys if they are not present var needsGroupByKeys = !selectionList.IsEmpty() && !orderAggNodes.IsEmpty(); Log.Debug(".getProcessor Using OrderByProcessorImpl"); var orderByProcessorFactory = new OrderByProcessorFactoryImpl(orderByList, groupByNodes, needsGroupByKeys, isSortUsingCollator); if (rowLimitSpec == null) { return(orderByProcessorFactory); } else { var rowLimitProcessorFactory = new RowLimitProcessorFactory(rowLimitSpec, variableService, optionalContextName); return(new OrderByProcessorOrderedLimitFactory(orderByProcessorFactory, rowLimitProcessorFactory)); } }
/// <summary> /// Ctor. /// </summary> /// <param name="rowLimitSpec">specification for row limit, or null if no row limit is defined</param> /// <param name="variableCompileTimeResolver">for retrieving variable state for use with row limiting</param> /// <param name="optionalContextName">context name</param> /// <throws>ExprValidationException exception</throws> public RowLimitProcessorFactoryForge( RowLimitSpec rowLimitSpec, VariableCompileTimeResolver variableCompileTimeResolver, string optionalContextName) { if (rowLimitSpec.NumRowsVariable != null) { numRowsVariableMetaData = variableCompileTimeResolver.Resolve(rowLimitSpec.NumRowsVariable); if (numRowsVariableMetaData == null) { throw new ExprValidationException( "Limit clause variable by name '" + rowLimitSpec.NumRowsVariable + "' has not been declared"); } string message = VariableUtil.CheckVariableContextName(optionalContextName, numRowsVariableMetaData); if (message != null) { throw new ExprValidationException(message); } if (!TypeHelper.IsNumeric(numRowsVariableMetaData.Type)) { throw new ExprValidationException("Limit clause requires a variable of numeric type"); } } else { numRowsVariableMetaData = null; currentRowLimit = rowLimitSpec.NumRows.GetValueOrDefault(Int32.MaxValue); if (currentRowLimit < 0) { currentRowLimit = Int32.MaxValue; } } if (rowLimitSpec.OptionalOffsetVariable != null) { offsetVariableMetaData = variableCompileTimeResolver.Resolve(rowLimitSpec.OptionalOffsetVariable); if (offsetVariableMetaData == null) { throw new ExprValidationException( "Limit clause variable by name '" + rowLimitSpec.OptionalOffsetVariable + "' has not been declared"); } string message = VariableUtil.CheckVariableContextName(optionalContextName, offsetVariableMetaData); if (message != null) { throw new ExprValidationException(message); } if (!TypeHelper.IsNumeric(offsetVariableMetaData.Type)) { throw new ExprValidationException("Limit clause requires a variable of numeric type"); } } else { offsetVariableMetaData = null; if (rowLimitSpec.OptionalOffset != null) { if (rowLimitSpec.OptionalOffset.Value <= 0) { throw new ExprValidationException("Limit clause requires a positive offset"); } currentOffset = rowLimitSpec.OptionalOffset.Value; } else { currentOffset = 0; } } }
/// <summary> /// Ctor. /// </summary> /// <param name="rowLimitSpec">specification for row limit, or null if no row limit is defined</param> /// <param name="variableService">for retrieving variable state for use with row limiting</param> /// <param name="optionalContextName">Name of the optional context.</param> /// <exception cref="ExprValidationException"> /// Limit clause variable by name '" + rowLimitSpec.NumRowsVariable + "' has not been declared /// or /// or /// Limit clause requires a variable of numeric type /// or /// Limit clause variable by name '" + rowLimitSpec.OptionalOffsetVariable + "' has not been declared /// or /// or /// Limit clause requires a variable of numeric type /// or /// Limit clause requires a positive offset /// </exception> /// <throws>com.espertech.esper.epl.expression.core.ExprValidationException if row limit specification validation fails</throws> public RowLimitProcessorFactory(RowLimitSpec rowLimitSpec, VariableService variableService, string optionalContextName) { if (rowLimitSpec.NumRowsVariable != null) { _numRowsVariableMetaData = variableService.GetVariableMetaData(rowLimitSpec.NumRowsVariable); if (_numRowsVariableMetaData == null) { throw new ExprValidationException("Limit clause variable by name '" + rowLimitSpec.NumRowsVariable + "' has not been declared"); } string message = VariableServiceUtil.CheckVariableContextName(optionalContextName, _numRowsVariableMetaData); if (message != null) { throw new ExprValidationException(message); } if (!TypeHelper.IsNumeric(_numRowsVariableMetaData.VariableType)) { throw new ExprValidationException("Limit clause requires a variable of numeric type"); } } else { _numRowsVariableMetaData = null; _currentRowLimit = rowLimitSpec.NumRows.GetValueOrDefault(); if (_currentRowLimit < 0) { _currentRowLimit = int.MaxValue; } } if (rowLimitSpec.OptionalOffsetVariable != null) { _offsetVariableMetaData = variableService.GetVariableMetaData(rowLimitSpec.OptionalOffsetVariable); if (_offsetVariableMetaData == null) { throw new ExprValidationException("Limit clause variable by name '" + rowLimitSpec.OptionalOffsetVariable + "' has not been declared"); } string message = VariableServiceUtil.CheckVariableContextName(optionalContextName, _offsetVariableMetaData); if (message != null) { throw new ExprValidationException(message); } if (!TypeHelper.IsNumeric(_offsetVariableMetaData.VariableType)) { throw new ExprValidationException("Limit clause requires a variable of numeric type"); } } else { _offsetVariableMetaData = null; if (rowLimitSpec.OptionalOffset != null) { _currentOffset = rowLimitSpec.OptionalOffset.GetValueOrDefault(); if (_currentOffset <= 0) { throw new ExprValidationException("Limit clause requires a positive offset"); } } else { _currentOffset = 0; } } }
public static OrderByProcessorFactoryForge GetProcessor( IList<SelectClauseExprCompiledSpec> selectionList, IList<OrderByItem> orderByList, RowLimitSpec rowLimitSpec, VariableCompileTimeResolver variableCompileTimeResolver, bool isSortUsingCollator, string optionalContextName, OrderByElementForge[][] orderByRollup) { // Get the order by expression nodes IList<ExprNode> orderByNodes = new List<ExprNode>(); foreach (var element in orderByList) { orderByNodes.Add(element.ExprNode); } // No order-by clause if (orderByList.IsEmpty()) { Log.Debug(".getProcessor Using no OrderByProcessor"); if (rowLimitSpec != null) { var rowLimitProcessorFactory = new RowLimitProcessorFactoryForge( rowLimitSpec, variableCompileTimeResolver, optionalContextName); return new OrderByProcessorRowLimitOnlyForge(rowLimitProcessorFactory); } return null; } // Determine aggregate functions used in select, if any IList<ExprAggregateNode> selectAggNodes = new List<ExprAggregateNode>(); foreach (var element in selectionList) { ExprAggregateNodeUtil.GetAggregatesBottomUp(element.SelectExpression, selectAggNodes); } // Get all the aggregate functions occuring in the order-by clause IList<ExprAggregateNode> orderAggNodes = new List<ExprAggregateNode>(); foreach (var orderByNode in orderByNodes) { ExprAggregateNodeUtil.GetAggregatesBottomUp(orderByNode, orderAggNodes); } ValidateOrderByAggregates(selectAggNodes, orderAggNodes); // Tell the order-by processor whether to compute group-by // keys if they are not present var needsGroupByKeys = !selectionList.IsEmpty() && !orderAggNodes.IsEmpty(); Log.Debug(".getProcessor Using OrderByProcessorImpl"); var elements = ToElementArray(orderByList); var comparator = GetComparator(elements, isSortUsingCollator); var orderByProcessorForge = new OrderByProcessorForgeImpl( elements, needsGroupByKeys, orderByRollup, comparator); if (rowLimitSpec == null) { return orderByProcessorForge; } { var rowLimitProcessorFactory = new RowLimitProcessorFactoryForge( rowLimitSpec, variableCompileTimeResolver, optionalContextName); return new OrderByProcessorOrderedLimitForge(orderByProcessorForge, rowLimitProcessorFactory); } }