public void ValidQueryTest()
 {
     var provider = new RecordParser(
         new JoinRecordProvider(
             new CollectionRecordProvider(
                 new[]
                 {
                     new Tuple<string, int, float>("aaa", 1, 2f),
                     new Tuple<string, int, float>("bbb", 2, 2f),
                     new Tuple<string, int, float>("bbb", 1, 3f),
                 }
                 ),
             new CollectionRecordProvider(
                 new[]
                 {
                     new Tuple<string, int, float>("aaa", 5, 7f),
                     new Tuple<string, int, float>("bbb", 6, 8f),
                 },
                 new[] {"mockString2", "mockInt2", "mockFloat2"}
                 ),
             "mockString",
             "mockString2"
             )
         );
     var data = provider.ParseData().ToArray();
     Assert.AreEqual(3, data.Count());
     Assert.AreEqual(5, (int) data[0]["mockInt2"]);
     Assert.AreEqual(6, (int) data[1]["mockInt2"]);
     Assert.AreEqual(6, (int) data[2]["mockInt2"]);
     Assert.AreEqual(2, (int) data[1]["mockInt"]);
     Assert.AreEqual(1, (int) data[2]["mockInt"]);
 }
 public void TestSingle()
 {
     var provider = new RecordParser(
         new LimitRecordProvider(5, new CollectionRecordProvider(new[]
         {
             new Tuple<string, int, float>("aaa", 1, 2.5f),
         })));
     Assert.AreEqual(provider.ParseData().Count(), 1);
 }
 public void TextBadFunc()
 {
     var provider = new RecordParser(
         new ComputedFieldProvider("computedField", ColumnType.Int, (data, bytes) => { throw new Exception(); },
         new CollectionRecordProvider(new[]
         {
             new Tuple<string, int, float>("aaa", 2, 2.5f),
         })));
     provider.ParseData();
 }
        public void TestSingle()
        {
            var provider = new RecordParser(
                new CountRecordProvider("mockString", "mockFloat", new CollectionRecordProvider(new[]
                {
                    new Tuple<string, int, float>("aaa", 1, 2.5f),
                })));
            Assert.AreEqual(provider.ParseData().Count(), 1);
            Assert.AreEqual((int)provider.ParseData().First()["count_of_mockFloat"], 1);

        }
        public void TestSingle()
        {
            var provider = new RecordParser(
                new UngroupedAverageProvider("mockFloat", new CollectionRecordProvider(new[]
                {
                    new Tuple<string, int, float>("aaa", 1, 2.5f),
                })));
            Assert.AreEqual(provider.ParseData().Count(), 1);
            Assert.AreEqual((float)provider.ParseData().First()["avg_of_mockFloat"], 2.5f);

        }
 public void MismatchedDataTypesTest()
 {
     var provider = new RecordParser(
         new JoinRecordProvider(
             new EmptyRecordProvider(),
             new EmptyRecordProvider(),
             "mockInt",
             "mockString"
             ));
     provider.ParseData();
 }
 public void NonExistentFieldTest()
 {
     var provider = new RecordParser(
         new JoinRecordProvider(
             new EmptyRecordProvider(),
             new EmptyRecordProvider(),
             "aaa",
             "mockString"
             ));
     provider.ParseData();
 }
 public void EmptyTest()
 {
     var provider = new RecordParser(
         new JoinRecordProvider(
             new EmptyRecordProvider(),
             new EmptyRecordProvider(),
             "mockString",
             "mockString"
             ));
     Assert.AreEqual(false, provider.ParseData().Any());
 }
 public void TestInt()
 {
     var provider = new RecordParser(
         new ComputedFieldProvider("computedField", ColumnType.Int, (data, bytes) => 3,
         new CollectionRecordProvider(new[]
         {
             new Tuple<string, int, float>("aaa", 2, 2.5f),
         })));
     Assert.AreEqual(provider.ParseData().Count(), 1);
     Assert.AreEqual((int)provider.ParseData().First()["computedField"], 3);
 }
 public void TestNoConstraints()
 {
     var provider = new RecordParser(
         new WhereRecordProvider(new CollectionRecordProvider(new[]
         {
             new Tuple<string, int, float>("aaa", 1, 1f),
             new Tuple<string, int, float>("aaa", 1, 2f),
             new Tuple<string, int, float>("bbb", 1, 1f),
             new Tuple<string, int, float>("bbb", 1, 4f),
         }), new List<IWhereQueryConstraint>()));
     Assert.AreEqual(4, provider.ParseData().Count());
 }
 public void TestHasNoResult()
 {
     var provider = new RecordParser(
         new WhereRecordProvider(new CollectionRecordProvider(new[]
         {
             new Tuple<string, int, float>("aaa", 1, 1f),
             new Tuple<string, int, float>("aaa", 1, 2f),
             new Tuple<string, int, float>("bbb", 1, 1f),
             new Tuple<string, int, float>("bbb", 1, 4f),
         }),
         new[] { new EqualityConstraint("mockString", "asd", new ByteConverter()), }));
     Assert.AreEqual(0, provider.ParseData().Count());
 }
 public void TestInvalid()
 {
     var provider = new RecordParser(
         new WhereRecordProvider(new CollectionRecordProvider(new[]
         {
             new Tuple<string, int, float>("aaa", 1, 1f),
             new Tuple<string, int, float>("aaa", 1, 2f),
             new Tuple<string, int, float>("bbb", 1, 1f),
             new Tuple<string, int, float>("bbb", 1, 4f),
         }), 
         new [] {new EqualityConstraint("asd", "asd", new ByteConverter()), }));
     provider.ParseData();
 }
 public void TestMultiple()
 {
     var provider = new RecordParser(
         new UngroupedAverageProvider("mockFloat", new CollectionRecordProvider(new[]
         {
             new Tuple<string, int, float>("aaa", 1, 1f),
             new Tuple<string, int, float>("aaa", 1, 2f),
             new Tuple<string, int, float>("bbb", 1, 1f),
             new Tuple<string, int, float>("bbb", 1, 4f),
         })));
     Assert.AreEqual(1, provider.ParseData().Count());
     Assert.AreEqual(2f, (float)provider.ParseData().First()["avg_of_mockFloat"]);
 }
        public void TestSingle()
        {
            var provider = new RecordParser(
                new SelectionRecordProvider( new [] {"mockString", "mockFloat"},
                new CollectionRecordProvider(new[]
                {
                    new Tuple<string, int, float>("aaa", 1, 2.5f),
                })));
            Assert.AreEqual(provider.ParseData().Count(), 1);
            Assert.AreEqual(2, provider.ParseData().First().Keys.Count);
            Assert.AreEqual(true, provider.ParseData().First().Keys.Contains("mockString"));
            Assert.AreEqual(true, provider.ParseData().First().Keys.Contains("mockFloat"));
            Assert.AreEqual((float)provider.ParseData().First()["mockFloat"], 2.5f);

        }
 public void TestMultiple()
 {
     var provider = new RecordParser(
         new LimitRecordProvider(3, new CollectionRecordProvider(new[]
         {
             new Tuple<string, int, float>("aaa", 1, 1f),
             new Tuple<string, int, float>("aaa", 1, 2f),
             new Tuple<string, int, float>("bbb", 1, 1f),
             new Tuple<string, int, float>("bbb", 1, 3f),
             new Tuple<string, int, float>("bbb", 1, 3f),
         })));
     Assert.AreEqual(3, provider.ParseData().Count());
     Assert.AreEqual("aaa", (string)provider.ParseData().First()["mockString"]);
     Assert.AreEqual("bbb", (string)provider.ParseData().Skip(2).First()["mockString"]);
     Assert.AreEqual(1f, (float)provider.ParseData().Skip(2).First()["mockFloat"]);
 }
 public void TestMultiple()
 {
     var provider = new RecordParser(
         new SelectionRecordProvider(new[] { "mockString", "mockFloat" },
         new CollectionRecordProvider(new[]
         {
             new Tuple<string, int, float>("aaa", 1, 2.5f),
             new Tuple<string, int, float>("bbb", 1, 2.5f),
             new Tuple<string, int, float>("ccc", 1, 2.5f),
             new Tuple<string, int, float>("ddd", 1, 2.5f),
         })));
     Assert.AreEqual(provider.ParseData().Count(), 4);
     Assert.AreEqual(2, provider.ParseData().First().Keys.Count);
     Assert.AreEqual(true, provider.ParseData().All( d => d.Keys.Contains("mockString")));
     Assert.AreEqual(true, provider.ParseData().All( d => d.Keys.Contains("mockFloat")));
 }
 public void TestSortByFloat()
 {
     var provider = new RecordParser(
         new SortingRecordProvider("mockFloat",
         new CollectionRecordProvider(new[]
         {
             new Tuple<string, int, float>("bbb", 1, -5f),
             new Tuple<string, int, float>("bab", 1, 3f),
             new Tuple<string, int, float>("ccc", 1, 4f),
             new Tuple<string, int, float>("aaa", 1, 5f),
         })));
     var results = provider.ParseData().ToArray();
     Assert.AreEqual(provider.ParseData().Count(), 4);
     Assert.AreEqual("bbb", (string)results[0]["mockString"]);
     Assert.AreEqual("bab", (string)results[1]["mockString"]);
     Assert.AreEqual("ccc", (string)results[2]["mockString"]);
     Assert.AreEqual("aaa", (string)results[3]["mockString"]);
 }
Example #18
0
        private async void RegionQuery()
        {
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();

            var averageQuery = new RecordParser(
                new UngroupedAverageProvider("cost",
                    new SelectionRecordProvider(new[] {"cost", "bnf_name"},
                        new OrderDatabaseReader("orders.dat", indexManager, QueryMode.Auto,
                            new List<IWhereQueryConstraint>
                            {
                                new ContainsQueryConstraint("bnf_name", "Flucloxacillin"),
                                new Not(new ContainsQueryConstraint("bnf_name", "Co-Fluampicil")),
                                new Not(new EqualityConstraint("bnf_name", "", byteConverter))
                            }))));
            float avg =  (float) (await GetUnformattedResultAsync(averageQuery)).First()["avg_of_cost"];
            Func<RecordMetaData, byte[], dynamic> differ = (recordMetaData, row) =>
            {
                float value = BitConverter.ToSingle(row, recordMetaData.ColumnDescriptors["avg_of_cost"].Offset);
                return value - avg;
            };
            var query =
                new ResultSetPrinter(
                    new RecordParser(
                        new ComputedFieldProvider("diff", ColumnType.Float, differ,
                            new AverageRecordProvider("region", "cost",
                                new WhereRecordProvider(
                                    new JoinRecordProvider(
                                        new SelectionRecordProvider(new List<string> {"cost", "practice", "bnf_name"},
                                            new OrderDatabaseReader("orders.dat", indexManager, QueryMode.Auto,
                                                new List<IWhereQueryConstraint>())),
                                        new SelectionRecordProvider(new List<string> {"id", "region"},
                                            new PracticeDatabaseReader("practices.dat", indexManager,
                                                new List<IWhereQueryConstraint>())),
                                        "practice",
                                        "id"),
                                    new List<IWhereQueryConstraint>
                                    {
                                        new ContainsQueryConstraint("bnf_name", "Flucloxacillin"),
                                        new Not(new ContainsQueryConstraint("bnf_name", "Co-Fluampicil")),
                                        new Not(new EqualityConstraint("bnf_name", "", byteConverter))
                                    })))));
            var results = await GetFormattedResultAsync(query);
            stopwatch.Stop();
            Output += $"{results}Time: {stopwatch.ElapsedMilliseconds} ms\n";
        }
Example #19
0
 private async Task<IEnumerable<IDictionary<string, dynamic>>> GetUnformattedResultAsync(RecordParser parser)
 {
     var task = new Task<IEnumerable<IDictionary<string, dynamic>>>(parser.ParseData);
     task.Start();
     return await task;
 }
 public void TestMultipleConstraints()
 {
     var provider = new RecordParser(
         new WhereRecordProvider(new CollectionRecordProvider(new[]
         {
             new Tuple<string, int, float>("aaa", 1, 1f),
             new Tuple<string, int, float>("aaa", 1, 2f),
             new Tuple<string, int, float>("bbb", 1, 1f),
             new Tuple<string, int, float>("bbb", 1, 4f),
         }),
         new[]
         {
             new EqualityConstraint("mockString", "aaa", new ByteConverter()), 
             new EqualityConstraint("mockFloat", 2f, new ByteConverter()), 
         }));
     Assert.AreEqual(1, provider.ParseData().Count());
     Assert.AreEqual(2f, (float)provider.ParseData().First()["mockFloat"]);
     Assert.AreEqual("aaa", (string)provider.ParseData().First()["mockString"]);
 }
Example #21
0
 private async void IndexedQuery()
 {
     var stopwatch = new Stopwatch();
     var reader = new RecordParser(new OrderDatabaseReader("orders.dat", indexManager, QueryMode.Auto,
         new List<IWhereQueryConstraint>
         {
             new StringEqualsConstraint("Practice", "A86001", byteConverter)
         }));
     stopwatch.Start();
     var results = await GetUnformattedResultAsync(reader);
     stopwatch.Stop();
     Output += $"Count: {results.Count()}, Time: {stopwatch.ElapsedMilliseconds} ms\n";
 }
Example #22
0
 public ResultSetPrinter(RecordParser parser)
 {
     this.parser = parser;
 }