Skip to content

Commit

Permalink
Add support for OLAP functions (#2984)
Browse files Browse the repository at this point in the history
  • Loading branch information
pierredebelen authored Jul 26, 2024
1 parent 54bd476 commit fdd3b40
Show file tree
Hide file tree
Showing 58 changed files with 2,439 additions and 353 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,21 +126,11 @@
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-pure-platform-dsl-store-java</artifactId>
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-pure-runtime-java-extension-compiled-functions-relation</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.finos.legend.pure</groupId>
<artifactId>legend-pure-runtime-java-engine-compiled</artifactId>
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-pure-runtime-java-extension-compiled-functions-unclassified</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.finos.legend.engine</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.eclipse.collections.impl.utility.ListIterate;
import org.finos.legend.engine.protocol.pure.v1.model.relationType.Column;
import org.finos.legend.engine.protocol.pure.v1.model.relationType.RelationType;
import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.multiplicity.Multiplicity;
import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType;
import org.finos.legend.pure.m3.navigation.ProcessorSupport;
import org.finos.legend.pure.m3.navigation._package._Package;
Expand All @@ -42,6 +43,6 @@ public static RelationType convert(org.finos.legend.pure.m3.coreinstance.meta.pu

public static org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relation.RelationType<?> convert(RelationType src, ProcessorSupport processorSupport, SourceInformation sourceInformation)
{
return _RelationType.build(ListIterate.collect(src.columns, c -> (CoreInstance) _Column.getColumnInstance(c.name, false, (GenericType) processorSupport.type_wrapGenericType(_Package.getByUserPath(c.type, processorSupport)), sourceInformation, processorSupport)).toList(), sourceInformation, processorSupport);
return _RelationType.build(ListIterate.collect(src.columns, c -> (CoreInstance) _Column.getColumnInstance(c.name, false, (GenericType) processorSupport.type_wrapGenericType(_Package.getByUserPath(c.type, processorSupport)), (Multiplicity) org.finos.legend.pure.m3.navigation.multiplicity.Multiplicity.newMultiplicity(0, 1, processorSupport), sourceInformation, processorSupport)).toList(), sourceInformation, processorSupport);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ private ValueSpecification proccessColSpecArray(ColSpecArray value)
cols.collect(c ->
{
Column<?, ?> theCol = ((RelationType<?>) c._genericType()._typeArguments().getLast()._rawType())._columns().getFirst();
return _Column.getColumnInstance(theCol._name(), false, _Column.getColumnType(theCol), null, processorSupport);
return _Column.getColumnInstance(theCol._name(), false, _Column.getColumnType(theCol), _Column.getColumnMultiplicity(theCol), null, processorSupport);
}),
null,
processorSupport
Expand Down Expand Up @@ -351,7 +351,7 @@ private ValueSpecification proccessColSpec(ColSpec colSpec)
ProcessorSupport processorSupport = context.pureModel.getExecutionSupport().getProcessorSupport();
if (colSpec.function1 == null)
{
return wrapInstanceValue(buildColSpec(colSpec.name, colSpec.type == null ? null : context.pureModel.getGenericType(colSpec.type, colSpec.sourceInformation), context.pureModel, context.pureModel.getExecutionSupport().getProcessorSupport()), context.pureModel);
return wrapInstanceValue(buildColSpec(colSpec.name, colSpec.type == null ? null : context.pureModel.getGenericType(colSpec.type, colSpec.sourceInformation), (Multiplicity) org.finos.legend.pure.m3.navigation.multiplicity.Multiplicity.newMultiplicity(0, 1, processorSupport), context.pureModel, context.pureModel.getExecutionSupport().getProcessorSupport()), context.pureModel);
}
else if (colSpec.function2 == null)
{
Expand All @@ -365,7 +365,7 @@ else if (colSpec.function2 == null)
new Root_meta_pure_metamodel_type_generics_GenericType_Impl("", null, context.pureModel.getClass("meta::pure::metamodel::type::generics::GenericType"))
._rawType(
_RelationType.build(
Lists.mutable.with(_Column.getColumnInstance(colSpec.name, false, funcReturnType(funcVS, context.pureModel), null, processorSupport)),
Lists.mutable.with(_Column.getColumnInstance(colSpec.name, false, funcReturnType(funcVS, context.pureModel), funcReturnMul(funcVS, context.pureModel), null, processorSupport)),
null,
processorSupport
)
Expand Down Expand Up @@ -405,7 +405,7 @@ else if (colSpec.function2 == null)
new Root_meta_pure_metamodel_type_generics_GenericType_Impl("", null, context.pureModel.getClass("meta::pure::metamodel::type::generics::GenericType"))
._rawType(
_RelationType.build(
Lists.mutable.with(_Column.getColumnInstance(colSpec.name, false, funcReturnType(func2VS, context.pureModel), null, processorSupport)),
Lists.mutable.with(_Column.getColumnInstance(colSpec.name, false, funcReturnType(func2VS, context.pureModel), funcReturnMul(func2VS, context.pureModel), null, processorSupport)),
null,
processorSupport
)
Expand Down Expand Up @@ -712,9 +712,9 @@ public ValueSpecification processClassInstance(RootGraphFetchTree rootGraphFetch
{
org.finos.legend.pure.m3.coreinstance.meta.pure.graphFetch.GraphFetchTree tree = HelperValueSpecificationBuilder.buildGraphFetchTree(rootGraphFetchTree, this.context, null, openVariables, processingContext);
GenericType genericType = new Root_meta_pure_metamodel_type_generics_GenericType_Impl("", null, context.pureModel.getClass("meta::pure::metamodel::type::generics::GenericType"))
._rawType(this.context.pureModel.getType("meta::pure::graphFetch::RootGraphFetchTree"))
._typeArguments(FastList.newListWith(new Root_meta_pure_metamodel_type_generics_GenericType_Impl("", null, context.pureModel.getClass("meta::pure::metamodel::type::generics::GenericType"))
._rawType(context.resolveClass(rootGraphFetchTree._class, rootGraphFetchTree.sourceInformation))));
._rawType(this.context.pureModel.getType("meta::pure::graphFetch::RootGraphFetchTree"))
._typeArguments(FastList.newListWith(new Root_meta_pure_metamodel_type_generics_GenericType_Impl("", null, context.pureModel.getClass("meta::pure::metamodel::type::generics::GenericType"))
._rawType(context.resolveClass(rootGraphFetchTree._class, rootGraphFetchTree.sourceInformation))));
return new Root_meta_pure_metamodel_valuespecification_InstanceValue_Impl("", SourceInformationHelper.toM3SourceInformation(rootGraphFetchTree.sourceInformation), context.pureModel.getClass("meta::pure::metamodel::valuespecification::InstanceValue"))
._genericType(genericType)
._multiplicity(this.context.pureModel.getMultiplicity("one"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ private static TypeAndMultiplicity getTypeAndMultiplicity(MutableList<RelationTy
RelationType<?> relType =
_RelationType.build(
types.flatCollect(RelationTypeAccessor::_columns)
.collect(c -> _Column.getColumnInstance(c._name(), false, _Column.getColumnType(c), null, processorSupport)),
.collect(c -> _Column.getColumnInstance(c._name(), false, _Column.getColumnType(c), _Column.getColumnMultiplicity(c), null, processorSupport)),
null,
processorSupport
);
Expand Down Expand Up @@ -297,7 +297,7 @@ public static TypeAndMultiplicity ExtendReturnInference(List<ValueSpecification>
Lists.mutable
.withAll((RichIterable<Column<?, ?>>) ((RelationType<?>) ps.get(0)._genericType()._typeArguments().getFirst()._rawType())._columns())
.withAll((RichIterable<Column<?, ?>>) ((RelationType<?>) ps.get(1)._genericType()._typeArguments().getLast()._rawType())._columns())
.collect(c -> (CoreInstance) _Column.getColumnInstance(c._name(), false, _Column.getColumnType(c), null, processorSupport)),
.collect(c -> (CoreInstance) _Column.getColumnInstance(c._name(), false, _Column.getColumnType(c), _Column.getColumnMultiplicity(c), null, processorSupport)),
null,
processorSupport
);
Expand Down Expand Up @@ -354,7 +354,7 @@ public static TypeAndMultiplicity ExtendReturnInference(List<ValueSpecification>
return Lists.mutable.with(
vs,
wrapInstanceValue(buildColSpec(foundColumn, cc.pureModel, ps), cc.pureModel),
wrapInstanceValue(buildColSpec(secondCol.name, _Column.getColumnType(foundColumn), cc.pureModel, ps), cc.pureModel)
wrapInstanceValue(buildColSpec(secondCol.name, _Column.getColumnType(foundColumn), _Column.getColumnMultiplicity(foundColumn), cc.pureModel, ps), cc.pureModel)
);
};

Expand Down Expand Up @@ -391,12 +391,12 @@ public static InstanceValue wrapInstanceValue(MutableList<? extends Any> values,
._values(values);
}

public static org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relation.ColSpec<?> buildColSpec(String name, GenericType colType, PureModel pureModel, ProcessorSupport ps)
public static org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relation.ColSpec<?> buildColSpec(String name, GenericType colType, Multiplicity multiplicity, PureModel pureModel, ProcessorSupport ps)
{
GenericType firstGenericType = new Root_meta_pure_metamodel_type_generics_GenericType_Impl("", null, pureModel.getClass("meta::pure::metamodel::type::generics::GenericType"))
._rawType(
_RelationType.build(
Lists.mutable.with(_Column.getColumnInstance(name, false, colType, null, ps)),
Lists.mutable.with(_Column.getColumnInstance(name, false, colType, multiplicity, null, ps)),
null,
ps
)
Expand All @@ -413,16 +413,16 @@ public static org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relation

public static org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relation.ColSpec<?> buildColSpec(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relation.Column<?, ?> col, PureModel pureModel, ProcessorSupport ps)
{
return buildColSpec(col._name(), _Column.getColumnType(col), pureModel, ps);
return buildColSpec(col._name(), _Column.getColumnType(col), _Column.getColumnMultiplicity(col), pureModel, ps);
}

public static final ParametersInference LambdaColCollectionInference = (parameters, ov, cc, pc) ->
{
ValueSpecification firstProcessedParameter = parameters.get(0).accept(new ValueSpecificationBuilder(cc, ov, pc));
GenericType gt = firstProcessedParameter._genericType();
if (parameters.get(1) instanceof ClassInstance)
if (parameters.get(1) instanceof ClassInstance)
{
((ColSpecArray)((ClassInstance) parameters.get(1)).value).colSpecs.forEach(col -> updateSimpleLambda(col.function1, gt, new org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Multiplicity(1, 1)));
((ColSpecArray) ((ClassInstance) parameters.get(1)).value).colSpecs.forEach(col -> updateSimpleLambda(col.function1, gt, new org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Multiplicity(1, 1)));
}
else
{
Expand Down Expand Up @@ -1108,11 +1108,11 @@ private void registerTDS()
{
if (c._name().equals(firstCol._name()))
{
return (CoreInstance) _Column.getColumnInstance(secondCol._name(), false, _Column.getColumnType(c), null, processorSupport);
return (CoreInstance) _Column.getColumnInstance(secondCol._name(), false, _Column.getColumnType(c), _Column.getColumnMultiplicity(c), null, processorSupport);
}
else
{
return (CoreInstance) _Column.getColumnInstance(c._name(), false, _Column.getColumnType(c), null, processorSupport);
return (CoreInstance) _Column.getColumnInstance(c._name(), false, _Column.getColumnType(c), _Column.getColumnMultiplicity(c), null, processorSupport);
}
}).toList(),
null,
Expand Down Expand Up @@ -1897,6 +1897,11 @@ public static GenericType funcReturnType(ValueSpecification vs, PureModel pm)
return funcType(vs._genericType(), pm)._returnType();
}

public static Multiplicity funcReturnMul(ValueSpecification vs, PureModel pm)
{
return funcType(vs._genericType(), pm)._returnMultiplicity();
}

private GenericType funcReturnType(ValueSpecification vs)
{
return funcType(vs._genericType(), this.pureModel)._returnType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,16 @@ function meta::pure::metamodel::serialization::grammar::printGenericType(generic
{
if ($genericType->instanceOf(GenericTypeOperation),
|let go = $genericType->cast(@GenericTypeOperation);
$go.left->printGenericType()+if($go.type == GenericTypeOperationType.Union,|'+',|'-')+$go.right->printGenericType();,
if($go.left->isEmpty(),|'',|$go.left->toOne()->printGenericType()) +
if(
[
pair(|$go.type == GenericTypeOperationType.Union,|'+'),
pair(|$go.type == GenericTypeOperationType.Difference,|'-'),
pair(|$go.type == GenericTypeOperationType.Subset,|'⊆')
],
|'='
) +
$go.right->printGenericType();,
|if ($genericType.rawType->isEmpty(),
|if ($genericType.typeParameter->isEmpty(),
|'',
Expand Down
Loading

0 comments on commit fdd3b40

Please sign in to comment.