use of org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.relation.View in project legend-pure by finos.
the class TestViewProcessing method testViewInSchemaPotentialIssue.
@Test
public void testViewInSchemaPotentialIssue() {
Loader.parseM3("###Relational\n" + " Database db(\n" + " Schema ep_Datastore(\n" + " Table Team( TEAM VARCHAR(200) PRIMARY KEY )\n" + " )\n" + " \n" + " Schema viewSchema(\n" + " View TeamDistinct(\n" + " ~distinct\n" + " TEAM: ep_Datastore.Team.TEAM PRIMARY KEY \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("db");
CoreInstance viewSchema = this.graphWalker.getSchema(db, "viewSchema");
CoreInstance teamDistinctView = this.graphWalker.getView(viewSchema, "TeamDistinct");
CoreInstance teamCol = teamDistinctView.getValueForMetaPropertyToOne(M2RelationalProperties.columns);
CoreInstance teamMappingCol = teamDistinctView.getValueForMetaPropertyToOne(M2RelationalProperties.columnMappings).getValueForMetaPropertyToOne(M2RelationalProperties.relationalOperationElement).getValueForMetaPropertyToOne(M2RelationalProperties.column);
CoreInstance viewPkCol = teamDistinctView.getValueForMetaPropertyToOne(M2RelationalProperties.primaryKey);
CoreInstance mainTable = teamDistinctView.getValueForMetaPropertyToOne(M2RelationalProperties.mainTableAlias).getValueForMetaPropertyToOne(M2RelationalProperties.relationalElement);
Assert.assertEquals(mainTable, teamMappingCol.getValueForMetaPropertyToOne(M3Properties.owner));
Assert.assertEquals(teamDistinctView, teamCol.getValueForMetaPropertyToOne(M3Properties.owner));
Assert.assertEquals(teamDistinctView, viewPkCol.getValueForMetaPropertyToOne(M3Properties.owner));
}
use of org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.relation.View in project legend-pure by finos.
the class TestViewProcessing method testRelationalViewDisallowOtherDbDependencyValidation.
@Test
public void testRelationalViewDisallowOtherDbDependencyValidation() {
this.expectedEx.expect(RuntimeException.class);
this.expectedEx.expectMessage("All tables referenced in View: multipleMainTablesView should come from the View's owning or included DB: 'with::view::db', table: 'orderTable' does not");
Loader.parseM3(dbWithViewDependentOnTableInOtherDb, this.repository, new ParserLibrary(Lists.immutable.with(new M3AntlrParser(), new MappingParser(), new RelationalParser())), ValidationType.DEEP, VoidM3M4StateListener.VOID_M3_M4_STATE_LISTENER, this.context);
}
use of org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.relation.View in project legend-pure by finos.
the class TestViewProcessing method testViewGroupWithIncorrectGroupByTableSpecification.
@Test
public void testViewGroupWithIncorrectGroupByTableSpecification() {
expectedEx.expect(RuntimeException.class);
expectedEx.expectMessage("View: TeamDistinct has a groupBy which refers to table: 'otherOrder' which is not the mainTable: 'Order'");
Loader.parseM3("###Relational\n" + " Database db(\n" + " Schema ep_Datastore(\n" + " Table Order( ID Integer PRIMARY KEY,\n" + " ACCOUNT_ID INTEGER,\n" + " PNL FLOAT\n" + " )\n" + " Table otherOrder( ID Integer PRIMARY KEY)" + " )\n" + " \n" + " Schema viewSchema(\n" + " View TeamDistinct(\n" + " ~groupBy (ep_Datastore.otherOrder.ID)\n" + " accountId: ep_Datastore.Order.ACCOUNT_ID PRIMARY KEY, \n" + " summedPnl: sum(ep_Datastore.Order.PNL) \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();
}
use of org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.relation.View in project legend-pure by finos.
the class ViewProcessing method processPrimaryKeys.
private static void processPrimaryKeys(View view, MapIterable<String, DataType> colMappingTypeByName) {
RichIterable<? extends Column> primaryKeyCols = view._primaryKey();
view._userDefinedPrimaryKey(primaryKeyCols.notEmpty());
if (primaryKeyCols.notEmpty()) {
setColumnTypes(primaryKeyCols, colMappingTypeByName);
for (Column col : primaryKeyCols) {
col._owner(view);
}
}
}
use of org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.relation.View in project legend-pure by finos.
the class ViewProcessing method setViewMainTableAlias.
private static void setViewMainTableAlias(View view, RelationalOperationElement mainTable, ProcessorSupport processorSupport) {
TableAlias mainTableAlias = buildTableAlias(mainTable, processorSupport);
view._mainTableAlias(mainTableAlias);
}
Aggregations