generated from finos/software-project-blueprint
-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Write API - reference implementation (#3292)
* Implement Write API - reference implementation * Add missing changes * Move comment to above write expected failure
- Loading branch information
Showing
11 changed files
with
183 additions
and
7 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
...ation-pure/src/main/resources/core_functions_relation/relation/functions/write/write.pure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2024 Goldman Sachs | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import meta::pure::metamodel::relation::*; | ||
import meta::pure::functions::relation::*; | ||
import meta::pure::store::*; | ||
import meta::pure::test::pct::*; | ||
|
||
native function <<PCT.function, functionType.SideEffectFunction>> meta::pure::functions::relation::write<T>(rel:Relation<T>[1], relationElementAccessor:RelationElementAccessor<T>[1]):Integer[1]; | ||
|
||
function <<PCT.test>> meta::pure::functions::relation::testWrite<T|m>(f:Function<{Function<{->T[m]}>[1]->T[m]}>[1]):Boolean[1] | ||
{ | ||
let expr = { | ||
| | ||
let targetTDS = meta::pure::metamodel::relation::newTDSRelationAccessor(#TDS | ||
val,str,other | ||
1,aaa,a | ||
#); | ||
let rowsAdded = #TDS | ||
val,str,other | ||
1,a,a | ||
3,ewe,b | ||
4,qw,c | ||
5,wwe,d | ||
6,weq,e | ||
#->write($targetTDS); | ||
$targetTDS->select(); | ||
}; | ||
|
||
let res = $f->eval($expr); | ||
|
||
assertEquals( '#TDS\n'+ | ||
' val,str,other\n'+ | ||
' 1,aaa,a\n'+ | ||
' 1,a,a\n'+ | ||
' 3,ewe,b\n'+ | ||
' 4,qw,c\n'+ | ||
' 5,wwe,d\n'+ | ||
' 6,weq,e\n'+ | ||
'#', $res->toString()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...rg/finos/legend/pure/runtime/java/extension/external/relation/compiled/natives/Write.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright 2024 Goldman Sachs | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package org.finos.legend.pure.runtime.java.extension.external.relation.compiled.natives; | ||
|
||
import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relation.Relation; | ||
import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relation.RelationElementAccessor; | ||
import org.finos.legend.pure.m3.execution.ExecutionSupport; | ||
import org.finos.legend.pure.runtime.java.compiled.generation.processors.natives.AbstractNativeFunctionGeneric; | ||
|
||
public class Write extends AbstractNativeFunctionGeneric | ||
{ | ||
public Write() | ||
{ | ||
super("org.finos.legend.pure.runtime.java.extension.external.relation.compiled.RelationNativeImplementation.write", new Class[]{Relation.class, RelationElementAccessor.class, ExecutionSupport.class}, false, true, false, "write_Relation_1__RelationElementAccessor_1__Integer_1_"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
...finos/legend/pure/runtime/java/extension/external/relation/interpreted/natives/Write.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright 2024 Goldman Sachs | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package org.finos.legend.pure.runtime.java.extension.external.relation.interpreted.natives; | ||
|
||
import org.eclipse.collections.api.list.ListIterable; | ||
import org.eclipse.collections.api.map.MutableMap; | ||
import org.eclipse.collections.api.stack.MutableStack; | ||
import org.finos.legend.pure.m3.compiler.Context; | ||
import org.finos.legend.pure.m3.exception.PureExecutionException; | ||
import org.finos.legend.pure.m3.navigation.Instance; | ||
import org.finos.legend.pure.m3.navigation.ProcessorSupport; | ||
import org.finos.legend.pure.m3.navigation.ValueSpecificationBootstrap; | ||
import org.finos.legend.pure.m4.ModelRepository; | ||
import org.finos.legend.pure.m4.coreinstance.CoreInstance; | ||
import org.finos.legend.pure.runtime.java.extension.external.relation.interpreted.natives.shared.Shared; | ||
import org.finos.legend.pure.runtime.java.extension.external.relation.interpreted.natives.shared.TDSCoreInstance; | ||
import org.finos.legend.pure.runtime.java.extension.external.relation.shared.TestTDS; | ||
import org.finos.legend.pure.runtime.java.interpreted.ExecutionSupport; | ||
import org.finos.legend.pure.runtime.java.interpreted.FunctionExecutionInterpreted; | ||
import org.finos.legend.pure.runtime.java.interpreted.VariableContext; | ||
import org.finos.legend.pure.runtime.java.interpreted.natives.InstantiationContext; | ||
import org.finos.legend.pure.runtime.java.interpreted.profiler.Profiler; | ||
|
||
import java.util.Stack; | ||
|
||
public class Write extends Shared | ||
{ | ||
public Write(FunctionExecutionInterpreted functionExecution, ModelRepository repository) | ||
{ | ||
super(functionExecution, repository); | ||
} | ||
|
||
@Override | ||
public CoreInstance execute(ListIterable<? extends CoreInstance> params, Stack<MutableMap<String, CoreInstance>> resolvedTypeParameters, Stack<MutableMap<String, CoreInstance>> resolvedMultiplicityParameters, VariableContext variableContext, MutableStack<CoreInstance> functionExpressionCallStack, Profiler profiler, InstantiationContext instantiationContext, ExecutionSupport executionSupport, Context context, ProcessorSupport processorSupport) throws PureExecutionException | ||
{ | ||
CoreInstance returnGenericType = getReturnGenericType(resolvedTypeParameters, resolvedMultiplicityParameters, functionExpressionCallStack, processorSupport); | ||
TestTDS sourceTds = getTDS(params, 0, processorSupport); | ||
CoreInstance coreInstance = params.get(1).getValueForMetaPropertyToOne("values"); | ||
if (!Instance.instanceOf(coreInstance, "meta::pure::metamodel::relation::TDSRelationAccessor", processorSupport)) | ||
{ | ||
throw new RuntimeException("Only source element of type meta::pure::metamodel::relation::TDSRelationAccessor is supported"); | ||
} | ||
TestTDS targetTds = getTDS(coreInstance, processorSupport); | ||
TDSCoreInstance resultTds = new TDSCoreInstance(targetTds.concatenate(sourceTds), returnGenericType, repository, processorSupport); | ||
Instance.setValueForProperty(coreInstance, "sourceElement", resultTds, processorSupport); | ||
return ValueSpecificationBootstrap.wrapValueSpecification(this.repository.newIntegerCoreInstance(sourceTds.getRowCount()), true, processorSupport); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters