Exemple #1
0
        public static PartitionedAggregatePlan RenderPartitionedAggregatePlan(Workspace Home, HScriptParser.Crudam_aggregateContext context)
        {

            // Get the data source //
            DataSet data = VisitorHelper.GetData(Home, context.full_table_name());
            string alias =
                (context.K_AS() != null)
                ? context.IDENTIFIER().GetText()
                : data.Name;

            // Create a register //
            StaticRegister memory = new StaticRegister(null);

            // Create expression visitor //
            ExpressionVisitor exp_vis = new ExpressionVisitor(null, Home, alias, data.Columns, memory);

            // Get where //
            Predicate where = VisitorHelper.GetWhere(exp_vis, context.where_clause());

            // Get the reader //
            //RecordReader reader = data.OpenReader(where);

            // Get the keys //
            FNodeSet keys =
                (context.K_BY() != null)
                ? exp_vis.ToNodes(context.expression_alias_list())
                : new FNodeSet();

            // Get the reducers //
            AggregateSet values =
                (context.K_OVER() != null)
                ? exp_vis.ToReducers(context.beta_reduction_list())
                : new AggregateSet();

            // Create a second register for the return memory //
            StaticRegister return_memory = new StaticRegister(null);

            // Need to build a visitor off of the aggregator schema //
            ExpressionVisitor agg_vis = new ExpressionVisitor(null, Home, "agg", AggregatePlan.GetInterimSchema(keys, values), return_memory);

            // Get the output //
            FNodeSet return_vars = VisitorHelper.GetReturnStatement(agg_vis, context.return_action().expression_or_wildcard_set());

            // Get the output cursor //
            RecordWriter out_put_writter = VisitorHelper.GetWriter(Home, return_vars.Columns, context.return_action());

            // Get the partitioner //
            int Partitions = VisitorHelper.GetPartitions(exp_vis, context.partitions());

            return new PartitionedAggregatePlan(out_put_writter, data, where, keys, values, return_vars, Home.TempSpace, Partitions);

        }
Exemple #2
0
        public static FNodeSet ParseFNodeSet(string Text, MemoryStruct LocalHeap, Workspace Home, string Alias, Schema Columns, Register Memory)
        {

            // Build text stream //
            AntlrInputStream ais = new AntlrInputStream(Text);
            HScriptLexer lex = new HScriptLexer(ais);

            // Build token tree //
            CommonTokenStream cts = new CommonTokenStream(lex);
            HScriptParser par = new HScriptParser(cts);

            // Build AST //
            IParseTree tree = par.expression_alias_list();
            if (tree == null)
                tree = par.expression_or_wildcard_set();
            
            // Visit each node getting the final node //
            ExpressionVisitor v = new ExpressionVisitor(LocalHeap, Home);
            v.AddSchema(Alias, Columns, Memory);

            if (tree is HScriptParser.Expression_or_wildcard_setContext)
            {
                HScriptParser.Expression_or_wildcard_setContext a = tree as HScriptParser.Expression_or_wildcard_setContext;
                return VisitorHelper.GetReturnStatement(v, a);
            }
            else if (tree is HScriptParser.Expression_alias_listContext)
            {
                HScriptParser.Expression_alias_listContext b = tree as HScriptParser.Expression_alias_listContext;
                return v.ToNodes(b);
            }

            throw new Exception("Expression is not an expression set: " + Text);

        }