public ExpressionNode CompileExpression(string expressionText, Type targetType, Scope scope) { // Parse the expression. Parser parser = new Parser(_errorReporter); ExpressionNode expressionNode = parser.ParseExpression(expressionText); // When the parser detected errors or could not even construct an AST it // does not make any sense to go ahead. if (_errorReporter.ErrorsSeen || expressionNode == null) { return(null); } PhaseRunner phaseRunner = new PhaseRunner(_errorReporter, expressionNode); phaseRunner.Phases.Add(PHASE_NORMALIZATION, new Normalizer()); phaseRunner.Phases.Add(PHASE_RESOLUTION, new Resolver(_errorReporter, scope)); phaseRunner.Phases.Add(PHASE_CONSTANT_FOLDING, new ConstantFolder(_errorReporter)); phaseRunner.Phases.Add(PHASE_VALIDATION, new Validator(_errorReporter, scope.DataContext.MetadataContext)); phaseRunner.Phases.Add(PHASE_CONVERSION_TO_TARGET_TYPE, delegate(AstNode input) { if (input == null || _errorReporter.ErrorsSeen) { return(null); } ExpressionNode expr = (ExpressionNode)input; Binder binder = new Binder(_errorReporter); return(binder.ConvertExpressionIfRequired(expr, targetType)); }); return((ExpressionNode)phaseRunner.Run()); }
public ResultAlgebraNode CompileQuery(string queryText, Scope scope) { // Algebraization Parser parser = new Parser(_errorReporter); QueryNode parsedQuery = parser.ParseQuery(queryText); // When the parser detected errors or could not even construct an AST it // does not make any sense to go ahead. if (_errorReporter.ErrorsSeen || parsedQuery == null) { return(null); } PhaseRunner phaseRunner = new PhaseRunner(_errorReporter, parsedQuery); phaseRunner.Phases.Add(PHASE_NORMALIZATION, new Normalizer()); phaseRunner.Phases.Add(PHASE_RESOLUTION, new Resolver(_errorReporter, scope)); phaseRunner.Phases.Add(PHASE_AGGREGATE_BINDING, new AggregateBinder(_errorReporter)); phaseRunner.Phases.Add(PHASE_VALIDATION, new Validator(_errorReporter, scope.DataContext.MetadataContext)); phaseRunner.Phases.Add(PHASE_CONSTANT_FOLDING, new ConstantFolder(_errorReporter)); phaseRunner.Phases.Add(PHASE_COLUMN_AND_AGGREGATE_EXPRESSION_REPLACEMENT, new ColumnAndAggregateExpressionReplacer()); phaseRunner.Phases.Add(PHASE_ALGEBRAIZATION, delegate(AstNode input) { return(Algebrizer.Convert((QueryNode)input)); }); phaseRunner.Phases.Add(PHASE_ROW_BUFFER_ENTRY_INLINING, new RowBufferEntryInliner()); phaseRunner.Phases.Add(PHASE_SEMI_JOIN_SIMPLIFICATION, new SemiJoinSimplifier()); phaseRunner.Phases.Add(PHASE_DECORRELATION, new Decorrelator()); phaseRunner.Phases.Add(PHASE_OUTER_JOIN_REMOVAL, new OuterJoinRemover()); phaseRunner.Phases.Add(PHASE_SELECTION_PUSHING, new SelectionPusher()); phaseRunner.Phases.Add(PHASE_JOIN_LINEARIZATION, new JoinLinearizer()); phaseRunner.Phases.Add(PHASE_OUTER_JOIN_REORDERING, new OuterJoinReorderer()); phaseRunner.Phases.Add(PHASE_JOIN_ORDER_OPTIMIZATION, new JoinOrderOptimizer()); phaseRunner.Phases.Add(PHASE_AT_MOST_ONE_ROW_REORDERING, new AtMostOneRowReorderer()); phaseRunner.Phases.Add(PHASE_OUTER_REFERENCE_LABELING, new OuterReferenceLabeler()); phaseRunner.Phases.Add(PHASE_SPOOL_INSERTION, new SpoolInserter()); phaseRunner.Phases.Add(PHASE_PUSH_COMPUTATIONS, new ComputationPusher()); phaseRunner.Phases.Add(PHASE_PHYSICAL_JOIN_OP_CHOOSING, new PhysicalJoinOperationChooser()); phaseRunner.Phases.Add(PHASE_OUTPUTLIST_GENERATION, new OutputListGenerator()); phaseRunner.Phases.Add(PHASE_NULL_SCAN_OPTIMIZATION, new NullScanOptimizer()); phaseRunner.Phases.Add(PHASE_FULL_OUTER_JOIN_EXPANSION, new FullOuterJoinExpander()); phaseRunner.Phases.Add(PHASE_OUTPUTLIST_OPTIMIZATION, new OutputListOptimizer()); phaseRunner.Phases.Add(PHASE_ROW_BUFFER_ENTRY_NAMING, new RowBufferEntryNamer()); // TODO: Acutally, we should perform "PushComputations" after "NullScanOptimization" since // we can merge some ComputeScalar nodes there. But currently the "PushComputations" // visitor does not correctly update the OutputList so later phases will fail. // TODO: The phases "SpoolInsertion" and "PhysicalJoinOperationChoosing" should be the last // entries but currently they must precede PHASE_OUTPUTLIST_GENERATION, PHASE_OUTPUTLIST_OPTIMIZATION, // and PHASE_ROW_BUFFER_ENTRY_NAMING. return((ResultAlgebraNode)phaseRunner.Run()); }