Skip to content

Commit

Permalink
HIVE-27885 : Cast decimal from string with space without digits befor…
Browse files Browse the repository at this point in the history
…e dot returns NULL (#4876)
  • Loading branch information
nareshpr authored Nov 22, 2023
1 parent a79097c commit ae89034
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ql/src/test/queries/clientpositive/cast2.q
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ select cast('1' as tinyint), cast('1' as smallint), cast('1' as int), cast('1' a

-- Check that leading/trailing space is handled consistently for numeric types
select cast(' 1 ' as tinyint), cast(' 1 ' as smallint), cast(' 1 ' as int), cast(' 1 ' as bigint), cast(' 1 ' as float), cast(' 1 ' as double), cast(' 1 ' as decimal(10,2));

-- Decimal cast with spaces/without digits before dot & only dot.
select cast(".0000 " as decimal(8,4)), cast(" .0000" as decimal(8,4)), cast(" .0000 " as decimal(8,4)), cast("." as decimal(8,4)), cast(". " as decimal(8,4)), cast(" . " as decimal(8,4)), cast(".00 00 " as decimal(8,4));
9 changes: 9 additions & 0 deletions ql/src/test/results/clientpositive/llap/cast2.q.out
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,12 @@ POSTHOOK: type: QUERY
POSTHOOK: Input: _dummy_database@_dummy_table
#### A masked pattern was here ####
1 1 1 1 1.0 1.0 1.00
PREHOOK: query: select cast(".0000 " as decimal(8,4)), cast(" .0000" as decimal(8,4)), cast(" .0000 " as decimal(8,4)), cast("." as decimal(8,4)), cast(". " as decimal(8,4)), cast(" . " as decimal(8,4)), cast(".00 00 " as decimal(8,4))
PREHOOK: type: QUERY
PREHOOK: Input: _dummy_database@_dummy_table
#### A masked pattern was here ####
POSTHOOK: query: select cast(".0000 " as decimal(8,4)), cast(" .0000" as decimal(8,4)), cast(" .0000 " as decimal(8,4)), cast("." as decimal(8,4)), cast(". " as decimal(8,4)), cast(" . " as decimal(8,4)), cast(".00 00 " as decimal(8,4))
POSTHOOK: type: QUERY
POSTHOOK: Input: _dummy_database@_dummy_table
#### A masked pattern was here ####
0.0000 0.0000 0.0000 NULL NULL NULL NULL
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ public static boolean fastSetFromBytes(byte[] bytes, int offset, int length, boo
}
break;
}
haveInteger = true;
digitValue = work - BYTE_DIGIT_ZERO;
if (digitNum == 0) {

Expand Down

0 comments on commit ae89034

Please sign in to comment.