-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ad53a0e
commit 1fa06c7
Showing
9 changed files
with
310 additions
and
19 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
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
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,104 @@ | ||
{-# LANGUAGE BlockArguments #-} | ||
{-# LANGUAGE OverloadedLists #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
|
||
module HStream.SQL.Codegen.ArraySpec where | ||
|
||
import qualified Data.Aeson as A | ||
import Data.Function | ||
import HStream.SQL.AST | ||
import HStream.SQL.Internal.Codegen | ||
import Test.Hspec | ||
|
||
spec :: Spec | ||
spec = describe "Array Scalar Functions" do | ||
|
||
it "ARRAY_DISTINCT__0" do | ||
unaryOpOnValue OpDistinct (A.Number <$> [1, 1, 2, 3, 1, 2] & A.Array) | ||
`shouldBe` (A.Number <$> [1, 2, 3] & A.Array) | ||
|
||
it "ARRAY_DISTINCT__1" do | ||
unaryOpOnValue OpDistinct ([A.String "apple", A.String "apple", A.Null, A.String "cherry"] & A.Array) | ||
`shouldBe` ([A.String "apple", A.Null, A.String "cherry"] & A.Array) | ||
|
||
it "ARRAY_EXCEPT__0" do | ||
binOpOnValue OpExcept (A.Number <$> [1, 2, 3, 1, 2] & A.Array) (A.Number <$> [2, 3] & A.Array) | ||
`shouldBe` A.Array [A.Number 1] | ||
|
||
it "ARRAY_EXCEPT__1" do | ||
binOpOnValue OpExcept (A.Array [A.String "apple", A.String "apple", A.Null, A.String "cherry"]) | ||
(A.Array [A.String "cherry"]) `shouldBe` A.Array [A.String "apple", A.Null] | ||
|
||
it "ARRAY_INTERSECT__0" do | ||
(binOpOnValue OpIntersect `on` (\x -> A.Number <$> x & A.Array)) [1, 2, 3, 1, 2] [2, 1] | ||
`shouldBe` (A.Number <$> [1, 2] & A.Array) | ||
|
||
it "ARRAY_INTERSECT__1" do | ||
binOpOnValue OpIntersect (A.Array [A.String "apple", A.String "apple", A.Null, A.String "cherry"]) | ||
(A.Array [A.String "apple"]) `shouldBe` A.Array [A.String "apple"] | ||
|
||
--- derived decEq | ||
it "ARRAY_MAX__0" do | ||
unaryOpOnValue OpArrMax (A.Array [A.Number (-1), A.Number 2, A.Null, A.Number 0]) | ||
`shouldBe` A.Null | ||
|
||
it "ARRAY_MAX__1" do | ||
unaryOpOnValue OpArrMax (A.Array [A.Bool True, A.Bool False]) | ||
`shouldBe` A.Bool True | ||
|
||
it "ARRAY_MAX__2" do | ||
unaryOpOnValue OpArrMax (A.Array [A.Number 23, A.Number 24, A.String "r"]) | ||
`shouldBe` A.Number 24 | ||
|
||
it "ARRAY_MAX__3" do | ||
unaryOpOnValue OpArrMax (A.Array [A.String "Foo", A.String "Bar", A.String "baz"]) | ||
`shouldBe` A.String "baz" | ||
|
||
it "ARRAY_MIN__0" do | ||
unaryOpOnValue OpArrMin (A.Array [A.Number (-1), A.Number 2, A.Null, A.Number 0]) | ||
`shouldBe` A.Number (-1) | ||
|
||
it "ARRAY_MIN__1" do | ||
unaryOpOnValue OpArrMin (A.Array [A.Bool True, A.Bool False]) | ||
`shouldBe` A.Bool False | ||
|
||
it "ARRAY_MIN__2" do | ||
unaryOpOnValue OpArrMin (A.Array [A.Number 23, A.Number 24, A.String "r"]) | ||
`shouldBe` A.String "r" | ||
|
||
it "ARRAY_MIN__3" do | ||
unaryOpOnValue OpArrMin (A.Array [A.String "Foo", A.String "Bar", A.String "baz"]) | ||
`shouldBe` A.String "Bar" | ||
|
||
it "ARRAY_REMOVE__0" do | ||
binOpOnValue OpRemove (A.Number <$> [1, 2, 3, 2, 1] & A.Array) (A.Number 2) | ||
`shouldBe` (A.Number <$> [1, 3, 1] & A.Array) | ||
|
||
it "ARRAY_REMOVE__1" do | ||
binOpOnValue OpRemove (A.Array [A.Bool False, A.Null, A.Bool True, A.Bool True]) (A.Bool False) | ||
`shouldBe` A.Array [A.Null, A.Bool True, A.Bool True] | ||
|
||
it "ARRAY_REMOVE__2" do | ||
binOpOnValue OpRemove (A.Array [A.String "Foo", A.String "Bar", A.Null, A.String "baz"]) A.Null | ||
`shouldBe` A.Array [A.String "Foo", A.String "Bar", A.String "baz"] | ||
|
||
it "ARRAY_SORT__0" do | ||
unaryOpOnValue OpSort (A.Array [A.Number (-1), A.Number 2, A.Null, A.Number 0]) | ||
`shouldBe` A.Array [A.Number (-1), A.Number 0, A.Number 2, A.Null] | ||
|
||
it "ARRAY_SORT__1" do | ||
unaryOpOnValue OpSort (A.Array [A.Bool False, A.Null, A.Bool True]) | ||
`shouldBe` A.Array [A.Bool False, A.Bool True, A.Null] | ||
|
||
it "ARRAY_SORT__2" do | ||
unaryOpOnValue OpSort (A.Array [A.String "Foo", A.String "Bar", A.Null, A.String "baz"]) | ||
`shouldBe` A.Array [A.String "Bar", A.String "Foo", A.String "baz", A.Null] | ||
|
||
it "ARRAY_UNION__0" do | ||
(binOpOnValue OpUnion `on` (\xs -> A.Number <$> xs & A.Array)) | ||
[1, 2, 3, 1, 2] [4, 1] `shouldBe` (\xs -> A.Number <$> xs & A.Array) [1, 2, 3, 4] | ||
|
||
it "ARRAY_UNION__1" do | ||
binOpOnValue OpUnion (A.Array [A.String "apple", A.String "apple", A.Null, A.String "cherry"]) | ||
(A.Array [A.String "cherry"]) `shouldBe` A.Array [A.String "apple", A.Null, A.String "cherry"] |
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,29 @@ | ||
{-# LANGUAGE BlockArguments #-} | ||
{-# LANGUAGE OverloadedLists #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
|
||
module HStream.SQL.Codegen.MathSpec where | ||
|
||
import qualified Data.Aeson as A | ||
import Data.Function | ||
import Data.Scientific | ||
import HStream.SQL.AST | ||
import HStream.SQL.Internal.Codegen | ||
import Test.HUnit | ||
import Test.Hspec | ||
|
||
spec :: Spec | ||
spec = describe "Math Scalar Functions" do | ||
|
||
-- Arith Expr | ||
|
||
it "binary add" do | ||
binOpOnValue OpAdd (A.Number 1) (A.Number 2) `shouldBe` (A.Number 3) | ||
|
||
it "floor" do | ||
unaryOpOnValue OpFloor (A.Number 1.5) | ||
`shouldBe` A.Number 1 | ||
|
||
it "ceil" do | ||
unaryOpOnValue OpCeil (A.Number 1.5) `shouldBe` A.Number 2 |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.