-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support the literals into Snowpark (#39)
Add support to the literals using the snowpark function lit for boolean, string, char, float and Int. Add test for lit literals.
- Loading branch information
1 parent
6a7243b
commit 55598ea
Showing
4 changed files
with
122 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module Morphir.Snowpark.Constants exposing (..) | ||
import Morphir.Scala.AST as Scala | ||
|
||
functionsNamespace : List String | ||
functionsNamespace = ["com", "snowpark", "functions"] | ||
|
||
applySnowparkFunc : String -> List Scala.Value -> Scala.Value | ||
applySnowparkFunc name args = | ||
Scala.Apply | ||
(Scala.Ref functionsNamespace name) | ||
(args |> List.map (\v -> Scala.ArgValue Nothing v)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
module Morphir.Snowpark.MapValueLiteralTests exposing (mapValueLiteralTests) | ||
import Expect | ||
import Test exposing (Test, describe, test) | ||
import Morphir.IR.Literal as Literal | ||
import Morphir.Snowpark.Backend exposing (mapValue) | ||
import Morphir.Scala.AST as Scala | ||
import Morphir.IR.Value as Value | ||
import Morphir.IR.Type as Type | ||
|
||
functionNamespace : List String | ||
functionNamespace = ["com", "snowpark", "functions"] | ||
|
||
booleanReference : Type.Type () | ||
booleanReference = Type.Reference () ( [ [ "morphir" ], [ "s", "d", "k" ] ], [ [ "basics" ] ], [ "boolean" ] ) [] | ||
booleanTest : Scala.Value | ||
booleanTest = Scala.Apply | ||
(Scala.Ref functionNamespace "lit") | ||
([Scala.ArgValue | ||
Nothing (Scala.Literal (Scala.BooleanLit True))]) | ||
|
||
stringReference : Type.Type () | ||
stringReference = Type.Reference () ( [ [ "morphir" ], [ "s", "d", "k" ] ], [ [ "basics" ] ], [ "boolean" ] ) [] | ||
stringTest : Scala.Value | ||
stringTest = Scala.Apply | ||
(Scala.Ref functionNamespace "lit") | ||
([Scala.ArgValue | ||
Nothing (Scala.Literal (Scala.StringLit "Hello world"))]) | ||
|
||
characterReference : Type.Type () | ||
characterReference = Type.Reference () ( [ [ "morphir" ], [ "s", "d", "k" ] ], [ [ "basics" ] ], [ "character" ] ) [] | ||
characterTest : Scala.Value | ||
characterTest = Scala.Apply | ||
(Scala.Ref functionNamespace "lit") | ||
([Scala.ArgValue | ||
Nothing (Scala.Literal (Scala.CharacterLit 'C'))]) | ||
|
||
floatReference : Type.Type () | ||
floatReference = Type.Reference () ( [ [ "morphir" ], [ "s", "d", "k" ] ], [ [ "basics" ] ], [ "float" ] ) [] | ||
floatTest : Scala.Value | ||
floatTest = Scala.Apply | ||
(Scala.Ref functionNamespace "lit") | ||
([Scala.ArgValue | ||
Nothing (Scala.Literal (Scala.FloatLit 3.24))]) | ||
|
||
|
||
integerReference : Type.Type () | ||
integerReference = Type.Reference () ( [ [ "morphir" ], [ "s", "d", "k" ] ], [ [ "basics" ] ], [ "integer" ] ) [] | ||
integerTest : Scala.Value | ||
integerTest = Scala.Apply | ||
(Scala.Ref functionNamespace "lit") | ||
([Scala.ArgValue | ||
Nothing (Scala.Literal (Scala.IntegerLit 5))]) | ||
|
||
mapValueLiteralTests: Test | ||
mapValueLiteralTests = | ||
let | ||
assertBooleanLiteral = | ||
test ("Convert boolean") <| | ||
\_ -> | ||
Expect.equal booleanTest (mapValue (Value.Literal booleanReference (Literal.BoolLiteral True))) | ||
assertStringLiteral = | ||
test ("Convert string") <| | ||
\_ -> | ||
Expect.equal stringTest (mapValue (Value.Literal stringReference (Literal.StringLiteral "Hello world"))) | ||
assertCharacterLiteral = | ||
test ("Convert character") <| | ||
\_ -> | ||
Expect.equal characterTest (mapValue (Value.Literal characterReference (Literal.CharLiteral 'C'))) | ||
assertFloatLiteral = | ||
test ("Convert float") <| | ||
\_ -> | ||
Expect.equal floatTest (mapValue (Value.Literal floatReference (Literal.FloatLiteral 3.24))) | ||
assertIntegerLiteral = | ||
test ("Convert integer") <| | ||
\_ -> | ||
Expect.equal integerTest (mapValue (Value.Literal integerReference (Literal.WholeNumberLiteral 5))) | ||
in | ||
describe "literalMapTransform" | ||
[ | ||
assertBooleanLiteral, | ||
assertStringLiteral, | ||
assertCharacterLiteral, | ||
assertFloatLiteral, | ||
assertIntegerLiteral | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters