1
Fork 0

order by tests

This commit is contained in:
Jake Wheat 2014-04-21 14:16:45 +03:00
parent 8cabf5abcf
commit 0248bb90b3
2 changed files with 75 additions and 41 deletions

15
TODO
View file

@ -1,9 +1,9 @@
continue 2011 review and tests continue 2011 review and tests
1. start replacing the 2003 stuff with 2011 1. create an error message document for the website
2. create an error message document for the website - base off ErrorMessages but add some more variations
- base of error messages but add some more variations 2. start thinking about automated tests for invalid syntax to catch
3. start thinking about tests for invalid syntax bad parsing
review names in the syntax for correspondence with sql standard, avoid review names in the syntax for correspondence with sql standard, avoid
gratuitous differences gratuitous differences
@ -18,6 +18,7 @@ refactor crufty bits
reorder the code reorder the code
reconsider the names and structure of the constructors in the syntax reconsider the names and structure of the constructors in the syntax
refactor the typename parser - it's a real mess refactor the typename parser - it's a real mess
fix the lexing
add documentation in Parser.lhs on the left factoring/error handling add documentation in Parser.lhs on the left factoring/error handling
approach approach
@ -63,6 +64,7 @@ rules for changing the multi keyword parsing:
change join defaults to be defaults change join defaults to be defaults
rough SQL 2011 todo, including tests to write: rough SQL 2011 todo, including tests to write:
review the commented out reserved keyword entries and work out how to review the commented out reserved keyword entries and work out how to
@ -87,7 +89,6 @@ character set behaviour review
datetime literals datetime literals
mixed quoting identifier chains mixed quoting identifier chains
names/identifiers careful review names/identifiers careful review
typenames: lengths, binary
general value bits general value bits
collate for collate for
numeric val fn numeric val fn
@ -95,12 +96,9 @@ string exp fn
datetime exp fn datetime exp fn
interval exp fn interval exp fn
rows rows
table value constructor
interval qualifier interval qualifier
query spec
with with
setop setop
explicit table
order/offset/fetch order/offset/fetch
search/cycle search/cycle
preds: preds:
@ -121,7 +119,6 @@ period
alias for * in select list alias for * in select list
create list of unsupported syntax: xml, ref, subtypes, modules? create list of unsupported syntax: xml, ref, subtypes, modules?
only
--- ---

View file

@ -1052,7 +1052,6 @@ create a list of type name variations:
> ,"timestamp"] > ,"timestamp"]
> --interval -- not allowed without interval qualifier > --interval -- not allowed without interval qualifier
> --row -- not allowed without row type body > --row -- not allowed without row type body
> --ref -- not allowed without reference type
> -- array -- not allowed on own > -- array -- not allowed on own
> -- multiset -- not allowed on own > -- multiset -- not allowed on own
@ -1062,8 +1061,10 @@ create a list of type name variations:
> ,("char varying(5)", PrecTypeName [Name "char varying"] 5) > ,("char varying(5)", PrecTypeName [Name "char varying"] 5)
> -- 1 scale > -- 1 scale
> ,("decimal(15,2)", PrecScaleTypeName [Name "decimal"] 15 2) > ,("decimal(15,2)", PrecScaleTypeName [Name "decimal"] 15 2)
> ,("char(3 octets)", PrecLengthTypeName [Name "char"] 3 Nothing (Just PrecOctets)) > ,("char(3 octets)"
> ,("varchar(50 characters)", PrecLengthTypeName [Name "varchar"] 50 Nothing (Just PrecCharacters)) > ,PrecLengthTypeName [Name "char"] 3 Nothing (Just PrecOctets))
> ,("varchar(50 characters)"
> ,PrecLengthTypeName [Name "varchar"] 50 Nothing (Just PrecCharacters))
> -- lob prec + with multiname > -- lob prec + with multiname
> ,("blob(3M)", PrecLengthTypeName [Name "blob"] 3 (Just PrecM) Nothing) > ,("blob(3M)", PrecLengthTypeName [Name "blob"] 3 (Just PrecM) Nothing)
> ,("blob(3T)", PrecLengthTypeName [Name "blob"] 3 (Just PrecT) Nothing) > ,("blob(3T)", PrecLengthTypeName [Name "blob"] 3 (Just PrecT) Nothing)
@ -1073,7 +1074,8 @@ create a list of type name variations:
> ,("blob(6G octets) " > ,("blob(6G octets) "
> ,PrecLengthTypeName [Name "blob"] 6 (Just PrecG) (Just PrecOctets)) > ,PrecLengthTypeName [Name "blob"] 6 (Just PrecG) (Just PrecOctets))
> ,("national character large object(7K) " > ,("national character large object(7K) "
> ,PrecLengthTypeName [Name "national character large object"] 7 (Just PrecK) Nothing) > ,PrecLengthTypeName [Name "national character large object"]
> 7 (Just PrecK) Nothing)
> -- 1 with and without tz > -- 1 with and without tz
> ,("time with time zone" > ,("time with time zone"
> ,TimeTypeName [Name "time"] Nothing True) > ,TimeTypeName [Name "time"] Nothing True)
@ -1261,7 +1263,8 @@ Specify a value that is syntactically self-delimited.
> ] > ]
> parenthesizedValueExpression :: TestItem > parenthesizedValueExpression :: TestItem
> parenthesizedValueExpression = Group "parenthesized value expression" $ map (uncurry TestValueExpr) > parenthesizedValueExpression = Group "parenthesized value expression"
> $ map (uncurry TestValueExpr)
> [("(3)", Parens (NumLit "3")) > [("(3)", Parens (NumLit "3"))
> ,("((3))", Parens $ Parens (NumLit "3")) > ,("((3))", Parens $ Parens (NumLit "3"))
> ] > ]
@ -1386,7 +1389,8 @@ Specify a value whose data type is to be inferred from its context.
<default specification> ::= DEFAULT <default specification> ::= DEFAULT
> contextuallyTypedValueSpecification :: TestItem > contextuallyTypedValueSpecification :: TestItem
> contextuallyTypedValueSpecification = Group "contextually typed value specification" > contextuallyTypedValueSpecification =
> Group "contextually typed value specification"
> $ map (uncurry TestValueExpr) > $ map (uncurry TestValueExpr)
> [("null", Iden [Name "null"]) > [("null", Iden [Name "null"])
> ,("array[]", Array (Iden [Name "array"]) []) > ,("array[]", Array (Iden [Name "array"]) [])
@ -1449,8 +1453,10 @@ Specify a value derived by the application of a function to an argument.
> \GROUP BY ROLLUP(SalesQuota);" > \GROUP BY ROLLUP(SalesQuota);"
> ,makeSelect > ,makeSelect
> {qeSelectList = [(Iden [Name "SalesQuota"],Nothing) > {qeSelectList = [(Iden [Name "SalesQuota"],Nothing)
> ,(App [Name "SUM"] [Iden [Name "SalesYTD"]],Just (Name "TotalSalesYTD")) > ,(App [Name "SUM"] [Iden [Name "SalesYTD"]]
> ,(App [Name "GROUPING"] [Iden [Name "SalesQuota"]],Just (Name "Grouping"))] > ,Just (Name "TotalSalesYTD"))
> ,(App [Name "GROUPING"] [Iden [Name "SalesQuota"]]
> ,Just (Name "Grouping"))]
> ,qeFrom = [TRSimple [Name "Sales",Name "SalesPerson"]] > ,qeFrom = [TRSimple [Name "Sales",Name "SalesPerson"]]
> ,qeGroupBy = [Rollup [SimpleGroup (Iden [Name "SalesQuota"])]]}) > ,qeGroupBy = [Rollup [SimpleGroup (Iden [Name "SalesQuota"])]]})
> ] > ]
@ -2412,7 +2418,8 @@ Specify construction of an array.
> ,ArrayCtor (makeSelect > ,ArrayCtor (makeSelect
> {qeSelectList = [(Star,Nothing)] > {qeSelectList = [(Star,Nothing)]
> ,qeFrom = [TRSimple [Name "t"]] > ,qeFrom = [TRSimple [Name "t"]]
> ,qeOrderBy = [SortSpec (Iden [Name "a"]) DirDefault NullsOrderDefault] })) > ,qeOrderBy = [SortSpec (Iden [Name "a"])
> DirDefault NullsOrderDefault]}))
> ] > ]
@ -2490,7 +2497,8 @@ Specify construction of a multiset.
> multisetValueConstructor :: TestItem > multisetValueConstructor :: TestItem
> multisetValueConstructor = Group "multiset value constructor" > multisetValueConstructor = Group "multiset value constructor"
> $ map (uncurry TestValueExpr) > $ map (uncurry TestValueExpr)
> [("multiset[a,b,c]", MultisetCtor[Iden [Name "a"], Iden [Name "b"], Iden [Name "c"]]) > [("multiset[a,b,c]", MultisetCtor[Iden [Name "a"]
> ,Iden [Name "b"], Iden [Name "c"]])
> ,("multiset(select * from t)", MultisetQueryCtor qe) > ,("multiset(select * from t)", MultisetQueryCtor qe)
> ,("table(select * from t)", MultisetQueryCtor qe) > ,("table(select * from t)", MultisetQueryCtor qe)
> ] > ]
@ -3265,13 +3273,25 @@ everywhere
> orderOffsetFetchQueryExpression = Group "order, offset, fetch query expression" > orderOffsetFetchQueryExpression = Group "order, offset, fetch query expression"
> $ map (uncurry TestQueryExpr) > $ map (uncurry TestQueryExpr)
> [-- todo: finish tests for order offset and fetch > [-- todo: finish tests for order offset and fetch
> {- ("select * from t order by a", undefined) > ("select a from t order by a"
> ,("select * from t offset 5 row", undefined) > ,qe {qeOrderBy = [SortSpec (Iden [Name "a"])
> ,("select * from t offset 5 rows", undefined) > DirDefault NullsOrderDefault]})
> ,("select * from t fetch first 5 row only", undefined) > ,("select a from t offset 5 row"
> ,("select * from t fetch next 5 rows with ties", undefined) > ,qe {qeOffset = Just $ NumLit "5"})
> ,("select * from t fetch first 5 percent rows only", undefined)-} > ,("select a from t offset 5 rows"
> ,qe {qeOffset = Just $ NumLit "5"})
> ,("select a from t fetch first 5 row only"
> ,qe {qeFetchFirst = Just $ NumLit "5"})
> -- todo: support with ties and percent in fetch
> --,("select a from t fetch next 5 rows with ties"
> --,("select a from t fetch first 5 percent rows only"
> ] > ]
> where
> qe = makeSelect
> {qeSelectList = [(Iden [Name "a"], Nothing)]
> ,qeFrom = [TRSimple [Name "t"]]
> }
== 7.14 <search or cycle clause> == 7.14 <search or cycle clause>
@ -3622,7 +3642,8 @@ Specify a quantified comparison.
> ,QuantifiedComparison (Iden [Name "a"]) [Name ">"] CPAll qe) > ,QuantifiedComparison (Iden [Name "a"]) [Name ">"] CPAll qe)
> ,("(a,b) <> all (select * from t)" > ,("(a,b) <> all (select * from t)"
> ,QuantifiedComparison > ,QuantifiedComparison
> (SpecialOp [Name "rowctor"] [Iden [Name "a"],Iden [Name "b"]]) [Name "<>"] CPAll qe) > (SpecialOp [Name "rowctor"] [Iden [Name "a"]
> ,Iden [Name "b"]]) [Name "<>"] CPAll qe)
> ] > ]
> where > where
> qe = makeSelect > qe = makeSelect
@ -3697,15 +3718,18 @@ Specify a test for matching rows.
> [("a match (select a from t)" > [("a match (select a from t)"
> ,Match (Iden [Name "a"]) False qe) > ,Match (Iden [Name "a"]) False qe)
> ,("(a,b) match (select a,b from t)" > ,("(a,b) match (select a,b from t)"
> ,Match (SpecialOp [Name "rowctor"] [Iden [Name "a"], Iden [Name "b"]]) False qea) > ,Match (SpecialOp [Name "rowctor"]
> [Iden [Name "a"], Iden [Name "b"]]) False qea)
> ,("(a,b) match unique (select a,b from t)" > ,("(a,b) match unique (select a,b from t)"
> ,Match (SpecialOp [Name "rowctor"] [Iden [Name "a"], Iden [Name "b"]]) True qea) > ,Match (SpecialOp [Name "rowctor"]
> [Iden [Name "a"], Iden [Name "b"]]) True qea)
> ] > ]
> where > where
> qe = makeSelect > qe = makeSelect
> {qeSelectList = [(Iden [Name "a"],Nothing)] > {qeSelectList = [(Iden [Name "a"],Nothing)]
> ,qeFrom = [TRSimple [Name "t"]]} > ,qeFrom = [TRSimple [Name "t"]]}
> qea = qe {qeSelectList = qeSelectList qe ++ [(Iden [Name "b"],Nothing)]} > qea = qe {qeSelectList = qeSelectList qe
> ++ [(Iden [Name "b"],Nothing)]}
TODO: simple, partial and full TODO: simple, partial and full
@ -4202,7 +4226,8 @@ osf
> ,AggregateApp [Name "array_agg"] > ,AggregateApp [Name "array_agg"]
> SQDefault > SQDefault
> [Iden [Name "a"]] > [Iden [Name "a"]]
> [SortSpec (Iden [Name "z"]) DirDefault NullsOrderDefault] > [SortSpec (Iden [Name "z"])
> DirDefault NullsOrderDefault]
> Nothing)] > Nothing)]
> where > where
@ -4249,22 +4274,34 @@ Specify a sort order.
> sortSpecificationList = Group "sort specification list" > sortSpecificationList = Group "sort specification list"
> $ map (uncurry TestQueryExpr) > $ map (uncurry TestQueryExpr)
> [("select * from t order by a" > [("select * from t order by a"
> ,qe {qeOrderBy = [SortSpec (Iden [Name "a"]) DirDefault NullsOrderDefault]}) > ,qe {qeOrderBy = [SortSpec (Iden [Name "a"])
> DirDefault NullsOrderDefault]})
> ,("select * from t order by a,b" > ,("select * from t order by a,b"
> ,qe {qeOrderBy = [SortSpec (Iden [Name "a"]) DirDefault NullsOrderDefault > ,qe {qeOrderBy = [SortSpec (Iden [Name "a"])
> ,SortSpec (Iden [Name "b"]) DirDefault NullsOrderDefault]}) > DirDefault NullsOrderDefault
> ,SortSpec (Iden [Name "b"])
> DirDefault NullsOrderDefault]})
> ,("select * from t order by a asc,b" > ,("select * from t order by a asc,b"
> ,qe {qeOrderBy = [SortSpec (Iden [Name "a"]) Asc NullsOrderDefault > ,qe {qeOrderBy = [SortSpec (Iden [Name "a"])
> ,SortSpec (Iden [Name "b"]) DirDefault NullsOrderDefault]}) > Asc NullsOrderDefault
> ,SortSpec (Iden [Name "b"])
> DirDefault NullsOrderDefault]})
> ,("select * from t order by a desc,b" > ,("select * from t order by a desc,b"
> ,qe {qeOrderBy = [SortSpec (Iden [Name "a"]) Desc NullsOrderDefault > ,qe {qeOrderBy = [SortSpec (Iden [Name "a"])
> ,SortSpec (Iden [Name "b"]) DirDefault NullsOrderDefault]}) > Desc NullsOrderDefault
> ,SortSpec (Iden [Name "b"])
> DirDefault NullsOrderDefault]})
> ,("select * from t order by a collate x desc,b" > ,("select * from t order by a collate x desc,b"
> ,qe {qeOrderBy = [SortSpec (Collate (Iden [Name "a"]) [Name "x"]) Desc NullsOrderDefault > ,qe {qeOrderBy = [SortSpec
> ,SortSpec (Iden [Name "b"]) DirDefault NullsOrderDefault]}) > (Collate (Iden [Name "a"]) [Name "x"])
> Desc NullsOrderDefault
> ,SortSpec (Iden [Name "b"])
> DirDefault NullsOrderDefault]})
> ,("select * from t order by 1,2" > ,("select * from t order by 1,2"
> ,qe {qeOrderBy = [SortSpec (NumLit "1") DirDefault NullsOrderDefault > ,qe {qeOrderBy = [SortSpec (NumLit "1")
> ,SortSpec (NumLit "2") DirDefault NullsOrderDefault]}) > DirDefault NullsOrderDefault
> ,SortSpec (NumLit "2")
> DirDefault NullsOrderDefault]})
> ] > ]
> where > where
> qe = makeSelect > qe = makeSelect