Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #228 by removing invalid sanity check. #230

Merged
merged 1 commit into from
Mar 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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