コード例 #1
0
ファイル: CommandCompiler.cs プロジェクト: pwdlugosz/Horse
        // 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);

        }
コード例 #2
0
ファイル: VisitorHelper.cs プロジェクト: pwdlugosz/Horse
        public static Lambda RenderLambda(Workspace Home, HScriptParser.LambdaGradientContext context)
        {

            string NewLambdaName = context.IDENTIFIER()[0].GetText();
            string BaseLambdaName = context.IDENTIFIER()[1].GetText();
            string GradientVariable = context.IDENTIFIER()[2].GetText();

            Lambda mu = Home.Lambdas[BaseLambdaName];
            Lambda mu_prime = mu.Gradient(NewLambdaName, GradientVariable);

            return mu_prime;

        }
コード例 #3
0
ファイル: VisitorHelper.cs プロジェクト: pwdlugosz/Horse
        // Lambdas //
        public static Lambda RenderLambda(Workspace Home, HScriptParser.LambdaGenericContext context)
        {

            // Get the name //
            string name = context.IDENTIFIER()[0].GetText();

            // Get all the pointers //
            List<string> pointers = new List<string>();
            for (int i = 1; i < context.IDENTIFIER().Count; i++)
            {
                string var_name = context.IDENTIFIER()[i].GetText();
                pointers.Add(var_name);
            }

            // Get the expression //
            PointerExpressionVisitor pev = new PointerExpressionVisitor(pointers, Home);

            // Build the node //
            FNode node = pev.ToNode(context.expression());

            // Build the lambda //
            Lambda mu = new Lambda(name, node, pointers);

            return mu;

        }
コード例 #4
0
ファイル: VisitorHelper.cs プロジェクト: pwdlugosz/Horse
        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]);
            }

        }
コード例 #5
0
ファイル: VisitorHelper.cs プロジェクト: pwdlugosz/Horse
        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]);
            }

        }
コード例 #6
0
ファイル: VisitorHelper.cs プロジェクト: pwdlugosz/Horse
        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);
            }

        }
コード例 #7
0
ファイル: VisitorHelper.cs プロジェクト: pwdlugosz/Horse
        public static void AllocateMemory(Workspace Home, MemoryStruct Heap, ExpressionVisitor Evaluator, HScriptParser.DeclareMatrixLiteralContext context)
        {

            string name = context.IDENTIFIER().GetText();
            CellAffinity type = GetAffinity(context.type());
            MatrixVisitor vis = new MatrixVisitor(Home, Heap, Evaluator);
            CellMatrix mat = vis.ToMatrix(context.matrix_expression()).Evaluate();
            Heap.Arrays.Reallocate(name, mat);

        }
コード例 #8
0
ファイル: VisitorHelper.cs プロジェクト: pwdlugosz/Horse
        public static void AllocateMemory(Workspace Home, MemoryStruct Heap, ExpressionVisitor Evaluator, HScriptParser.DeclareMatrix2DContext context)
        {

            string name = context.IDENTIFIER().GetText();
            CellAffinity type = GetAffinity(context.type());
            int rows = (int)Evaluator.ToNode(context.expression()[0]).Evaluate().valueINT;
            int cols = (int)Evaluator.ToNode(context.expression()[1]).Evaluate().valueINT;
            CellMatrix mat = new CellMatrix(rows, cols, type);
            Heap.Arrays.Reallocate(name, mat);

        }
コード例 #9
0
ファイル: VisitorHelper.cs プロジェクト: pwdlugosz/Horse
        // Heap allocations //
        public static void AllocateMemory(Workspace Home, MemoryStruct Heap, ExpressionVisitor Evaluator, HScriptParser.DeclareScalarContext context)
        {

            string name = context.IDENTIFIER().GetText();
            CellAffinity type = GetAffinity(context.type());
            Cell value = (context.ASSIGN() != null) ? Evaluator.ToNode(context.expression()).Evaluate() : new Cell(type);

            Heap.Scalars.Reallocate(name, value);

        }
コード例 #10
0
ファイル: CommandCompiler.cs プロジェクト: pwdlugosz/Horse
        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);

        }
コード例 #11
0
ファイル: CommandCompiler.cs プロジェクト: pwdlugosz/Horse
 internal static DeclareMatrixNode RenderDeclareNode(Workspace Home, ExpressionVisitor Evaluator, HScriptParser.DeclareMatrix2DContext context)
 {
     string name = context.IDENTIFIER().GetText();
     int row = (int)Evaluator.ToNode(context.expression()[0]).Evaluate().valueINT;
     int col = (int)Evaluator.ToNode(context.expression()[1]).Evaluate().valueINT;
     CellAffinity affinity = VisitorHelper.GetAffinity(context.type());
     MNodeLiteral m = new MNodeLiteral(null, new Gidran.CellMatrix(row, 1, affinity));
     return new DeclareMatrixNode(Home.GlobalHeap, name, m);
 }
コード例 #12
0
ファイル: CommandCompiler.cs プロジェクト: pwdlugosz/Horse
        internal static DeclareMatrixNode RenderDeclareNode(Workspace Home, ExpressionVisitor Evaluator, HScriptParser.DeclareMatrixLiteralContext context)
        {

            string name = context.IDENTIFIER().GetText();
            MatrixVisitor MEvaluator = new MatrixVisitor(Home, Home.GlobalHeap, Evaluator);
            MNode node = MEvaluator.ToMatrix(context.matrix_expression());
            return new DeclareMatrixNode(Home.GlobalHeap, name, node);

        }
コード例 #13
0
ファイル: CommandCompiler.cs プロジェクト: pwdlugosz/Horse
        internal static DeclareScalarNode RenderDeclareNode(Workspace Home, ExpressionVisitor Evaluator, HScriptParser.DeclareScalarContext context)
        {

            string name = context.IDENTIFIER().GetText();
            FNode node = Evaluator.ToNode(context.expression());
            return new DeclareScalarNode(Home.GlobalHeap, name, node);

        }
コード例 #14
0
ファイル: CommandCompiler.cs プロジェクト: pwdlugosz/Horse
        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);

        }
コード例 #15
0
ファイル: CommandCompiler.cs プロジェクト: pwdlugosz/Horse
        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;

        }