use of org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.RelationalOperationElementWithJoin in project legend-pure by finos.
the class RelationalOperationElementProcessor method processColumnExpr.
static void processColumnExpr(RelationalOperationElement impl, CoreInstance implementation, CoreInstance mappingOwner, MutableSet<TableAlias> tableAliases, Matcher matcher, ProcessorState state, ModelRepository repository, ProcessorSupport processorSupport) throws PureCompilationException {
if (impl instanceof TableAliasColumn) {
processTableAliasColumn((TableAliasColumn) impl, mappingOwner, tableAliases, processorSupport);
} else if (impl instanceof DynaFunction) {
processDynaFunction((DynaFunction) impl, implementation, mappingOwner, tableAliases, matcher, state, repository, processorSupport);
} else if (impl instanceof RelationalOperationElementWithJoin) {
RelationalOperationElement relationalOperationElement = ((RelationalOperationElementWithJoin) impl)._relationalOperationElement();
if (relationalOperationElement != null) {
if (relationalOperationElement instanceof DynaFunction) {
processDynaFunction((DynaFunction) relationalOperationElement, implementation, mappingOwner, tableAliases, matcher, state, repository, processorSupport);
} else if (relationalOperationElement instanceof TableAliasColumn) {
processTableAliasColumn((TableAliasColumn) relationalOperationElement, mappingOwner, tableAliases, processorSupport);
}
}
JoinTreeNode joinTreeNode = ((RelationalOperationElementWithJoin) impl)._joinTreeNode();
if (joinTreeNode != null) {
processJoinTreeNode(joinTreeNode, mappingOwner, matcher, state, repository, processorSupport);
tableAliases.clear();
}
} else if (impl instanceof Literal) {
// Do nothing
} else {
throw new PureCompilationException(impl.getSourceInformation(), "Not Supported Yet! " + impl);
}
}
use of org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.RelationalOperationElementWithJoin 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.RelationalOperationElementWithJoin in project legend-engine by finos.
the class HelperRelationalBuilder method processRelationalOperationElement.
public static RelationalOperationElement processRelationalOperationElement(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.model.operation.RelationalOperationElement operationElement, CompileContext context, MutableMap<String, org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.TableAlias> aliasMap, MutableList<org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.TableAliasColumn> selfJoinTargets) {
if (operationElement instanceof org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.model.operation.TableAliasColumn) {
org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.model.operation.TableAliasColumn tableAliasColumn = (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.model.operation.TableAliasColumn) operationElement;
// Self join
if (tableAliasColumn.table.table.equals(SELF_JOIN_TABLE_NAME) && tableAliasColumn.tableAlias.equals(SELF_JOIN_TABLE_NAME)) {
org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.TableAliasColumn selfJoin = new Root_meta_relational_metamodel_TableAliasColumn_Impl("")._columnName(tableAliasColumn.column);
selfJoinTargets.add(selfJoin);
return selfJoin;
}
Relation relation = getRelation((Database) context.resolveStore(tableAliasColumn.table.database, tableAliasColumn.table.sourceInformation), tableAliasColumn.table.schema, tableAliasColumn.table.table, tableAliasColumn.table.sourceInformation);
Column col = getColumn(relation, tableAliasColumn.column, tableAliasColumn.sourceInformation);
TableAlias alias = aliasMap.getIfAbsentPut(tableAliasColumn.table.schema + "." + tableAliasColumn.tableAlias, (Function0<TableAlias>) () -> new Root_meta_relational_metamodel_TableAlias_Impl("")._name(tableAliasColumn.tableAlias)._relationalElement(col._owner())._database(HelperRelationalBuilder.resolveDatabase(tableAliasColumn.table.getDb(), tableAliasColumn.table.sourceInformation, context)));
return new Root_meta_relational_metamodel_TableAliasColumn_Impl("")._columnName(col._name())._column(col)._alias(alias);
} else if (operationElement instanceof ElementWithJoins) {
ElementWithJoins elementWithJoins = (ElementWithJoins) operationElement;
RelationalOperationElementWithJoin res = new Root_meta_relational_metamodel_RelationalOperationElementWithJoin_Impl("")._joinTreeNode(buildElementWithJoinsJoinTreeNode(elementWithJoins.joins, context));
return elementWithJoins.relationalElement == null ? res : res._relationalOperationElement(processRelationalOperationElement(elementWithJoins.relationalElement, context, UnifiedMap.newMap(), selfJoinTargets));
} else if (operationElement instanceof DynaFunc) {
DynaFunc dynaFunc = (DynaFunc) operationElement;
MutableList<RelationalOperationElement> ps = ListIterate.collect(dynaFunc.parameters, relationalOperationElement -> processRelationalOperationElement(relationalOperationElement, context, aliasMap, selfJoinTargets));
return new Root_meta_relational_metamodel_DynaFunction_Impl("")._name(dynaFunc.funcName)._parameters(ps);
} else if (operationElement instanceof org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.model.operation.Literal) {
org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.model.operation.Literal literal = (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.model.operation.Literal) operationElement;
return new Root_meta_relational_metamodel_Literal_Impl("")._value(convertLiteral(convertLiteral(literal.value)));
} else if (operationElement instanceof org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.model.operation.LiteralList) {
org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.model.operation.LiteralList literalList = (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.model.operation.LiteralList) operationElement;
return new Root_meta_relational_metamodel_LiteralList_Impl("")._values(ListIterate.collect(literalList.values, l -> new Root_meta_relational_metamodel_Literal_Impl("")._value(convertLiteral(l.value))));
}
throw new UnsupportedOperationException();
}
use of org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.RelationalOperationElementWithJoin in project legend-pure by finos.
the class RelationalOperationElementProcessor method populateColumnExpressionReferenceUsages.
static void populateColumnExpressionReferenceUsages(CoreInstance columnExpression, ModelRepository repository, ProcessorSupport processorSupport) {
if (columnExpression instanceof TableAliasColumn) {
populateTableAliasColumnReferenceUsages((TableAliasColumn) columnExpression, repository, processorSupport);
} else if (columnExpression instanceof DynaFunction) {
populateDynaFunctionReferenceUsages((DynaFunction) columnExpression, repository, processorSupport);
} else if (columnExpression instanceof RelationalOperationElementWithJoin) {
RelationalOperationElement relationalOperationElement = ((RelationalOperationElementWithJoin) columnExpression)._relationalOperationElement();
if (relationalOperationElement != null) {
if (relationalOperationElement instanceof DynaFunction) {
populateDynaFunctionReferenceUsages((DynaFunction) relationalOperationElement, repository, processorSupport);
} else if (relationalOperationElement instanceof TableAliasColumn) {
populateTableAliasColumnReferenceUsages((TableAliasColumn) relationalOperationElement, repository, processorSupport);
}
}
JoinTreeNode joinTreeNode = ((RelationalOperationElementWithJoin) columnExpression)._joinTreeNode();
if (joinTreeNode != null) {
populateJoinTreeNodeReferenceUsages(joinTreeNode, repository, processorSupport);
}
}
}
use of org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.RelationalOperationElementWithJoin in project legend-pure by finos.
the class RelationalPropertyMappingProcessor method processRelationalPropertyMapping.
static MutableSet<TableAlias> processRelationalPropertyMapping(PropertyMapping propertyMapping, Matcher matcher, ProcessorState state, ModelRepository repository, String depth, ProcessorSupport processorSupport, PropertyMappingsImplementation implementation, PropertyMappingsImplementation topLevel) {
if (MilestoningFunctions.isAutoGeneratedMilestoningNamedDateProperty(propertyMapping._property(), processorSupport)) {
throw new PureCompilationException(propertyMapping.getSourceInformation(), "Class : [" + PackageableElement.getUserPathForPackageableElement(((SetImplementation) implementation)._class()) + "] has temporal specification. Hence mapping of property : [milestoning] is reserved and should not be explicit in the mapping");
}
MutableSet<TableAlias> tableAliases = Sets.mutable.empty();
String newDepth = depth + "_" + ((ModelElement) propertyMapping._propertyCoreInstance())._name();
CoreInstance sourceSetImplementationId = repository.newStringCoreInstance_cached(depth);
if (implementation instanceof EmbeddedRelationalInstanceSetImplementation) {
propertyMapping._sourceSetImplementationId(sourceSetImplementationId.getName());
}
if (propertyMapping instanceof EmbeddedRelationalInstanceSetImplementation) {
EmbeddedRelationalInstanceSetImplementation embeddedRelationalInstanceSetImplementation = (EmbeddedRelationalInstanceSetImplementation) propertyMapping;
if (!(implementation instanceof EmbeddedRelationalInstanceSetImplementation)) {
propertyMapping._sourceSetImplementationId(implementation._id());
}
String newId;
if (embeddedRelationalInstanceSetImplementation._id() == null) {
CoreInstance new_Id = repository.newStringCoreInstance_cached(newDepth);
embeddedRelationalInstanceSetImplementation._id(new_Id.getName());
embeddedRelationalInstanceSetImplementation._targetSetImplementationId(new_Id.getName());
newId = newDepth;
} else {
newId = embeddedRelationalInstanceSetImplementation._id();
}
RootRelationalInstanceSetImplementation owner = embeddedRelationalInstanceSetImplementation._setMappingOwner();
if (owner == null) {
embeddedRelationalInstanceSetImplementation._setMappingOwner((RootRelationalInstanceSetImplementation) topLevel);
}
Property property = (Property) ImportStub.withImportStubByPass(embeddedRelationalInstanceSetImplementation._propertyCoreInstance(), processorSupport);
CoreInstance targetClass = property._classifierGenericType() == null || property._classifierGenericType()._typeArguments() == null || property._classifierGenericType()._typeArguments().size() < 2 || property._classifierGenericType()._typeArguments().toList().get(1) == null ? null : ImportStub.withImportStubByPass(property._classifierGenericType()._typeArguments().toList().get(1)._rawTypeCoreInstance(), processorSupport);
embeddedRelationalInstanceSetImplementation._classCoreInstance(targetClass);
RichIterable<? extends PropertyMapping> embeddedPropertyMappings = embeddedRelationalInstanceSetImplementation._propertyMappings();
tableAliases.addAll(processRelationalPropertyMappings(embeddedPropertyMappings, embeddedRelationalInstanceSetImplementation, (RootRelationalInstanceSetImplementation) topLevel, newId, matcher, state, repository, processorSupport));
RelationalInstanceSetImplementationProcessor.processUserDefinedPrimaryKey(embeddedRelationalInstanceSetImplementation, topLevel, matcher, state, repository, processorSupport);
if (propertyMapping instanceof OtherwiseEmbeddedRelationalInstanceSetImplementation) {
OtherwiseEmbeddedRelationalInstanceSetImplementation otherwiseEmbeddedRelationalInstanceSetImplementation = (OtherwiseEmbeddedRelationalInstanceSetImplementation) propertyMapping;
PropertyMapping otherwiseMapping = otherwiseEmbeddedRelationalInstanceSetImplementation._otherwisePropertyMapping();
otherwiseMapping._sourceSetImplementationId(sourceSetImplementationId.getName());
// relationalOperationElement
RelationalOperationElement impl = ((RelationalPropertyMapping) otherwiseMapping)._relationalOperationElement();
RelationalOperationElementProcessor.processColumnExpr(impl, topLevel, topLevel, tableAliases, matcher, state, repository, processorSupport);
}
} else {
// Transformer
if (propertyMapping instanceof RelationalPropertyMapping) {
GrammarInfoStub transformerStub = (GrammarInfoStub) ((RelationalPropertyMapping) propertyMapping)._transformerCoreInstance();
EnumerationMappingProcessor.processsEnumerationTransformer(transformerStub, propertyMapping, processorSupport);
// relationalOperationElement
RelationalOperationElement impl = ((RelationalPropertyMapping) propertyMapping)._relationalOperationElement();
RelationalOperationElementProcessor.processColumnExpr(impl, topLevel, topLevel, tableAliases, matcher, state, repository, processorSupport);
propertyMapping._store(impl instanceof RelationalOperationElementWithJoin ? ((RelationalOperationElementWithJoin) impl)._joinTreeNode()._database() : null);
}
}
return tableAliases;
}
Aggregations