Skip to content

Commit 91af4a5

Browse files
committed
Fix #228 by removing invalid sanity check. (#230)
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.
1 parent f11922c commit 91af4a5

File tree

2 files changed

+100
-9
lines changed

2 files changed

+100
-9
lines changed

lang/src/org/partiql/lang/syntax/SqlParser.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -635,9 +635,6 @@ class SqlParser(private val ion: IonSystem) : Parser {
635635
if(type != TYPE) {
636636
errMalformedParseTree("Expected ParseType.TYPE instead of $type")
637637
}
638-
if(children.size > 1) {
639-
errMalformedParseTree("Apparently DataType needs multiple lengths, sizes, etc")
640-
}
641638
val sqlDataType = SqlDataType.forTypeName(token!!.keywordText!!)
642639
if(sqlDataType == null) {
643640
errMalformedParseTree("Invalid DataType: ${token.keywordText!!}")

lang/test/org/partiql/lang/syntax/SqlParserTest.kt

Lines changed: 100 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -825,22 +825,116 @@ class SqlParserTest : SqlParserTestBase() {
825825
"(term (exp (cast (term (exp (lit 5))) (term (exp (type character_varying))))))"
826826
)
827827

828+
829+
@Test
830+
fun castASVarChar() = assertExpression(
831+
"""(cast
832+
(id a case_insensitive)
833+
(type character_varying)
834+
)
835+
""",
836+
"CAST(a AS VARCHAR)",
837+
"""(term (exp (cast (term (exp (id a case_insensitive)))
838+
(term (exp (type character_varying)))
839+
)))
840+
"""
841+
)
842+
828843
@Test
829-
fun castArg() = assertExpression(
844+
fun castASVarCharWithLength() = assertExpression(
830845
"""(cast
831-
(+ (lit 5) (id a case_insensitive))
846+
(id a case_insensitive)
832847
(type character_varying 1)
833848
)
834849
""",
835-
"CAST(5 + a AS VARCHAR(1))",
836-
"""(term (exp (cast (term (exp (+ (term (exp (lit 5)))
837-
(term (exp (id a case_insensitive)))
838-
)))
850+
"CAST(a AS VARCHAR(1))",
851+
"""(term (exp (cast (term (exp (id a case_insensitive)))
839852
(term (exp (type character_varying 1)))
840853
)))
841854
"""
842855
)
843856

857+
@Test
858+
fun castAsDecimal() = assertExpression(
859+
"""(cast
860+
(id a case_insensitive)
861+
(type decimal)
862+
)
863+
""",
864+
"CAST(a AS DECIMAL)",
865+
"""(term (exp (cast (term (exp (id a case_insensitive)))
866+
(term (exp (type decimal)))
867+
)))
868+
"""
869+
)
870+
871+
@Test
872+
fun castAsDecimalScaleOnly() = assertExpression(
873+
"""(cast
874+
(id a case_insensitive)
875+
(type decimal 1)
876+
)
877+
""",
878+
"CAST(a AS DECIMAL(1))",
879+
"""(term (exp (cast (term (exp (id a case_insensitive)))
880+
(term (exp (type decimal 1)))
881+
)))
882+
"""
883+
)
884+
@Test
885+
fun castAsDecimalScaleAndPrecision() = assertExpression(
886+
"""(cast
887+
(id a case_insensitive)
888+
(type decimal 1 2)
889+
)
890+
""",
891+
"CAST(a AS DECIMAL(1, 2))",
892+
"""(term (exp (cast (term (exp (id a case_insensitive)))
893+
(term (exp (type decimal 1 2)))
894+
)))
895+
"""
896+
)
897+
@Test
898+
fun castAsNumeric() = assertExpression(
899+
"""(cast
900+
(id a case_insensitive)
901+
(type numeric)
902+
)
903+
""",
904+
"CAST(a AS NUMERIC)",
905+
"""(term (exp (cast (term (exp (id a case_insensitive)))
906+
(term (exp (type numeric)))
907+
)))
908+
"""
909+
)
910+
911+
@Test
912+
fun castAsNumericScaleOnly() = assertExpression(
913+
"""(cast
914+
(id a case_insensitive)
915+
(type numeric 1)
916+
)
917+
""",
918+
"CAST(a AS NUMERIC(1))",
919+
"""(term (exp (cast (term (exp (id a case_insensitive)))
920+
(term (exp (type numeric 1)))
921+
)))
922+
"""
923+
)
924+
@Test
925+
fun castAsNumericScaleAndPrecision() = assertExpression(
926+
"""(cast
927+
(id a case_insensitive)
928+
(type numeric 1 2)
929+
)
930+
""",
931+
"CAST(a AS NUMERIC(1, 2))",
932+
"""(term (exp (cast (term (exp (id a case_insensitive)))
933+
(term (exp (type numeric 1 2)))
934+
)))
935+
"""
936+
)
937+
844938
//****************************************
845939
// searched CASE
846940
//****************************************

0 commit comments

Comments
 (0)