Esempio n. 1
0
        private OrderByContext CreateOrderByContextForDistinctRowWithoutGroupBy(SelectCommand selectCommand, GroupByContext groupByContext)
        {
            if (!groupByContext.GetItems().Any() && selectCommand.Projections.IsDistinctRow())
            {
                int index = 0;
                ICollection <OrderByItem> orderByItems = new LinkedList <OrderByItem>();
                foreach (var projectionSegment in selectCommand.Projections.GetProjections())
                {
                    if (projectionSegment is ColumnProjectionSegment columnProjectionSegment)
                    {
                        var         columnOrderByItemSegment = new ColumnOrderByItemSegment(columnProjectionSegment.GetColumn(), OrderDirectionEnum.ASC);
                        OrderByItem item = new OrderByItem(columnOrderByItemSegment);
                        item.SetIndex(index);
                        orderByItems.Add(item);
                        index++;
                    }
                }

                if (orderByItems.Any())
                {
                    return(new OrderByContext(orderByItems, true));
                }
            }

            return(null);
        }
        private bool IsSameProjection(ShorthandProjection shorthandProjection, ColumnOrderByItemSegment orderItem, SelectCommand selectCommand)
        {
            if (shorthandProjection.GetOwner() == null)
            {
                throw new ShardingException("shorthandProjection can not found owner");
            }
            SimpleTableSegment tableSegment = Find(shorthandProjection.GetOwner(), selectCommand);

            return(_schemaMetaData.ContainsColumn(tableSegment.GetTableName().GetIdentifier().GetValue(), orderItem.GetColumn().GetIdentifier().GetValue()));
        }