示例#1
0
        /// <summary>
        /// Return an in-memory table that contains the topN rows from the table in the filename.
        /// </summary>
        /// <param name="builder">ignored</param>
        /// <param name="filename">filename of table to load. Schema is inferred from header row.</param>
        /// <param name="topN">reads the topN rows from the table.</param>
        /// <returns>a in-memory table containing the topN rows from the supplied file.</returns>
        public static MutableDataTable ReadSampleTopN(this DataTableBuilder builder, string filename, int topN = 100)
        {
            Debug.Assert(builder != null);
            if (filename == null)
            {
                throw new ArgumentNullException("filename");
            }

            DataTable        source = new StreamingDataTable(filename);
            MutableDataTable dt     = Analyze.SampleTopN(source, topN);

            return(dt);
        }
示例#2
0
        public static MutableDataTable Read(TextReader stream, char delimiter = '\0', string[] defaultColumns = null)
        {
            // TextReader is not seekable. Need to convert to a Stream so we can seek.
            // We're asking for a Mutable dt anyways, so it's already expected to load it in memory.
            string contents = stream.ReadToEnd();
            var    bytes    = Encoding.UTF8.GetBytes(contents);

            contents = null;
            using (MemoryStream ms = new MemoryStream(bytes))
            {
                var dtLazy = new StreamingDataTable(ms, defaultColumns, delimiter);

                var dt = Utility.ToMutable(dtLazy);
                return(dt);
            }
        }
示例#3
0
        public static MutableDataTable Read(TextReader stream, char delimiter = '\0', string[] defaultColumns = null)
        {
            // TextReader is not seekable. Need to convert to a Stream so we can seek.
            // We're asking for a Mutable dt anyways, so it's already expected to load it in memory.
            string contents = stream.ReadToEnd();
            var bytes = Encoding.UTF8.GetBytes(contents);
            contents = null;
            using (MemoryStream ms = new MemoryStream(bytes))
            {
                var dtLazy = new StreamingDataTable(ms, defaultColumns, delimiter);

                var dt = Utility.ToMutable(dtLazy);
                return dt;
            }
        }