Skip to content

Commit

Permalink
Fix #228 by removing invalid sanity check. (#230)
Browse files Browse the repository at this point in the history
This sanity check threw an exception from SqlParser whenever a data type
reference that included more than one argument was encountered.  The
check appears to have been completely erroneous from the start and on
removing it, no other modifications were needed.  However, note that 
at this time we do not actually do anything with those arguments.  At this
time their presence is simply tolerated to improve SQL-92 
compatibility.  See #231 for one way we could use these arguments.

This commit also adds a few tests to SqlParserTests to cover this
scenario and prevent regressions.
  • Loading branch information
dlurton authored Mar 25, 2020
1 parent 51f2669 commit 74a270b
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 9 deletions.
3 changes: 0 additions & 3 deletions lang/src/org/partiql/lang/syntax/SqlParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -718,9 +718,6 @@ class SqlParser(private val ion: IonSystem) : Parser {
if(type != TYPE) {
errMalformedParseTree("Expected ParseType.TYPE instead of $type")
}
if(children.size > 1) {
errMalformedParseTree("Apparently DataType needs multiple lengths, sizes, etc")
}
val sqlDataType = SqlDataType.forTypeName(token!!.keywordText!!)
if(sqlDataType == null) {
errMalformedParseTree("Invalid DataType: ${token.keywordText!!}")
Expand Down
106 changes: 100 additions & 6 deletions lang/test/org/partiql/lang/syntax/SqlParserTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -909,22 +909,116 @@ class SqlParserTest : SqlParserTestBase() {
"(term (exp (cast (term (exp (lit 5))) (term (exp (type character_varying))))))"
)


@Test
fun castASVarChar() = assertExpression(
"""(cast
(id a case_insensitive)
(type character_varying)
)
""",
"CAST(a AS VARCHAR)",
"""(term (exp (cast (term (exp (id a case_insensitive)))
(term (exp (type character_varying)))
)))
"""
)

@Test
fun castArg() = assertExpression(
fun castASVarCharWithLength() = assertExpression(
"""(cast
(+ (lit 5) (id a case_insensitive))
(id a case_insensitive)
(type character_varying 1)
)
""",
"CAST(5 + a AS VARCHAR(1))",
"""(term (exp (cast (term (exp (+ (term (exp (lit 5)))
(term (exp (id a case_insensitive)))
)))
"CAST(a AS VARCHAR(1))",
"""(term (exp (cast (term (exp (id a case_insensitive)))
(term (exp (type character_varying 1)))
)))
"""
)

@Test
fun castAsDecimal() = assertExpression(
"""(cast
(id a case_insensitive)
(type decimal)
)
""",
"CAST(a AS DECIMAL)",
"""(term (exp (cast (term (exp (id a case_insensitive)))
(term (exp (type decimal)))
)))
"""
)

@Test
fun castAsDecimalScaleOnly() = assertExpression(
"""(cast
(id a case_insensitive)
(type decimal 1)
)
""",
"CAST(a AS DECIMAL(1))",
"""(term (exp (cast (term (exp (id a case_insensitive)))
(term (exp (type decimal 1)))
)))
"""
)
@Test
fun castAsDecimalScaleAndPrecision() = assertExpression(
"""(cast
(id a case_insensitive)
(type decimal 1 2)
)
""",
"CAST(a AS DECIMAL(1, 2))",
"""(term (exp (cast (term (exp (id a case_insensitive)))
(term (exp (type decimal 1 2)))
)))
"""
)
@Test
fun castAsNumeric() = assertExpression(
"""(cast
(id a case_insensitive)
(type numeric)
)
""",
"CAST(a AS NUMERIC)",
"""(term (exp (cast (term (exp (id a case_insensitive)))
(term (exp (type numeric)))
)))
"""
)

@Test
fun castAsNumericScaleOnly() = assertExpression(
"""(cast
(id a case_insensitive)
(type numeric 1)
)
""",
"CAST(a AS NUMERIC(1))",
"""(term (exp (cast (term (exp (id a case_insensitive)))
(term (exp (type numeric 1)))
)))
"""
)
@Test
fun castAsNumericScaleAndPrecision() = assertExpression(
"""(cast
(id a case_insensitive)
(type numeric 1 2)
)
""",
"CAST(a AS NUMERIC(1, 2))",
"""(term (exp (cast (term (exp (id a case_insensitive)))
(term (exp (type numeric 1 2)))
)))
"""
)

//****************************************
// searched CASE
//****************************************
Expand Down

0 comments on commit 74a270b

Please sign in to comment.