Beispiel #1
0
        public void GetOutputStructure_WrongComponentTwoDatasetsJoinExpr_DurationScalarStructure(bool isMemership, TestExprType type)
        {
            foreach (string name in DatasetClauseOperator.ClauseNames.Where(name => !name.In("Pivot", "Unpivot", "Subspace")))
            {
                IExpression joinExpr            = ModelResolvers.JoinExprResolver(TestExprFactory.GetExpression("join", ExpressionFactoryNameTarget.OperatorSymbol));
                IExpression ds1Expr             = TestExprFactory.GetExpression("get", ExpressionFactoryNameTarget.OperatorSymbol);
                IExpression ds2Expr             = TestExprFactory.GetExpression("get", ExpressionFactoryNameTarget.OperatorSymbol);
                IExpression clauseExpr          = TestExprFactory.GetExpression(name, ExpressionFactoryNameTarget.ResultName);
                IExpression periodIndicatorExpr = TestExprFactory.GetExpression("period_indicator", ExpressionFactoryNameTarget.OperatorSymbol);
                IExpression paramExpr           = TestExprFactory.GetExpression(type);
                if (isMemership)
                {
                    paramExpr.OperatorDefinition = ModelResolvers.OperatorResolver("#");
                }

                joinExpr.AddOperand("ds", ModelResolvers.ExprResolver());
                joinExpr.Operands["ds"].AddOperand("ds_1", ds1Expr);
                joinExpr.Operands["ds"].AddOperand("ds_2", ds2Expr);
                joinExpr.AddOperand(name, clauseExpr);
                clauseExpr.AddOperand("ds_1", periodIndicatorExpr);
                periodIndicatorExpr.AddOperand("ds_1", paramExpr);

                ds1Expr.Structure = ModelResolvers.DsResolver();
                ds1Expr.Structure.Identifiers.Add(new StructureComponent(BasicDataType.Integer, "Id1"));
                ds1Expr.Structure.Identifiers.Add(new StructureComponent((BasicDataType)type, "Id2"));
                ds1Expr.Structure.Measures.Add(new StructureComponent(BasicDataType.String, "Me1"));
                ds2Expr.Structure = ds1Expr.Structure.GetCopy();

                Assert.ThrowsAny <VtlOperatorError>(() => { periodIndicatorExpr.OperatorDefinition.GetOutputStructure(periodIndicatorExpr); });
            }
        }
        public void Build_AggrAnalyticOperatorExpr_Expr()
        {
            List <string> opSymbols = new List <string>(AggrFunctionOperator.Symbols);

            opSymbols.AddRange(AnalyticFunctionOperator.Symbols);

            foreach (string opSymbol in opSymbols)
            {
                ApplyBranch applyBranch = new ApplyBranch(ModelResolvers.ExprResolver, this._exprTextGenerator);

                Mock <IOperatorDefinition> opDefMock = new Mock <IOperatorDefinition>();
                opDefMock.SetupGet(opDef => opDef.Symbol).Returns(opSymbol);
                opDefMock.Setup(opDef => opDef.GetOutputStructure(It.IsAny <IExpression>()))
                .Returns((IExpression expr) => { return(ModelResolvers.DsResolver()); });

                IExpression expr = TestExprFactory.GetExpression(opSymbol, ExpressionFactoryNameTarget.OperatorSymbol);
                expr.OperatorDefinition = opDefMock.Object;
                expr.AddOperand("ds", ModelResolvers.ExprResolver());
                expr.AddOperand("group", ModelResolvers.ExprResolver());
                expr.AddOperand("having", ModelResolvers.ExprResolver());
                expr.AddOperand("over", ModelResolvers.ExprResolver());

                IExpression result = applyBranch.Build(expr);

                Assert.NotNull(result.Structure);
                Assert.Equal("Generated text", result.ExpressionText);
                Assert.Equal("Apply", result.ResultName);
                Assert.Equal("apply", result.ParamSignature);
                Assert.Equal(expr.OperatorSymbol, result.OperatorSymbol);
                Assert.Equal(1, result.OperandsCollection.Count);
                Assert.True(result.Operands.ContainsKey("ds"));
            }
        }
        public void Constructor_JoinExpr_JoinExpr()
        {
            IExpression           expr    = TestExprFactory.GetExpression("join", ExpressionFactoryNameTarget.OperatorSymbol);
            IExpression           refExpr = ModelResolvers.ExprResolver();
            ITransformationSchema schema  = ModelResolvers.SchemaResolver();

            refExpr.AddOperand("ds", expr);
            expr.ContainingSchema    = schema;
            expr.ReferenceExpression = refExpr;

            IJoinExpression joinExpr2 = ModelResolvers.JoinExprResolver(expr);

            joinExpr2.BasicStructure = ModelResolvers.DsResolver();

            JoinExpression joinExpr = new JoinExpression(joinExpr2);

            Assert.Equal(expr.ParentExpression, joinExpr.ParentExpression);
            Assert.Equal(expr.ContainingSchema, joinExpr.ContainingSchema);
            Assert.Equal(expr.ExpressionText, joinExpr.ExpressionText);
            Assert.Equal(expr.LineNumber, joinExpr.LineNumber);
            Assert.Equal(expr.OperandsCollection, joinExpr.OperandsCollection);
            Assert.Equal(expr.OperatorDefinition, joinExpr.OperatorDefinition);
            Assert.Equal(expr.ParamSignature, joinExpr.ParamSignature);
            Assert.Equal(expr.ReferenceExpression, joinExpr.ReferenceExpression);
            Assert.Equal(expr.ResultName, joinExpr.ResultName);
            Assert.Equal(expr.Structure, joinExpr.Structure);
            Assert.Equal(joinExpr2.BasicStructure, joinExpr.BasicStructure);
        }
Beispiel #4
0
        public void GetOutputStructure_CorrectNoParamOneDatasetJoinExpr_DurationScalarStructure()
        {
            foreach (string name in DatasetClauseOperator.ClauseNames.Where(name => !name.In("Pivot", "Unpivot", "Subspace")))
            {
                IExpression joinExpr            = ModelResolvers.JoinExprResolver(TestExprFactory.GetExpression("join", ExpressionFactoryNameTarget.OperatorSymbol));
                IExpression datasetExpr         = TestExprFactory.GetExpression("get", ExpressionFactoryNameTarget.OperatorSymbol);
                IExpression clauseExpr          = TestExprFactory.GetExpression(name, ExpressionFactoryNameTarget.ResultName);
                IExpression periodIndicatorExpr = TestExprFactory.GetExpression("period_indicator", ExpressionFactoryNameTarget.OperatorSymbol);

                joinExpr.AddOperand("ds", ModelResolvers.ExprResolver());
                joinExpr.Operands["ds"].AddOperand("ds_1", datasetExpr);
                joinExpr.AddOperand(name, clauseExpr);
                clauseExpr.AddOperand("ds_1", periodIndicatorExpr);

                datasetExpr.Structure = ModelResolvers.DsResolver();
                datasetExpr.Structure.Identifiers.Add(new StructureComponent(BasicDataType.Integer, "Id1"));
                datasetExpr.Structure.Identifiers.Add(new StructureComponent(BasicDataType.TimePeriod, "Id2"));
                datasetExpr.Structure.Measures.Add(new StructureComponent(BasicDataType.String, "Me1"));

                IDataStructure expectedStructure = ModelResolvers.DsResolver("duration_var", ComponentType.Measure, BasicDataType.Duration);

                IDataStructure dataStructure = periodIndicatorExpr.OperatorDefinition.GetOutputStructure(periodIndicatorExpr);

                Assert.True(expectedStructure.EqualsObj(dataStructure));
            }
        }
        public void GetOutputStructure_GroupNScalarsExpr_DataStructure()
        {
            IJoinExpression joinExpr = ModelResolvers.JoinExprResolver(this._exprFac.GetExpression("join", ExpressionFactoryNameTarget.OperatorSymbol));

            for (int i = 3; i <= 5; i++) // very expensive
            {
                TestExprType[][] combinations = Enum.GetValues(typeof(TestExprType)).Cast <TestExprType>().Where(type => (int)type <= 8).GetCombinations(i);

                foreach (TestExprType[] combination in combinations)
                {
                    IExpression compCreateExpr = this._exprFac.GetExpression("group", ExpressionFactoryNameTarget.OperatorSymbol);
                    joinExpr.AddOperand("ds_1", compCreateExpr);

                    IDataStructure expectedStructure = ModelResolvers.DsResolver();
                    for (int k = 2; k <= i; k++)
                    {
                        IExpression idExpr = ModelResolvers.ExprResolver();
                        idExpr.ExpressionText = $"Id{k}";
                        idExpr.Structure      = ModelResolvers.DsResolver($"Id{k}", ComponentType.Identifier, (BasicDataType)combination[k - 1]);
                        compCreateExpr.AddOperand($"ds_{k}", idExpr);

                        expectedStructure.AddStructure(compCreateExpr.Operands[$"ds_{k}"].Structure);
                    }

                    IDataStructure dataStructure = compCreateExpr.OperatorDefinition.GetOutputStructure(compCreateExpr);

                    Assert.True(expectedStructure.EqualsObj(dataStructure));
                }
            }
        }
Beispiel #6
0
        public void GetOutputStructure_CorrectDatasetCollectionExpr_BoolScalarStructure()
        {
            foreach (string opSymbol in this._operators)
            {
                IExpression collectionExpr = ModelResolvers.ExprResolver();
                collectionExpr.Structure          = ModelResolvers.DsResolver();
                collectionExpr.OperatorDefinition = ModelResolvers.OperatorResolver("collection");
                collectionExpr.Structure.Measures.Add(new StructureComponent(BasicDataType.Integer));
                collectionExpr.Structure.Measures.Add(new StructureComponent(BasicDataType.Number));
                collectionExpr.Structure.Measures.Add(new StructureComponent(BasicDataType.None));

                IExpression inExpr = ModelResolvers.ExprResolver();
                inExpr.AddOperand("ds_1", TestExprFactory.GetExpression(TestExprType.NumbersDataset));
                inExpr.AddOperand("ds_2", collectionExpr);

                inExpr.Operands["ds_1"].Structure.Measures.RemoveAt(1);

                inExpr.OperatorDefinition = ModelResolvers.OperatorResolver(opSymbol);

                IExpression expected = TestExprFactory.GetExpression(TestExprType.BoolsDataset);
                expected.Structure.Measures.RemoveAt(1);

                IDataStructure dataStructure = inExpr.OperatorDefinition.GetOutputStructure(inExpr);

                Assert.True(expected.Structure.EqualsObj(dataStructure));
            }
        }
        public void GetOutputStructure_Group2ScalarsExpr_DataStructure(params TestExprType[] types)
        {
            IExpression compCreateExpr = this._exprFac.GetExpression("group", ExpressionFactoryNameTarget.OperatorSymbol);
            IExpression idExpr1        = ModelResolvers.ExprResolver();
            IExpression idExpr2        = ModelResolvers.ExprResolver();

            idExpr1.ExpressionText = "Id1";
            idExpr2.ExpressionText = "Id2";
            idExpr1.Structure      = ModelResolvers.DsResolver("Id1", ComponentType.Identifier, (BasicDataType)types[0]);
            idExpr2.Structure      = ModelResolvers.DsResolver("Id2", ComponentType.Identifier, (BasicDataType)types[1]);
            compCreateExpr.AddOperand("ds_1", idExpr1);
            compCreateExpr.AddOperand("ds_2", idExpr2);

            IJoinExpression joinExpr = ModelResolvers.JoinExprResolver(this._exprFac.GetExpression("join", ExpressionFactoryNameTarget.OperatorSymbol));

            joinExpr.AddOperand("ds_1", compCreateExpr);

            IDataStructure expectedStructure = compCreateExpr.Operands["ds_1"].Structure.GetCopy();

            expectedStructure.Identifiers.Add(compCreateExpr.Operands["ds_2"].Structure.GetCopy().Identifiers[0]);

            IDataStructure dataStructure = compCreateExpr.OperatorDefinition.GetOutputStructure(compCreateExpr);

            Assert.True(expectedStructure.EqualsObj(dataStructure));
        }
        public void Build_NotAggrAnalyticOperatorExpr_Expr(string opSymbol)
        {
            ApplyBranch applyBranch = new ApplyBranch(ModelResolvers.ExprResolver, this._exprTextGenerator);

            Mock <IOperatorDefinition> opDefMock = new Mock <IOperatorDefinition>();

            opDefMock.SetupGet(opDef => opDef.Symbol).Returns(opSymbol);
            opDefMock.Setup(opDef => opDef.GetOutputStructure(It.IsAny <IExpression>()))
            .Returns((IExpression expr) => { return(ModelResolvers.DsResolver()); });

            IExpression expr = TestExprFactory.GetExpression(opSymbol, ExpressionFactoryNameTarget.OperatorSymbol);

            expr.OperatorDefinition = opDefMock.Object;
            expr.AddOperand("ds", ModelResolvers.ExprResolver());
            expr.AddOperand("group", ModelResolvers.ExprResolver());
            expr.AddOperand("having", ModelResolvers.ExprResolver());
            expr.AddOperand("over", ModelResolvers.ExprResolver());

            IExpression result = applyBranch.Build(expr);

            Assert.NotNull(result.Structure);
            Assert.Equal("Generated text", result.ExpressionText);
            Assert.Equal("Apply", result.ResultName);
            Assert.Equal("apply", result.ParamSignature);
            Assert.Equal(expr.OperatorSymbol, result.OperatorSymbol);
            Assert.Equal(expr.OperandsCollection.Count, result.OperandsCollection.Count);

            for (int i = 0; i < expr.OperandsCollection.Count; i++)
            {
                Assert.Equal(expr.OperandsCollection.ToArray()[i].ParamSignature, result.OperandsCollection.ToArray()[i].ParamSignature);
            }
        }
Beispiel #9
0
        public void Build_Expr_Expr(params string[] opSymbols)
        {
            DsBranch dsBranch = new DsBranch(this._exprFac, this._exprTextGenerator);

            IExpression expr     = ModelResolvers.ExprResolver();
            IExpression expected = ModelResolvers.ExprResolver();

            for (int i = 0; i < opSymbols.Length; i++)
            {
                IExpression subExpr = this._exprFac.GetExpression(opSymbols[i], ExpressionFactoryNameTarget.OperatorSymbol); // local expFactory expected
                subExpr.Structure      = ModelResolvers.DsResolver();
                subExpr.ExpressionText = opSymbols[i];

                expr.AddOperand($"ds_{i}", subExpr);
                if (opSymbols[i].In("get", "ref", "#", "join"))
                {
                    expected.AddOperand($"ds_{i}", subExpr);
                }
            }

            IExpression result = dsBranch.Build(expr);

            Assert.Equal(expected.OperandsCollection.Count, result.OperandsCollection.Count);

            foreach (string opSymbol in opSymbols.Where(opS => opS.In("get", "ref", "#", "join")))
            {
                Assert.True(result.OperandsCollection.Where(op => op.OperatorSymbol == opSymbol).Count() == 1);
            }
        }
Beispiel #10
0
        public void Structure_IsSingleComponentTrue_IsScalarTrue()
        {
            Expression expr = new Expression();

            expr.Structure = ModelResolvers.DsResolver("comp", ComponentType.Measure, BasicDataType.Integer);

            Assert.True(expr.IsScalar);
        }
Beispiel #11
0
        public void Structure_IsSingleComponentFalse_IsScalarFalse()
        {
            Expression expr = new Expression();

            expr.Structure = ModelResolvers.DsResolver("comp1", ComponentType.Measure, BasicDataType.Integer);
            expr.Structure.Measures.Add(new StructureComponent(BasicDataType.Boolean, "comp2"));

            Assert.False(expr.IsScalar);
        }
        public void AddMainExpr_ScalarExpr_ThrowsException()
        {
            JoinBuilder joinBuilder = new JoinBuilder(ModelResolvers.JoinExprResolver, this.joinBranches);

            IExpression mainExpr = TestExprFactory.GetExpression("+", ExpressionFactoryNameTarget.OperatorSymbol);

            mainExpr.ResultName = "main";
            mainExpr.Structure  = ModelResolvers.DsResolver();
            mainExpr.Structure.Measures.Add(new StructureComponent(BasicDataType.Integer));

            Assert.ThrowsAny <Exception>(() => { joinBuilder.AddMainExpr(mainExpr); });
        }
        private ICollection <IRuleExpression> GetRuleExpressions(IRuleset ruleset)
        {
            IRuleExpression expr1_1 = ModelResolvers.RuleExprResolver(TestExprFactory.GetExpression("comp", ExpressionFactoryNameTarget.OperatorSymbol), ruleset);
            IRuleExpression expr1_2 = ModelResolvers.RuleExprResolver(TestExprFactory.GetExpression("comp", ExpressionFactoryNameTarget.OperatorSymbol), ruleset);
            IRuleExpression expr2_1 = ModelResolvers.RuleExprResolver(TestExprFactory.GetExpression("comp", ExpressionFactoryNameTarget.OperatorSymbol), ruleset);
            IRuleExpression expr2_2 = ModelResolvers.RuleExprResolver(TestExprFactory.GetExpression("comp", ExpressionFactoryNameTarget.OperatorSymbol), ruleset);
            IRuleExpression expr3_1 = ModelResolvers.RuleExprResolver(TestExprFactory.GetExpression("comp", ExpressionFactoryNameTarget.OperatorSymbol), ruleset);
            IRuleExpression expr3_2 = ModelResolvers.RuleExprResolver(TestExprFactory.GetExpression("comp", ExpressionFactoryNameTarget.OperatorSymbol), ruleset);
            IRuleExpression expr4_1 = ModelResolvers.RuleExprResolver(TestExprFactory.GetExpression("comp", ExpressionFactoryNameTarget.OperatorSymbol), ruleset);
            IRuleExpression expr4_2 = ModelResolvers.RuleExprResolver(TestExprFactory.GetExpression("comp", ExpressionFactoryNameTarget.OperatorSymbol), ruleset);

            expr1_1.Structure = ModelResolvers.DsResolver("x", ComponentType.Measure, BasicDataType.Integer);
            expr1_2.Structure = ModelResolvers.DsResolver("x", ComponentType.Measure, BasicDataType.Integer);
            expr2_1.Structure = ModelResolvers.DsResolver("y", ComponentType.Measure, BasicDataType.Integer);
            expr2_2.Structure = ModelResolvers.DsResolver("y", ComponentType.Measure, BasicDataType.Number);
            expr3_1.Structure = ModelResolvers.DsResolver("z", ComponentType.Measure, BasicDataType.String);
            expr3_2.Structure = ModelResolvers.DsResolver("z", ComponentType.Measure, BasicDataType.None);
            expr4_2.Structure = ModelResolvers.DsResolver("var4", ComponentType.Measure, BasicDataType.None);
            expr4_1.Structure = ModelResolvers.DsResolver("var4", ComponentType.Measure, BasicDataType.None);

            expr1_1.ExpressionText = "x";
            expr1_2.ExpressionText = "x";
            expr2_1.ExpressionText = "y";
            expr2_2.ExpressionText = "y";
            expr3_1.ExpressionText = "z";
            expr3_2.ExpressionText = "z";
            expr4_2.ExpressionText = "var4";
            expr4_1.ExpressionText = "var4";

            expr1_1.ResultName += "1_1";
            expr1_2.ResultName += "1_2";
            expr2_1.ResultName += "2_1";
            expr2_2.ResultName += "2_2";
            expr3_1.ResultName += "3_1";
            expr3_2.ResultName += "3_2";
            expr4_2.ResultName += "4_1";
            expr4_1.ResultName += "4_2";

            List <IRuleExpression> ruleExprs = new List <IRuleExpression>();

            ruleExprs.Add(expr1_1);
            ruleExprs.Add(expr1_2);
            ruleExprs.Add(expr2_1);
            ruleExprs.Add(expr2_2);
            ruleExprs.Add(expr3_1);
            ruleExprs.Add(expr3_2);
            ruleExprs.Add(expr4_1);
            ruleExprs.Add(expr4_2);

            return(ruleExprs);
        }
Beispiel #14
0
        public void GetOutputStructure_WrongDatasetParamExpr_ThrowsException(TestExprType type)
        {
            IExpression periodIndicatorExpr = TestExprFactory.GetExpression("period_indicator", ExpressionFactoryNameTarget.OperatorSymbol);
            IExpression datasetExpr         = TestExprFactory.GetExpression("get", ExpressionFactoryNameTarget.OperatorSymbol);

            periodIndicatorExpr.AddOperand("ds_1", datasetExpr);

            datasetExpr.Structure = ModelResolvers.DsResolver();
            datasetExpr.Structure.Identifiers.Add(new StructureComponent(BasicDataType.Integer, "Id1"));
            datasetExpr.Structure.Identifiers.Add(new StructureComponent((BasicDataType)type, "Id2"));
            datasetExpr.Structure.Measures.Add(new StructureComponent(BasicDataType.String, "Me1"));

            Assert.ThrowsAny <VtlOperatorError>(() => { periodIndicatorExpr.OperatorDefinition.GetOutputStructure(periodIndicatorExpr); });
        }
        public void GetOutputStructure_CorrectScalars_DataStructure(params TestExprType[] types)
        {
            IExpression collectionExpr = TestExprFactory.GetExpression(types);

            collectionExpr.OperatorDefinition = ModelResolvers.OperatorResolver("collection");

            IDataStructure expected = ModelResolvers.DsResolver();

            expected.Measures.Add(new StructureComponent((BasicDataType)types[0]));
            expected.Measures.Add(new StructureComponent((BasicDataType)types[1]));

            IDataStructure dataStructure = collectionExpr.OperatorDefinition.GetOutputStructure(collectionExpr);

            Assert.True(expected.EqualsObj(dataStructure));
        }
Beispiel #16
0
        public void GetOutputStructure_NoTimeIdentifiersExpr_ThrowsException(string symbol, BasicDataType type)
        {
            IExpression timeExpr = ModelResolvers.ExprResolver();

            timeExpr.OperatorDefinition = ModelResolvers.OperatorResolver(symbol);

            IExpression timeDsExpr = ModelResolvers.ExprResolver();

            timeDsExpr.Structure = ModelResolvers.DsResolver("Id1", ComponentType.Identifier, type);
            timeDsExpr.Structure.Identifiers.Add(new StructureComponent(BasicDataType.Integer, "Id2"));

            timeExpr.AddOperand("ds_1", timeDsExpr);

            Assert.ThrowsAny <VtlOperatorError>(() => { timeExpr.OperatorDefinition.GetOutputStructure(timeExpr); });
        }
        public void Build_Expr_Expr()
        {
            UsingBranch usingBranch = new UsingBranch(this._exprFac);

            IExpression     expr     = TestExprFactory.GetExpression("join", ExpressionFactoryNameTarget.OperatorSymbol);
            IJoinExpression joinExpr = ModelResolvers.JoinExprResolver(expr);

            IExpression ds1Expr = TestExprFactory.GetExpression("get", ExpressionFactoryNameTarget.OperatorSymbol);

            ds1Expr.Structure = ModelResolvers.DsResolver();
            ds1Expr.Structure.Identifiers.Add(new StructureComponent(BasicDataType.Integer, "Id1"));
            ds1Expr.Structure.Identifiers.Add(new StructureComponent(BasicDataType.Boolean, "Id2"));

            IExpression ds2Expr = TestExprFactory.GetExpression("get", ExpressionFactoryNameTarget.OperatorSymbol);

            ds2Expr.Structure = ModelResolvers.DsResolver();
            ds2Expr.Structure.Identifiers.Add(new StructureComponent(BasicDataType.Integer, "Id1"));
            ds2Expr.Structure.Identifiers.Add(new StructureComponent(BasicDataType.Boolean, "Id2"));
            ds2Expr.Structure.Identifiers.Add(new StructureComponent(BasicDataType.String, "Id3"));

            IExpression dsBranch = ModelResolvers.ExprResolver();

            dsBranch.AddOperand("ds_1", ds1Expr);
            dsBranch.AddOperand("ds_2", ds2Expr);

            joinExpr.AddOperand("ds", dsBranch);

            IExpression expected = TestExprFactory.GetExpression("Using", ExpressionFactoryNameTarget.ResultName);

            expected.ParamSignature = "using";
            expected.ExpressionText = "using Id1, Id2";

            IExpression expected_1 = ModelResolvers.ExprResolver();
            IExpression expected_2 = ModelResolvers.ExprResolver();

            expected_1.ExpressionText = "Id1";
            expected_2.ExpressionText = "Id2";

            expected.AddOperand("Id1", expected_1);
            expected.AddOperand("Id2", expected_2);

            IExpression result = usingBranch.Build(joinExpr);

            Assert.Equal(expected.OperandsCollection.Count, result.OperandsCollection.Count);
            Assert.Equal(expected.Operands["Id1"].ExpressionText, result.Operands["Id1"].ExpressionText);
            Assert.Equal(expected.Operands["Id2"].ExpressionText, result.Operands["Id2"].ExpressionText);
            Assert.Equal(expected.ExpressionText, result.ExpressionText);
        }
Beispiel #18
0
        public void GetOutputStructure_1TimeIdentifierExpr_DataStructure(string symbol, BasicDataType timeType)
        {
            IExpression timeExpr = ModelResolvers.ExprResolver();

            timeExpr.OperatorDefinition = ModelResolvers.OperatorResolver(symbol);

            IExpression timeDsExpr = ModelResolvers.ExprResolver();

            timeDsExpr.Structure = ModelResolvers.DsResolver("Id1", ComponentType.Identifier, timeType);
            timeDsExpr.Structure.Identifiers.Add(new StructureComponent(BasicDataType.Integer, "Id2"));

            timeExpr.AddOperand("ds_1", timeDsExpr);

            IDataStructure dataStructure = timeExpr.OperatorDefinition.GetOutputStructure(timeExpr);

            Assert.True(timeDsExpr.Structure.EqualsObj(dataStructure));
        }
Beispiel #19
0
        public void Build_Expr_Expr()
        {
            RenameBranch renameBranch = new RenameBranch(this._exprFac, this._exprTextGenerator);

            IExpression expr = TestExprFactory.GetExpression("=", ExpressionFactoryNameTarget.OperatorSymbol);

            expr.LineNumber = 10;
            expr.Structure  = ModelResolvers.DsResolver("Me1", ComponentType.Measure, BasicDataType.Boolean);
            expr.Structure.Measures[0].BaseComponentName = "Me1_v2";

            IExpression expected     = TestExprFactory.GetExpression("rename", ExpressionFactoryNameTarget.OperatorSymbol);
            IExpression expected_1   = TestExprFactory.GetExpression("renameExpr", ExpressionFactoryNameTarget.OperatorSymbol);
            IExpression expected_1_1 = TestExprFactory.GetExpression("comp", ExpressionFactoryNameTarget.OperatorSymbol);
            IExpression expected_1_2 = TestExprFactory.GetExpression("comp", ExpressionFactoryNameTarget.OperatorSymbol);

            expected_1_1.ExpressionText = "Me1_v2";
            expected_1_2.ExpressionText = "Me1";

            expected.LineNumber     = expr.LineNumber;
            expected_1.LineNumber   = expr.LineNumber;
            expected_1_1.LineNumber = expr.LineNumber;
            expected_1_2.LineNumber = expr.LineNumber;

            expected.AddOperand("ds_1", expected_1);
            expected_1.AddOperand("ds_1", expected_1_1);
            expected_1.AddOperand("ds_2", expected_1_2);

            IExpression result = renameBranch.Build(expr);

            Assert.Equal(expected.OperandsCollection.Count, result.OperandsCollection.Count);
            Assert.Equal(expected.Operands["ds_1"].OperandsCollection.Count, result.Operands["ds_1"].OperandsCollection.Count);

            Assert.Equal(expected.OperatorSymbol, result.OperatorSymbol);
            Assert.Equal(expected.Operands["ds_1"].OperatorSymbol, result.Operands["ds_1"].OperatorSymbol);

            Assert.Equal(expected.Operands["ds_1"].Operands["ds_1"].OperatorSymbol, result.Operands["ds_1"].Operands["ds_1"].OperatorSymbol);
            Assert.Equal(expected.Operands["ds_1"].Operands["ds_2"].OperatorSymbol, result.Operands["ds_1"].Operands["ds_2"].OperatorSymbol);

            Assert.Equal(expected.Operands["ds_1"].Operands["ds_1"].ExpressionText, result.Operands["ds_1"].Operands["ds_1"].ExpressionText);
            Assert.Equal(expected.Operands["ds_1"].Operands["ds_2"].ExpressionText, result.Operands["ds_1"].Operands["ds_2"].ExpressionText);

            Assert.Equal(expected.LineNumber, result.LineNumber);
            Assert.Equal(expected.Operands["ds_1"].LineNumber, result.Operands["ds_1"].LineNumber);
            Assert.Equal(expected.Operands["ds_1"].Operands["ds_1"].LineNumber, result.Operands["ds_1"].Operands["ds_1"].LineNumber);
            Assert.Equal(expected.Operands["ds_1"].Operands["ds_2"].LineNumber, result.Operands["ds_1"].Operands["ds_2"].LineNumber);
        }
        public void AddMainExpr_JoinExpr_AddsMainExpr()
        {
            JoinBuilder joinBuilder = new JoinBuilder(ModelResolvers.JoinExprResolver, this.joinBranches);

            IExpression mainExpr = TestExprFactory.GetExpression("join", ExpressionFactoryNameTarget.OperatorSymbol);

            mainExpr.ResultName = "main";
            mainExpr.Structure  = ModelResolvers.DsResolver();
            mainExpr.Structure.Identifiers.Add(new StructureComponent(BasicDataType.Integer));
            mainExpr.Structure.Measures.Add(new StructureComponent(BasicDataType.Integer));

            joinBuilder.AddMainExpr(mainExpr);

            Assert.Equal(mainExpr.ResultName, joinBuilder.Branches["main"].ResultName);
            Assert.Equal(mainExpr.OperatorSymbol, joinBuilder.Branches["main"].OperatorSymbol);
            Assert.True(mainExpr.Structure.EqualsObj(joinBuilder.Branches["main"].Structure));
            Assert.False(joinBuilder.IsCleared);
        }
Beispiel #21
0
        public void GetOutputStructure_RenameComponentExpr_DataStructure(ComponentType compType)
        {
            IExpression renameExpr  = ModelResolvers.ExprResolver();
            IExpression compExpr    = ModelResolvers.ExprResolver();
            IExpression oldCompExpr = ModelResolvers.ExprResolver();

            compExpr.ExpressionText       = "component";
            compExpr.OperatorDefinition   = ModelResolvers.OperatorResolver("comp");
            oldCompExpr.Structure         = ModelResolvers.DsResolver("oldComponent", compType, BasicDataType.Integer);
            renameExpr.OperatorDefinition = ModelResolvers.OperatorResolver("renameExpr");
            renameExpr.AddOperand("ds_1", oldCompExpr);
            renameExpr.AddOperand("ds_2", compExpr);

            IDataStructure dataStructure = compExpr.OperatorDefinition.GetOutputStructure(compExpr);

            Assert.True(dataStructure.IsSingleComponent);
            Assert.True(oldCompExpr.Structure.Components[0].EqualsObj(dataStructure.Components[0]));
        }
        public void AddMainExpr_NonScalarConvertableToJoinExpr_AddsMainExpr()
        {
            JoinBuilder joinBuilder = new JoinBuilder(ModelResolvers.JoinExprResolver, this.joinBranches);

            foreach (string symbol in JoinOperators.Operators)
            {
                IExpression mainExpr = TestExprFactory.GetExpression(symbol, ExpressionFactoryNameTarget.OperatorSymbol);
                mainExpr.ResultName = "main";
                mainExpr.Structure  = ModelResolvers.DsResolver();
                mainExpr.Structure.Identifiers.Add(new StructureComponent(BasicDataType.Integer));
                mainExpr.Structure.Measures.Add(new StructureComponent(BasicDataType.Integer));

                joinBuilder.AddMainExpr(mainExpr);

                Assert.Equal(mainExpr, joinBuilder.Branches["main"]);
                Assert.False(joinBuilder.IsCleared);
            }
        }
        public void GetSupersetAliasStructure_SupersetStructure()
        {
            for (int i = 0; i < 2; i++)
            {
                JoinExpression joinExpr = new JoinExpression(TestExprFactory.GetExpression("join", ExpressionFactoryNameTarget.OperatorSymbol));
                joinExpr.AddOperand("ds", ModelResolvers.ExprResolver());

                IExpression expr1 = ModelResolvers.ExprResolver();
                expr1.Structure = ModelResolvers.DsResolver();
                expr1.Structure.Identifiers.Add(new StructureComponent(BasicDataType.Integer, "Id1"));
                expr1.Structure.Identifiers.Add(new StructureComponent(BasicDataType.String, "Id2"));

                IExpression expr2 = ModelResolvers.ExprResolver();
                expr2.Structure = ModelResolvers.DsResolver();
                expr2.Structure.Identifiers.Add(new StructureComponent(BasicDataType.Integer, "Id1"));
                expr2.Structure.Identifiers.Add(new StructureComponent(BasicDataType.String, "Id2"));

                joinExpr.Operands["ds"].AddOperand("ds_1", expr1);
                joinExpr.Operands["ds"].AddOperand("ds_2", expr2);

                IExpression expr3 = ModelResolvers.ExprResolver();
                if (i == 1)
                {
                    expr3.Structure = ModelResolvers.DsResolver();
                    expr3.Structure.Identifiers.Add(new StructureComponent(BasicDataType.Integer, "Id1"));
                    expr3.Structure.Identifiers.Add(new StructureComponent(BasicDataType.String, "Id2"));
                    expr3.Structure.Identifiers.Add(new StructureComponent(BasicDataType.Number, "Id3"));
                    joinExpr.Operands["ds"].AddOperand("ds_3", expr3);
                }

                IDataStructure result = joinExpr.GetSupersetAliasStructure();

                if (i == 0)
                {
                    Assert.True(expr1.Structure.EqualsObj(result));
                }
                else
                {
                    Assert.True(expr3.Structure.EqualsObj(result));
                }
            }
        }
Beispiel #24
0
        public void GetOutputStructure_MoreThan1TimeIdentifierExpr_ThrowsException(string symbol, params BasicDataType[] timeTypes)
        {
            IExpression timeExpr = ModelResolvers.ExprResolver();

            timeExpr.OperatorDefinition = ModelResolvers.OperatorResolver(symbol);

            IExpression timeDsExpr = ModelResolvers.ExprResolver();

            timeDsExpr.Structure = ModelResolvers.DsResolver();

            for (int i = 0; i < timeTypes.Length; i++)
            {
                timeDsExpr.Structure.Identifiers.Add(new StructureComponent(timeTypes[i], $"Id{i + 1}"));
            }

            timeDsExpr.Structure.Identifiers.Add(new StructureComponent(BasicDataType.Integer, $"Id{timeTypes.Length}"));
            timeExpr.AddOperand("ds_1", timeDsExpr);

            Assert.ThrowsAny <VtlOperatorError>(() => { timeExpr.OperatorDefinition.GetOutputStructure(timeExpr); });
        }
        public void InferStructure_ValueDomainRuleset_AssignsStructure()
        {
            DatapointRuleset ruleset = this.GetValueDomainRuleset();

            IDataStructure expectedStructure = ModelResolvers.DsResolver();

            expectedStructure.Measures.Add(new StructureComponent(BasicDataType.None, "var4"));
            expectedStructure.Measures.Add(new StructureComponent(BasicDataType.Integer, "x"));
            expectedStructure.Measures.Add(new StructureComponent(BasicDataType.Integer, "y"));
            expectedStructure.Measures.Add(new StructureComponent(BasicDataType.String, "z"));

            ruleset.InferStructure();
            IDataStructure dataStructure = ruleset.Structure;

            Assert.True(expectedStructure.EqualsObj(dataStructure));
            Assert.Equal(expectedStructure.Measures[0].ComponentName, dataStructure.Measures[0].ComponentName);
            Assert.Equal(expectedStructure.Measures[1].ComponentName, dataStructure.Measures[1].ComponentName);
            Assert.Equal(expectedStructure.Measures[2].ComponentName, dataStructure.Measures[2].ComponentName);
            Assert.Equal(expectedStructure.Measures[3].ComponentName, dataStructure.Measures[3].ComponentName);
        }
Beispiel #26
0
        public void GetOutputStructure_CorrectDatasetParamExpr_DurationScalarStructure()
        {
            IExpression periodIndicatorExpr = TestExprFactory.GetExpression("period_indicator", ExpressionFactoryNameTarget.OperatorSymbol);
            IExpression datasetExpr         = TestExprFactory.GetExpression("get", ExpressionFactoryNameTarget.OperatorSymbol);

            periodIndicatorExpr.AddOperand("ds_1", datasetExpr);

            datasetExpr.Structure = ModelResolvers.DsResolver();
            datasetExpr.Structure.Identifiers.Add(new StructureComponent(BasicDataType.Integer, "Id1"));
            datasetExpr.Structure.Identifiers.Add(new StructureComponent(BasicDataType.TimePeriod, "Id2"));
            datasetExpr.Structure.Measures.Add(new StructureComponent(BasicDataType.String, "Me1"));

            IDataStructure expectedStructure = datasetExpr.Structure.GetCopy();

            expectedStructure.Measures[0] = new StructureComponent(BasicDataType.Duration, "duration_var");

            IDataStructure dataStructure = periodIndicatorExpr.OperatorDefinition.GetOutputStructure(periodIndicatorExpr);

            Assert.True(expectedStructure.EqualsObj(dataStructure));
        }
        public void GetSupersetAlias_Exprs_SupersetExpr()
        {
            for (int i = 0; i < 2; i++)
            {
                List <IExpression> exprs = new List <IExpression>();

                IExpression expr1 = ModelResolvers.ExprResolver();
                expr1.Structure = ModelResolvers.DsResolver();
                expr1.Structure.Identifiers.Add(new StructureComponent(BasicDataType.Integer, "Id1"));
                expr1.Structure.Identifiers.Add(new StructureComponent(BasicDataType.String, "Id2"));

                IExpression expr2 = ModelResolvers.ExprResolver();
                expr2.Structure = ModelResolvers.DsResolver();
                expr2.Structure.Identifiers.Add(new StructureComponent(BasicDataType.Integer, "Id1"));
                expr2.Structure.Identifiers.Add(new StructureComponent(BasicDataType.String, "Id2"));

                exprs.Add(expr1);
                exprs.Add(expr2);

                IExpression expr3 = ModelResolvers.ExprResolver();
                if (i == 1)
                {
                    expr3.Structure = ModelResolvers.DsResolver();
                    expr3.Structure.Identifiers.Add(new StructureComponent(BasicDataType.Integer, "Id1"));
                    expr3.Structure.Identifiers.Add(new StructureComponent(BasicDataType.String, "Id2"));
                    expr3.Structure.Identifiers.Add(new StructureComponent(BasicDataType.Number, "Id3"));
                    exprs.Add(expr3);
                }

                IExpression result = JoinExpression.GetSupersetAlias(exprs);

                if (i == 0)
                {
                    Assert.Equal(expr1, result);
                }
                else
                {
                    Assert.Equal(expr3, result);
                }
            }
        }
        public void GetSupersetAlias_ExprsNoSupersetExpr_Null()
        {
            List <IExpression> exprs = new List <IExpression>();

            IExpression expr1 = ModelResolvers.ExprResolver();

            expr1.Structure = ModelResolvers.DsResolver();
            expr1.Structure.Identifiers.Add(new StructureComponent(BasicDataType.Integer, "Id1"));
            expr1.Structure.Identifiers.Add(new StructureComponent(BasicDataType.String, "Id2"));

            IExpression expr2 = ModelResolvers.ExprResolver();

            expr2.Structure = ModelResolvers.DsResolver();
            expr2.Structure.Identifiers.Add(new StructureComponent(BasicDataType.Integer, "Id1"));
            expr2.Structure.Identifiers.Add(new StructureComponent(BasicDataType.String, "Id3"));

            exprs.Add(expr1);
            exprs.Add(expr2);

            Assert.Null(JoinExpression.GetSupersetAlias(exprs));
        }
Beispiel #29
0
        public void GetOutputStructure_WrongNoParamDatasetClauseExpr_ThrowsException(BasicDataType type)
        {
            foreach (string name in DatasetClauseOperator.ClauseNames)
            {
                IExpression datasetClauseExpr   = ModelResolvers.ExprResolver();
                IExpression datasetExpr         = ModelResolvers.ExprResolver();
                IExpression clauseExpr          = TestExprFactory.GetExpression(name, ExpressionFactoryNameTarget.ResultName);
                IExpression periodIndicatorExpr = TestExprFactory.GetExpression("period_indicator", ExpressionFactoryNameTarget.OperatorSymbol);

                datasetClauseExpr.AddOperand("ds_1", datasetExpr);
                datasetClauseExpr.AddOperand("ds_2", clauseExpr);
                clauseExpr.AddOperand("ds_1", periodIndicatorExpr);

                datasetExpr.Structure = ModelResolvers.DsResolver();
                datasetExpr.Structure.Identifiers.Add(new StructureComponent(BasicDataType.Integer, "Id1"));
                datasetExpr.Structure.Identifiers.Add(new StructureComponent(type, "Id2"));
                datasetExpr.Structure.Measures.Add(new StructureComponent(BasicDataType.String, "Me1"));

                Assert.ThrowsAny <VtlOperatorError>(() => { periodIndicatorExpr.OperatorDefinition.GetOutputStructure(periodIndicatorExpr); });
            }
        }
Beispiel #30
0
        public void GetOutputStructure_Correct2Operands()
        {
            IExpression expr = ModelResolvers.ExprResolver();

            expr.OperatorDefinition = ModelResolvers.OperatorResolver("sub");

            IExpression operand1 = TestExprFactory.GetDatasetExpr(new KeyValuePair <ComponentType, BasicDataType>(ComponentType.Identifier, BasicDataType.Integer));
            IExpression operand2 = TestExprFactory.GetDatasetExpr(new KeyValuePair <ComponentType, BasicDataType>(ComponentType.Identifier, BasicDataType.String));

            expr.AddOperand("ds_1", operand1);
            expr.AddOperand("ds_2", operand2);

            IDataStructure operandCollection = ModelResolvers.DsResolver();

            operandCollection.AddStructure(operand1.Structure);
            operandCollection.AddStructure(operand2.Structure);

            IDataStructure dataStructure = expr.OperatorDefinition.GetOutputStructure(expr);

            Assert.True(operandCollection.EqualsObj(dataStructure));
        }