Beispiel #1
0
 // Statics //
 /// <summary>
 /// Dumps any read stream to a path
 /// </summary>
 /// <param name="Path"></param>
 /// <param name="Stream"></param>
 public static void Dump(string Path, RecordReader Stream)
 {
     using (StreamWriter sw = new StreamWriter(Path))
     {
         sw.WriteLine(Stream.Columns.ToNameString('\t'));
         while (Stream.CanAdvance)
         {
             sw.WriteLine(Stream.ReadNext().ToString('\t'));
         }
         sw.Flush();
     }
 }
Beispiel #2
0
        // Internal debugging //
        /// <summary>
        /// Dumps the entire table to a flat file
        /// </summary>
        /// <param name="Path"></param>
        internal virtual void Dump(string Path)
        {
            using (StreamWriter sw = new StreamWriter(Path))
            {
                sw.WriteLine(this.Columns.ToNameString('\t'));
                RecordReader rs = this.OpenReader();
                while (rs.CanAdvance)
                {
                    sw.WriteLine(rs.ReadNext().ToString('\t'));
                }

                sw.Flush();
            }
        }
Beispiel #3
0
        /// <summary>
        /// Calibrates the index
        /// </summary>
        public virtual void Calibrate()
        {
            if (this._Header.RecordCount != 0 || this._Parent.RecordCount == 0)
            {
                return;
            }

            RecordReader stream = this._Parent.OpenReader();

            while (stream.CanAdvance)
            {
                RecordKey rk  = stream.PositionKey;
                Record    rec = stream.ReadNext();

                this.Insert(rec, rk);
            }
        }
Beispiel #4
0
        //public static void ImportLines(Host Host, string Dir, string Alias, string RawPath, int Skip, int LineSize)
        //{

        //    // Create the table //
        //    Schema q = new Schema();
        //    q.Add("ROW_ID", CellAffinity.LONG);
        //    q.Add("RAW_TEXT", CellAffinity.CSTRING, LineSize);
        //    Table t = Host.CreateTable(Dir, Alias, q);

        //    // Read in the lines //
        //    using (RecordWriter rw = t.OpenWriter())
        //    {
        //        Import(rw, RawPath, new char[] { }, char.MaxValue, Skip);
        //    }


        //}

        public static void Export(RecordReader Reader, string RawPath, bool Headers, char Delim, char Escape)
        {
            using (FileStream fs = File.Create(RawPath))
            {
                using (StreamWriter sw = new StreamWriter(fs))
                {
                    if (Headers)
                    {
                        sw.WriteLine(Util.StringUtil.ToString(Reader.Columns, Delim, Escape));
                    }

                    while (Reader.CanAdvance)
                    {
                        string s = Util.StringUtil.ToString(Reader.ReadNext(), Delim, Escape);
                        sw.WriteLine(s);
                    }
                }
            }
        }
Beispiel #5
0
        public static RecordKey CheckSort(Table Element, Key Columns)
        {
            Record Last    = null;
            Record Current = null;

            RecordReader rr = Element.OpenReader();

            Current = rr.ReadNext();

            while (rr.CanAdvance)
            {
                if (Last != null && Record.Compare(Last, Current, Columns) > 0)
                {
                    return(rr.PositionKey);
                }
                Last    = Current;
                Current = rr.ReadNext();
            }

            return(RecordKey.RecordNotFound);
        }
Beispiel #6
0
        // Distinct Support //
        public static void Distinct(Table Element, RecordWriter Writer, RecordMatcher Comparer)
        {
            // Check if the table is a heap //
            if (!(Element is HeapTable))
            {
                throw new Exception("Can only sort a HeapTable");
            }
            if (Element.Header.IndexHeaders.Count != 0)
            {
                throw new Exception("Can not sort a table with indexes");
            }

            // Step 1: sort table //
            Sort(Element, Comparer);

            // Step 2: create a shell //
            //Table t = Element.Host.CreateTempTable(Element.Columns);

            // Step 3: open a reader //
            RecordReader rr = Element.OpenReader();

            // Step 4: write to the shell //
            Record lag = null;

            while (rr.CanAdvance)
            {
                Record current = rr.ReadNext();

                if (lag == null)
                {
                    Writer.Insert(current);
                }
                else if (Comparer.Compare(lag, current) != 0)
                {
                    Writer.Insert(current);
                }

                lag = current;
            }
        }