Ejemplo n.º 1
0
        void TestRoundTripLongColumn <T>(IEnumerable <T> testElements, int columnId, IEnumerable <long?> expectedResults)
        {
            var memStream = new MemoryStream();

            using (var writer = new OrcWriter <T>(memStream, new WriterConfiguration()))            //Use the default configuration
            {
                writer.AddRows(testElements);
            }

            memStream.Seek(0, SeekOrigin.Begin);

            var dataFile = new DataFileHelper(memStream);
            var stream   = dataFile.GetStream();
            var fileTail = new FileTail(stream);

            var expectedEnumerator = expectedResults.GetEnumerator();

            foreach (var stripe in fileTail.Stripes)
            {
                var stripeStreamCollection = stripe.GetStripeStreamCollection();
                var longReader             = new LongReader(stripeStreamCollection, (uint)columnId);
                var resultEnumerator       = longReader.Read().GetEnumerator();

                ulong count = 0;
                while (resultEnumerator.MoveNext())
                {
                    Assert.True(expectedEnumerator.MoveNext());
                    Assert.Equal(expectedEnumerator.Current, resultEnumerator.Current);
                    count++;
                }
                Assert.Equal(stripe.NumRows, count);
            }
            Assert.False(expectedEnumerator.MoveNext());                        //We should have used all expected results
        }
Ejemplo n.º 2
0
        void RoundTripSingleInt(int numValues)
        {
            var pocos  = new List <SingleIntPoco>();
            var random = new Random(123);

            for (int i = 0; i < numValues; i++)
            {
                pocos.Add(new SingleIntPoco {
                    Int = random.Next()
                });
            }

            var    stream = new MemoryStream();
            Footer footer;

            StripeStreamHelper.Write(stream, pocos, out footer);
            var stripeStreams = StripeStreamHelper.GetStripeStreams(stream, footer);
            var longReader    = new LongReader(stripeStreams, 1);
            var results       = longReader.Read().ToArray();

            for (int i = 0; i < numValues; i++)
            {
                Assert.Equal(pocos[i].Int, results[i]);
            }
        }
Ejemplo n.º 3
0
        public void ReadColumn9_ShouldProduceExpectedResults()
        {
            var stripeStreams = GetStripeStreamCollection();
            var longReader    = new LongReader(stripeStreams, 9);
            var results       = longReader.Read().ToArray();

            Assert.Equal(1920800, results.Length);
            for (int i = 0; i < results.Length; i++)
            {
                var expected = (i / 274400);
                Assert.True(results[i].HasValue);
                Assert.Equal(expected, results[i].Value);
            }
        }
Ejemplo n.º 4
0
        // Add some non-zero constants to the mix.
        public void AddConstantsToTDB(RandoopConfiguration config)
        {
            foreach (SimpleTypeValues vs in config.simpleTypeValues)
            {
                Type type = Type.GetType(vs.simpleType);

                if (type == null)
                {
                    throw new Common.RandoopBareExceptions.InternalError("invalid simple type in XML config file.");
                }

                foreach (FileName fn in vs.fileNames)
                {
                    string fileName = fn.fileName;
                    if (!File.Exists(fileName))
                    {
                        throw new Common.RandoopBareExceptions.InvalidUserParamsException("Configuration file does not exist: " + fileName);
                    }

                    if (type.Equals(typeof(sbyte)))
                    {
                        SByteReader r = new SByteReader();
                        foreach (object o in r.Read(fileName))
                        {
                            this.AddPlan(Plan.Constant(typeof(sbyte), o));
                        }
                    }
                    else if (type.Equals(typeof(byte)))
                    {
                        ByteReader r = new ByteReader();
                        foreach (object o in r.Read(fileName))
                        {
                            this.AddPlan(Plan.Constant(typeof(byte), o));
                        }
                    }
                    else if (type.Equals(typeof(short)))
                    {
                        ShortReader r = new ShortReader();
                        foreach (object o in r.Read(fileName))
                        {
                            this.AddPlan(Plan.Constant(typeof(short), o));
                        }
                    }
                    else if (type.Equals(typeof(ushort)))
                    {
                        UshortReader r = new UshortReader();
                        foreach (object o in r.Read(fileName))
                        {
                            this.AddPlan(Plan.Constant(typeof(ushort), o));
                        }
                    }
                    else if (type.Equals(typeof(int)))
                    {
                        IntReader r = new IntReader();
                        foreach (object o in r.Read(fileName))
                        {
                            this.AddPlan(Plan.Constant(typeof(int), o));
                        }
                    }
                    else if (type.Equals(typeof(uint)))
                    {
                        UintReader r = new UintReader();
                        foreach (object o in r.Read(fileName))
                        {
                            this.AddPlan(Plan.Constant(typeof(uint), o));
                        }
                    }
                    else if (type.Equals(typeof(long)))
                    {
                        LongReader r = new LongReader();
                        foreach (object o in r.Read(fileName))
                        {
                            this.AddPlan(Plan.Constant(typeof(long), o));
                        }
                    }
                    else if (type.Equals(typeof(ulong)))
                    {
                        UlongReader r = new UlongReader();
                        foreach (object o in r.Read(fileName))
                        {
                            this.AddPlan(Plan.Constant(typeof(ulong), o));
                        }
                    }
                    else if (type.Equals(typeof(char)))
                    {
                        CharReader r = new CharReader();
                        foreach (object o in r.Read(fileName))
                        {
                            this.AddPlan(Plan.Constant(typeof(char), o));
                        }
                    }
                    else if (type.Equals(typeof(float)))
                    {
                        FloatReader r = new FloatReader();
                        foreach (object o in r.Read(fileName))
                        {
                            this.AddPlan(Plan.Constant(typeof(float), o));
                        }
                    }
                    else if (type.Equals(typeof(double)))
                    {
                        DoubleReader r = new DoubleReader();
                        foreach (object o in r.Read(fileName))
                        {
                            this.AddPlan(Plan.Constant(typeof(double), o));
                        }
                    }
                    else if (type.Equals(typeof(bool)))
                    {
                        BoolReader r = new BoolReader();
                        foreach (object o in r.Read(fileName))
                        {
                            this.AddPlan(Plan.Constant(typeof(bool), o));
                        }
                    }
                    else if (type.Equals(typeof(decimal)))
                    {
                        DecimalReader r = new DecimalReader();
                        foreach (object o in r.Read(fileName))
                        {
                            this.AddPlan(Plan.Constant(typeof(decimal), o));
                        }
                    }
                    else
                    {
                        if (!type.Equals(typeof(string)))
                        {
                            throw new Common.RandoopBareExceptions.InternalError("invalid simple type in XML config file.");
                        }
                        Common.StringReader r = new Common.StringReader();
                        foreach (object o in r.Read(fileName))
                        {
                            this.AddPlan(Plan.Constant(typeof(string), o));
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("Usage: <FILENAME>");
                return;
            }

            var filename = args[0];
            var stream   = new FileStream(filename, FileMode.Open, FileAccess.Read);
            var fileTail = new FileTail(stream);

            foreach (var stripe in fileTail.Stripes)
            {
                Console.WriteLine($"Reading stripe with {stripe.NumRows} rows");
                var stripeStreamCollection = stripe.GetStripeStreamCollection();

                if (fileTail.Footer.Types[0].Kind != ColumnTypeKind.Struct)
                {
                    throw new InvalidDataException($"The base type must be {nameof(ColumnTypeKind.Struct)}");
                }
                var names = fileTail.Footer.Types[0].FieldNames;

                for (int columnId = 1; columnId < fileTail.Footer.Types.Count; columnId++)
                {
                    var columnType = fileTail.Footer.Types[columnId];
                    var columnName = names[columnId - 1];

                    switch (columnType.Kind)
                    {
                    case ColumnTypeKind.Long:
                    case ColumnTypeKind.Int:
                    case ColumnTypeKind.Short:
                    {
                        Console.WriteLine($"Reading longs from column {columnId} ({columnName})");
                        var reader = new LongReader(stripeStreamCollection, (uint)columnId);
                        var count  = reader.Read().Count();
                        Console.WriteLine($"Done reading {count} longs");
                        break;
                    }

                    case ColumnTypeKind.Byte:
                    {
                        Console.WriteLine($"Reading bytes from column {columnId} ({columnName})");
                        var reader = new ByteReader(stripeStreamCollection, (uint)columnId);
                        var count  = reader.Read().Count();
                        Console.WriteLine($"Done reading {count} bytes");
                        break;
                    }

                    case ColumnTypeKind.Boolean:
                    {
                        Console.WriteLine($"Reading bools from column {columnId} ({columnName})");
                        var reader = new BooleanReader(stripeStreamCollection, (uint)columnId);
                        var count  = reader.Read().Count();
                        Console.WriteLine($"Done reading {count} bools");
                        break;
                    }

                    case ColumnTypeKind.Float:
                    {
                        Console.WriteLine($"Reading floats from column {columnId} ({columnName})");
                        var reader = new FloatReader(stripeStreamCollection, (uint)columnId);
                        var count  = reader.Read().Count();
                        Console.WriteLine($"Done reading {count} floats");
                        break;
                    }

                    case ColumnTypeKind.Double:
                    {
                        Console.WriteLine($"Reading doubles from column {columnId} ({columnName})");
                        var reader = new DoubleReader(stripeStreamCollection, (uint)columnId);
                        var count  = reader.Read().Count();
                        Console.WriteLine($"Done reading {count} doubles");
                        break;
                    }

                    case ColumnTypeKind.Binary:
                    {
                        Console.WriteLine($"Reading binary from column {columnId} ({columnName})");
                        var reader = new ColumnTypes.BinaryReader(stripeStreamCollection, (uint)columnId);
                        var count  = reader.Read().Count();
                        Console.WriteLine($"Done reading {count} binaries");
                        break;
                    }

                    case ColumnTypeKind.Decimal:
                    {
                        Console.WriteLine($"Reading decimals from column {columnId} ({columnName})");
                        var reader = new DecimalReader(stripeStreamCollection, (uint)columnId);
                        var count  = reader.Read().Count();
                        Console.WriteLine($"Done reading {count} decimals");
                        break;
                    }

                    case ColumnTypeKind.Timestamp:
                    {
                        Console.WriteLine($"Reading timestamps from column {columnId} ({columnName})");
                        var reader = new TimestampReader(stripeStreamCollection, (uint)columnId);
                        var count  = reader.Read().Count();
                        Console.WriteLine($"Done reading {count} timestamps");
                        break;
                    }

                    case ColumnTypeKind.Date:
                    {
                        Console.WriteLine($"Reading dates from column {columnId} ({columnName})");
                        var reader = new DateReader(stripeStreamCollection, (uint)columnId);
                        var count  = reader.Read().Count();
                        Console.WriteLine($"Done reading {count} dates");
                        break;
                    }

                    case ColumnTypeKind.String:
                    {
                        Console.WriteLine($"Reading strings from column {columnId} ({columnName})");
                        var reader = new ColumnTypes.StringReader(stripeStreamCollection, (uint)columnId);
                        var count  = reader.Read().Count();
                        Console.WriteLine($"Done reading {count} strings");
                        break;
                    }

                    default:
                        throw new NotImplementedException();
                    }
                }

                Console.WriteLine("Done reading stripe");
            }
        }
Ejemplo n.º 6
0
        // Add some non-zero constants to the mix.
        public void AddConstantsToTDB(RandoopConfiguration config)
        {
            foreach (SimpleTypeValues vs in config.simpleTypeValues)
            {
                Type type = Type.GetType(vs.simpleType);

                if (type == null)
                {
                    throw new Common.RandoopBareExceptions.InternalError("invalid simple type in XML config file.");
                }

                foreach (FileName fn in vs.fileNames)
                {
                    string fileName = fn.fileName;
                    if (!File.Exists(fileName))
                    {
                        throw new Common.RandoopBareExceptions.InvalidUserParamsException("Configuration file does not exist: " + fileName);
                    }

                    if (type.Equals(typeof(sbyte)))
                    {
                        SByteReader r = new SByteReader();
                        foreach (object o in r.Read(fileName))
                            this.AddPlan(Plan.Constant(typeof(sbyte), o));
                    }
                    else if (type.Equals(typeof(byte)))
                    {
                        ByteReader r = new ByteReader();
                        foreach (object o in r.Read(fileName))
                            this.AddPlan(Plan.Constant(typeof(byte), o));
                    }
                    else if (type.Equals(typeof(short)))
                    {
                        ShortReader r = new ShortReader();
                        foreach (object o in r.Read(fileName))
                            this.AddPlan(Plan.Constant(typeof(short), o));
                    }
                    else if (type.Equals(typeof(ushort)))
                    {
                        UshortReader r = new UshortReader();
                        foreach (object o in r.Read(fileName))
                            this.AddPlan(Plan.Constant(typeof(ushort), o));
                    }
                    else if (type.Equals(typeof(int)))
                    {
                        IntReader r = new IntReader();
                        foreach (object o in r.Read(fileName))
                            this.AddPlan(Plan.Constant(typeof(int), o));
                    }
                    else if (type.Equals(typeof(uint)))
                    {
                        UintReader r = new UintReader();
                        foreach (object o in r.Read(fileName))
                            this.AddPlan(Plan.Constant(typeof(uint), o));
                    }
                    else if (type.Equals(typeof(long)))
                    {
                        LongReader r = new LongReader();
                        foreach (object o in r.Read(fileName))
                            this.AddPlan(Plan.Constant(typeof(long), o));
                    }
                    else if (type.Equals(typeof(ulong)))
                    {
                        UlongReader r = new UlongReader();
                        foreach (object o in r.Read(fileName))
                            this.AddPlan(Plan.Constant(typeof(ulong), o));
                    }
                    else if (type.Equals(typeof(char)))
                    {
                        CharReader r = new CharReader();
                        foreach (object o in r.Read(fileName))
                            this.AddPlan(Plan.Constant(typeof(char), o));
                    }
                    else if (type.Equals(typeof(float)))
                    {
                        FloatReader r = new FloatReader();
                        foreach (object o in r.Read(fileName))
                            this.AddPlan(Plan.Constant(typeof(float), o));
                    }
                    else if (type.Equals(typeof(double)))
                    {
                        DoubleReader r = new DoubleReader();
                        foreach (object o in r.Read(fileName))
                            this.AddPlan(Plan.Constant(typeof(double), o));
                    }
                    else if (type.Equals(typeof(bool)))
                    {
                        BoolReader r = new BoolReader();
                        foreach (object o in r.Read(fileName))
                            this.AddPlan(Plan.Constant(typeof(bool), o));
                    }
                    else if (type.Equals(typeof(decimal)))
                    {
                        DecimalReader r = new DecimalReader();
                        foreach (object o in r.Read(fileName))
                            this.AddPlan(Plan.Constant(typeof(decimal), o));
                    }
                    else
                    {
                        if (!type.Equals(typeof(string)))
                        {
                            throw new Common.RandoopBareExceptions.InternalError("invalid simple type in XML config file.");
                        }
                        Common.StringReader r = new Common.StringReader();
                        foreach (object o in r.Read(fileName))
                            this.AddPlan(Plan.Constant(typeof(string), o));
                    }
                }
            }
        }