Esempio n. 1
0
            public string Exec(params string[] args)
            {
                Init(args);
                BuffersContext rb = StartBuffers();

                Run();
                ResetBuffers(rb);
                return(ReadToEnd());
            }
Esempio n. 2
0
            protected internal virtual List <KeyValuePair <ByteSlice, ByteSlice> > RunMap(
                IEnumerator <ByteSlice> input, List <InputDataInfo> InputInfo)
            {
                long mapiter = -1;

                StaticGlobals.MapIteration = mapiter;
                JMapOutput     output         = new JMapOutput();
                BuffersContext rb             = StartBuffers();
                int            nextii         = -1;
                int            nextstartindex = -1;

                if (InputInfo.Count > 0)
                {
                    nextii         = 0;
                    nextstartindex = 0;
                }
                while (input.MoveNext())
                {
                    StaticGlobals.MapIteration = ++mapiter;
                    if (mapiter == nextstartindex)
                    {
                        this.MapInputFileIndex = nextii;
                        this.MapInputFileName  = InputInfo[nextii].FileName;
                        if (++nextii < InputInfo.Count)
                        {
                            nextstartindex = InputInfo[nextii].StartIndex;
                        }
                        else
                        {
                            nextii         = -1;
                            nextstartindex = -1;
                        }
                    }
                    Map(input.Current, output);
                    ResetBuffers(rb);
                }
                return(output.results);
            }
Esempio n. 3
0
            public virtual void RunReduce(List <KeyValuePair <ByteSlice, ByteSlice> > mapped)
            {
                long reduceiter = -1;

                StaticGlobals.ReduceIteration = reduceiter;
                BuffersContext rb                = StartBuffers();
                string         outputdfsfile     = null;
                string         outputdfsfiletype = null;

                if (OutputFile != null)
                {
                    outputdfsfile = OutputFile;
                    if (outputdfsfile.StartsWith("dfs://", StringComparison.OrdinalIgnoreCase))
                    {
                        outputdfsfile = outputdfsfile.Substring(6);
                    }
                    int reclen;
                    {
                        int iat = outputdfsfile.IndexOf('@');
                        if (-1 == iat)
                        {
                            reclen            = -1;
                            outputdfsfiletype = "zd";
                        }
                        else
                        {
                            if (!int.TryParse(outputdfsfile.Substring(iat + 1), out reclen) || reclen < 1)
                            {
                                throw new Exception("Invalid record length: dfs://" + outputdfsfile);
                            }
                            outputdfsfile = outputdfsfile.Substring(0, iat);
                            //DSpace_OutputRecordLength = reclen;
                            DSpace_OutputRecordLength = reclen;
                            outputdfsfiletype         = "rbin@" + reclen;
                        }
                    }
                }

                ReduceInitialize();
                ResetBuffers(rb);

                JReduceInput  input  = new JReduceInput(mapped);
                JReduceOutput output = new JReduceOutput();

                while (input._MoveNextKey())
                {
                    StaticGlobals.ReduceIteration = ++reduceiter;
                    Reduce(input._CurrentKey, input, output);
                    ResetBuffers(rb);
                }

                ReduceFinalize();
                ResetBuffers(rb);

                if (null == outputdfsfile)
                {
#if DEBUG
                    if (output.results.Count != 0)
                    {
                        throw new Exception("Reduce output with no output file specified");
                    }
#endif
                }
                else
                {
                    bool addnewlines   = (DSpace_OutputRecordLength < 1);
                    int  contentlength = 0;
                    checked
                    {
                        int trailing = addnewlines ? 2 : 0;
                        for (int i = 0; i < output.results.Count; i++)
                        {
                            contentlength += output.results[i].Length + trailing;
                        }
                    }
                    byte[] content = new byte[contentlength];
                    {
                        int ic = 0;
                        for (int i = 0; i < output.results.Count; i++)
                        {
                            output.results[i].CopyTo(content, ic);
                            ic += output.results[i].Length;
                            if (addnewlines)
                            {
                                content[ic++] = (byte)'\r';
                                content[ic++] = (byte)'\n';
                            }
                        }
                        if (ic != content.Length)
                        {
                            throw new Exception("DEBUG:  RunReduce: reduce output content length miscalculation");
                        }
                    }
                    dfsclient.SetFileContent(outputdfsfile, outputdfsfiletype, content, contentlength);
                }
            }
Esempio n. 4
0
 protected virtual void ResetBuffers(BuffersContext rb)
 {
     Stack.ResetStack(rb.stack);
     recordset.ResetBuffers(rb.recordset);
 }