Skip to content

Commit

Permalink
Generate a new backend for Snowpark (finos#33)
Browse files Browse the repository at this point in the history
Generate empty files for ELM modules in the IR
  • Loading branch information
sfc-gh-aramirezfuentes authored and sfc-gh-lfallasavendano committed Dec 13, 2023
1 parent 8e28912 commit 4672b8d
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cli/src/Morphir/Elm/Target.elm
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Morphir.SpringBoot.Backend.Codec
import Morphir.TypeScript.Backend
import Morphir.TypeSpec.Backend
import Morphir.TypeSpec.Backend.Codec
import Morphir.Snowpark.Backend



Expand All @@ -34,6 +35,7 @@ type BackendOptions
| SparkOptions Morphir.Scala.Spark.Backend.Options
| JsonSchemaOptions Morphir.JsonSchema.Backend.Options
| TypeSpecOptions Morphir.TypeSpec.Backend.Options
| SnowparkOptions Morphir.Snowpark.Backend.Options


decodeOptions : Result Error String -> Decode.Decoder BackendOptions
Expand All @@ -53,6 +55,9 @@ decodeOptions gen =

Ok "Spark" ->
Decode.map SparkOptions (Decode.succeed Morphir.Scala.Spark.Backend.Options)

Ok "Snowpark" ->
Decode.map SnowparkOptions (Decode.succeed Morphir.Snowpark.Backend.Options)

Ok "JsonSchema" ->
Decode.map JsonSchemaOptions Morphir.JsonSchema.Backend.Codec.decodeOptions
Expand Down Expand Up @@ -85,6 +90,9 @@ mapDistribution back dist =

SparkOptions options ->
Ok <| Morphir.Spark.Backend.mapDistribution options dist

SnowparkOptions options ->
Ok <| Morphir.Snowpark.Backend.mapDistribution options dist

JsonSchemaOptions options ->
Morphir.JsonSchema.Backend.mapDistribution options dist
Expand Down
73 changes: 73 additions & 0 deletions src/Morphir/Snowpark/Backend.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
module Morphir.Snowpark.Backend exposing (..)

import Dict
import List
import Morphir.File.FileMap exposing (FileMap)
import Morphir.IR.Distribution as Distribution exposing (..)
import Morphir.IR.Name as Name
import Morphir.IR.Package as Package
import Morphir.IR.Path exposing (Path)
import Morphir.IR.Type exposing (Type)
import Morphir.Scala.AST as Scala
import Morphir.Scala.PrettyPrinter as PrettyPrinter
import Morphir.TypeSpec.Backend exposing (mapModuleDefinition)

type alias Options =
{}

mapDistribution : Options -> Distribution -> FileMap
mapDistribution _ distro =
case distro of
Distribution.Library packageName _ packageDef ->
mapPackageDefinition distro packageName packageDef


mapPackageDefinition : Distribution -> Package.PackageName -> Package.Definition ta (Type ()) -> FileMap
mapPackageDefinition _ packagePath packageDef =
let
generatedScala =
packageDef.modules
|> Dict.toList
|> List.concatMap
(\( modulePath, _ ) ->
mapModuleDefinition packagePath modulePath
)
in
generatedScala
|> List.map
(\compilationUnit ->
let
fileContent =
compilationUnit
|> PrettyPrinter.mapCompilationUnit (PrettyPrinter.Options 2 80)
in
( ( compilationUnit.dirPath, compilationUnit.fileName ), fileContent )
)
|> Dict.fromList


mapModuleDefinition : Package.PackageName -> Path -> List Scala.CompilationUnit
mapModuleDefinition currentPackagePath currentModulePath =
let
( scalaPackagePath, moduleName ) =
case currentModulePath |> List.reverse of
[] ->
( [], [] )

lastName :: reverseModulePath ->
let
parts =
List.append currentPackagePath (List.reverse reverseModulePath)
in
( parts |> (List.concat >> List.map String.toLower), lastName )

moduleUnit : Scala.CompilationUnit
moduleUnit =
{ dirPath = scalaPackagePath
, fileName = (moduleName |> Name.toTitleCase) ++ ".scala"
, packageDecl = scalaPackagePath
, imports = []
, typeDecls = []
}
in
[ moduleUnit ]

0 comments on commit 4672b8d

Please sign in to comment.