Skip to content

Commit

Permalink
Resolve class properties from supertype on mapping compilation (#2988)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yasirmod17 authored Jul 31, 2024
1 parent 9185ff3 commit 817648f
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import org.eclipse.collections.api.RichIterable;
import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.api.list.ListIterable;
import org.eclipse.collections.impl.utility.LazyIterate;
import org.eclipse.collections.impl.utility.ListIterate;
import org.finos.legend.engine.protocol.pure.v1.model.context.EngineErrorType;
Expand Down Expand Up @@ -56,6 +57,7 @@
import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecificationContext;
import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.VariableExpression;
import org.finos.legend.pure.m3.navigation.M3Paths;
import org.finos.legend.pure.m3.navigation.linearization.C3Linearization;
import org.finos.legend.pure.m4.coreinstance.CoreInstance;
import org.finos.legend.pure.runtime.java.compiled.execution.CompiledExecutionSupport;
import org.slf4j.Logger;
Expand Down Expand Up @@ -473,7 +475,8 @@ public static AbstractProperty<?> getAppliedProperty(CompileContext context, org
for (CoreInstance c_type : org.finos.legend.pure.m3.navigation.type.Type.getGeneralizationResolutionOrder(_class, context.pureModel.getExecutionSupport().getProcessorSupport()))
{
org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class<?> type = (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class<?>) c_type;
AbstractProperty<?> property = type._properties().detect(p -> name.equals(p.getName()));
ListIterable<CoreInstance> orderedGeneralizations = C3Linearization.getTypeGeneralizationLinearization(type, context.pureModel.getExecutionSupport().getProcessorSupport());
AbstractProperty<?> property = getCompatibleProperty(orderedGeneralizations, name);
if (property != null)
{
return property;
Expand All @@ -497,6 +500,20 @@ public static AbstractProperty<?> getAppliedProperty(CompileContext context, org
throw new EngineException("Can't find property '" + name + "' in [" + org.finos.legend.pure.m3.navigation.type.Type.getGeneralizationResolutionOrder(_class, context.pureModel.getExecutionSupport().getProcessorSupport()).makeString(", ") + "]", sourceInformation, EngineErrorType.COMPILATION);
}

public static AbstractProperty<?> getCompatibleProperty(ListIterable<CoreInstance> orderedGeneralizations, String name)
{
for (CoreInstance instance : orderedGeneralizations)
{
org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class<?> type = (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class<?>) instance;
AbstractProperty<?> property = type._properties().detect(p -> name.equals(p.getName()));
if (property != null)
{
return property;
}
}
return null;
}

public static QualifiedProperty<?> getCompatibleDerivedProperty(RichIterable<? extends QualifiedProperty<?>> qualifiedProperties, String name, Optional<? extends List<? extends org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification>> parameters)
{
RichIterable<? extends QualifiedProperty<?>> propertiesWithSameName = qualifiedProperties.select(p -> name.equals(p._name()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2702,4 +2702,63 @@ public void testCompilationMissingEnumMapping() throws Exception
Assert.assertEquals(1, warnings.size());
Assert.assertEquals("{\"sourceInformation\":{\"sourceId\":\"\",\"startLine\":24,\"startColumn\":9,\"endLine\":24,\"endColumn\":33},\"message\":\"Missing an EnumerationMapping for the enum property 'type'. Enum properties require an EnumerationMapping in order to transform the store values into the Enum.\"}", new ObjectMapper().writeValueAsString(warnings.get(0)));
}

@Test
public void testMappingToPropertyWithDerivedPropertyConflict()
{
test("###Relational\n" +

"Database demo::stores::Db\n" +
"(\n" +
" Schema First\n" +
" (\n" +
" Table Source\n" +
" (\n" +
" accountNumber INTEGER PRIMARY KEY,\n" +
" name VARCHAR(200)\n" +
" )\n" +
" )\n" +
")\n" +
"\n" +
"\n" +
"###Pure\n" +
"Class demo::model::ChildClass extends demo::model::BaseClass, demo::model::BaseClass2 \n" +
"{\n" +
" Name: String[1];\n" +
" accountNumber(num: Integer[1],name: String[1]) {$num + $name->size()}: Integer[1];\n" +
"}\n" +
"\n" +
"Class demo::model::BaseClass2 extends demo::model::BaseClass2Parent\n" +
"{\n" +
"}\n" +
"\n" +
"Class demo::model::BaseClass extends demo::model::BaseClassParent\n" +
"{\n" +
"}\n" +
"\n" +
"Class demo::model::BaseClassParent\n" +
"{\n" +
"}\n" +
"\n" +
"Class demo::model::BaseClass2Parent\n" +
"{\n" +
" accountNumber: Integer[1];\n" +
"}\n" +
"\n" +
"\n" +
"###Mapping\n" +
"Mapping demo::mapping::Map1\n" +
"(\n" +
" *demo::model::ChildClass: Relational\n" +
" {\n" +
" ~primaryKey\n" +
" (\n" +
" [demo::stores::Db]First.Source.accountNumber\n" +
" )\n" +
" ~mainTable [demo::stores::Db]First.Source\n" +
" Name: [demo::stores::Db]First.Source.name,\n" +
" accountNumber: [demo::stores::Db]First.Source.accountNumber\n" +
" }\n" +
")\n");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,25 @@
</execution>
</executions>
</plugin>
<plugin>
<!-- for TC -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>dependency-analyze</id>
<phase>test-compile</phase>
<goals>
<goal>analyze-only</goal>
</goals>
<configuration>
<ignoredUnusedDeclaredDependencies>
<ignoredUnusedDeclaredDependency>com.fasterxml.jackson.core:jackson-databind</ignoredUnusedDeclaredDependency>
</ignoredUnusedDeclaredDependencies>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down Expand Up @@ -150,6 +169,12 @@
</dependency>
<!-- Http Client -->

<!-- JACKSON -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<!-- JACKSON -->
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
Expand Down

0 comments on commit 817648f

Please sign in to comment.