Search in sources :

Example 1 with Operation

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

the class TestEmbeddedGrammar method testEmbeddedMappingWithIds.

@Test
public void testEmbeddedMappingWithIds() {
    Loader.parseM3("import other::*;\n" + "import meta::pure::mapping::*;\n" + "\n" + "Class other::Person\n" + "{\n" + "    name:String[1];\n" + "    firm:Firm[1];\n" + "    address:Address[0..1];\n" + "}\n" + "Class other::Firm\n" + "{\n" + "    legalName:String[1];\n" + "    employees:Person[1];\n" + "    address:Address[1];\n" + "}\n" + "Class other::Address\n" + "{\n" + "    line1:String[1];\n" + "}\n" + "   function meta::pure::router::operations::union(o:OperationSetImplementation[1]):SetImplementation[*]\n" + "   {\n" + "       $o.parameters.setImplementation;\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" + "    address VARCHAR(200)\n" + "   )\n" + "   Table employeeFirmDenormTable2\n" + "   (\n" + "    id INT PRIMARY KEY,\n" + "    name VARCHAR(200),\n" + "    firmId INT,\n" + "    legalName VARCHAR(200),\n" + "    address VARCHAR(200)\n" + "   )\n" + ")\n" + "###Mapping\n" + "import other::*;\n" + "import mapping::*;\n" + "Mapping mappingPackage::myMapping\n" + "(\n" + "    Person[per1]: Relational\n" + "    {\n" + "        name : [db]employeeFirmDenormTable.name,\n" + "        firm\n" + "        (\n" + "            ~primaryKey ([db]employeeFirmDenormTable.legalName)\n" + "            legalName : [db]employeeFirmDenormTable.legalName,\n" + "            address\n" + "            (\n" + "                line1: [db]employeeFirmDenormTable.address\n" + "            )\n" + "        ),\n" + "        address\n" + "        (\n" + "            line1: [db]employeeFirmDenormTable.address\n" + "        )\n" + "    }\n" + "    Person[per2]: Relational\n" + "    {\n" + "        name : [db]employeeFirmDenormTable2.name,\n" + "        firm\n" + "        (\n" + "            ~primaryKey ([db]employeeFirmDenormTable2.legalName)\n" + "            legalName : [db]employeeFirmDenormTable2.legalName,\n" + "            address\n" + "            (\n" + "                line1: [db]employeeFirmDenormTable2.address\n" + "            )\n" + "        ),\n" + "        address\n" + "        (\n" + "            line1: [db]employeeFirmDenormTable2.address\n" + "        )\n" + "    }\n" + "    *Person : Operation\n" + "    {\n" + "               meta::pure::router::operations::union_OperationSetImplementation_1__SetImplementation_MANY_( per1, per2 )   \n" + "    }\n" + ")\n", this.repository, new ParserLibrary(Lists.immutable.with(new M3AntlrParser(), new MappingParser(), new RelationalParser(), new OperationParser())), ValidationType.DEEP, VoidM3M4StateListener.VOID_M3_M4_STATE_LISTENER, this.context);
    this.runtime.compile();
    CoreInstance mapping = this.graphWalker.getMapping("mappingPackage::myMapping");
    assertNotNull(mapping);
    assertEquals(9, this.graphWalker.getClassMappings(mapping).size());
    CoreInstance personMapping = this.graphWalker.getClassMappingById(mapping, "per1");
    validatePersonMapping(personMapping, "employeeFirmDenormTable");
    CoreInstance personMapping2 = this.graphWalker.getClassMappingById(mapping, "per2");
    validatePersonMapping(personMapping2, "employeeFirmDenormTable2");
}
Also used : 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) OperationParser(org.finos.legend.pure.m2.dsl.mapping.serialization.grammar.v1.OperationParser) Test(org.junit.Test)

Example 2 with Operation

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

the class DatabaseUnloadUnbind method processFilter.

private void processFilter(Filter filter, ProcessorSupport processorSupport) {
    Operation operation = filter._operation();
    scanOperation(operation, null, processorSupport);
}
Also used : BinaryOperation(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.operation.BinaryOperation) UnaryOperation(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.operation.UnaryOperation) Operation(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.operation.Operation)

Example 3 with Operation

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

the class RelationalOperationElementUnbind method cleanNode.

public static void cleanNode(RelationalOperationElement element, ModelRepository modelRepository, ProcessorSupport processorSupport) throws PureCompilationException {
    if (element instanceof TableAliasColumn) {
        TableAliasColumn tableAliasColumn = (TableAliasColumn) element;
        ImportStub database = (ImportStub) tableAliasColumn._alias()._databaseCoreInstance();
        Shared.cleanUpReferenceUsage(database, tableAliasColumn, processorSupport);
        Shared.cleanImportStub(database, processorSupport);
        tableAliasColumn._columnRemove();
        TableAlias alias = tableAliasColumn._alias();
        alias._relationalElementRemove();
    } else if (element instanceof DynaFunction) {
        for (RelationalOperationElement val : ((DynaFunction) element)._parameters()) {
            cleanNode(val, modelRepository, processorSupport);
        }
    } else if (element instanceof RelationalOperationElementWithJoin) {
        if (((RelationalOperationElementWithJoin) element)._relationalOperationElement() != null) {
            cleanNode(((RelationalOperationElementWithJoin) element)._relationalOperationElement(), modelRepository, processorSupport);
        }
        if (((RelationalOperationElementWithJoin) element)._joinTreeNode() != null) {
            cleanJoinTreeNode(((RelationalOperationElementWithJoin) element)._joinTreeNode(), modelRepository, processorSupport);
        }
    } else if (element instanceof Literal) {
    // Nothing to do
    } else {
        throw new RuntimeException("TO CODE: clean relational operation element node of type " + PackageableElement.getUserPathForPackageableElement(element.getClassifier()));
    }
}
Also used : RelationalOperationElement(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.RelationalOperationElement) Literal(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.Literal) TableAlias(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.TableAlias) TableAliasColumn(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.TableAliasColumn) ImportStub(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.ImportStub) DynaFunction(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.DynaFunction) RelationalOperationElementWithJoin(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.RelationalOperationElementWithJoin)

Example 4 with Operation

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

the class AntlrContextToM3CoreInstance method buildArithmeticWithListParam.

// Build arithmetic op which can handle list of params (like lisp eg (+ u v z y z))
private SimpleFunctionExpression buildArithmeticWithListParam(ArithmeticPartContext ctx, ArithOp op, CoreInstance initialValue, String exprName, MutableList<String> typeParametersNames, LambdaContext lambdaContext, String space, boolean wrapFlag, ImportGroup importId, boolean addLines) {
    MutableList<CoreInstance> others = Lists.mutable.empty();
    Function0<List<TerminalNode>> getTokens;
    Function<Integer, TerminalNode> getToken;
    switch(op) {
        case PLUS:
            getTokens = ctx::PLUS;
            getToken = ctx::PLUS;
            break;
        case TIMES:
            getTokens = ctx::STAR;
            getToken = ctx::STAR;
            break;
        case MINUS:
            getTokens = ctx::MINUS;
            getToken = ctx::MINUS;
            break;
        default:
            throw new IllegalStateException("Unexpected arithmetic operation for buildArithmeticWithListParam: " + op);
    }
    String op_str = op.toString().toLowerCase();
    for (ExpressionContext eCtx : ctx.expression()) {
        others.add(this.expression(eCtx, exprName, typeParametersNames, lambdaContext, space, wrapFlag, importId, addLines));
    }
    TerminalNode newOp = getToken.apply(getTokens.value().size() - 1);
    SimpleFunctionExpression sfe = SimpleFunctionExpressionInstance.createPersistent(this.repository, this.sourceInformation.getPureSourceInformation(newOp.getSymbol()), null, null, importId, null);
    sfe._functionName(op_str);
    sfe._parametersValues(Lists.mutable.<ValueSpecification>of(this.doWrap(Lists.mutable.with(initialValue).withAll(others))));
    return sfe;
}
Also used : NotExpressionContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.NotExpressionContext) ExpressionContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.ExpressionContext) LetExpressionContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.LetExpressionContext) BuildMilestoningVariableExpressionContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.BuildMilestoningVariableExpressionContext) PropertyExpressionContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.PropertyExpressionContext) DefaultValueExpressionContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.DefaultValueExpressionContext) FunctionVariableExpressionContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.FunctionVariableExpressionContext) CombinedExpressionContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.CombinedExpressionContext) AtomicExpressionContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.AtomicExpressionContext) SignedExpressionContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.SignedExpressionContext) PropertyOrFunctionExpressionContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.PropertyOrFunctionExpressionContext) SimpleFunctionExpression(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.SimpleFunctionExpression) PrimitiveCoreInstance(org.finos.legend.pure.m4.coreinstance.primitive.PrimitiveCoreInstance) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) MutableList(org.eclipse.collections.api.list.MutableList) FastList(org.eclipse.collections.impl.list.mutable.FastList) List(java.util.List) TerminalNode(org.antlr.v4.runtime.tree.TerminalNode)

Example 5 with Operation

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

the class DatabaseProcessor method processFilter.

private void processFilter(Filter filter, Database defaultDb, ProcessorSupport processorSupport) throws PureCompilationException {
    MutableMap<String, MutableMap<String, CoreInstance>> tableByAlias = UnifiedMap.newMap();
    Operation operation = filter._operation();
    MutableList<TableAliasColumn> selfJoinTarget = FastList.newList();
    scanOperation(operation, tableByAlias, selfJoinTarget, defaultDb, null, processorSupport, false);
}
Also used : MutableMap(org.eclipse.collections.api.map.MutableMap) UnaryOperation(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.operation.UnaryOperation) BinaryOperation(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.operation.BinaryOperation) Operation(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.operation.Operation) TableAliasColumn(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.TableAliasColumn)

Aggregations

Operation (org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.operation.Operation)6 TableAlias (org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.TableAlias)5 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)5 TerminalNode (org.antlr.v4.runtime.tree.TerminalNode)4 TableAliasColumn (org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.TableAliasColumn)4 BinaryOperation (org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.operation.BinaryOperation)4 UnaryOperation (org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.operation.UnaryOperation)4 SimpleFunctionExpression (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.SimpleFunctionExpression)3 RelationalOperationElement (org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.RelationalOperationElement)3 PrimitiveCoreInstance (org.finos.legend.pure.m4.coreinstance.primitive.PrimitiveCoreInstance)3 MutableMap (org.eclipse.collections.api.map.MutableMap)2 ValueSpecification (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification)2 Column (org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.Column)2 RelationalOperationElementWithJoin (org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.RelationalOperationElementWithJoin)2 NamedRelation (org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.relation.NamedRelation)2 Relation (org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.relation.Relation)2 M3AntlrParser (org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3AntlrParser)2 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 RuleContext (org.antlr.v4.runtime.RuleContext)1