Skip to content

Commit

Permalink
Relational Mapper Packageable Element (#2817)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrudula-gs authored Apr 30, 2024
1 parent 6a0065a commit 936400d
Show file tree
Hide file tree
Showing 28 changed files with 1,330 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.externalFormat.ExternalFormatSchemaSet;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.function.FunctionTest;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.function.FunctionTestSuite;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapper.RelationalMapper;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.Mapping;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.mappingTest.MappingTest;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.mappingTest.MappingTestSuite;
Expand Down Expand Up @@ -100,6 +101,7 @@ public List<Function0<List<ProtocolSubTypeInfo<?>>>> getExtraProtocolSubTypeInfo
.withSubtype(Unit.class, "unit")
.withSubtype(ExternalFormatSchemaSet.class, "externalFormatSchemaSet")
.withSubtype(Binding.class, "binding")
.withSubtype(RelationalMapper.class, "relationalMapper")
.build(),
// Runtime
ProtocolSubTypeInfo.newBuilder(Runtime.class)
Expand Down Expand Up @@ -172,6 +174,7 @@ public Map<java.lang.Class<? extends PackageableElement>, String> getExtraProtoc
.withKeyValue(DataElement.class, "meta::pure::data::DataElement")
.withKeyValue(ExternalFormatSchemaSet.class, "meta::external::format::shared::metamodel::SchemaSet")
.withKeyValue(Binding.class, "meta::external::format::shared::binding::Binding")
.withKeyValue(SectionIndex.class, "meta::pure::metamodel::section::SectionIndex");
.withKeyValue(SectionIndex.class, "meta::pure::metamodel::section::SectionIndex")
.withKeyValue(RelationalMapper.class, "meta::relational::metamodel::RelationalMapper");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ public enum PackageableElementType
DATASPACE,
DIAGRAM,
FILE_GENERATION,
DATA
DATA,
QUERYPOSTPROCESSOR
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public static PureModelContextData newPureModelContextData(
@Deprecated @JsonProperty("connections") Collection<? extends PackageableElement> connections,
@Deprecated @JsonProperty("fileGenerations") Collection<? extends PackageableElement> fileGenerations,
@Deprecated @JsonProperty("generationSpecifications") Collection<? extends PackageableElement> generationSpecifications,
@Deprecated @JsonProperty("relationalMapper") Collection<? extends PackageableElement> relationalMapper,
@Deprecated @JsonProperty("serializableModelSpecifications") Collection<? extends PackageableElement> serializableModelSpecifications)
{
MutableList<PackageableElement> allElements = (elements == null) ? Lists.mutable.empty() : Lists.mutable.withAll(elements);
Expand Down Expand Up @@ -129,6 +130,7 @@ public static PureModelContextData newPureModelContextData(
Optional.ofNullable(connections).ifPresent(allElements::addAll);
Optional.ofNullable(fileGenerations).ifPresent(allElements::addAll);
Optional.ofNullable(generationSpecifications).ifPresent(allElements::addAll);
Optional.ofNullable(relationalMapper).ifPresent(allElements::addAll);
Optional.ofNullable(serializableModelSpecifications).ifPresent(allElements::addAll);
return newPureModelContextData(serializer, origin, allElements);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// 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.engine.protocol.pure.v1.model.packageableElement.mapper;

import java.util.Collections;
import java.util.List;

public class DatabaseMapper
{
public String databaseName;
public List<SchemaPtr> schemas = Collections.emptyList();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// 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.engine.protocol.pure.v1.model.packageableElement.mapper;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElement;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElementVisitor;

import java.util.Collections;
import java.util.List;

@JsonIgnoreProperties(ignoreUnknown = true)
public class RelationalMapper extends PackageableElement
{
public List<DatabaseMapper> databaseMappers = Collections.emptyList();
public List<SchemaMapper> schemaMappers = Collections.emptyList();
public List<TableMapper> tableMappers = Collections.emptyList();

@Override
public <T> T accept(PackageableElementVisitor<T> visitor)
{
return visitor.visit(this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 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.engine.protocol.pure.v1.model.packageableElement.mapper;

public class SchemaMapper
{
public SchemaPtr from;
public String to;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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.engine.protocol.pure.v1.model.packageableElement.mapper;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.bson.codecs.pojo.annotations.BsonIgnore;
import org.finos.legend.engine.protocol.pure.v1.model.SourceInformation;

public class SchemaPtr
{
public String _type;
public String schema;
public String database;
public SourceInformation sourceInformation;

public SchemaPtr()
{
}

@JsonIgnore
@BsonIgnore
public String getDb()
{
return this.database;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 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.engine.protocol.pure.v1.model.packageableElement.mapper;

public class TableMapper
{
public TablePtr from;
public String to;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// 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.engine.protocol.pure.v1.model.packageableElement.mapper;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.bson.codecs.pojo.annotations.BsonIgnore;
import org.finos.legend.engine.protocol.pure.v1.model.SourceInformation;

public class TablePtr
{
public String _type;
public String table;
public String schema;
public String database;
public SourceInformation sourceInformation;

public TablePtr()
{
}

@JsonIgnore
@BsonIgnore
public String getDb()
{
return this.database;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ FROM: 'from';
TO: 'to';
SCHEMA_FROM: 'schemaFrom';
SCHEMA_TO: 'schemaTo';
MAPPERS: 'mappers';
MAPPERS: 'mappers';
RELATIONAL_MAPPER: 'relationalMapper';
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,11 @@ schemaMapper: SCHEMA BRACE_OPEN
(
mapperFrom | mapperTo
)* BRACE_CLOSE
;

// -------------------------------------- RELATIONAL MAPPER -------------------------------------
relationalMapperPostProcessor: RELATIONAL_MAPPER
BRACE_OPEN
(qualifiedName (COMMA qualifiedName)*)?
BRACE_CLOSE
;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
lexer grammar RelationalMapperLexerGrammar;

import CoreLexerGrammar;

// -------------------------------------- KEYWORD --------------------------------------
IMPORT : 'import';
RELATIONALMAPPER : 'RelationalMapper';
DATABASEMAPPER : 'DatabaseMappers';
SCHEMAMAPPER : 'SchemaMappers';
TABLEMAPPER : 'TableMappers';
INCLUDE : 'include';
RELATIONAL_MAPPER : 'relationalMapper';
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
parser grammar RelationalMapperParserGrammar;

import CoreParserGrammar;

options
{
tokenVocab = RelationalMapperLexerGrammar;
}

// -------------------------------------- IDENTIFIER --------------------------------------

unquotedIdentifier: VALID_STRING | IMPORT | INCLUDE | RELATIONAL_MAPPER
;
identifier: unquotedIdentifier | STRING
;


// -------------------------------------- DEFINITION --------------------------------------

imports: (importStatement)*
;
importStatement: IMPORT packagePath PATH_SEPARATOR STAR SEMI_COLON
;
definition: imports
(relationalMapper)*
EOF
;
relationalMapper: RELATIONALMAPPER qualifiedName
PAREN_OPEN
(databaseMapperSection)?
(schemaMapperSection)?
(tableMapperSection)?
PAREN_CLOSE
;
databaseMapperSection: DATABASEMAPPER COLON
BRACKET_OPEN
(databaseMapper(COMMA databaseMapper)*)?
BRACKET_CLOSE
SEMI_COLON
;
schemaMapperSection: SCHEMAMAPPER COLON
BRACKET_OPEN
(schemaMapper(COMMA schemaMapper)*)?
BRACKET_CLOSE
SEMI_COLON
;
tableMapperSection: TABLEMAPPER COLON
BRACKET_OPEN
(tableMapper(COMMA tableMapper)*)?
BRACKET_CLOSE
SEMI_COLON
;
include: INCLUDE qualifiedName
;


// -------------------------------------- DATABASE MAPPERS --------------------------------------

databaseMapper: BRACKET_OPEN
(schemaReference (COMMA schemaReference)*)?
BRACKET_CLOSE ARROW STRING

;
schemaReference: database DOT schema
;
database: qualifiedName
;
schema: identifier
;

// -------------------------------------- SCHEMA MAPPERS --------------------------------------

schemaMapper: schemaReference ARROW STRING
;

// -------------------------------------- TABLE MAPPERS --------------------------------------

tableReference: database DOT schema DOT table
;
tableMapper: tableReference ARROW STRING
;
table: identifier
;
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
import org.eclipse.collections.impl.list.mutable.FastList;
import org.eclipse.collections.impl.utility.ListIterate;
import org.finos.legend.engine.protocol.pure.v1.model.SourceInformation;
import org.finos.legend.engine.protocol.pure.v1.model.context.PackageableElementPointer;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.postprocessor.Mapper;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.postprocessor.MapperPostProcessor;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.postprocessor.RelationalMapperPostProcessor;
import org.finos.legend.pure.generated.*;

import java.util.List;
Expand Down Expand Up @@ -59,13 +61,26 @@ public static Root_meta_pure_alloy_connections_MapperPostProcessor createMapperP
return createMapperPostProcessor(mapper.mappers, context);
}

public static Root_meta_pure_alloy_connections_RelationalMapperPostProcessor createRelationalMapperPostProcessor(RelationalMapperPostProcessor relationalMapper, CompileContext context)
{
return createRelationalMapperPostProcessor(relationalMapper.relationalMappers, context);
}

public static Root_meta_pure_alloy_connections_MapperPostProcessor createMapperPostProcessor(List<Mapper> mappers, CompileContext context)
{
Root_meta_pure_alloy_connections_MapperPostProcessor p = new Root_meta_pure_alloy_connections_MapperPostProcessor_Impl("", null, context.pureModel.getClass("meta::pure::alloy::connections::MapperPostProcessor"));
p._mappers(createMappers(mappers, context));
return p;
}

public static Root_meta_pure_alloy_connections_RelationalMapperPostProcessor createRelationalMapperPostProcessor(List<PackageableElementPointer> relationalMappers, CompileContext context)
{
Root_meta_pure_alloy_connections_RelationalMapperPostProcessor p = new Root_meta_pure_alloy_connections_RelationalMapperPostProcessor_Impl("", null, context.pureModel.getClass("meta::pure::alloy::connections::RelationalMapperPostProcessor"));
MutableList<Root_meta_relational_metamodel_RelationalMapper> rm = ListIterate.collect(relationalMappers, r -> RelationalCompilerExtension.getRelationalMapper(r.path));
p._relationalMappers(rm);
return p;
}

public static MutableList<Root_meta_pure_alloy_connections_Mapper> createMappers(List<Mapper> mappers, CompileContext context)
{
return ListIterate.collect(mappers, m ->
Expand Down
Loading

0 comments on commit 936400d

Please sign in to comment.