Skip to content

Commit

Permalink
[CALCITE-6560] Add test in SqlParserTest
Browse files Browse the repository at this point in the history
  • Loading branch information
NobiGo committed Sep 4, 2024
1 parent fb40c86 commit 912c77a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,11 @@ public int getPrecision() {
writer.keyword(getTypeName().getSimple());
}

if (sqlTypeName.allowsPrec() && (precision >= 0)) {
if (sqlTypeName.allowsPrec() && (precision != RelDataType.PRECISION_NOT_SPECIFIED)) {
final SqlWriter.Frame frame =
writer.startList(SqlWriter.FrameTypeEnum.FUN_CALL, "(", ")");
writer.print(precision);
if (sqlTypeName.allowsScale() && (scale >= 0)) {
if (sqlTypeName.allowsScale() && (scale != RelDataType.SCALE_NOT_SPECIFIED)) {
writer.sep(",", true);
writer.print(scale);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,15 @@ protected static SortedSet<String> keywords(@Nullable String dialect) {
.ok("SELECT 999");
}

@Test void testDecimalWithNegativeScale() {
sql("select cast(15 as decimal(3, 1))")
.ok("SELECT CAST(15 AS DECIMAL(3, 1))");
sql("select cast(15 as decimal(3, -1))")
.ok("SELECT CAST(15 AS DECIMAL(3, -1))");
sql("select cast(15 as decimal(3, 0))")
.ok("SELECT CAST(15 AS DECIMAL(3, 0))");
}

@Test void testDerivedColumnList() {
sql("select * from emp as e (empno, gender) where true")
.ok("SELECT *\n"
Expand Down

0 comments on commit 912c77a

Please sign in to comment.