Review Board 1.7.22


HIVE-5726: The DecimalTypeInfo instance associated with a decimal constant is not in line with the precision/scale of the constant

Review Request #15217 - Created Nov. 4, 2013 and updated

Xuefu Zhang
trunk
HIVE-5726
Reviewers
hive
hive-git
With this patch, the resuting schema from constant is in accordance with the constant instead of the default from the type.
New tests are added. Test suite passed.
common/src/java/org/apache/hadoop/hive/common/type/HiveDecimal.java
Revision 606f6d4 New Change
[20] 219 lines
[+20] [+] private static BigDecimal normalize(BigDecimal bd, boolean allowRounding) {
220
      return null;
220
      return null;
221
    }
221
    }
222

    
   
222

   
223
    int maxScale = Math.min(MAX_SCALE, Math.min(MAX_PRECISION - intDigits, bd.scale()));
223
    int maxScale = Math.min(MAX_SCALE, Math.min(MAX_PRECISION - intDigits, bd.scale()));
224
    if (bd.scale() > maxScale ) {
224
    if (bd.scale() > maxScale ) {
225
      bd = allowRounding ? bd.setScale(maxScale, RoundingMode.HALF_UP) : null;
225
      if (allowRounding) {

    
   
226
        bd = bd.setScale(maxScale, RoundingMode.HALF_UP);

    
   
227
        // Trimming is again necessary, because rounding may introduce new trailing 0's.

    
   
228
        bd = trim(bd);

    
   
229
      } else {

    
   
230
        bd = null;

    
   
231
      }
226
    }
232
    }
227

    
   
233

   
228
    return bd;
234
    return bd;
229
  }
235
  }
230

    
   
236

   
[+20] [20] 21 lines
ql/src/java/org/apache/hadoop/hive/ql/parse/TypeCheckProcFactory.java
Revision 47d7995 New Change
 
ql/src/test/queries/clientpositive/ctas_hadoop20.q
Revision 4961b97 New Change
 
ql/src/test/results/clientpositive/ctas_hadoop20.q.out
Revision 885e985 New Change
 
ql/src/test/results/clientpositive/literal_decimal.q.out
Revision 2d1ae55 New Change
 
  1. common/src/java/org/apache/hadoop/hive/common/type/HiveDecimal.java: Loading...
  2. ql/src/java/org/apache/hadoop/hive/ql/parse/TypeCheckProcFactory.java: Loading...
  3. ql/src/test/queries/clientpositive/ctas_hadoop20.q: Loading...
  4. ql/src/test/results/clientpositive/ctas_hadoop20.q.out: Loading...
  5. ql/src/test/results/clientpositive/literal_decimal.q.out: Loading...