Skip to content

Commit

Permalink
Use platform function to convert type in relational store accessor co…
Browse files Browse the repository at this point in the history
…mpilation (#3121)
  • Loading branch information
gs-ssh16 authored Sep 25, 2024
1 parent 3278ab9 commit 611e3bc
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
import org.finos.legend.engine.shared.core.function.Function4;
import org.finos.legend.engine.shared.core.function.Procedure3;
import org.finos.legend.engine.shared.core.operational.errorManagement.EngineException;
import org.finos.legend.pure.generated.platform_store_relational_functions;
import org.finos.legend.pure.generated.Root_meta_core_runtime_Connection;
import org.finos.legend.pure.generated.Root_meta_external_store_relational_runtime_RelationalDatabaseConnection;
import org.finos.legend.pure.generated.Root_meta_external_store_relational_runtime_RelationalDatabaseConnection_Impl;
Expand Down Expand Up @@ -136,14 +137,10 @@
import org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.TableAlias;
import org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.TableAliasAccessor;
import org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.datatype.*;
import org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.datatype.Double;
import org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.datatype.Float;
import org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.datatype.Integer;
import org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.relation.NamedRelation;
import org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.relation.Relation;
import org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.relation.Table;
import org.finos.legend.pure.m3.navigation.ProcessorSupport;
import org.finos.legend.pure.m3.navigation._package._Package;
import org.finos.legend.pure.m3.navigation.relation._Column;
import org.finos.legend.pure.m3.navigation.relation._RelationType;
import org.finos.legend.pure.m4.coreinstance.CoreInstance;
Expand Down Expand Up @@ -801,7 +798,7 @@ public List<Function4<RelationStoreAccessor, Store, CompileContext, ProcessingCo
{
name = name.substring(1, name.length() - 1);
}
return (CoreInstance) _Column.getColumnInstance(name, false, convertTypes(col._type(), processorSupport), (Multiplicity) org.finos.legend.pure.m3.navigation.multiplicity.Multiplicity.newMultiplicity(col._nullable() ? 0 : 1, 1, processorSupport), sourceInformation, processorSupport);
return (CoreInstance) _Column.getColumnInstance(name, false, convertTypes(col._type(), context), (Multiplicity) org.finos.legend.pure.m3.navigation.multiplicity.Multiplicity.newMultiplicity(col._nullable() ? 0 : 1, 1, processorSupport), sourceInformation, processorSupport);
}).toList(), sourceInformation, processorSupport);

GenericType genericType = new Root_meta_pure_metamodel_type_generics_GenericType_Impl("", null, context.pureModel.getClass("meta::pure::metamodel::type::generics::GenericType"))
Expand Down Expand Up @@ -829,46 +826,13 @@ public List<Function4<RelationStoreAccessor, Store, CompileContext, ProcessingCo
});
}

private GenericType convertTypes(DataType c, ProcessorSupport processorSupport)
private GenericType convertTypes(DataType c, CompileContext compileContext)
{
String primitiveType;
if (c instanceof Varchar)
{
primitiveType = "String";
}
else if (c instanceof Integer)
{
primitiveType = "Integer";
}
else if (c instanceof BigInt)
{
primitiveType = "Integer";
}
else if (c instanceof Bit)
{
primitiveType = "Boolean";
}
else if (c instanceof Double || c instanceof Float)
{
primitiveType = "Float";
}
else if (c instanceof Decimal)
{
primitiveType = "Decimal";
}
else if (c instanceof Date)
{
primitiveType = "Date";
}
else if (c instanceof Timestamp)
{
primitiveType = "DateTime";
}
else
{
throw new RuntimeException("Implement support for '" + c.getClass().getName() + "'");
}
return (GenericType) processorSupport.type_wrapGenericType(_Package.getByUserPath(primitiveType, processorSupport));
return (GenericType) compileContext.pureModel.getExecutionSupport().getProcessorSupport().type_wrapGenericType(
platform_store_relational_functions.Root_meta_relational_metamodel_datatype_dataTypeToCompatiblePureType_DataType_1__Type_1_(
c, compileContext.pureModel.getExecutionSupport()
)
);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,38 @@ public void testCompilationOfRelationStoreAccessor()
"}");
}

@Test
public void testCompilationOfRelationStoreAccessorWithTypes()
{
test("###Relational\n" +
"Database test::myDB\n" +
"(\n" +
" Table dataTable\n" +
" (\n" +
" pk INTEGER PRIMARY KEY,\n" +
" ti TINYINT,\n" +
" si SMALLINT,\n" +
" int INTEGER,\n" +
" bi BIGINT,\n" +
" vc VARCHAR(200),\n" +
" c CHAR(1),\n" +
" date DATE,\n" +
" ts TIMESTAMP,\n" +
" f FLOAT,\n" +
" d DOUBLE,\n" +
" bit BIT,\n" +
" dec DECIMAL(18,6),\n" +
" r REAL,\n" +
" n NUMERIC(18,6)\n" +
" )\n" +
")\n" +
"###Pure\n" +
"function my::func():Any[*]" +
"{" +
" #>{test::myDB.dataTable}#->filter(c|$c.pk == 1);" +
"}");
}

@Test
public void testCompilationWithSchema()
{
Expand Down

0 comments on commit 611e3bc

Please sign in to comment.