Ejemplo n.º 1
0
        // Note: appendsizes can be null, but the return will still be valid.
        // Sizes exclude header data.
        protected virtual int GetNumberOfRemoteOutputFilesCreated(int n, IList <long> appendsizes)
        {
            int result = 0;

            foreach (SlaveInfo slave in dslaves)
            {
                slave.nstm.WriteByte((byte)'r');
                Entry.ToBytes(n, buf, 0);
                XContent.SendXContent(slave.nstm, buf, 4);
                int len;
                buf = XContent.ReceiveXBytes(slave.nstm, out len, buf);
                if (len >= 4)
                {
                    result += Entry.BytesToInt(buf);

                    if (null != appendsizes)
                    {
                        for (int offset = 4; offset + 8 <= len; offset += 8)
                        {
                            appendsizes.Add(Entry.BytesToLong(buf, offset));
                        }
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 2
0
        public Int64 GetInt64()
        {
            Int64 x = Entry.BytesToLong(Buffer, CurrentGetPos);

            CurrentGetPos += 8;
            return(x);
        }
Ejemplo n.º 3
0
        public DateTime GetDateTime(ByteSlice input)
        {
#if DEBUG_FTGET
            if (Types.IsNullValue(input))
            {
                throw new Exception("DEBUG:  GetDateTime: (Types.IsNullValue(input))");
            }
#endif
            List <byte> buf = AllocBuffer(input.Length - 1);
            ByteSlice.Prepare(input, 1, input.Length - 1).AppendTo(buf);
            Int64 x = Entry.BytesToLong(buf);
            FreeLastBuffer(buf);
            return(new DateTime(x));
        }
Ejemplo n.º 4
0
        public static void DbAggregators_BIT_OR(string tablename)
        {
            {
                System.Data.Common.DbProviderFactory fact = DbProviderFactories.GetFactory("DSpace_DataProvider");
                DbConnection conn = fact.CreateConnection();
                try
                {
                    conn.ConnectionString = "Data Source = localhost";
                    conn.Open();

                    {
                        Console.WriteLine("Testing BIT_OR(long)...");
                        DbCommand cmd = conn.CreateCommand();
                        cmd.CommandText = "select id, BIT_OR(costl) from " + tablename + " group by id";

                        Dictionary <int, byte[]> expected = new Dictionary <int, byte[]>();
                        List <long> values = new List <long>();
                        values.Add(100);
                        values.Add(200);
                        values.Add(400);
                        expected[10] = bitop(values.ToArray(), 2);

                        values.Clear();
                        values.Add(705);
                        values.Add(900);
                        expected[20] = bitop(values.ToArray(), 2);

                        values.Clear();
                        values.Add(705);
                        values.Add(1000);
                        values.Add(100);
                        expected[30] = bitop(values.ToArray(), 2);
                        Dictionary <int, int> resultCount = new Dictionary <int, int>();

                        DbDataReader reader = cmd.ExecuteReader();
                        while (reader.Read())
                        {
                            int  id = reader.GetInt32(0);
                            long op = reader.GetInt64(1);
                            if (!expected.ContainsKey(id))
                            {
                                throw new Exception("id returned from BIT_OR group by is invalid.");
                            }
                            long expop = Entry.ToInt64((UInt64)Entry.BytesToLong(expected[id], 0));

                            if (op != expop)
                            {
                                throw new Exception("Expected BIT_OR: " + expop.ToString() + ", but got " + op.ToString() + " instead.");
                            }
                            if (!resultCount.ContainsKey(id))
                            {
                                resultCount[id] = 0;
                            }
                            resultCount[id]++;
                        }
                        reader.Close();

                        int count = 0;
                        foreach (int c in resultCount.Values)
                        {
                            count += c;
                        }

                        if (count != 3)
                        {
                            throw new Exception("Expected row count: 3, but got " + count.ToString() + " instead.");
                        }
                        Console.WriteLine("Expected results received.");
                    }
                }
                finally
                {
                    conn.Close();
                }
            }
        }
Ejemplo n.º 5
0
            public override void OnRemote(IEnumerator <ByteSlice> input, System.IO.Stream output)
            {
                string TableName     = DSpace_ExecArgs[0];
                string DfsOutputName = DSpace_ExecArgs[1]; // Actually the input of this job.
                string RowInfo       = Qa.QlArgsUnescape(DSpace_ExecArgs[2]);
                string DisplayInfo   = DSpace_ExecArgs[3];
                long   TopCount      = long.Parse(DSpace_ExecArgs[4]);
                string sOptions      = (DSpace_ExecArgs.Length > 5) ? DSpace_ExecArgs[5] : "";
                bool   joined        = -1 != sOptions.IndexOf("JOINED");

                InitColInfos(RowInfo, DisplayInfo);

                StringBuilder sb = new StringBuilder();

                sb.Length = 0;
                bool ShouldCleanName = !joined;

                foreach (ColInfo ci in cols)
                {
                    string name = ci.Name;
                    if (ShouldCleanName)
                    {
                        name = CleanColumnName(ci.Name);
                    }
                    sb.AppendFormat("{0,-" + ci.DisplayWidth.ToString() + "} ", name);
                }
                string hsep = new string('-', sb.Length);

                DSpace_Log(sb.ToString());
                DSpace_Log(hsep);

                for (ByteSlice rowbuf;
                     (TopCount == -1 || TopCount > 0) &&
                     input.MoveNext();
                     )
                {
                    rowbuf = input.Current;

                    sb.Length = 0;
                    foreach (ColInfo ci in cols)
                    {
                        ByteSlice cval = ByteSlice.Prepare(rowbuf, ci.StartOffset, ci.Size);
                        if (0 != cval[0])
                        {
                            sb.AppendFormat("{0,-" + ci.DisplayWidth.ToString() + "} ", "NULL");
                        }
                        else
                        {
                            if (ci.Type.StartsWith("char"))
                            {
                                string charsvalue = System.Text.Encoding.Unicode.GetString(ByteSlice.Prepare(cval, 1, cval.Length - 1).ToBytes());
                                charsvalue = charsvalue.TrimEnd('\0');
                                sb.AppendFormat("{0,-" + ci.DisplayWidth.ToString() + "} ", charsvalue);
                            }
                            else if ("int" == ci.Type)
                            {
                                Int32 x = Entry.BytesToInt(ByteSlice.Prepare(cval, 1, cval.Length - 1).ToBytes());
                                x = Entry.ToInt32((UInt32)x);
                                sb.AppendFormat("{0,-" + ci.DisplayWidth.ToString() + "} ", x);
                            }
                            else if ("long" == ci.Type)
                            {
                                Int64 x = Entry.BytesToLong(ByteSlice.Prepare(cval, 1, cval.Length - 1).ToBytes());
                                x = Entry.ToInt64((UInt64)x);
                                sb.AppendFormat("{0,-" + ci.DisplayWidth.ToString() + "} ", x);
                            }
                            else if ("double" == ci.Type)
                            {
                                recordset rs = recordset.Prepare(ByteSlice.Prepare(cval, 1, cval.Length - 1));
                                double    x  = rs.GetDouble();
                                sb.AppendFormat("{0,-" + ci.DisplayWidth.ToString() + "} ", x);
                            }
                            else if ("DateTime" == ci.Type)
                            {
                                Int64    x  = Entry.BytesToLong(ByteSlice.Prepare(cval, 1, cval.Length - 1).ToBytes());
                                DateTime dt = new DateTime(x);
                                sb.AppendFormat("{0,-" + ci.DisplayWidth.ToString() + "} ", dt);
                            }
                            else
                            {
                                sb.AppendFormat("{0,-" + ci.DisplayWidth.ToString() + "} ",
                                                "?"); // Not supported yet.
                            }
                        }
                    }
                    DSpace_Log(sb.ToString());
                    if (TopCount != -1)
                    {
                        TopCount--;
                    }
                }

                DSpace_Log(hsep);
            }