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;
}
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);
}
}
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;
}
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));
}
Aggregations