Пример #1
0
        public void RelationshipJoin()
        {
            RequiredDataContainer ModelData = VirtualMapDataProvider.VirtualMapModel();

            QueryableEntity Person = new QueryableEntity(ModelData.EntityRelationshipModel.FindByName("Person"));
            QueryableEntity Pet    = new QueryableEntity(ModelData.EntityRelationshipModel.FindByName("Pet"));

            RelationshipJoinOperator RJoinOp = new RelationshipJoinOperator(Person,
                                                                            (Relationship)ModelData.EntityRelationshipModel.FindByName("HasPet"),
                                                                            new List <QueryableEntity>()
            {
                Pet
            },
                                                                            ModelData.ERMongoMapping);

            VirtualMap    RJoinVMap       = RJoinOp.ComputeVirtualMap();
            List <string> VirtualMapRules = RJoinVMap.GetRulesAsStringList();

            Assert.IsNotNull(RJoinVMap, "Virtual map cannot be null");

            List <string> RulesToMatch = new List <string>()
            {
                "_id",
                "name",
                "age",
                "data_HasPet.Pet_petId",
                "data_HasPet.Pet_name",
                "data_HasPet.Pet_type",
                "data_HasPet.Pet_ownerId"
            };

            Assert.IsTrue(!VirtualMapRules.Except(RulesToMatch).Any() && !RulesToMatch.Except(VirtualMapRules).Any());
        }
Пример #2
0
        public void ProjectStageShowFields()
        {
            //RequiredDataContainer ModelData = VirtualMapDataProvider.VirtualMapModel();
            var ModelData = QueryBuilderParser.ParseMapping(Utils.ReadMappingFile("Mappings/virtual-map.mapping"));

            QueryableEntity Person = new QueryableEntity(ModelData.EntityRelationshipModel.FindByName("Person"));
            QueryableEntity Pet    = new QueryableEntity(ModelData.EntityRelationshipModel.FindByName("Pet"));

            RelationshipJoinOperator RJoinOp = new RelationshipJoinOperator(
                Person,
                (Relationship)ModelData.EntityRelationshipModel.FindByName("HasPet"),
                new List <QueryableEntity>()
            {
                Pet
            },
                ModelData.ERMongoMapping);

            VirtualMap RJoinVMap = RJoinOp.ComputeVirtualMap();

            Assert.IsNotNull(RJoinVMap, "RJOIN Virtual map cannot be null");

            List <ProjectArgument> ProjectArguments = new List <ProjectArgument>();

            ProjectArguments.Add(new ProjectArgument(Person.GetAttribute("name"), Person, new BooleanExpr(true)));
            ProjectArguments.Add(new ProjectArgument(Person.GetAttribute("age"), Person, new BooleanExpr(true)));
            ProjectArguments.Add(new ProjectArgument(Pet.GetAttribute("name"), Pet, new BooleanExpr(true)));

            ProjectStage ProjectOp = new ProjectStage(ProjectArguments, RJoinVMap);

            VirtualMap ProjectVirtualMap = ProjectOp.ComputeVirtualMap(RJoinVMap);

            Assert.IsNotNull(ProjectVirtualMap, "Project virtual map cannot be null");

            List <string> VirtualMapRules = ProjectVirtualMap.GetRulesAsStringList();

            List <string> RulesToMatch = new List <string>()
            {
                "name",
                "age",
                "data_HasPet.Pet_name",
            };

            Assert.IsTrue(!VirtualMapRules.Except(RulesToMatch).Any() && !RulesToMatch.Except(VirtualMapRules).Any(), "Virtual maps do not match");
        }
Пример #3
0
        public void ProjectComputedEntity()
        {
            // Asserts if the query result for a relationship join operation is equal
            // to a handcrafted query
            RequiredDataContainer ModelData = ProjectDataProvider.ComputedEntityData();

            // Load handcrafted query
            string HandcraftedQuery = Utils.ReadQueryFromFile("HandcraftedQueries/projectQuery.js");

            // Assert if the handcrafted query is not null
            Assert.IsNotNull(HandcraftedQuery);

            // Prepare query generator
            ComputedEntity CarRepairedByGarage = new ComputedEntity("CarManufacturedBy",
                                                                    new QueryableEntity((Entity)ModelData.EntityRelationshipModel.FindByName("Car"), "car"),
                                                                    (Relationship)ModelData.EntityRelationshipModel.FindByName("ManufacturedBy"),
                                                                    new List <QueryableEntity> {
                new QueryableEntity((Entity)ModelData.EntityRelationshipModel.FindByName("Manufacturer"), "manufacturer")
            });

            RelationshipJoinOperator RJoinOp = new RelationshipJoinOperator(
                new QueryableEntity((Entity)ModelData.EntityRelationshipModel.FindByName("Person"), "person"),
                (Relationship)ModelData.EntityRelationshipModel.FindByName("Owns"),
                new List <QueryableEntity> {
                new QueryableEntity(CarRepairedByGarage)
            },
                ModelData.ERMongoMapping);

            VirtualMap VMap = RJoinOp.ComputeVirtualMap();

            Dictionary <string, ProjectExpression> ProjectPersonAttrs = new Dictionary <string, ProjectExpression>();

            QueryableEntity Person       = new QueryableEntity(ModelData.EntityRelationshipModel.FindByName("Person"));
            QueryableEntity Car          = new QueryableEntity(ModelData.EntityRelationshipModel.FindByName("Car"));
            QueryableEntity Manufacturer = new QueryableEntity(ModelData.EntityRelationshipModel.FindByName("Manufacturer"));

            List <ProjectArgument> ProjectArguments = new List <ProjectArgument>();

            ProjectArguments.Add(new ProjectArgument(Person.GetAttribute("name"), Person, new BooleanExpr(true)));
            ProjectArguments.Add(new ProjectArgument(Car.GetAttribute("model"), Car, new BooleanExpr(true)));
            ProjectArguments.Add(new ProjectArgument(Car.GetAttribute("year"), Car, new BooleanExpr(true)));
            ProjectArguments.Add(new ProjectArgument(Manufacturer.GetAttribute("name"), Manufacturer, new BooleanExpr(true)));

            ProjectStage ProjectOp = new ProjectStage(ProjectArguments, VMap);

            List <AlgebraOperator> OpList = new List <AlgebraOperator> {
                RJoinOp, ProjectOp
            };
            FromArgument StartArg = new FromArgument(new QueryableEntity(ModelData.EntityRelationshipModel.FindByName("Person")),
                                                     ModelData.ERMongoMapping);

            QueryGenerator QueryGen = new QueryGenerator(StartArg, OpList);

            string GeneratedQuery = QueryGen.Run();

            // Assert if generated query is not null
            Assert.IsNotNull(GeneratedQuery);

            // Run Queries
            QueryRunner Runner = new QueryRunner("mongodb://localhost:27017", "ceManyToMany2");

            string HandcraftedResult = Runner.GetJSON(HandcraftedQuery);
            string GeneratedResult   = Runner.GetJSON(GeneratedQuery);

            // Check if either result is null
            Assert.IsNotNull(HandcraftedResult);
            Assert.IsNotNull(GeneratedResult);

            // Check if both results are equal
            Assert.IsTrue(JToken.DeepEquals(JToken.Parse(HandcraftedResult), JToken.Parse(GeneratedResult)));
        }
Пример #4
0
        public static void Main()
        {
            DataContainer data = CreateDataContainer();

            QueryableEntity Person = new QueryableEntity(data.EntityRelationshipModel.FindByName("Person"));
            QueryableEntity Car    = new QueryableEntity(data.EntityRelationshipModel.FindByName("Car"));
            Relationship    Drives = (Relationship)data.EntityRelationshipModel.FindByName("Drives");
            ModelMapping    Map    = data.ERMongoMapping;

            QueryableEntity Garage = new QueryableEntity(data.EntityRelationshipModel.FindByName("Garage"));

            RelationshipJoinOperator RJoinDrives = new RelationshipJoinOperator(
                Person,
                Drives,
                new List <QueryableEntity>()
            {
                Car
            },
                Map);

            CartesianProductOperator CartesianOp = new CartesianProductOperator(
                Person,
                Garage,
                Map);

            ProjectArgument ProjectArg1 = new ProjectArgument(Person.GetAttribute("name"), Person, new BooleanExpr(true));
            ProjectArgument ProjectArg2 = new ProjectArgument(Person.GetAttribute("surname"), Person, new BooleanExpr(true));
            ProjectArgument ProjectArg3 = new ProjectArgument(Car.GetAttribute("reg_no"), Car, new BooleanExpr(true));

            ProjectStage ProjectOp = new ProjectStage(new ProjectArgument[] { ProjectArg1, ProjectArg2, ProjectArg3 }, RJoinDrives.ComputeVirtualMap());

            MapRule        PersonRule = Map.FindMainRule(Person.Element);
            SelectArgument SelectArg  = new SelectArgument(new EqExpr($"${PersonRule.GetRuleValueForAttribute( Person.GetAttribute( "surname" ) )}", "Smith"));
            SelectStage    SelectOp   = new SelectStage(SelectArg, Map);

            //List<MongoDBOperator> Operations = RJoinDrives.Run().Commands;

            //foreach ( MongoDBOperator Op in Operations )
            //{
            //    Console.WriteLine( Op.GetType().Name );
            //    Console.WriteLine( Op.ToString() );
            //    Console.WriteLine( Op.ToJavaScript() );

            //    if ( Op is LookupOperator )
            //    {
            //        LookupOperator OpAsLookup = (LookupOperator)Op;
            //        foreach ( MongoDBOperator PipelineOp in OpAsLookup.Pipeline )
            //        {
            //            Console.WriteLine( PipelineOp.GetType().Name );
            //            Console.WriteLine( PipelineOp.ToString() );
            //            Console.WriteLine( PipelineOp.ToJavaScript() );
            //        }
            //    }
            //}

            QueryGenerator QueryGen = new QueryGenerator(new FromArgument(Person, Map), new List <AlgebraOperator>()
            {
                SelectOp
            });
            string Query = QueryGen.Run();

            Console.WriteLine($"Query: {Environment.NewLine}{Query}");

            Console.Read();
        }