1
Fork 0

renames OrderField->SortSpec, InThing->InPredValue

This commit is contained in:
Jake Wheat 2013-12-18 16:27:06 +02:00
parent b89f2a011c
commit b631497a04
8 changed files with 40 additions and 40 deletions

View file

@ -121,8 +121,8 @@ the fixity code.
> name n = case n of > name n = case n of
> QName q -> '"' : q > QName q -> '"' : q
> Name m -> m > Name m -> m
> orderExps = map (toHaskell . (\(OrderField a _ _) -> a)) > orderExps = map (toHaskell . (\(SortSpec a _ _) -> a))
> orderInf = map (\(OrderField _ b c) -> (b,c)) > orderInf = map (\(SortSpec _ b c) -> (b,c))
@ -171,7 +171,7 @@ the fixity code.
> in In b (toSql e0) sq > in In b (toSql e0) sq
> _ -> err e > _ -> err e
> where > where
> sord = zipWith (\(i0,i1) ce -> OrderField (toSql ce) i0 i1) > sord = zipWith (\(i0,i1) ce -> SortSpec (toSql ce) i0 i1)
> ltom (HSE.List []) = Nothing > ltom (HSE.List []) = Nothing
> ltom (HSE.List [ex]) = Just $ toSql ex > ltom (HSE.List [ex]) = Just $ toSql ex
> ltom ex = err ex > ltom ex = err ex

View file

@ -712,10 +712,10 @@ where, having, limit, offset).
> having :: P ScalarExpr > having :: P ScalarExpr
> having = keywordScalarExpr "having" > having = keywordScalarExpr "having"
> orderBy :: P [OrderField] > orderBy :: P [SortSpec]
> orderBy = try (keyword_ "order") *> keyword_ "by" *> commaSep1 ob > orderBy = try (keyword_ "order") *> keyword_ "by" *> commaSep1 ob
> where > where
> ob = OrderField > ob = SortSpec
> <$> scalarExpr > <$> scalarExpr
> <*> option Asc (choice [Asc <$ keyword_ "asc" > <*> option Asc (choice [Asc <$ keyword_ "asc"
> ,Desc <$ keyword_ "desc"]) > ,Desc <$ keyword_ "desc"])

View file

@ -266,12 +266,12 @@
> ge (Rollup es) = text "rollup" <> parens (commaSep $ map ge es) > ge (Rollup es) = text "rollup" <> parens (commaSep $ map ge es)
> ge (GroupingSets es) = text "grouping sets" <> parens (commaSep $ map ge es) > ge (GroupingSets es) = text "grouping sets" <> parens (commaSep $ map ge es)
> orderBy :: [OrderField] -> Doc > orderBy :: [SortSpec] -> Doc
> orderBy [] = empty > orderBy [] = empty
> orderBy os = sep [text "order by" > orderBy os = sep [text "order by"
> ,nest 9 $ commaSep $ map f os] > ,nest 9 $ commaSep $ map f os]
> where > where
> f (OrderField e d n) = > f (SortSpec e d n) =
> scalarExpr e > scalarExpr e
> <+> (if d == Asc then empty else text "desc") > <+> (if d == Asc then empty else text "desc")
> <+> (case n of > <+> (case n of

View file

@ -6,10 +6,10 @@
> ,Name(..) > ,Name(..)
> ,TypeName(..) > ,TypeName(..)
> ,Duplicates(..) > ,Duplicates(..)
> ,OrderField(..) > ,SortSpec(..)
> ,Direction(..) > ,Direction(..)
> ,NullsOrder(..) > ,NullsOrder(..)
> ,InThing(..) > ,InPredValue(..)
> ,SubQueryExprType(..) > ,SubQueryExprType(..)
> ,Frame(..) > ,Frame(..)
> ,FrameRows(..) > ,FrameRows(..)
@ -67,7 +67,7 @@
> {aggName :: Name -- ^ aggregate function name > {aggName :: Name -- ^ aggregate function name
> ,aggDistinct :: Maybe Duplicates -- ^ distinct > ,aggDistinct :: Maybe Duplicates -- ^ distinct
> ,aggArgs :: [ScalarExpr]-- ^ args > ,aggArgs :: [ScalarExpr]-- ^ args
> ,aggOrderBy :: [OrderField] -- ^ order by > ,aggOrderBy :: [SortSpec] -- ^ order by
> } > }
> -- | window application, which adds over (partition by a order > -- | window application, which adds over (partition by a order
> -- by b) to regular function application. Explicit frames are > -- by b) to regular function application. Explicit frames are
@ -76,7 +76,7 @@
> {wnName :: Name -- ^ window function name > {wnName :: Name -- ^ window function name
> ,wnArgs :: [ScalarExpr] -- ^ args > ,wnArgs :: [ScalarExpr] -- ^ args
> ,wnPartition :: [ScalarExpr] -- ^ partition by > ,wnPartition :: [ScalarExpr] -- ^ partition by
> ,wnOrderBy :: [OrderField] -- ^ order by > ,wnOrderBy :: [SortSpec] -- ^ order by
> ,wnFrame :: Maybe Frame -- ^ frame clause > ,wnFrame :: Maybe Frame -- ^ frame clause
> } > }
> -- | Infix binary operators. This is used for symbol operators > -- | Infix binary operators. This is used for symbol operators
@ -114,7 +114,7 @@
> | SubQueryExpr SubQueryExprType QueryExpr > | SubQueryExpr SubQueryExprType QueryExpr
> -- | in list literal and in subquery, if the bool is false it > -- | in list literal and in subquery, if the bool is false it
> -- means not in was used ('a not in (1,2)') > -- means not in was used ('a not in (1,2)')
> | In Bool ScalarExpr InThing > | In Bool ScalarExpr InPredValue
> deriving (Eq,Show,Read) > deriving (Eq,Show,Read)
> -- | Represents an identifier name, which can be quoted or unquoted. > -- | Represents an identifier name, which can be quoted or unquoted.
@ -131,7 +131,7 @@
> -- | Used for 'expr in (scalar expression list)', and 'expr in > -- | Used for 'expr in (scalar expression list)', and 'expr in
> -- (subquery)' syntax. > -- (subquery)' syntax.
> data InThing = InList [ScalarExpr] > data InPredValue = InList [ScalarExpr]
> | InQueryExpr QueryExpr > | InQueryExpr QueryExpr
> deriving (Eq,Show,Read) > deriving (Eq,Show,Read)
@ -150,7 +150,7 @@
> deriving (Eq,Show,Read) > deriving (Eq,Show,Read)
> -- | Represents one field in an order by list. > -- | Represents one field in an order by list.
> data OrderField = OrderField ScalarExpr Direction NullsOrder > data SortSpec = SortSpec ScalarExpr Direction NullsOrder
> deriving (Eq,Show,Read) > deriving (Eq,Show,Read)
> -- | Represents 'nulls first' or 'nulls last' in an order by clause. > -- | Represents 'nulls first' or 'nulls last' in an order by clause.
@ -199,7 +199,7 @@
> ,qeWhere :: Maybe ScalarExpr > ,qeWhere :: Maybe ScalarExpr
> ,qeGroupBy :: [GroupingExpr] > ,qeGroupBy :: [GroupingExpr]
> ,qeHaving :: Maybe ScalarExpr > ,qeHaving :: Maybe ScalarExpr
> ,qeOrderBy :: [OrderField] > ,qeOrderBy :: [SortSpec]
> ,qeOffset :: Maybe ScalarExpr > ,qeOffset :: Maybe ScalarExpr
> ,qeFetch :: Maybe ScalarExpr > ,qeFetch :: Maybe ScalarExpr
> } > }

4
TODO
View file

@ -11,7 +11,7 @@ add to website: pretty printed tpch, maybe other queries as
add preamble to the rendered test page add preamble to the rendered test page
add links from the supported sql page to the rendered test page for add links from the supported sql page to the rendered test page for
each section each section -> have to section up the tests some more
== testing == testing
@ -35,7 +35,7 @@ have to do fixity for this to work
all ansi string literal syntax? all ansi string literal syntax?
check ansi standard for operators check ansi standard for operators (keywords and symbols)
== other == other

View file

@ -33,7 +33,7 @@ Some tests for parsing full queries.
> ,qeGroupBy = [SimpleGroup $ Iden "a"] > ,qeGroupBy = [SimpleGroup $ Iden "a"]
> ,qeHaving = Just $ BinOp (App "count" [NumLit "1"]) > ,qeHaving = Just $ BinOp (App "count" [NumLit "1"])
> ">" (NumLit "5") > ">" (NumLit "5")
> ,qeOrderBy = [OrderField (Iden "s") Asc NullsOrderDefault] > ,qeOrderBy = [SortSpec (Iden "s") Asc NullsOrderDefault]
> } > }
> ) > )
> ] > ]

View file

@ -89,22 +89,22 @@ These are a few misc tests which don't fit anywhere else.
> orderBy :: TestItem > orderBy :: TestItem
> orderBy = Group "orderBy" $ map (uncurry TestQueryExpr) > orderBy = Group "orderBy" $ map (uncurry TestQueryExpr)
> [("select a from t order by a" > [("select a from t order by a"
> ,ms [OrderField (Iden "a") Asc NullsOrderDefault]) > ,ms [SortSpec (Iden "a") Asc NullsOrderDefault])
> ,("select a from t order by a, b" > ,("select a from t order by a, b"
> ,ms [OrderField (Iden "a") Asc NullsOrderDefault > ,ms [SortSpec (Iden "a") Asc NullsOrderDefault
> ,OrderField (Iden "b") Asc NullsOrderDefault]) > ,SortSpec (Iden "b") Asc NullsOrderDefault])
> ,("select a from t order by a asc" > ,("select a from t order by a asc"
> ,ms [OrderField (Iden "a") Asc NullsOrderDefault]) > ,ms [SortSpec (Iden "a") Asc NullsOrderDefault])
> ,("select a from t order by a desc, b desc" > ,("select a from t order by a desc, b desc"
> ,ms [OrderField (Iden "a") Desc NullsOrderDefault > ,ms [SortSpec (Iden "a") Desc NullsOrderDefault
> ,OrderField (Iden "b") Desc NullsOrderDefault]) > ,SortSpec (Iden "b") Desc NullsOrderDefault])
> ,("select a from t order by a desc nulls first, b desc nulls last" > ,("select a from t order by a desc nulls first, b desc nulls last"
> ,ms [OrderField (Iden "a") Desc NullsFirst > ,ms [SortSpec (Iden "a") Desc NullsFirst
> ,OrderField (Iden "b") Desc NullsLast]) > ,SortSpec (Iden "b") Desc NullsLast])
> ] > ]
> where > where

View file

@ -322,7 +322,7 @@ target_string
> ,("sum(a order by a)" > ,("sum(a order by a)"
> ,AggregateApp "sum" Nothing [Iden "a"] > ,AggregateApp "sum" Nothing [Iden "a"]
> [OrderField (Iden "a") Asc NullsOrderDefault]) > [SortSpec (Iden "a") Asc NullsOrderDefault])
> ,("sum(all a)" > ,("sum(all a)"
> ,AggregateApp "sum" (Just All) [Iden "a"] []) > ,AggregateApp "sum" (Just All) [Iden "a"] [])
@ -344,46 +344,46 @@ target_string
> ,("sum(a) over (order by b)" > ,("sum(a) over (order by b)"
> ,WindowApp "sum" [Iden "a"] [] > ,WindowApp "sum" [Iden "a"] []
> [OrderField (Iden "b") Asc NullsOrderDefault] Nothing) > [SortSpec (Iden "b") Asc NullsOrderDefault] Nothing)
> ,("sum(a) over (order by b desc,c)" > ,("sum(a) over (order by b desc,c)"
> ,WindowApp "sum" [Iden "a"] [] > ,WindowApp "sum" [Iden "a"] []
> [OrderField (Iden "b") Desc NullsOrderDefault > [SortSpec (Iden "b") Desc NullsOrderDefault
> ,OrderField (Iden "c") Asc NullsOrderDefault] Nothing) > ,SortSpec (Iden "c") Asc NullsOrderDefault] Nothing)
> ,("sum(a) over (partition by b order by c)" > ,("sum(a) over (partition by b order by c)"
> ,WindowApp "sum" [Iden "a"] [Iden "b"] > ,WindowApp "sum" [Iden "a"] [Iden "b"]
> [OrderField (Iden "c") Asc NullsOrderDefault] Nothing) > [SortSpec (Iden "c") Asc NullsOrderDefault] Nothing)
> ,("sum(a) over (partition by b order by c range unbounded preceding)" > ,("sum(a) over (partition by b order by c range unbounded preceding)"
> ,WindowApp "sum" [Iden "a"] [Iden "b"] > ,WindowApp "sum" [Iden "a"] [Iden "b"]
> [OrderField (Iden "c") Asc NullsOrderDefault] > [SortSpec (Iden "c") Asc NullsOrderDefault]
> $ Just $ FrameFrom FrameRange UnboundedPreceding) > $ Just $ FrameFrom FrameRange UnboundedPreceding)
> ,("sum(a) over (partition by b order by c range 5 preceding)" > ,("sum(a) over (partition by b order by c range 5 preceding)"
> ,WindowApp "sum" [Iden "a"] [Iden "b"] > ,WindowApp "sum" [Iden "a"] [Iden "b"]
> [OrderField (Iden "c") Asc NullsOrderDefault] > [SortSpec (Iden "c") Asc NullsOrderDefault]
> $ Just $ FrameFrom FrameRange $ Preceding (NumLit "5")) > $ Just $ FrameFrom FrameRange $ Preceding (NumLit "5"))
> ,("sum(a) over (partition by b order by c range current row)" > ,("sum(a) over (partition by b order by c range current row)"
> ,WindowApp "sum" [Iden "a"] [Iden "b"] > ,WindowApp "sum" [Iden "a"] [Iden "b"]
> [OrderField (Iden "c") Asc NullsOrderDefault] > [SortSpec (Iden "c") Asc NullsOrderDefault]
> $ Just $ FrameFrom FrameRange Current) > $ Just $ FrameFrom FrameRange Current)
> ,("sum(a) over (partition by b order by c rows 5 following)" > ,("sum(a) over (partition by b order by c rows 5 following)"
> ,WindowApp "sum" [Iden "a"] [Iden "b"] > ,WindowApp "sum" [Iden "a"] [Iden "b"]
> [OrderField (Iden "c") Asc NullsOrderDefault] > [SortSpec (Iden "c") Asc NullsOrderDefault]
> $ Just $ FrameFrom FrameRows $ Following (NumLit "5")) > $ Just $ FrameFrom FrameRows $ Following (NumLit "5"))
> ,("sum(a) over (partition by b order by c range unbounded following)" > ,("sum(a) over (partition by b order by c range unbounded following)"
> ,WindowApp "sum" [Iden "a"] [Iden "b"] > ,WindowApp "sum" [Iden "a"] [Iden "b"]
> [OrderField (Iden "c") Asc NullsOrderDefault] > [SortSpec (Iden "c") Asc NullsOrderDefault]
> $ Just $ FrameFrom FrameRange UnboundedFollowing) > $ Just $ FrameFrom FrameRange UnboundedFollowing)
> ,("sum(a) over (partition by b order by c \n\ > ,("sum(a) over (partition by b order by c \n\
> \range between 5 preceding and 5 following)" > \range between 5 preceding and 5 following)"
> ,WindowApp "sum" [Iden "a"] [Iden "b"] > ,WindowApp "sum" [Iden "a"] [Iden "b"]
> [OrderField (Iden "c") Asc NullsOrderDefault] > [SortSpec (Iden "c") Asc NullsOrderDefault]
> $ Just $ FrameBetween FrameRange > $ Just $ FrameBetween FrameRange
> (Preceding (NumLit "5")) > (Preceding (NumLit "5"))
> (Following (NumLit "5"))) > (Following (NumLit "5")))