Search in sources :

Example 1 with Join

use of org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.join.Join in project legend-pure by finos.

the class TestSimpleGrammar method testMappingAssociation.

@Test
public void testMappingAssociation() {
    Loader.parseM3("import other::*;\n" + "\n" + "Class other::Person\n" + "{\n" + "    name:String[1];\n" + "}\n" + "Class other::Firm\n" + "{\n" + "    legalName:String[1];\n" + "}\n" + "Association other::Firm_Person\n" + "{\n" + "    firm:Firm[1];\n" + "    employees:Person[1];\n" + "}\n" + "###Relational\n" + "Database mapping::db(\n" + "   Table employeeFirmDenormTable\n" + "   (\n" + "    id INT PRIMARY KEY,\n" + "    name VARCHAR(200),\n" + "    firmId INT,\n" + "    legalName VARCHAR(200)\n" + "   )\n" + "   Join firmJoin(employeeFirmDenormTable.firmId = {target}.firmId)\n" + ")\n" + "###Mapping\n" + "import other::*;\n" + "import mapping::*;\n" + "Mapping mappingPackage::subMapping1\n" + "(\n" + "    Person[per1]: Relational\n" + "    {\n" + "        name : [db]employeeFirmDenormTable.name\n" + "    }\n" + "    Firm[fir1]: Relational\n" + "    {\n" + "        legalName : [db]employeeFirmDenormTable.legalName\n" + "    }\n" + "\n" + "    Firm_Person: Relational\n" + "    {\n" + "        AssociationMapping\n" + "        (\n" + "           employees[fir1,per1] : [db]@firmJoin,\n" + "           firm[per1,fir1] : [db]@firmJoin\n" + "        )\n" + "    }\n" + ")\n", this.repository, new ParserLibrary(Lists.immutable.with(new M3AntlrParser(), new MappingParser(), new RelationalParser())), ValidationType.DEEP, VoidM3M4StateListener.VOID_M3_M4_STATE_LISTENER, this.context);
    this.runtime.compile();
    CoreInstance mapping = this.graphWalker.getMapping("mappingPackage::subMapping1");
    Assert.assertNotNull(mapping);
    ListIterable<? extends CoreInstance> associationMappings = this.graphWalker.getAssociationMappings(mapping);
    Assert.assertEquals(1, associationMappings.size());
    CoreInstance associationMapping = associationMappings.getFirst();
    Assert.assertNotNull(associationMapping);
    CoreInstance employeesMapping = this.graphWalker.getClassMappingImplementationPropertyMapping(associationMapping, "employees");
    Assert.assertNotNull(employeesMapping);
    Assert.assertEquals("fir1", employeesMapping.getValueForMetaPropertyToOne(M2MappingProperties.sourceSetImplementationId).getName());
    Assert.assertEquals("per1", employeesMapping.getValueForMetaPropertyToOne(M2MappingProperties.targetSetImplementationId).getName());
    CoreInstance firmPropertyMapping = this.graphWalker.getClassMappingImplementationPropertyMapping(associationMapping, "firm");
    Assert.assertNotNull(firmPropertyMapping);
    Assert.assertEquals("per1", firmPropertyMapping.getValueForMetaPropertyToOne(M2MappingProperties.sourceSetImplementationId).getName());
    Assert.assertEquals("fir1", firmPropertyMapping.getValueForMetaPropertyToOne(M2MappingProperties.targetSetImplementationId).getName());
}
Also used : EnumerationMappingParser(org.finos.legend.pure.m2.dsl.mapping.serialization.grammar.v1.EnumerationMappingParser) MappingParser(org.finos.legend.pure.m2.dsl.mapping.serialization.grammar.v1.MappingParser) ParserLibrary(org.finos.legend.pure.m3.serialization.grammar.ParserLibrary) M3AntlrParser(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3AntlrParser) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) RelationalParser(org.finos.legend.pure.m2.relational.serialization.grammar.v1.RelationalParser) Test(org.junit.Test)

Example 2 with Join

use of org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.join.Join in project legend-pure by finos.

the class TestSimpleGrammar method testMapping.

@Test
public void testMapping() {
    Loader.parseM3("import other::deep::*;\n" + "import other::*;\n" + "\n" + "Class other::Person\n" + "{\n" + "    name:String[1];\n" + "    firm:Firm[1];\n" + "}\n" + "Class other::deep::Firm\n" + "{\n" + "    legalName:String[1];\n" + "    employees:Person[1];\n" + "}\n" + "###Relational\n" + "Database mapping::pack::db(Table employeeTable\n" + "(\n" + "    id INT PRIMARY KEY,\n" + "    name VARCHAR(200),\n" + "    firmId INT\n" + ")\n" + "Table firmTable\n" + "(\n" + "    id INT PRIMARY KEY,\n" + "    name VARCHAR(200)\n" + ")\n" + "\n" + "Join Employee_Firm\n" + "(\n" + "    employeeTable.firmId = [mapping::pack::db]firmTable.id\n" + "))\n" + "###Mapping\n" + "import other::deep::*;\n" + "import mapping::pack::*;\n" + "Mapping mappingPackage::myMapping\n" + "(\n" + "    other::Person: Relational\n" + "            {\n" + "                name : [db]employeeTable.name,\n" + "                firm : [db]@Employee_Firm\n" + "            }\n" + "    Firm : Relational\n" + "           {\n" + "                legalName: [db]firmTable.name,\n" + "                employees: [db]@Employee_Firm\n" + "           }\n" + ")\n", this.repository, new ParserLibrary(Lists.immutable.with(new M3AntlrParser(), new MappingParser(), new RelationalParser())), ValidationType.DEEP, VoidM3M4StateListener.VOID_M3_M4_STATE_LISTENER, this.context);
    this.runtime.compile();
    CoreInstance db = this.graphWalker.getDbInstance("mapping::pack::db");
    Assert.assertNotNull(db);
    ListIterable<? extends CoreInstance> schemas = this.graphWalker.getSchemas(db);
    Assert.assertEquals(1, schemas.size());
    CoreInstance defaultSchema = this.graphWalker.getDefaultSchema(db);
    Assert.assertNotNull(defaultSchema);
    Assert.assertNotNull(this.graphWalker.getTable(defaultSchema, "employeeTable"));
    Assert.assertNotNull(this.graphWalker.getTable(defaultSchema, "firmTable"));
    CoreInstance employeeTable = this.graphWalker.getTable(defaultSchema, "employeeTable");
    CoreInstance firmTable = this.graphWalker.getTable(defaultSchema, "firmTable");
    ListIterable<? extends CoreInstance> employeeTableColumns = this.graphWalker.getColumns(employeeTable);
    ListIterable<? extends CoreInstance> firmTableColumns = this.graphWalker.getColumns(firmTable);
    Assert.assertEquals(3, employeeTableColumns.size());
    Assert.assertEquals(2, firmTableColumns.size());
    Assert.assertNotNull(this.graphWalker.getColumn(employeeTable, "id"));
    Assert.assertNotNull(this.graphWalker.getColumn(employeeTable, "name"));
    Assert.assertNotNull(this.graphWalker.getColumn(firmTable, "id"));
    Assert.assertNotNull(this.graphWalker.getColumn(firmTable, "name"));
    Assert.assertEquals(200, this.graphWalker.getColumnSize(this.graphWalker.getColumn(firmTable, "name")));
    Assert.assertEquals("Varchar", this.graphWalker.getClassifier(this.graphWalker.getColumnType(this.graphWalker.getColumn(firmTable, "name"))));
    CoreInstance mapping = this.graphWalker.getMapping("mappingPackage::myMapping");
    Assert.assertNotNull(mapping);
    Assert.assertEquals(2, this.graphWalker.getClassMappings(mapping).size());
    CoreInstance personMapping = this.graphWalker.getClassMapping(mapping, "Person");
    Assert.assertNotNull(personMapping);
    CoreInstance firmMapping = this.graphWalker.getClassMapping(mapping, "Firm");
    Assert.assertNotNull(firmMapping);
    Assert.assertEquals("employeeTable", this.graphWalker.getName(this.graphWalker.getClassMappingImplementationMainTable(personMapping)));
    Assert.assertEquals("firmTable", this.graphWalker.getName(this.graphWalker.getClassMappingImplementationMainTable(firmMapping)));
    Assert.assertEquals(2, this.graphWalker.getClassMappingImplementationPropertyMappings(personMapping).size());
    Assert.assertEquals(2, this.graphWalker.getClassMappingImplementationPropertyMappings(firmMapping).size());
    CoreInstance namePropMapping = this.graphWalker.getClassMappingImplementationPropertyMapping(personMapping, "name");
    CoreInstance firmPropMapping = this.graphWalker.getClassMappingImplementationPropertyMapping(personMapping, "firm");
    Assert.assertNotNull(firmPropMapping);
    CoreInstance nameColumnAlias = this.graphWalker.getClassMappingImplementationPropertyMappingRelationalOperationElement(namePropMapping);
    Assert.assertEquals("employeeTable", this.graphWalker.getTableAliasColumnAliasName(nameColumnAlias));
    Assert.assertEquals("name", this.graphWalker.getTableAliasColumnColumnName(nameColumnAlias));
    CoreInstance firmJoinNode = this.graphWalker.getRelationalOperationElementJoinTreeNode(this.graphWalker.getClassMappingImplementationPropertyMappingRelationalOperationElement(firmPropMapping));
    Assert.assertEquals("Employee_Firm", this.graphWalker.getRelationalOperationElementJoinTreeNodeJoinName(firmJoinNode));
    CoreInstance legalNamePropMapping = this.graphWalker.getClassMappingImplementationPropertyMapping(firmMapping, "legalName");
    CoreInstance legalNameColumnAlias = this.graphWalker.getClassMappingImplementationPropertyMappingRelationalOperationElement(legalNamePropMapping);
    Assert.assertEquals("firmTable", this.graphWalker.getTableAliasColumnAliasName(legalNameColumnAlias));
    Assert.assertEquals("name", this.graphWalker.getTableAliasColumnColumnName(legalNameColumnAlias));
    CoreInstance employeesPropMapping = this.graphWalker.getClassMappingImplementationPropertyMappingRelationalOperationElement(firmPropMapping);
    CoreInstance employeesJoinNode = this.graphWalker.getRelationalOperationElementJoinTreeNode(employeesPropMapping);
    Assert.assertEquals("Employee_Firm", this.graphWalker.getRelationalOperationElementJoinTreeNodeJoinName(employeesJoinNode));
}
Also used : EnumerationMappingParser(org.finos.legend.pure.m2.dsl.mapping.serialization.grammar.v1.EnumerationMappingParser) MappingParser(org.finos.legend.pure.m2.dsl.mapping.serialization.grammar.v1.MappingParser) ParserLibrary(org.finos.legend.pure.m3.serialization.grammar.ParserLibrary) M3AntlrParser(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3AntlrParser) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) RelationalParser(org.finos.legend.pure.m2.relational.serialization.grammar.v1.RelationalParser) Test(org.junit.Test)

Example 3 with Join

use of org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.join.Join in project legend-pure by finos.

the class TestSimpleGrammar method testMappingIncludes.

@Test
public void testMappingIncludes() {
    String pureCode = "import other::*;\n" + "\n" + "Class other::Person\n" + "{\n" + "    name:String[1];\n" + "    firm:Firm[1];\n" + "}\n" + "Class other::Firm\n" + "{\n" + "    legalName:String[1];\n" + "    employees:Person[1];\n" + "}\n" + "###Relational\n" + "Database mapping::db(\n" + "   Table employeeFirmDenormTable\n" + "   (\n" + "    id INT PRIMARY KEY,\n" + "    name VARCHAR(200),\n" + "    firmId INT,\n" + "    legalName VARCHAR(200)\n" + "   )\n" + "   Join firmJoin(employeeFirmDenormTable.firmId = {target}.firmId)\n" + ")\n" + "###Mapping\n" + "import other::*;\n" + "import mapping::*;\n" + "import mappingPackage::*;\n" + "Mapping mappingPackage::subMapping1\n" + "(\n" + "    Person: Relational\n" + "    {\n" + "        name : [db]employeeFirmDenormTable.name\n" + "    }\n" + ")\n" + "Mapping mappingPackage::subMapping2\n" + "(\n" + "    Firm: Relational\n" + "    {\n" + "        legalName : [db]employeeFirmDenormTable.legalName\n" + "    }\n" + ")\n" + "Mapping mappingPackage::myMapping\n" + "(\n" + "    include mappingPackage::subMapping1\n" + "    include subMapping2\n" + ")\n";
    Loader.parseM3(pureCode, this.repository, new ParserLibrary(Lists.immutable.with(new M3AntlrParser(), new MappingParser(), new RelationalParser())), ValidationType.DEEP, VoidM3M4StateListener.VOID_M3_M4_STATE_LISTENER, this.context);
    this.runtime.compile();
    CoreInstance mapping = this.graphWalker.getMapping("mappingPackage::myMapping");
    Assert.assertNotNull(mapping);
    ListIterable<? extends CoreInstance> includes = this.graphWalker.getMany(mapping, M3Properties.includes);
    Assert.assertEquals(2, includes.size());
    MutableList<String> includedMappingPaths = includes.collect(new Function<CoreInstance, String>() {

        @Override
        public String valueOf(CoreInstance include) {
            return PackageableElement.getUserPathForPackageableElement(graphWalker.getOne(include, M3Properties.included));
        }
    }, FastList.<String>newList(2));
    Verify.assertListsEqual(Lists.fixedSize.with("mappingPackage::subMapping1", "mappingPackage::subMapping2"), includedMappingPaths);
}
Also used : EnumerationMappingParser(org.finos.legend.pure.m2.dsl.mapping.serialization.grammar.v1.EnumerationMappingParser) MappingParser(org.finos.legend.pure.m2.dsl.mapping.serialization.grammar.v1.MappingParser) ParserLibrary(org.finos.legend.pure.m3.serialization.grammar.ParserLibrary) M3AntlrParser(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3AntlrParser) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) RelationalParser(org.finos.legend.pure.m2.relational.serialization.grammar.v1.RelationalParser) Test(org.junit.Test)

Example 4 with Join

use of org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.join.Join in project legend-pure by finos.

the class TestPureRuntimeClassMapping method testMilestoningMappingUnbindStability.

@Test
public void testMilestoningMappingUnbindStability() {
    String modelTrade = "Class my::Trade{\n" + "   id:Integer[1];\n" + "   product:my::Product[1];\n" + "}";
    String modelProduct = "Class my::Product{\n" + "   id:Integer[1];\n" + "}";
    String modelProductTemporal = "Class <<temporal.businesstemporal>> my::Product{\n" + "   id:Integer[1];\n" + "}";
    String storeAndMapping = "###Mapping\n" + "import meta::relational::tests::*;\n" + "import my::*;\n" + "\n" + "Mapping myMapping\n" + "(\n" + "   Trade : Relational {id : [myDB] tradeTable.ID, product : [myDB] @trade_product} \n" + "   Product : Relational { id : [myDB] productTable.ID}\n" + ")\n" + "###Relational\n" + "Database myDB\n" + "(\n" + "   Table tradeTable(ID INT PRIMARY KEY, PRODID INT)\n" + "   Table productTable(ID INT PRIMARY KEY)\n" + "   \n" + "   Join trade_product(tradeTable.PRODID = productTable.ID)\n" + ")";
    String f = "function f():Any[0..1]{let m = myMapping}";
    RuntimeVerifier.verifyOperationIsStable(new RuntimeTestScriptBuilder().createInMemorySource("modelTrade.pure", modelTrade).createInMemorySource("modelProductTemporal.pure", modelProductTemporal).createInMemorySource("storeAndMapping.pure", storeAndMapping).createInMemorySource("f.pure", f).compile(), new RuntimeTestScriptBuilder().deleteSource("modelProductTemporal.pure").createInMemorySource("modelProduct.pure", modelProduct).compile().deleteSource("modelProduct.pure").createInMemorySource("modelProductTemporal.pure", modelProductTemporal).compile(), this.runtime, this.functionExecution, this.getAdditionalVerifiers());
}
Also used : RuntimeTestScriptBuilder(org.finos.legend.pure.m3.RuntimeTestScriptBuilder) Test(org.junit.Test)

Example 5 with Join

use of org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.join.Join in project legend-pure by finos.

the class TestNavigateForRelationalAndMappingFromCoordinates method testNavigateForProperty.

@Test
public void testNavigateForProperty() throws Exception {
    Source source = this.runtime.createInMemorySource("propertySample.pure", "###Pure\n" + "import a::*;\n" + "\n" + "Class a::Person\n" + "{\n" + "   id : Integer[1];\n" + "   name : String[1];\n" + "   firmId : Integer[1];\n" + "}\n" + "\n" + "Class a::Firm\n" + "{\n" + "   id : Integer[1];\n" + "   name : String[1];\n" + "}\n" + "\n" + "Association a::Person_Firm\n" + "{\n" + "   person : Person[1];\n" + "   firm : Firm[1];\n" + "}\n" + "\n" + "###Relational\n" + "Database a::PersonFirmDatabase\n" + "(\n" + "   Table person (ID INT, NAME VARCHAR(200), FIRM_ID INT)\n" + "   Table firm(ID INT, NAME VARCHAR(200))\n" + "   Join person_firm(person.FIRM_ID = firm.ID)\n" + ")\n" + "\n" + "###Mapping\n" + "import a::*;\n" + "\n" + "Mapping a::PersonFirmMappin\n" + "(\n" + "   Person[personAlias] : Relational\n" + "   {\n" + "      scope([PersonFirmDatabase]person)\n" + "      (\n" + "         id : ID,\n" + "         name : NAME,\n" + "         firmId : FIRM_ID\n" + "      )\n" + "   }\n" + "   \n" + "   Firm : Relational\n" + "   {\n" + "      scope([PersonFirmDatabase]firm)\n" + "      (\n" + "        id : ID,\n" + "        name : NAME\n" + "      )\n" + "   }\n" + "   \n" + "   Person_Firm : Relational\n" + "   {\n" + "      AssociationMapping\n" + "      (\n" + "         firm[personAlias,a_Firm] : [PersonFirmDatabase]@person_firm,\n" + "         person[a_Firm,personAlias] : [PersonFirmDatabase]@person_firm\n" + "      )\n" + "   }\n" + ")");
    this.runtime.compile();
    CoreInstance found = source.navigate(59, 10, this.processorSupport);
    Assert.assertTrue(found instanceof PropertyInstance);
    Assert.assertEquals("firm", ((PropertyInstance) found)._name());
    Assert.assertEquals("propertySample.pure", found.getSourceInformation().getSourceId());
    Assert.assertEquals(20, found.getSourceInformation().getLine());
    Assert.assertEquals(4, found.getSourceInformation().getColumn());
    found = source.navigate(59, 11, this.processorSupport);
    Assert.assertTrue(found instanceof PropertyInstance);
    Assert.assertEquals("firm", ((PropertyInstance) found)._name());
    Assert.assertEquals("propertySample.pure", found.getSourceInformation().getSourceId());
    Assert.assertEquals(20, found.getSourceInformation().getLine());
    Assert.assertEquals(4, found.getSourceInformation().getColumn());
    found = source.navigate(59, 13, this.processorSupport);
    Assert.assertTrue(found instanceof PropertyInstance);
    Assert.assertEquals("firm", ((PropertyInstance) found)._name());
    Assert.assertEquals("propertySample.pure", found.getSourceInformation().getSourceId());
    Assert.assertEquals(20, found.getSourceInformation().getLine());
    Assert.assertEquals(4, found.getSourceInformation().getColumn());
    found = source.navigate(60, 10, this.processorSupport);
    Assert.assertTrue(found instanceof PropertyInstance);
    Assert.assertEquals("person", ((PropertyInstance) found)._name());
    Assert.assertEquals("propertySample.pure", found.getSourceInformation().getSourceId());
    Assert.assertEquals(19, found.getSourceInformation().getLine());
    Assert.assertEquals(4, found.getSourceInformation().getColumn());
    found = source.navigate(60, 12, this.processorSupport);
    Assert.assertTrue(found instanceof PropertyInstance);
    Assert.assertEquals("person", ((PropertyInstance) found)._name());
    Assert.assertEquals("propertySample.pure", found.getSourceInformation().getSourceId());
    Assert.assertEquals(19, found.getSourceInformation().getLine());
    Assert.assertEquals(4, found.getSourceInformation().getColumn());
    found = source.navigate(60, 15, this.processorSupport);
    Assert.assertTrue(found instanceof PropertyInstance);
    Assert.assertEquals("person", ((PropertyInstance) found)._name());
    Assert.assertEquals("propertySample.pure", found.getSourceInformation().getSourceId());
    Assert.assertEquals(19, found.getSourceInformation().getLine());
    Assert.assertEquals(4, found.getSourceInformation().getColumn());
}
Also used : CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) PropertyInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.PropertyInstance) Source(org.finos.legend.pure.m3.serialization.runtime.Source) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)37 RelationalParser (org.finos.legend.pure.m2.relational.serialization.grammar.v1.RelationalParser)26 ParserLibrary (org.finos.legend.pure.m3.serialization.grammar.ParserLibrary)26 M3AntlrParser (org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3AntlrParser)26 MappingParser (org.finos.legend.pure.m2.dsl.mapping.serialization.grammar.v1.MappingParser)25 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)24 PureCompilationException (org.finos.legend.pure.m4.exception.PureCompilationException)18 Join (org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.join.Join)17 RelationalOperationElementWithJoin (org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.RelationalOperationElementWithJoin)12 PureParserException (org.finos.legend.pure.m4.serialization.grammar.antlr.PureParserException)12 RelationalOperationElement (org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.RelationalOperationElement)8 RootRelationalInstanceSetImplementation (org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.RootRelationalInstanceSetImplementation)7 TableAlias (org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.TableAlias)7 JoinTreeNode (org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.join.JoinTreeNode)7 EnumerationMappingParser (org.finos.legend.pure.m2.dsl.mapping.serialization.grammar.v1.EnumerationMappingParser)6 SetImplementation (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.SetImplementation)6 InstanceSetImplementation (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.InstanceSetImplementation)4 Operation (org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.operation.Operation)4 NamedRelation (org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.relation.NamedRelation)4 TreeNode (org.finos.legend.pure.m3.coreinstance.meta.pure.functions.collection.TreeNode)3