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");
}
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);
}
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()));
}
}
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;
}
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);
}
Aggregations