Search in sources :

Example 1 with BindingTransformer

use of org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.BindingTransformer in project legend-engine by finos.

the class RelationalParseTreeWalker method buildBindingTransformer.

private BindingTransformer buildBindingTransformer(RelationalParserGrammar.BindingTransformerContext ctx) {
    String binding = PureGrammarParserUtility.fromQualifiedName(ctx.qualifiedName().packagePath() == null ? Collections.emptyList() : ctx.qualifiedName().packagePath().identifier(), ctx.qualifiedName().identifier());
    BindingTransformer bindingTransformer = new BindingTransformer();
    bindingTransformer.binding = binding;
    return bindingTransformer;
}
Also used : BindingTransformer(org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.BindingTransformer)

Example 2 with BindingTransformer

use of org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.BindingTransformer in project legend-engine by finos.

the class HelperRelationalBuilder method buildSemiStructuredPropertyMapping.

private static PropertyMapping buildSemiStructuredPropertyMapping(Property<?, ?> property, RelationalPropertyMapping propertyMapping, PropertyMappingsImplementation parent, RootRelationalInstanceSetImplementation topParent, MutableList<EmbeddedRelationalInstanceSetImplementation> embeddedRelationalPropertyMappings, MutableMap<String, TableAlias> aliasMap, CompileContext context) {
    Root_meta_external_shared_format_binding_Binding binding = HelperExternalFormat.getBinding(propertyMapping.bindingTransformer.binding, context);
    Type propertyType = property._genericType()._rawType();
    if (!"Class".equals(propertyType._classifierGenericType()._rawType()._name())) {
        throw new EngineException("Binding transformer can be used with complex properties only. Property '" + property._name() + "' return type is '" + propertyType._name() + "'", propertyMapping.sourceInformation, EngineErrorType.COMPILATION);
    }
    if (!core_pure_model_modelUnit.Root_meta_pure_model_unit_resolve_ModelUnit_1__ResolvedModelUnit_1_(binding._modelUnit(), context.getExecutionSupport()).classes(context.getExecutionSupport()).contains(propertyType)) {
        throw new EngineException("Class: " + platform_pure_corefunctions_meta.Root_meta_pure_functions_meta_elementToPath_PackageableElement_1__String_1_(propertyType, context.getExecutionSupport()) + " should be included in modelUnit for binding: " + propertyMapping.bindingTransformer.binding, propertyMapping.sourceInformation, EngineErrorType.COMPILATION);
    }
    ExternalFormatExtension<?, ?, ?> schemaExtension = HelperExternalFormat.getExternalFormatExtension(binding);
    Root_meta_external_shared_format_binding_validation_BindingDetail bindingDetail = schemaExtension.bindDetails(binding, context);
    if (bindingDetail instanceof Root_meta_external_shared_format_binding_validation_SuccessfulBindingDetail) {
        RelationalOperationElement relationalOperationElement = processRelationalOperationElement(propertyMapping.relationalOperation, context, aliasMap, FastList.newList());
        Root_meta_external_shared_format_binding_BindingTransformer<?> bindingTransformer = new Root_meta_external_shared_format_binding_BindingTransformer_Impl<>("")._binding(binding)._class((Class<?>) propertyType);
        return buildSemiStructuredEmbeddedPropertyMapping(binding, (Root_meta_external_shared_format_binding_validation_SuccessfulBindingDetail) bindingDetail, property, (Class<?>) propertyType, relationalOperationElement, parent, topParent, embeddedRelationalPropertyMappings, true, bindingTransformer, context);
    } else {
        throw new EngineException("External format content type: '" + binding._contentType() + "' not yet supported", propertyMapping.sourceInformation, EngineErrorType.COMPILATION);
    }
}
Also used : Root_meta_external_shared_format_binding_Binding(org.finos.legend.pure.generated.Root_meta_external_shared_format_binding_Binding) GenericType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType) DataType(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.model.datatype.DataType) EngineErrorType(org.finos.legend.engine.protocol.pure.v1.model.context.EngineErrorType) Type(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type) Root_meta_external_shared_format_binding_validation_SuccessfulBindingDetail(org.finos.legend.pure.generated.Root_meta_external_shared_format_binding_validation_SuccessfulBindingDetail) Root_meta_external_shared_format_binding_BindingTransformer_Impl(org.finos.legend.pure.generated.Root_meta_external_shared_format_binding_BindingTransformer_Impl) RelationalOperationElement(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.RelationalOperationElement) EngineException(org.finos.legend.engine.shared.core.operational.errorManagement.EngineException) Root_meta_external_shared_format_binding_validation_BindingDetail(org.finos.legend.pure.generated.Root_meta_external_shared_format_binding_validation_BindingDetail)

Example 3 with BindingTransformer

use of org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.BindingTransformer in project legend-engine by finos.

the class RelationalParseTreeWalker method visitRelationalPropertyMapping.

private PropertyMapping visitRelationalPropertyMapping(RelationalParserGrammar.RelationalPropertyMappingContext ctx, PropertyPointer propertyPointer, LocalMappingPropertyInfo localMappingPropertyInfo, ScopeInfo scopeInfo, String classMappingId, String targetId) {
    RelationalPropertyMapping relationalPropertyMapping = new RelationalPropertyMapping();
    relationalPropertyMapping.sourceInformation = this.walkerSourceInformation.getSourceInformation(ctx);
    relationalPropertyMapping.localMappingProperty = localMappingPropertyInfo;
    relationalPropertyMapping.property = propertyPointer;
    relationalPropertyMapping.source = classMappingId;
    relationalPropertyMapping.target = targetId;
    relationalPropertyMapping.enumMappingId = ctx.transformer() != null && ctx.transformer().enumTransformer() != null ? PureGrammarParserUtility.fromIdentifier(ctx.transformer().enumTransformer().identifier()) : null;
    relationalPropertyMapping.bindingTransformer = ctx.transformer() != null && ctx.transformer().bindingTransformer() != null ? buildBindingTransformer(ctx.transformer().bindingTransformer()) : null;
    relationalPropertyMapping.relationalOperation = this.visitOperation(ctx.operation(), scopeInfo);
    return relationalPropertyMapping;
}
Also used : EmbeddedRelationalPropertyMapping(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.mapping.EmbeddedRelationalPropertyMapping) OtherwiseEmbeddedRelationalPropertyMapping(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.mapping.OtherwiseEmbeddedRelationalPropertyMapping) RelationalPropertyMapping(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.mapping.RelationalPropertyMapping)

Example 4 with BindingTransformer

use of org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.BindingTransformer in project legend-engine by finos.

the class TestRelationalMappingGrammarParser method testLocalMappingPropertyParsing.

@Test
public void testLocalMappingPropertyParsing() throws Exception {
    String val = "###Mapping\n" + "Mapping mappingPackage::myMapping\n" + "(\n" + "    Person: Relational\n" + "    {\n" + "        firstName : [db]personTable.firstName,\n" + "        +localProp : String[1] : [db]personTable.firstName\n" + "    }\n" + ")\n";
    PureModelContextData data = PureGrammarParser.newInstance().parseModel(val);
    String expected = "{\"_type\":\"data\",\"serializer\":null,\"origin\":null,\"elements\":[{\"_type\":\"mapping\",\"name\":\"myMapping\",\"sourceInformation\":{\"sourceId\":\"\",\"startLine\":2,\"startColumn\":1,\"endLine\":9,\"endColumn\":1},\"classMappings\":[{\"_type\":\"relational\",\"id\":null,\"mappingClass\":null,\"extendsClassMappingId\":null,\"root\":false,\"sourceInformation\":{\"sourceId\":\"\",\"startLine\":4,\"startColumn\":5,\"endLine\":8,\"endColumn\":5},\"classSourceInformation\":{\"sourceId\":\"\",\"startLine\":4,\"startColumn\":5,\"endLine\":4,\"endColumn\":10},\"primaryKey\":[],\"propertyMappings\":[{\"_type\":\"relationalPropertyMapping\",\"property\":{\"property\":\"firstName\",\"sourceInformation\":{\"sourceId\":\"mappingPackage::myMapping\",\"startLine\":6,\"startColumn\":9,\"endLine\":6,\"endColumn\":17},\"class\":\"Person\"},\"source\":null,\"target\":null,\"localMappingProperty\":null,\"sourceInformation\":{\"sourceId\":\"mappingPackage::myMapping\",\"startLine\":6,\"startColumn\":19,\"endLine\":6,\"endColumn\":45},\"enumMappingId\":null,\"relationalOperation\":{\"_type\":\"column\",\"sourceInformation\":{\"sourceId\":\"mappingPackage::myMapping\",\"startLine\":6,\"startColumn\":21,\"endLine\":6,\"endColumn\":45},\"table\":{\"_type\":\"Table\",\"table\":\"personTable\",\"schema\":\"default\",\"database\":\"db\",\"mainTableDb\":\"db\",\"sourceInformation\":{\"sourceId\":\"mappingPackage::myMapping\",\"startLine\":6,\"startColumn\":25,\"endLine\":6,\"endColumn\":35}},\"tableAlias\":\"personTable\",\"column\":\"firstName\"},\"bindingTransformer\":null},{\"_type\":\"relationalPropertyMapping\",\"property\":{\"property\":\"localProp\",\"sourceInformation\":{\"sourceId\":\"mappingPackage::myMapping\",\"startLine\":7,\"startColumn\":10,\"endLine\":7,\"endColumn\":18},\"class\":null},\"source\":null,\"target\":null,\"localMappingProperty\":{\"type\":\"String\",\"multiplicity\":{\"lowerBound\":1,\"upperBound\":1},\"sourceInformation\":{\"sourceId\":\"mappingPackage::myMapping\",\"startLine\":7,\"startColumn\":20,\"endLine\":7,\"endColumn\":30}},\"sourceInformation\":{\"sourceId\":\"mappingPackage::myMapping\",\"startLine\":7,\"startColumn\":32,\"endLine\":7,\"endColumn\":58},\"enumMappingId\":null,\"relationalOperation\":{\"_type\":\"column\",\"sourceInformation\":{\"sourceId\":\"mappingPackage::myMapping\",\"startLine\":7,\"startColumn\":34,\"endLine\":7,\"endColumn\":58},\"table\":{\"_type\":\"Table\",\"table\":\"personTable\",\"schema\":\"default\",\"database\":\"db\",\"mainTableDb\":\"db\",\"sourceInformation\":{\"sourceId\":\"mappingPackage::myMapping\",\"startLine\":7,\"startColumn\":38,\"endLine\":7,\"endColumn\":48}},\"tableAlias\":\"personTable\",\"column\":\"firstName\"},\"bindingTransformer\":null}],\"mainTable\":null,\"distinct\":false,\"groupBy\":[],\"filter\":null,\"class\":\"Person\"}],\"includedMappings\":[],\"associationMappings\":[],\"enumerationMappings\":[],\"tests\":[],\"package\":\"mappingPackage\"},{\"_type\":\"sectionIndex\",\"name\":\"SectionIndex\",\"sourceInformation\":null,\"sections\":[{\"_type\":\"importAware\",\"parserName\":\"Pure\",\"elements\":[],\"sourceInformation\":{\"sourceId\":\"\",\"startLine\":1,\"startColumn\":1,\"endLine\":1,\"endColumn\":8},\"imports\":[]},{\"_type\":\"importAware\",\"parserName\":\"Mapping\",\"elements\":[\"mappingPackage::myMapping\"],\"sourceInformation\":{\"sourceId\":\"\",\"startLine\":2,\"startColumn\":8,\"endLine\":11,\"endColumn\":2},\"imports\":[]}],\"package\":\"__internal__\"}]}";
    Assert.assertEquals(expected, PureProtocolObjectMapperFactory.getNewObjectMapper().writeValueAsString(data));
}
Also used : PureModelContextData(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData) Test(org.junit.Test)

Aggregations

EngineErrorType (org.finos.legend.engine.protocol.pure.v1.model.context.EngineErrorType)1 PureModelContextData (org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData)1 EmbeddedRelationalPropertyMapping (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.mapping.EmbeddedRelationalPropertyMapping)1 OtherwiseEmbeddedRelationalPropertyMapping (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.mapping.OtherwiseEmbeddedRelationalPropertyMapping)1 RelationalPropertyMapping (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.mapping.RelationalPropertyMapping)1 DataType (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.model.datatype.DataType)1 BindingTransformer (org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.BindingTransformer)1 EngineException (org.finos.legend.engine.shared.core.operational.errorManagement.EngineException)1 Root_meta_external_shared_format_binding_Binding (org.finos.legend.pure.generated.Root_meta_external_shared_format_binding_Binding)1 Root_meta_external_shared_format_binding_BindingTransformer_Impl (org.finos.legend.pure.generated.Root_meta_external_shared_format_binding_BindingTransformer_Impl)1 Root_meta_external_shared_format_binding_validation_BindingDetail (org.finos.legend.pure.generated.Root_meta_external_shared_format_binding_validation_BindingDetail)1 Root_meta_external_shared_format_binding_validation_SuccessfulBindingDetail (org.finos.legend.pure.generated.Root_meta_external_shared_format_binding_validation_SuccessfulBindingDetail)1 Type (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type)1 GenericType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType)1 RelationalOperationElement (org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.RelationalOperationElement)1 Test (org.junit.Test)1