Ejemplo n.º 1
0
        internal static GroupByStage CreateStaticGroupBy(
            Type inputType,
            SqlTypeInfo previousStageTypeInfo,
            ParameterExpression previousStageParameterExpression,
            FromAliases fromAliases)
        {
            var tupleType    = GetTupleType(typeof(int));
            var groupingType = GetGroupingType(tupleType, inputType);

            //There is no group by, so there is no key or possibility to select anything else than aggregations
            var keyTypeInfo = SqlTypeInfo.NewBuilder().Build();

            var groupParameter = Expression.Parameter(groupingType);

            var keyParameterExpression = GetKeyParameterExpression(groupingType, groupParameter);

            var constructor       = tupleType.GetConstructor(new[] { typeof(int) });
            var groupByExpression = Expression.New(constructor, new[] { Expression.Constant(1) });

            return(new GroupByStage(
                       groupingType,
                       inputType,
                       previousStageTypeInfo,
                       keyTypeInfo,
                       groupParameter,
                       keyParameterExpression,
                       previousStageParameterExpression,
                       groupByExpression,
                       tupleType,
                       fromAliases
                       ));
        }
Ejemplo n.º 2
0
 public DistinctStage(
     SqlTypeInfo sqlTypeInfo,
     ParameterExpression parameterExpression,
     Type type,
     FromAliases fromAliases
     )
 {
     TypeInfo            = sqlTypeInfo;
     ParameterExpression = parameterExpression;
     CurrentType         = type;
     FromAliases         = fromAliases;
 }
Ejemplo n.º 3
0
 public OrderByStage(
     Type currentType,
     SqlTypeInfo typeInfo,
     ParameterExpression parameterExpression,
     FromAliases fromAliases,
     IImmutableList <SortItem> sortItems)
 {
     CurrentType         = currentType;
     TypeInfo            = typeInfo;
     ParameterExpression = parameterExpression;
     FromAliases         = fromAliases;
     SortItems           = sortItems;
 }
Ejemplo n.º 4
0
 public WhereStage(
     SqlTypeInfo sqlTypeInfo,
     ParameterExpression parameterExpression,
     Expression whereExpression,
     Type type,
     FromAliases fromAliases,
     bool containsFullTextSearch
     )
 {
     TypeInfo               = sqlTypeInfo;
     ParameterExpression    = parameterExpression;
     WhereExpression        = whereExpression;
     CurrentType            = type;
     FromAliases            = fromAliases;
     ContainsFullTextSearch = containsFullTextSearch;
 }
Ejemplo n.º 5
0
 public OffsetStage(
     SqlTypeInfo sqlTypeInfo,
     ParameterExpression parameterExpression,
     Type type,
     FromAliases fromAliases,
     int?skip,
     int?take
     )
 {
     TypeInfo            = sqlTypeInfo;
     ParameterExpression = parameterExpression;
     CurrentType         = type;
     FromAliases         = fromAliases;
     Skip = skip;
     Take = take;
 }
Ejemplo n.º 6
0
 public SelectStage(
     SqlTypeInfo sqlTypeInfo,
     ParameterExpression parameterExpression,
     MemberInitExpression selectExpression,
     Type newType,
     Type oldType,
     ParameterExpression inParameterExpression,
     FromAliases fromAliases,
     IImmutableList <ColumnMetadata> columns)
 {
     TypeInfo              = sqlTypeInfo;
     ParameterExpression   = parameterExpression;
     SelectExpression      = selectExpression;
     CurrentType           = newType;
     OldType               = oldType;
     InParameterExpression = inParameterExpression;
     FromAliases           = fromAliases;
     Columns               = columns;
 }
Ejemplo n.º 7
0
 public HavingStage(
     Type currentType,
     Type valueType,
     SqlTypeInfo mainTypeInfo,
     SqlTypeInfo keyTypeInfo,
     ParameterExpression groupParameterExpression,
     Expression keyParameterExpression,
     ParameterExpression valueParameterExpression,
     FromAliases fromAliases,
     Expression filterExpression)
 {
     CurrentType              = currentType;
     ValueType                = valueType;
     TypeInfo                 = mainTypeInfo;
     KeyTypeInfo              = keyTypeInfo;
     ParameterExpression      = groupParameterExpression;
     KeyParameterExpression   = keyParameterExpression;
     ValueParameterExpression = valueParameterExpression;
     FromAliases              = fromAliases;
     FilterExpression         = filterExpression;
 }
Ejemplo n.º 8
0
 public GroupedOrderByStage(
     Type currentType,
     Type valueType,
     SqlTypeInfo mainTypeInfo,
     SqlTypeInfo keyTypeInfo,
     ParameterExpression groupParameterExpression,
     Expression keyParameterExpression,
     ParameterExpression valueParameterExpression,
     FromAliases fromAliases,
     IImmutableList <SortItem> sortItems)
 {
     CurrentType              = currentType;
     ValueType                = valueType;
     TypeInfo                 = mainTypeInfo;
     KeyTypeInfo              = keyTypeInfo;
     ParameterExpression      = groupParameterExpression;
     KeyParameterExpression   = keyParameterExpression;
     ValueParameterExpression = valueParameterExpression;
     FromAliases              = fromAliases;
     SortItems                = sortItems;
 }
Ejemplo n.º 9
0
        public override void VisitFromClause(FromClause fromClause)
        {
            var tableReference = fromClause.TableReference;

            if (tableReference is FromTableReference namedTableReference)
            {
                var tableName = namedTableReference.TableName;
                Debug.Assert(tableName != null);

                if (!_visitorMetadata.TablesMetadata.TryGetTable(tableName, out _table))
                {
                    throw new SqlErrorException($"The table '{tableName}' was not found");
                }
                //Add the table name to the aliases as well, to support using the tablename infront of columns
                FromAliases.AddAlias(tableName);

                var alias = namedTableReference?.Alias;
                if (alias != null)
                {
                    FromAliases.AddAlias(alias);
                }
            }
            else if (tableReference is Subquery queryDerivedTable)
            {
                MainVisitor mainVisitor = new MainVisitor(_visitorMetadata);
                queryDerivedTable.Accept(mainVisitor);
                Stages = mainVisitor.Stages;

                var alias = queryDerivedTable?.Alias;
                if (alias != null)
                {
                    FromAliases.AddAlias(alias);
                }
            }
            else
            {
                throw new SqlErrorException("Subqueries or joins are not supported at this time");
            }
        }
Ejemplo n.º 10
0
        public FromTableStage(
            string tableName,
            SqlTypeInfo sqlTypeInfo,
            ParameterExpression parameterExpression,
            Type currentType,
            FromAliases fromAliases,
            IReadSqlParameters parameters)
        {
            Debug.Assert(tableName != null, $"{nameof(tableName)} was null");
            Debug.Assert(sqlTypeInfo != null, $"{nameof(sqlTypeInfo)} was null");
            Debug.Assert(parameterExpression != null, $"{nameof(parameterExpression)} was null");
            Debug.Assert(currentType != null, $"{nameof(currentType)} was null");
            Debug.Assert(fromAliases != null, $"{nameof(fromAliases)} was null");
            Debug.Assert(parameters != null, $"{nameof(parameters)} was null");

            TableName           = tableName;
            TypeInfo            = sqlTypeInfo;
            ParameterExpression = parameterExpression;
            CurrentType         = currentType;
            FromAliases         = fromAliases;
            Parameters          = parameters;
        }
Ejemplo n.º 11
0
 public GroupByStage(
     Type currentType,
     Type valueType,
     SqlTypeInfo mainTypeInfo,
     SqlTypeInfo keyTypeInfo,
     ParameterExpression groupParameterExpression,
     Expression keyParameterExpression,
     ParameterExpression valueParameterExpression,
     Expression groupByExpression,
     Type keyType,
     FromAliases fromAliases)
 {
     CurrentType              = currentType;
     ValueType                = valueType;
     TypeInfo                 = mainTypeInfo;
     KeyTypeInfo              = keyTypeInfo;
     ParameterExpression      = groupParameterExpression;
     KeyParameterExpression   = keyParameterExpression;
     ValueParameterExpression = valueParameterExpression;
     GroupByExpression        = groupByExpression;
     KeyType     = keyType;
     FromAliases = fromAliases;
 }
Ejemplo n.º 12
0
 public SelectAggregateFunctionStage(
     SqlTypeInfo sqlTypeInfo,
     ParameterExpression parameterExpression,
     Type currentType,
     Type oldType,
     FromAliases fromAliases,
     string functionName,
     ParameterExpression inParameter,
     string columnName,
     IImmutableList <Expression> parameters,
     Type functionOutType
     )
 {
     TypeInfo            = sqlTypeInfo;
     ParameterExpression = parameterExpression;
     CurrentType         = currentType;
     FromAliases         = fromAliases;
     FunctionName        = functionName;
     InParameter         = inParameter;
     OldType             = oldType;
     ColumnName          = columnName;
     Parameters          = parameters;
     FunctionOutType     = functionOutType;
 }