public AccessingOperationExpression Offset(IdExpression idExpression) { IExpression booleanExpression; IExpression constantExpression; IExpression arithmeticOperationExpression1; IExpression arithmeticOperationExpression2; IExpression loc; TypeToken typeToken = idExpression.TypeToken; MatchThenLookAhead('['); booleanExpression = Boolean(); MatchThenLookAhead(']'); typeToken = ((ArrayTypeToken)typeToken).OfTypeToken; constantExpression = new ConstantExpression(typeToken.Width, _emitterNode); arithmeticOperationExpression1 = new ArithmeticOperationExpression(new Token('*'), booleanExpression, constantExpression, _emitterNode); loc = arithmeticOperationExpression1; while (LookAheadToken?.Tag == '[') { MatchThenLookAhead('['); booleanExpression = Boolean(); MatchThenLookAhead(']'); typeToken = ((ArrayTypeToken)typeToken).OfTypeToken; constantExpression = new ConstantExpression(typeToken.Width, _emitterNode); arithmeticOperationExpression1 = new ArithmeticOperationExpression(new Token('*'), booleanExpression, constantExpression, _emitterNode); arithmeticOperationExpression2 = new ArithmeticOperationExpression(new Token('+'), loc, arithmeticOperationExpression1, _emitterNode); loc = arithmeticOperationExpression2; } return(new AccessingOperationExpression(idExpression, loc, typeToken, _emitterNode)); }
public static RenderedProjectionDefinition <TResult> TranslateGroup <TKey, TDocument, TResult>(Expression <Func <TDocument, TKey> > idProjector, Expression <Func <IGrouping <TKey, TDocument>, TResult> > groupProjector, IBsonSerializer <TDocument> parameterSerializer, IBsonSerializerRegistry serializerRegistry) { var keyBinder = new SerializationInfoBinder(serializerRegistry); var boundKeyExpression = BindSerializationInfo(keyBinder, idProjector, parameterSerializer); if (!(boundKeyExpression is ISerializationExpression)) { var keySerializer = SerializerBuilder.Build(boundKeyExpression, serializerRegistry); boundKeyExpression = new SerializationExpression( boundKeyExpression, new BsonSerializationInfo(null, keySerializer, typeof(TKey))); } var idExpression = new IdExpression(boundKeyExpression, ((ISerializationExpression)boundKeyExpression).SerializationInfo); var groupBinder = new GroupSerializationInfoBinder(BsonSerializer.SerializerRegistry); groupBinder.RegisterMemberReplacement(typeof(IGrouping <TKey, TDocument>).GetProperty("Key"), idExpression); var groupSerializer = new ArraySerializer <TDocument>(parameterSerializer); var boundGroupExpression = BindSerializationInfo(groupBinder, groupProjector, groupSerializer); var projectionSerializer = (IBsonSerializer <TResult>)SerializerBuilder.Build(boundGroupExpression, serializerRegistry); var projection = ProjectionBuilder.Build(boundGroupExpression).AsBsonDocument; // must have an "_id" in a group document if (!projection.Contains("_id")) { var idProjection = ProjectionBuilder.Build(boundKeyExpression); projection.InsertAt(0, new BsonElement("_id", idProjection)); } return(new RenderedProjectionDefinition <TResult>(projection, projectionSerializer)); }
public int VisitIdExpression(IdExpression ast, Frame frame) { int valSize = ast.Type.Visit(this, null); EncodeFetch(ast.Identifier, frame, valSize); return(valSize); }
public T2 Assign() { T2 statement = default; Token token = LookAheadToken; MatchThenLookAhead(TokenTag.ID); IdExpression idExpression = TopSymbol.Get(token); if (idExpression is null) { Error($"{token} undeclared"); } if (LookAheadToken?.Tag == '=') { LookAhead(); statement = (T2)Activator.CreateInstance(typeof(SetStatement), new object[] { idExpression, Boolean(), _emitterNode }); } else { AccessingOperationExpression accessingOperationExpression = Offset(idExpression); MatchThenLookAhead('='); statement = (T2)Activator.CreateInstance(typeof(SetElementStatement), new object[] { accessingOperationExpression, Boolean(), _emitterNode }); } MatchThenLookAhead(';'); return(statement); }
public SetStatement(IdExpression idExpression, IExpression expression, Node node) : base(node) { _idExpression = idExpression; _expression = expression; if (Check(_idExpression.TypeToken, expression.TypeToken) == null) { _node.Error("Type Error"); } }
public SetElementStatement(AccessingOperationExpression accessingOperationExpression, Expression expression, Node node) : base(node) { _arrayExpression = accessingOperationExpression.ArrayExpression; _indexExpression = accessingOperationExpression.IndexExpression; _expression = expression; if (Check(accessingOperationExpression.TypeToken, _expression.TypeToken) == null) { _node.Error("Type Error"); } }
public AbstractImport(TContext context) { Context = context; _compiledIdExpression = IdExpression.Compile(); if (CanUpdate) { _idProperty = CreateIdProperty(); Properties.Add(_idProperty); } }
public void GetAndEvaluateIdExpression() { IdExpression expression = IdExpression.Instance; Assert.IsNotNull(expression); Machine machine = new Machine(); machine.Push(1); expression.Evaluate(machine); Assert.AreEqual(1, machine.StackCount); Assert.AreEqual(1, machine.Pop()); }
public static ProjectionInfo <TResult> TranslateGroup <TKey, TDocument, TResult>(Expression <Func <TDocument, TKey> > idProjector, Expression <Func <IGrouping <TKey, TDocument>, TResult> > groupProjector, IBsonSerializer <TDocument> parameterSerializer, IBsonSerializerRegistry serializerRegistry) { if (groupProjector.Body.NodeType != ExpressionType.New) { throw new NotSupportedException("Must use an anonymous type for constructing $group pipeline operators."); } var keyBinder = new SerializationInfoBinder(serializerRegistry); var boundKeyExpression = BindSerializationInfo(keyBinder, idProjector, parameterSerializer); if (!(boundKeyExpression is ISerializationExpression)) { var keySerializer = SerializerBuilder.Build(boundKeyExpression, serializerRegistry); boundKeyExpression = new SerializationExpression( boundKeyExpression, new BsonSerializationInfo(null, keySerializer, typeof(TKey))); } var idExpression = new IdExpression(boundKeyExpression, ((ISerializationExpression)boundKeyExpression).SerializationInfo); var groupBinder = new GroupSerializationInfoBinder(BsonSerializer.SerializerRegistry); groupBinder.RegisterMemberReplacement(typeof(IGrouping <TKey, TDocument>).GetProperty("Key"), idExpression); var groupSerializer = new ArraySerializer <TDocument>(parameterSerializer); var boundGroupExpression = BindSerializationInfo(groupBinder, groupProjector, groupSerializer); var projectionSerializer = (IBsonSerializer <TResult>)SerializerBuilder.Build(boundGroupExpression, serializerRegistry); var projection = ProjectionBuilder.Build(boundGroupExpression).AsBsonDocument; // must have an "_id" in a group document if (!projection.Contains("_id")) { var idProjection = ProjectionBuilder.Build(boundKeyExpression); projection.InsertAt(0, new BsonElement("_id", idProjection)); } return(new ProjectionInfo <TResult>(projection, projectionSerializer)); }
public TypeDenoter VisitIdExpression(IdExpression ast, Void arg) { ast.Identifier.Visit(this, null); ast.Type = ast.Identifier.Declaration.Type; return(ast.Type); }
/// <summary> /// Generates SqlTable and sub query for an aggregation. /// </summary> /// <param name="structuredQuery">The structured query.</param> /// <param name="entity">The AggregateEntity that represents the aggregation in the 'from' tree.</param> /// <param name="parentTable">The table that this aggregation joins up to. Can be null if the aggregation is being performed at the top level.</param> /// <param name="sqlQuery">The query object.</param> /// <returns> /// The table /// </returns> private EntityTables RegisterAggregateEntity(StructuredQuery structuredQuery, AggregateEntity entity, SqlTable parentTable, SqlQuery sqlQuery) { if (entity.GroupedEntity == null) { throw new Exception("Aggregate entity must have GroupedEntity set."); } if (entity.RelatedEntities.Count > 0) { throw new Exception("Aggregate entity should not have related entities."); // note: no logical reason not to, however it's likely indicative of a bug elsewhere } // Establish sub query // Note that sub query has its distinct reference manager for tracking tables and other elements. SqlQuery subquery = sqlQuery.CreateSubQuery( ); subquery.ParentQuery = sqlQuery; sqlQuery.Subqueries.Add(subquery); // Get joining table for the entity being grouped EntityTables childTables = BuildEntityTableJoinTree(structuredQuery, entity.GroupedEntity, parentTable, subquery); //hmm SqlTable childTable = childTables.HeadTable; subquery.FromClause.RootTable = childTable; // Note: we passed in parentTable above so that the child can learn about the joining column // However, it will actually try to join to the table when we don't want it to, so need to manually unlink it afterwards. childTable.Parent = null; if (parentTable != null) { parentTable.Children.Remove(childTable); } // Create the proxy table // Note: parentTable may be null for root aggregate SqlTable proxyTable = sqlQuery.CreateJoinedTable("", // not applicable "ag", parentTable, JoinHint.Unspecified, childTable.JoinColumn, parentTable?.IdColumn); //if the used condition under current aggregate grouped entity or related entities, set joinhint to requried if (structuredQuery.Conditions.Any(c => c.Operator != ConditionType.Unspecified && c.Operator != ConditionType.IsNull && ConditionContainArgument(c) && c.Expression is ResourceDataColumn && MatchGroupedEntityNode(((ResourceDataColumn)c.Expression).NodeId, entity.GroupedEntity) )) { proxyTable.JoinHint = JoinHint.Required; } //TODO, this hacky code is resolved a special sql query issue (bug 24406), both Pete and me agree with this is not the best solution, but can fix current bug //TODO, we can remove this hacky code when report builder allows set the aggregated field in analyzer. ConvertConditionExpressionToAggregate(structuredQuery.Conditions, entity); proxyTable.SubQuery = new SqlUnion(subquery); subquery.ProxyTable = proxyTable; // Proxy the join column through the sub query select statement // (If it actually joins to something) if (childTable.JoinColumn != null) { string joinColumnAlias = sqlQuery.AliasManager.CreateAlias("aggCol"); string joinColumnSql = GetColumnSql(childTable, childTable.JoinColumn); var joinColumn = new SqlSelectItem { Expression = new SqlExpression { Sql = joinColumnSql }, Alias = joinColumnAlias }; subquery.SelectClause.Items.Add(joinColumn); subquery.GroupByClause.Expressions.Add(joinColumn.Expression); proxyTable.JoinColumn = joinColumnAlias; var idExpr = new IdExpression { NodeId = entity.GroupedEntity.NodeId }; sqlQuery.References.RegisterMappedExpression(idExpr, joinColumn.Expression); } // Add additional grouping columns if (entity.GroupBy != null && entity.GroupBy.Count > 0) { proxyTable.GroupByMap = new Dictionary <ScalarExpression, SqlExpression>(); foreach (ScalarExpression expr in entity.GroupBy) { try { SqlExpression sqlExpr; if (TryConvertExpression(expr, subquery, false, out sqlExpr)) { if (!_querySettings.FullAggregateClustering) { // If we're not clustering everywhere, then explicitly cluster in summarize group-bys still. sqlExpr = ApplyClusterOperation(sqlExpr, expr.ClusterOperation, sqlQuery); } proxyTable.GroupByMap[expr] = sqlExpr; var mappedSqlExpr = CreateAggregateMappingExpression(sqlQuery, proxyTable, sqlExpr); sqlQuery.References.RegisterMappedExpression(expr, mappedSqlExpr); if (sqlExpr.OrderingSqlCallback != null && sqlExpr.OrderingSqlRequiresGrouping) { mappedSqlExpr.OrderingSqlCallback = exprTmp => CreateAggregateOrderbyMappingExpression(sqlQuery, proxyTable, sqlExpr.OrderingSql).Sql; } } } catch { } } } // Return proxy table return(new EntityTables(proxyTable)); }