use of org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.relation.BusinessSnapshotMilestoning in project legend-pure by finos.
the class TestSimpleGrammar method testTableWithBusinessSnapshotMilestoning.
@Test
public void testTableWithBusinessSnapshotMilestoning() {
this.runtime.createInMemorySource("test.pure", "###Relational\n" + "Database pack::ProductDatabase (\n" + " Table ProductTable\n" + " (\n" + " milestoning( \n" + " business(BUS_SNAPSHOT_DATE = snapshotDate)\n" + " )" + " id INT PRIMARY KEY,\n" + " name VARCHAR(200),\n" + " snapshotDate Date\n" + " )\n" + ")\n");
this.runtime.compile();
Database productDatabase = (Database) this.runtime.getCoreInstance("pack::ProductDatabase");
RichIterable<? extends Milestoning> milestonings = productDatabase._schemas().getFirst()._tables().getFirst()._milestoning().selectInstancesOf(BusinessSnapshotMilestoning.class);
Assert.assertEquals(1, milestonings.size());
Assert.assertTrue(milestonings.getFirst() instanceof BusinessSnapshotMilestoning);
BusinessSnapshotMilestoning businessSnapshotMilestoning = (BusinessSnapshotMilestoning) milestonings.getFirst();
Assert.assertEquals("snapshotDate", businessSnapshotMilestoning._snapshotDate()._name());
Assert.assertNull(businessSnapshotMilestoning._infinityDate());
}
use of org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.relation.BusinessSnapshotMilestoning in project legend-pure by finos.
the class DatabaseProcessor method processTableMilestoning.
private static void processTableMilestoning(CoreInstance tableCoreInstance, MapIterable<String, Column> columnsByName, Matcher matcher, ProcessorState processorState, ProcessorSupport processorSupport) {
if (tableCoreInstance instanceof Table) {
Table table = (Table) tableCoreInstance;
for (Milestoning milestoningInfo : table._milestoning()) {
milestoningInfo._owner(table);
if (milestoningInfo instanceof BusinessMilestoning) {
BusinessMilestoning businessMilestoning = (BusinessMilestoning) milestoningInfo;
if (processorSupport.instance_instanceOf(businessMilestoning._from(), M3Paths.String)) {
String businessFrom = businessMilestoning._from() == null ? "" : businessMilestoning._from().getName();
Column businessFromColumn = getColumn(table, columnsByName, businessFrom);
businessMilestoning._from(businessFromColumn);
}
if (processorSupport.instance_instanceOf(businessMilestoning._thru(), M3Paths.String)) {
String businessThru = businessMilestoning._thru() == null ? "" : businessMilestoning._thru().getName();
Column businessThruColumn = getColumn(table, columnsByName, businessThru);
businessMilestoning._thru(businessThruColumn);
}
} else if (milestoningInfo instanceof BusinessSnapshotMilestoning) {
BusinessSnapshotMilestoning businessSnapshotMilestoning = (BusinessSnapshotMilestoning) milestoningInfo;
if (processorSupport.instance_instanceOf(businessSnapshotMilestoning._snapshotDate(), M3Paths.String)) {
String snapshotDateColumnName = businessSnapshotMilestoning._snapshotDate().getName();
Column snapshotDateColumn = getColumn(table, columnsByName, snapshotDateColumnName);
if (!(snapshotDateColumn._type() instanceof Date)) {
throw new PureCompilationException(snapshotDateColumn.getSourceInformation(), "Column set as BUS_SNAPSHOT_DATE can only be of type : [Date]");
}
businessSnapshotMilestoning._snapshotDate(snapshotDateColumn);
}
} else if (milestoningInfo instanceof ProcessingMilestoning) {
ProcessingMilestoning processingMilestoning = (ProcessingMilestoning) milestoningInfo;
if (processorSupport.instance_instanceOf(processingMilestoning._in(), M3Paths.String)) {
String processingIn = processingMilestoning._in() == null ? "" : processingMilestoning._in().getName();
Column processingInColumn = getColumn(table, columnsByName, processingIn);
processingMilestoning._in(processingInColumn);
}
if (processorSupport.instance_instanceOf(processingMilestoning._out(), M3Paths.String)) {
String processingOut = processingMilestoning._out() == null ? "" : processingMilestoning._out().getName();
Column processingOutColumn = getColumn(table, columnsByName, processingOut);
processingMilestoning._out(processingOutColumn);
}
} else {
PostProcessor.processElement(matcher, milestoningInfo, processorState, processorSupport);
if (!milestoningInfo.hasBeenProcessed()) {
throw new PureCompilationException(milestoningInfo.getSourceInformation(), "Unknown milestoning type: " + PackageableElement.getUserPathForPackageableElement(milestoningInfo.getClassifier()));
}
}
}
}
}
Aggregations