Beispiel #1
0
        // Reads //
        public static StagedReadName RenderStagedReadPlan(Workspace Home, HScriptParser.Crudam_readContext 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 local heap to work off of //
            MemoryStruct local_heap = new MemoryStruct(true);

            // Create a record register //
            StreamRegister memory = new StreamRegister(null);

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

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

            // Create a reader //
            RecordReader reader = data.OpenReader(where);

            // Attach the reader to the register //
            memory.BaseStream = reader;

            // Create the action visitor //
            ActionVisitor act_vis = new ActionVisitor(Home, local_heap, exp_vis);

            // Get the declarations //
            if (context.crudam_declare_many() != null)
            {
                VisitorHelper.AllocateMemory(Home, local_heap, exp_vis, context.crudam_declare_many());
            }

            // Get the initial actionset //
            TNode pre_run =
                (context.init_action() != null)
                ? act_vis.ToNode(context.init_action().query_action())
                : new TNodeNothing(null);

            // Get the main actionset //
            TNode run = act_vis.ToNode(context.main_action().query_action());

            // Get the final actionset //
            TNode post_run =
                (context.final_action() != null)
                ? act_vis.ToNode(context.final_action().query_action())
                : new TNodeNothing(null);

            return new StagedReadName(reader, pre_run, run, post_run);

        }
Beispiel #2
0
        private static void AppendSet(ExpressionVisitor Evaluator, FNodeSet Fields, HScriptParser.EOW_tables_starContext context)
        {

            if (Evaluator.Columns.Count == 0)
                return; // no need to toss an exception

            string alias = Evaluator.Columns.Keys.First();
            FNodeSet nodes = new FNodeSet(Evaluator.Columns[alias]);
            nodes.AssignRegister(Evaluator.Registers[alias]);

            string suffix = (context.K_AS() == null) ? null : context.IDENTIFIER().GetText();

            for (int i = 0; i < nodes.Count; i++)
            {
                Fields.Add((suffix == null) ? nodes.Alias(i) : suffix + nodes.Alias(i), nodes[i]);
            }

        }
Beispiel #3
0
        private static void AppendSet(ExpressionVisitor Evaluator, FNodeSet Fields, HScriptParser.EOW_table_starContext context)
        {

            string alias = context.IDENTIFIER()[0].GetText();
            if (!Evaluator.Columns.ContainsKey(alias))
                throw new Exception(string.Format("Alias '{0}' does not exist", alias));

            FNodeSet nodes = new FNodeSet(Evaluator.Columns[alias]);
            nodes.AssignRegister(Evaluator.Registers[alias]);

            string suffix = (context.K_AS() == null) ? null : context.IDENTIFIER()[1].GetText();

            for (int i = 0; i < nodes.Count; i++)
            {
                Fields.Add((suffix == null) ? nodes.Alias(i) : suffix + nodes.Alias(i), nodes[i]);
            }

        }
Beispiel #4
0
        private static void AppendSet(ExpressionVisitor Evaluator, FNodeSet Fields, HScriptParser.EOW_global_starContext context)
        {

            string suffix =
                (context.K_AS() == null)
                ? null
                : context.IDENTIFIER().GetText();

            for (int i = 0; i < Evaluator.GlobalHeap.Scalars.Count; i++)
            {
                string alias =
                    (suffix == null)
                    ? Evaluator.LocalHeap.Scalars.Name(i)
                    : suffix + Evaluator.LocalHeap.Scalars.Name(i);
                FNode node = new FNodeHeapRef(null, Evaluator.GlobalHeap, i);
                Fields.Add(alias, node);
            }

        }
Beispiel #5
0
        public static FastReadPlan RenderFastReadPlan(Workspace Home, HScriptParser.Crudam_read_fastContext 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 record register //
            StreamRegister memory = new StreamRegister(null);

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

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

            // Create a reader //
            RecordReader reader = data.OpenReader(where);

            // Attach the reader to the register //
            memory.BaseStream = reader;

            // Get the fields being returned //
            FNodeSet nodes = VisitorHelper.GetReturnStatement(exp_vis, context.return_action().expression_or_wildcard_set());

            // Get the output cursor from the return statement //
            RecordWriter writer = VisitorHelper.GetWriter(Home, nodes.Columns, context.return_action());

            return new FastReadPlan(data, where, nodes, writer);

        }
Beispiel #6
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);

        }
Beispiel #7
0
        internal static ReadMapNode RenderMapNode(Workspace Home, int PartitionID, HScriptParser.Crudam_read_maprContext 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 local heap to work off of //
            MemoryStruct local_heap = new MemoryStruct(true);

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

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

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

            // Create a reader //
            RecordReader reader = data.OpenReader(where);

            // Get the declarations //
            if (context.crudam_declare_many() != null)
            {
                VisitorHelper.AllocateMemory(Home, local_heap, exp_vis, context.crudam_declare_many());
            }

            // Get the map actions //
            ActionVisitor act_vis = new ActionVisitor(Home, local_heap, exp_vis);
            act_vis.IsAsync = true;
            TNode map = act_vis.ToNode(context.map_action().query_action());

            // Get the reduce actions //
            act_vis = new ActionVisitor(Home, local_heap, exp_vis);
            act_vis.IsAsync = false;
            TNode red = act_vis.ToNode(context.reduce_action().query_action());

            ReadMapNode node = new ReadMapNode(PartitionID, map, red, memory, where);

            return node;

        }