use of org.finos.legend.pure.generated.Root_meta_relational_metamodel_TableAliasColumn_Impl in project legend-engine by finos.
the class HelperRelationalBuilder method processRelationalPrimaryKey.
public static void processRelationalPrimaryKey(RootRelationalInstanceSetImplementation rootRelationalInstanceSetImplementation) {
if (rootRelationalInstanceSetImplementation._groupBy() != null) {
rootRelationalInstanceSetImplementation._primaryKey(rootRelationalInstanceSetImplementation._groupBy()._columns());
} else // TODO handle distinct
if (rootRelationalInstanceSetImplementation._primaryKey().isEmpty()) {
Relation relation = (Relation) rootRelationalInstanceSetImplementation._mainTableAlias()._relationalElement();
final TableAlias finalMainTable = rootRelationalInstanceSetImplementation._mainTableAlias();
RichIterable<? extends Column> columns = FastList.newList();
if (relation instanceof Table) {
columns = ((Table) relation)._primaryKey();
} else if (relation instanceof View) {
columns = ((View) relation)._primaryKey();
}
RichIterable<TableAliasColumn> primaryKey = columns.collect(new Function<Column, TableAliasColumn>() {
@Override
public TableAliasColumn valueOf(Column column) {
TableAliasColumn tableAliasColumn = new Root_meta_relational_metamodel_TableAliasColumn_Impl("");
tableAliasColumn._column(column);
tableAliasColumn._alias(finalMainTable);
return tableAliasColumn;
}
});
rootRelationalInstanceSetImplementation._primaryKey(primaryKey);
}
}
use of org.finos.legend.pure.generated.Root_meta_relational_metamodel_TableAliasColumn_Impl 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();
}
Aggregations