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));
                }
            }
        }
        public void GetOutputStructure_NScalarsExpr_DataStructure(string opSymbol)
        {
            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 = TestExprFactory.GetExpression(combination);
                    compCreateExpr.OperatorDefinition = this._exprFac.OperatorResolver(opSymbol);
                    joinExpr.AddOperand("ds_1", compCreateExpr);

                    IDataStructure expectedStructure = compCreateExpr.Operands["ds_1"].Structure.GetCopy();
                    for (int k = 2; k <= i; k++)
                    {
                        expectedStructure.AddStructure(compCreateExpr.Operands[$"ds_{k}"].Structure);
                    }

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

                    Assert.True(expectedStructure.EqualsObj(dataStructure));
                }
            }
        }
示例#3
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_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 GetOutputStructure_Correct1Superset1SubsetExpr_SupersetModified(params TestExprType[] types)
        {
            foreach (string opSymbol in this._operators)
            {
                IExpression arithmeticExpr = TestExprFactory.GetExpression(types);
                arithmeticExpr.OperatorDefinition = ModelResolvers.OperatorResolver(opSymbol);

                arithmeticExpr.Operands["ds_1"].Structure.Identifiers.Add(new StructureComponent(BasicDataType.Integer, "Id2"));

                IDataStructure expectedStructure = arithmeticExpr.Operands[$"ds_1"].Structure.GetCopy();
                for (int i = 0; i < expectedStructure.Measures.Count; i++)
                {
                    BasicDataType dataType = arithmeticExpr.Operands[$"ds_2"].Structure.Measures[i].ValueDomain.DataType;
                    if (dataType == BasicDataType.Number)
                    {
                        expectedStructure.Measures[i].ValueDomain = new ValueDomain(dataType);
                    }
                    if (expectedStructure.Measures[i].ValueDomain.DataType == BasicDataType.None)
                    {
                        expectedStructure.Measures[i].ValueDomain = new ValueDomain(BasicDataType.Integer);
                    }
                }

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

                Assert.True(expectedStructure.EqualsObj(dataStructure));
            }
        }
        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));
        }
示例#7
0
        public void GetOutputStructure_OneMeasureDatasetNScalarsExpr_OneMeasureIntStructure(string opSymbol, params TestExprType[] types)
        {
            IExpression stringExpr = TestExprFactory.GetExpression(types);

            stringExpr.OperatorDefinition = ModelResolvers.OperatorResolver(opSymbol);
            stringExpr.Operands["ds_1"].Structure.Measures.RemoveAt(1);

            IDataStructure expected = stringExpr.Operands["ds_1"].Structure.GetCopy();

            expected.Measures.Clear();
            expected.Measures.Add(new StructureComponent(BasicDataType.Integer, "int_var"));

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

            Assert.True(expected.EqualsObj(dataStructure));
        }
示例#8
0
        public void GetOutputStructure_1OneMeasureDataset2CorrectScalarsArgsExpr_OneMeasureBoolStructure(params TestExprType[] types)
        {
            IExpression betweenExpr = TestExprFactory.GetExpression(types);

            betweenExpr.OperatorDefinition = ModelResolvers.OperatorResolver("between");
            betweenExpr.Operands["ds_1"].Structure.Measures.RemoveAt(1);

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

            expectedStructure.Measures.Clear();
            expectedStructure.Measures.Add(new StructureComponent(BasicDataType.Boolean, "bool_var"));

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

            Assert.True(expectedStructure.EqualsObj(dataStructure));
        }
示例#9
0
        public void GetOutputStructure_CorrectOneMeasureDatasetExpr_OneMeasureBoolDatasetStructure(TestExprType type)
        {
            IExpression notExpr = TestExprFactory.GetExpression(new TestExprType[] { type });

            notExpr.OperatorDefinition = ModelResolvers.OperatorResolver("not");
            notExpr.Operands["ds_1"].Structure.Measures.RemoveAt(1);

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

            expectedStructure.Measures.Clear();
            expectedStructure.Measures.Add(new StructureComponent(BasicDataType.Boolean, "bool_var"));

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

            Assert.True(expectedStructure.EqualsObj(dataStructure));
        }
示例#10
0
        public void GetOutputStructure_2DatasetsExpr_StringsSupersetStructure(string opSymbol, params TestExprType[] types)
        {
            IExpression stringExpr = TestExprFactory.GetExpression(types);

            stringExpr.OperatorDefinition = ModelResolvers.OperatorResolver(opSymbol);

            IDataStructure expected = stringExpr.Operands["ds_1"].Structure;

            expected.Identifiers.Add(new StructureComponent(BasicDataType.Integer, "Id2"));
            expected.Measures[0].ValueDomain = new ValueDomain(BasicDataType.String);
            expected.Measures[1].ValueDomain = new ValueDomain(BasicDataType.String);

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

            Assert.True(expected.EqualsObj(dataStructure));
        }
        public void GetOutputStructure_1CorrectScalar1OneMeasureDatasetArgsExpr_OneMeasureBoolStructure(params TestExprType[] types)
        {
            foreach (string opSymbol in this._operators)
            {
                IExpression equalityExpr = TestExprFactory.GetExpression(types);
                equalityExpr.OperatorDefinition = ModelResolvers.OperatorResolver(opSymbol);
                equalityExpr.Operands["ds_2"].Structure.Measures.RemoveAt(1);

                IDataStructure expectedStructure = equalityExpr.Operands["ds_2"].Structure.GetCopy();
                expectedStructure.Measures.Clear();
                expectedStructure.Measures.Add(new StructureComponent(BasicDataType.Boolean, "bool_var"));

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

                Assert.True(expectedStructure.EqualsObj(dataStructure));
            }
        }
示例#12
0
        public void GetOutputStructure_Correct2EqualIdsDatasetsExpr_OneMeasureBoolStructure()
        {
            TestExprType[][] combinations = Enum.GetValues(typeof(TestExprType)).Cast <TestExprType>().GetCombinations(2);
            TestExprType[][] datasetCombs = combinations.Where(wrongComb => (int)wrongComb[0] > 8 && (int)wrongComb[1] > 8).ToArray();

            foreach (TestExprType[] datasetComb in datasetCombs)
            {
                IExpression existsInExpr = TestExprFactory.GetExpression(datasetComb);
                existsInExpr.OperatorDefinition = ModelResolvers.OperatorResolver("exists_in");

                IDataStructure expectedStructure = existsInExpr.Operands["ds_1"].Structure.GetCopy();
                expectedStructure.Measures.Clear();
                expectedStructure.Measures.Add(new StructureComponent(BasicDataType.Boolean, "bool_var"));

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

                Assert.True(expectedStructure.EqualsObj(dataStructure));
            }
        }
        public void GetOutputStructure_2ScalarsExpr_DataStructure(string opSymbol, params TestExprType[] types)
        {
            IExpression compCreateExpr = TestExprFactory.GetExpression(types);

            compCreateExpr.OperatorDefinition = this._exprFac.OperatorResolver(opSymbol);
            compCreateExpr.Operands["ds_2"].Structure.Measures[0].ComponentName += "2";

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

            joinExpr.AddOperand("ds_1", compCreateExpr);

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

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

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

            Assert.True(expectedStructure.EqualsObj(dataStructure));
        }
        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);
        }
示例#15
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));
        }
示例#16
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));
        }
        public void GetOutputStructure_Correct1Scalar1DatasetExpr_DataStructure(params TestExprType[] types)
        {
            foreach (string opSymbol in this._operators)
            {
                IExpression arithmeticExpr = TestExprFactory.GetExpression(types);
                arithmeticExpr.OperatorDefinition = ModelResolvers.OperatorResolver(opSymbol);

                IDataStructure expectedStructure = arithmeticExpr.Operands["ds_2"].Structure.GetCopy();
                if (types[0] == TestExprType.Number)
                {
                    foreach (StructureComponent measure in expectedStructure.Measures)
                    {
                        measure.ValueDomain = new ValueDomain(BasicDataType.Number);
                    }
                }

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

                Assert.True(expectedStructure.EqualsObj(dataStructure));
            }
        }
        public void GetOutputStructure_CorrectExprJoin_CorrectScalarStructure(string compName)
        {
            IExpression membershipExpr = TestExprFactory.GetExpression(TestExprType.IntsDataset, TestExprType.Integer);

            IDataStructure expectedStructure = null;

            switch (compName)
            {
            case "Id1":
                membershipExpr.Operands["ds_2"].Structure = ModelResolvers.DsResolver(compName, ComponentType.Identifier, BasicDataType.Integer);
                expectedStructure = ModelResolvers.DsResolver(compName, ComponentType.Identifier, BasicDataType.Integer);
                break;

            case "Me1":
                membershipExpr.Operands["ds_2"].Structure = ModelResolvers.DsResolver(compName, ComponentType.Measure, BasicDataType.Integer);
                expectedStructure = ModelResolvers.DsResolver(compName, ComponentType.Measure, BasicDataType.Integer);
                break;

            case "NV_At1":
                membershipExpr.Operands["ds_1"].Structure.NonViralAttributes.Add(new StructureComponent(BasicDataType.Integer, "NV_At1"));
                membershipExpr.Operands["ds_2"].Structure = ModelResolvers.DsResolver(compName, ComponentType.NonViralAttribute, BasicDataType.Integer);
                expectedStructure = ModelResolvers.DsResolver(compName, ComponentType.NonViralAttribute, BasicDataType.Integer);
                break;

            case "V_At1":
                membershipExpr.Operands["ds_1"].Structure.ViralAttributes.Add(new StructureComponent(BasicDataType.Integer, "V_At1"));
                membershipExpr.Operands["ds_2"].Structure = ModelResolvers.DsResolver(compName, ComponentType.ViralAttribute, BasicDataType.Integer);
                expectedStructure = ModelResolvers.DsResolver(compName, ComponentType.ViralAttribute, BasicDataType.Integer);
                break;
            }

            membershipExpr.OperatorDefinition         = ModelResolvers.OperatorResolver("#");
            membershipExpr.OperatorDefinition.Keyword = "Component";

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

            Assert.True(expectedStructure.EqualsObj(dataStructure));
        }
        public void GetOutputStructure_CorrectExprNonJoin_CorrectStructure(string compName, TestExprType compType)
        {
            string       name   = string.Empty;
            TestExprType?dsType = null;

            switch (compType)
            {
            case TestExprType.Integer:
                name   = "int_var";
                dsType = TestExprType.IntsDataset;
                break;

            case TestExprType.Number:
                name   = "num_var";
                dsType = TestExprType.NumbersDataset;
                break;

            case TestExprType.String:
                name   = "string_var";
                dsType = TestExprType.StringsDataset;
                break;

            case TestExprType.Boolean:
                name   = "bool_var";
                dsType = TestExprType.BoolsDataset;
                break;

            case TestExprType.Time:
                name   = "time_var";
                dsType = TestExprType.TimesDataset;
                break;

            case TestExprType.Date:
                name   = "date_var";
                dsType = TestExprType.DatesDataset;
                break;

            case TestExprType.TimePeriod:
                name   = "period_var";
                dsType = TestExprType.TimePeriodsDataset;
                break;

            case TestExprType.Duration:
                name   = "duration_var";
                dsType = TestExprType.DurationsDataset;
                break;

            case TestExprType.None:
                name   = "null";
                dsType = TestExprType.NonesDataset;
                break;

            default: throw new Exception();
            }

            IExpression membershipExpr = TestExprFactory.GetExpression((TestExprType)dsType, compType);

            membershipExpr.Operands["ds_2"].ExpressionText = compName;
            membershipExpr.Operands["ds_2"].Structure.Components[0].ComponentName = compName;

            IDataStructure expectedStructure = TestExprFactory.GetExpression((TestExprType)dsType).Structure;

            expectedStructure.Measures.Clear();
            if (compName == "Me1")
            {
                expectedStructure.Measures.Add(new StructureComponent((BasicDataType)compType, compName));
            }
            else
            {
                if (compName != "Id1")
                {
                    expectedStructure.Measures.Add(new StructureComponent((BasicDataType)compType, name));
                }
                else
                {
                    membershipExpr.Operands["ds_2"].Structure = ModelResolvers.DsResolver(compName, ComponentType.Identifier, (BasicDataType)compType);
                    expectedStructure.Measures.Add(new StructureComponent((BasicDataType)compType, compType.GetVariableName()));
                }
            }

            if (compName == "NV_At1")
            {
                membershipExpr.Operands["ds_1"].Structure.NonViralAttributes.Add(new StructureComponent((BasicDataType)compType, compName));
                membershipExpr.Operands["ds_2"].Structure = ModelResolvers.DsResolver(compName, ComponentType.NonViralAttribute, (BasicDataType)compType);
                expectedStructure.NonViralAttributes.Add(new StructureComponent((BasicDataType)compType, compName));
            }
            else if (compName == "V_At1")
            {
                membershipExpr.Operands["ds_1"].Structure.ViralAttributes.Add(new StructureComponent((BasicDataType)compType, compName));
                membershipExpr.Operands["ds_2"].Structure = ModelResolvers.DsResolver(compName, ComponentType.ViralAttribute, (BasicDataType)compType);
                expectedStructure.ViralAttributes.Add(new StructureComponent((BasicDataType)compType, compName));
            }

            membershipExpr.OperatorDefinition = ModelResolvers.OperatorResolver("#");

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

            Assert.True(expectedStructure.EqualsObj(dataStructure));
            Assert.Equal(expectedStructure.Measures[0].ComponentName, dataStructure.Measures[0].ComponentName);
        }